Archived

This topic is now archived and is closed to further replies.

Visualc

glLookAt big big problem

Recommended Posts

i using the camera part4 from http://www.gametutorials.com but i have a problem: this is the original code: void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z, g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z, g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z); Draw3DSGrid(); CreatePyramid(-6, 3, 6, 1, 6); CreatePyramid(6, 3, 6, 1, 6); CreatePyramid(6, 3, -6, 1, 6); CreatePyramid(-6, 3, -6, 1, 6); glTranslatef(g_Camera.m_vView.x, 0, g_Camera.m_vView.z); CreatePyramid(0, 2, 0, 1, 1); glRotatef(180, 1, 0, 0); CreatePyramid(0, -1, 0, 1, 1); SwapBuffers(g_hDC); } ok, i change the code for this: void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z, g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z, g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z); glTranslatef(g_Camera.m_vView.x, 0, g_Camera.m_vView.z); glCallList(f16); SwapBuffers(g_hDC); } the f-16 appeard correcty, after i put this code: void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z, g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z, g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z); glTranslatef(g_Camera.m_vView.x, 0, g_Camera.m_vView.z); glCallList(f16); glLoadIdentity(); glTranslatef(bla bla bla); glRotatef(bla bla bla); glCallList(Tower); glFlush(); SwapBuffers(g_hDC); } it is the problem: Tower not appeard, but if i put off glLoadIdendtity() and Tower appeard but this tower move with the f-16 and move with the camera... why?, i try with glPop and glPushMatrix, but the problem continuos.... please help me

Share this post


Link to post
Share on other sites
glLoadidentity();
resets your moldeview matrix so any tranformations you did are gone

for exemple you have a quad in front of your screen
if you rotate it it will be rotated right
but if after you rotated and drawned it you do glLoadidentity that rotation will be gone and the quad wen you render the scne
glSwapBuffers(); the quad will be like it will never was rotated
instead you must use glPushmatrix() and glPopMatrix try this

void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,
g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z,
g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);


glPushMatrix();
glTranslatef(g_Camera.m_vView.x, 0, g_Camera.m_vView.z);
glCallList(f16);
glPopMatrix();


glTranslatef(bla bla bla);
glRotatef(bla bla bla);
glCallList(Tower);
glFlush();

SwapBuffers(g_hDC);
}


i believe that is your problem at i think

Share this post


Link to post
Share on other sites
Wait My Mistake try


void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,
g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z,
g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);



glPushMatrix();
glTranslatef(g_Camera.m_vView.x, 0, g_Camera.m_vView.z);

glCallList(f16);
glPopMatrix();

glPushMatrix();
glTranslatef(bla bla bla);
glRotatef(bla bla bla);
glCallList(Tower);
glPopMatrix();

glFlush();

SwapBuffers(g_hDC);
}

try it

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Doh...

  
glPushMatrix();

gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,
g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z,
g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);

glPopMatrix();

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

  
glPushMatrix();
gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z, g_Camera.m_vView.x, g_Camera.m_vView.y, g_Camera.m_vView.z, g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);
glPopMatrix();


wont this kill the transformation that glulookat makes?
try

  
loadident
glPushMatrix();
glulookat(....);


glpush
transform
draw
glpop


glPopMatrix();

this way you preserve the glulookat matrix through all your transforms.

Share this post


Link to post
Share on other sites