我正在尝试使用牛顿物理和 OpenGL 模拟旋转框。这就是我已经实施的。
float mat44[16] = {
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1
};
box.mat = &mat44[0];
box.x_size = 0.50;
box.y_size = 0.50;
box.z_size = 0.50;
nWorld = NewtonCreate(NULL, NULL);
NewtonCollision * collision = NULL;
collision = NewtonCreateBox(nWorld, box.x_size, box.y_size, box.z_size,NULL);
body = NewtonCreateBody(nWorld, collision);
NewtonReleaseCollision (nWorld, collision);
NewtonBodySetMassMatrix(body, 10.0, 2.0, 2.0, 2.0);
NewtonBodySetMatrix (body, box.mat);
float omega[3] = {0.0f, 10.0f, 0.0f};
NewtonBodySetOmega (body, &omega[0]);
在渲染循环中我正在做这些事情。
NewtonUpdate(nWorld, time);
float m[16];
NewtonBodyGetMatrix(body, &m[0]);
box.mat = m;
我的问题是如何使用 matrix(box.mat) 绘制一个立方体(实际上是 8 个点)?如何使用矩阵计算更新的顶点?