Original Post
Hi, I have a small problem in my code, I have a matrix4x4 with object rotation and translation values, now I like the camera folow the object, like a 3rd person camera. I made this code: How it work, I set the camera position (eye) and where it look (center). This code work for some time, but cause some view problem before some time... Thanks for the help Edited with addition of source tags, please check the forum faq for details on the tags for posting code [Edited by - _the_phantom_ on April 5, 2005 1:14:37 PM]
void cShipLook( cShipObject &object,
float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ )
{
// Ax, Ay, Az, Bx, By, Bz, Cx, Cy, Cz, Tx, Ty, Tz as float
// Rotation
Ax = object.cShipQuaternion[0];
Bx = object.cShipQuaternion[1];
Cx = object.cShipQuaternion[2];
Ay = object.cShipQuaternion[4];
By = object.cShipQuaternion[5];
Cy = object.cShipQuaternion[6];
Az = object.cShipQuaternion[8];
Bz = object.cShipQuaternion[9];
Cz = object.cShipQuaternion[10];
// Position
Tx = object.cShipQuaternion[12];
Ty = object.cShipQuaternion[13];
Tz = object.cShipQuaternion[14];
camera.eye.x = Tx+(eyeX*Ax)+(eyeY*Ay)+(eyeZ*Az);
camera.eye.y = Ty+(eyeX*Bx)+(eyeY*By)+(eyeZ*Bz);
camera.eye.z = Tz+(eyeX*Cx)+(eyeY*Cy)+(eyeZ*Cz);
camera.center.x = Tx+(centerX*Ax)+(centerY*Ay)+(centerZ*Az);
camera.center.y = Ty+(centerX*Bx)+(centerY*By)+(centerZ*Bz);
camera.center.z = Tz+(centerX*Cx)+(centerY*Cy)+(centerZ*Cz);
camera.up.x = Ay;
camera.up.y = By;
camera.up.z = Cy;
V_Graphic.v_SetCamera( camera ); // Work like glLookAt( ... )
}