Hi all,
I’m tring to add something like a “fixed screen” into an OpenGL game instead of first or third person that already works. To do that I moved my camera with gluLookAt but when I move my character into the scene its movements are wrong (forward is sometimes backward, left is right, and so on…). I guess 9.070 FAQ solve my issue: http://www.opengl.org/resources/faq/technical/transformations.htm but I don’t know how to implement it.
I looked at my CG notes and I read I need to switch coordinate system. To do that I created a inverseMatrix code that computes inverse of a 4x4 matrix param I pass to it. Then I get MODELVIEW matrix, compute the inverse and finally I load the inverse matrix, but this process doesn’t work. Someone here can help me, please? thanks
snippet of my code:
GLvoid angleView(GLvoid)
{
GLfloat *mat;
GLfloat m[16];
GLfloat s[16];
GLfloat e[3];
GLfloat n[3];
resetMatrix(m);
resetMatrix(s);
e[0]=0.0f;
e[1]=world.miny+0.01;
e[2]=0.0f;
n[0]=0.0f;
n[1]=-1.0f;
n[2]=0.0f;
glViewport(0,0, status.width, status.height);
enableLights();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
/*put eye of view into uppper corner of my room:*/
gluLookAt(world.minx,world.maxy,world.minz,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f);
/*Movement:*/
glPushMatrix();
glTranslatef(-status.xpos, 0.0f, -status.zpos);
glRotatef(360.0f -status.yrot, 0, 1.0f, 0);
drawGuido();/*draw my Character*/
glGetFloatv(GL_MODELVIEW_MATRIX,m);/*get matrix*/
mat=inverseMatrix(m);/*compute inverse matrix*/
glLoadMatrixf(mat);/*load inverse matrix*/
glPopMatrix();
lightInit();
draw_lights();
draw_scene(0,0,0,status.width,status.height);
/*Draw room*/
if(!getFlag(&status,FL_DONTDRAW)){
callWorldList(&world);
}
if(getFlag(&status,FL_LIGHTING))/*draw shadow:*/
{
drawShadow(s,m,l2_pos,e,n,0);
}
}