GLuint DrawGLWindow()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(x,y,z);
if(keys[VK_UP])
{
z+=1.0f;
}
if(keys[VK_DOWN])
{
z-=1.0f;
}
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.0f);
glRotatef(move,0.0f,1.0f,1.0f);
p.SolidCube(1.0f);
move+=1.0f;
return TRUE;
}
As you can see the code is supposed to let you move only foward and backwards but it doesn''t move at all...I''m a noob here so please explain in plain english
What's wrong with this code?!
Okay I''ve been trying to figure out why this doesn''t work for a while I can''t figure out what''s wrong here''s the code...
The problem is because you pretty much reset the transformation (all the movements) matrix with the loadidentity call...... and after you have done your own custom transformations, you reset it again and do some more.. before the object is drawn.. so the code you used to have control over the translation doesn''t do jack..
Well first off, after setting the translation for movement you load the identity matrix again which kills that previous translation. Now, thats what happens assuming this code is exactly as it appears in your program.
If this is not the problem then I''ll be happy to take another look once you provide more code.
-out
If this is not the problem then I''ll be happy to take another look once you provide more code.
-out
GLuint DrawGLWindow(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
if(keys[VK_UP])
{
z+=1.0f;
}
if(keys[VK_DOWN])
{
z-=1.0f;
}
glTranslatef(x,y,z);
glRotatef(move,0.0f,1.0f,1.0f);
p.SolidCube(1.0f);
move+=1.0f;
return TRUE;
}
What you wanna do is make the glTranslate call after the input is gathered so that the new Z value will be used. Also for a single object, only make one call to glLoadIdentity at the beginning of drawing each object to reset the modelview matrix before moving an object each frame. Your second call to glLoadIdentity would wipe out the translation before it, and end up only applying your rotation.
Give that a shot.
________________________________________________
Chris McGuirk
Lead Programmer - Axiom Engine
C# gaming, the way of the future!
http://axiomengine.sourceforge.net
[edited by - leedgitar on September 3, 2003 10:07:55 PM]
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
if(keys[VK_UP])
{
z+=1.0f;
}
if(keys[VK_DOWN])
{
z-=1.0f;
}
glTranslatef(x,y,z);
glRotatef(move,0.0f,1.0f,1.0f);
p.SolidCube(1.0f);
move+=1.0f;
return TRUE;
}
What you wanna do is make the glTranslate call after the input is gathered so that the new Z value will be used. Also for a single object, only make one call to glLoadIdentity at the beginning of drawing each object to reset the modelview matrix before moving an object each frame. Your second call to glLoadIdentity would wipe out the translation before it, and end up only applying your rotation.
Give that a shot.
________________________________________________
Chris McGuirk
Lead Programmer - Axiom Engine
C# gaming, the way of the future!
http://axiomengine.sourceforge.net
[edited by - leedgitar on September 3, 2003 10:07:55 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement