Hi,
I try to compute the matrix generated by gluLookAt to use it to render my scene.
I have good results with gluLookAt, but not using the matrix i compute.
To compute the matrix i use this code:
GLGXMATRIX* GLGXMatrixLookAt( GLGXMATRIX* pResult,GLGXVECTOR3 *pPosition,GLGXVECTOR3 *pTarget,GLGXVECTOR3 *pUp)
{
GLGXVECTOR3 forward = *pTarget - *pPosition;
GLGXVec3Normalize(&forward,&forward);
GLGXVECTOR3 up;
GLGXVec3Normalize(&up,pUp);
GLGXVECTOR3 side;
GLGXVec3Cross(&side, &up, &forward);
pResult->_11 = side.x;
pResult->_12 = side.y;
pResult->_13 = side.z;
pResult->_14 = 0.0f;
pResult->_21 = up.x;
pResult->_22 = up.y;
pResult->_23 = up.z;
pResult->_24 = 0.0f;
pResult->_31 = forward.x;
pResult->_32 = forward.y;
pResult->_33 = forward.z;
pResult->_34 = 0.0f;
pResult->_41 = -pPosition->x;
pResult->_42 = -pPosition->y;
pResult->_43 = -pPosition->z;
pResult->_44 = 1.0f;
// where matrix._11,..._12,..._13,..._14,..._21... equal matrix[0],...[1],...[2],...[3],...[4],...
return pResult;
}
To render my scene i use:
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
/*
gluLookAt(this->Scene->Cameras[0].Loc.x,this->Scene->Cameras[0].Loc.y,this->Scene->Cameras[0].Loc.z,
this->Scene->Cameras[0].Eye.x,this->Scene->Cameras[0].Eye.y,this->Scene->Cameras[0].Eye.z,
this->Scene->Cameras[0].Up.x, this->Scene->Cameras[0].Up.y, this->Scene->Cameras[0].Up.z);
*/
GLGXMATRIX matrix; // Is Identity
GLGXMatrixLookAt(&matrix,&this->Scene->Cameras[0].Loc,&this->Scene->Cameras[0].Eye,&this->Scene->Cameras[0].Up);
glPushMatrix(); // Not used with gluLookAt
glMultMatrixf(matrix); // Not used with gluLookAt
this->Scene->Lights[0].Set();
glColor3ub(255,0,255);
this->Scene->Render();
glPopMatrix(); // Not used with gluLookAt
The camera seems to be upside down. I can’t find what is wrong. I have tried to reverse the vectors, the cross products, …
Is it in rendering ?