Game Development Community

Seems 'roll' is disabled... please help

by Jeff Trudeau · in Torque Game Engine · 11/21/2003 (3:45 pm) · 2 replies

1.
Searching through camera.cc, it seems that roll is disabled, and I would like to determine the easiest way to get it working. I saw this function

void Camera::setPosition(const Point3F& pos, const Point3F& rot, MatrixF *mat)
{
MatrixF xRot, zRot;
xRot.set(EulerF(rot.x, 0, 0));
zRot.set(EulerF(0, 0, rot.z));
mat->mul(zRot, xRot);
mat->setColumn(3,pos);
mRot = rot;
}

and noticed there was no information regarding rotation about the y-axis. So, it be changed in this manner to support 'roll' about the y-axis, however it still is not figuring in the y-axis rotation in the multplication of the two (will be three matrices).

void Camera::setPosition(const Point3F& pos, const Point3F& rot, MatrixF *mat)
{
MatrixF xRot, yRot, zRot;
xRot.set(EulerF(rot.x, 0, 0));
yRot.set(EulerF(0, rot.y, 0));
zRot.set(EulerF(0, 0, rot.z));
mat->mul(zRot, xRot);
mat->setColumn(3,pos);
mRot = rot;
}

I realize that matrix multiplication is not commutative, so then in what order would the multiplication need to be carried out?

2.
Also, I doubt this is all that would be required to enable a 'roll' effect, as I found these two functions within tsMesh.cc:

// quick function to force object to face camera -- currently throws out roll :(
void forceFaceCamera()
{
MatrixF mat;
Point4F p;

dglGetModelview(&mat);
mat.getColumn(3,&p);
mat.identity();
mat.setColumn(3,p);
dglLoadMatrix(&mat);
if (TSShapeInstance::smRenderData.objectScale)
glScalef(TSShapeInstance::smRenderData.objectScale->x,
TSShapeInstance::smRenderData.objectScale->y,
TSShapeInstance::smRenderData.objectScale->z);
}

void forceFaceCameraZAxis()
{
MatrixF mat;
dglGetModelview(&mat);
Point3F z;
mat.getColumn(2,&z); // this is where the z-axis goes, keep it here but reset x and y
Point3F x,y;
if (mFabs(z.y) < 0.99f)
{
// mCross(Point3F(0,1,0),tAxis,&x);
x.set(z.z,0,-z.x);
x.normalize();
mCross(z,x,&y);
}
else
{
// mCross(z,Point3F(1,0,0),&y);
y.set(0,z.z,-z.y);
y.normalize();
mCross(y,z,&x);
}
mat.setColumn(0,x);
mat.setColumn(1,y);
mat.setColumn(2,z);
dglLoadMatrix(&mat);
if (TSShapeInstance::smRenderData.objectScale)
glScalef(TSShapeInstance::smRenderData.objectScale->x,TSShapeInstance::smRenderData.objectScale->y,TSShapeInstance::smRenderData.objectScale->z);
}

This is just about all I could find related to 'rolling' the object and getting the camera to follow suit. Am I to assume that if I were able to bandage these functions to allow support for rotation about the y-axis, and enabled roll within default.bind.cs, that the object (and camera) would behave in the manner of which I am thinking? I have a bad feeling that I am missing some rather large detail...

#1
11/21/2003 (4:32 pm)
Using matrice's in this fashion will lead to gimble lock.

you need to use a quaternion.
#2
11/21/2003 (4:56 pm)
If you want to get roll and such working, you should probably look into the vehicle branch of the code. It's already all working solidly there.