Sign in to follow this  

glLoadIdentity... and mouselook

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, first off I would like to say hello everyone on this forum I have learned much from this site and I figured this would be the best place to ask around for this particulat issue. I working with some code that involves mouselook and matrices. I can get the mouselook successfully working, but the matrix does not work correctly unless I have the "glLoadIdentity();" added to the top of the matrix code, but then the mouselook doesn't work at all. The mouselook is simply a sub that reads the mouse input and translate the view accordingly. I can have one or the other but not both. Does anyone know how I can tackle this particular issue simply, it's probably one line of code that I am missing or some simple solution sitting right in front of my face. -Zakyrus

Share this post


Link to post
Share on other sites
Well, the code I am playing around with is actually Lesson38 with some slight modifications. I added a simple camera that allows 6D0F, the camera works but only when the glLoadIdentity() under the DrawButterflies() sub is disabled, but then the butterflies behave differently. Here is the code:


void DrawButterflies (void) // Draw The Scene
{
for (int loop=0; loop<50; loop++) // Loop Of 50 (Draw 50 Objects)
{

glLoadIdentity (); // Reset The Modelview Matrix
glBindTexture(GL_TEXTURE_2D, texture[obj[loop].tex]); // Bind Our Texture
glTranslatef(obj[loop].x,obj[loop].y,obj[loop].z); // Position The Object
glRotatef(45.0f,1.0f,0.0f,0.0f); // Rotate On The X-Axis
glRotatef((obj[loop].spinz),0.0f,0.0f,1.0f); // Spin On The Z-Axis

glBegin(GL_TRIANGLES); // Begin Drawing Triangles
// First Triangle
glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); // Point 1 (Top Right)
glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f, obj[loop].flap); // Point 2 (Top Left)
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); // Point 3 (Bottom Left)

// Second Triangle
glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); // Point 1 (Top Right)
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); // Point 2 (Bottom Left)
glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,-1.0f, obj[loop].flap); // Point 3 (Bottom Right)

glEnd(); // Done Drawing Triangles

obj[loop].y-=obj[loop].yi; // Move Object Down The Screen
obj[loop].spinz+=obj[loop].spinzi; // Increase Z Rotation By spinzi
obj[loop].flap+=obj[loop].fi; // Increase flap Value By fi

if (obj[loop].y<-18.0f) // Is Object Off The Screen?
{
SetObject(loop); // If So, Reassign New Values
}

if ((obj[loop].flap>1.0f) || (obj[loop].flap<-1.0f)) // Time To Change Flap Direction?
{
obj[loop].fi=-obj[loop].fi; // Change Direction By Making fi = -fi
}
}

Sleep(15); // Create A Short Delay (15 Milliseconds)

glFlush (); // Flush The GL Rendering Pipeline
}




and under the DrawGLScene();


int DrawGLScene() // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,0.0f);
GetUserInput(); // Call mousemove/kb input

// Mouse tranlations:
GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
GLfloat ytrans = -ypos;
GLfloat sceneroty = 360.0f - yrot;
glRotatef(lookupdown,1.0f,0,0);
glRotatef(sceneroty,0,1.0f,0);
glTranslatef(xtrans, ytrans, ztrans);

DrawButterflies(); //Call function to draw butterflies

return TRUE; // Keep Going
}



-Zakyrus

Share this post


Link to post
Share on other sites
Well, the standard way of doing things is to apply the camera matrix, then multiply that by the frame of the object(s) that you're drawing. In your case, you're clearing the matrix after you apply the camera. From what I can see in your code, you need to apply the camera matrix, then apply each of the individual butterfly matrices, separately. That should work.

Share this post


Link to post
Share on other sites
Quote:
Original post by python_regious
you need to apply the camera matrix, then apply each of the individual butterfly matrices, separately. That should work.


Ok, can you please be a little more specific? I kind of know what your talking about, but I recently started to programming matrices. I have applied the camera matrix, but how do I apply EACH of the butterfly matrices seperately?

-Zakyrus

Share this post


Link to post
Share on other sites
Nevermind, I figured out what I was missing. I added the glPushMatrix() command instead of glLoadIdentity(), and added glPopMatrix() right before the glEnd() command. Thanks everyone.

-Zakyrus

Share this post


Link to post
Share on other sites

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this