I’m trying to simulate rotating box using Newton Physics and OpenGL. This is what i have implemented.
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]);
inside the rendering loop i’m doing these things.
NewtonUpdate(nWorld, time);
float m[16];
NewtonBodyGetMatrix(body, &m[0]);
box.mat = m;
my problem is how to draw a cube (actually 8 points) using the matrix(box.mat) ? how can i calculate updated vertex points using the matrix ?
You consider the vertex as a column vector and multiply your matrix by it.
Where [ v.x, v.y, v.z, 1 ] is the vertex position and
ris the output vertex.Incidentally, if you’re using OpenGL, the “correct” thing to do is feed OpenGL the unchanged vertices and simply use
box.matas the “model matrix” for OpenGL (part of the model-view matrix).