glLookAt big big problem
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
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
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
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
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
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();
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
loadidentglPushMatrix();glulookat(....);glpushtransformdrawglpopglPopMatrix();this way you preserve the glulookat matrix through all your transforms.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement