Okay.
Now here's my problem. Basically I've set up Newton to work with Quake2, and it works great so far, but there's some really odd things happening with angles and origins.
Sometimes, like if I throw a box on stairs, the box will violently twist and rotate in very very weird directions, or it will come to a stop on an angle (like a 45 degree angle).. I don't know if this is my code or not, here's my callback:
- Code: Select all
void SetMeshTransformEvent(const NewtonBody* body, const float* matrix)
{
edict_t *attached = (edict_t*)NewtonBodyGetUserData (body);
// copy the matrix into an irrlicht matrix4
mat4x4_t mat;
memcpy(mat, matrix, sizeof(float)*16);
// Retreive the user data attached to the newton body
//gi.dprintf ("%f %f %f\n", mat[12], mat[13], mat[14]);
attached->s.origin[0] = mat[12];
attached->s.origin[2] = mat[13];
attached->s.origin[1] = mat[14];
//NewtonBodyGetMatrix (body, &mat[0]);
NewtonGetEulerAngle (&mat[0], &attached->s.angles[0]);
attached->s.angles[0] = RAD2DEG(attached->s.angles[0]);
attached->s.angles[1] = RAD2DEG(attached->s.angles[1]);
attached->s.angles[2] = RAD2DEG(attached->s.angles[2]);
gi.linkentity(attached);
}
Now, I just want to note that Quake2 ONLY supports euler angles and origin in MIDDLE of body, am I to assume that the matrix will always fulfill these, or will the origin shift depending on the center of gravity?
Another example is, for example, cylinders; now I assume that the "resting" (or starting) of a cylinder is sitting on it's sides so that it would roll, right? It seems that when spheres or cylinders roll, they are rolling in the wrong direction (angle-wise)! If I stack boxes, they will fall down correctly, but again, angles will violently twist for no reason. Also, cylinders seem to stack at spawn, so do they spawn on their top or on their side? The documentation is unclear on this..
-Paril