Sign in to follow this  

Rotations help

This topic is 3568 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

I've made a moving map system and I want to add something similar to a HUD along the bottom of the window. I thought the easiest way to do would just be to draw a rectangle a few units in front of the camera and have it follow the camera. I have done this fine when translating along any of the axes but I cant get my had around the maths I will need to keep it facing the camera when rotating around an axis (I will only be rotating around the z and x axes). These images might make it easier to explain: image The left image looks as it should and that bar stays where it is when i pan around the map or zoom in, however as soon as I rotate it (on the right) the rectangle rotates as well. The camera function which controls all the movements on screen is:
	void camera (void) {

	glRotatef(xrot,1.0,0.0,0.0); 
	glRotatef(yrot,0.0,1.0,0.0); 
	glRotatef(zrot,0.0,0.0,1.0); 
	glTranslated(-xpos,-ypos,-zpos); 
}

And my code to draw the rectangle at the bottom is.
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(xpos, ypos, zpos+10);
	glTexCoord2f(0.0, 1.0); glVertex3f(xpos, ypos-800, zpos+10); 
	glTexCoord2f(1.0, 1.0); glVertex3f(xpos-10000, ypos-800, zpos+10); 
	glTexCoord2f(1.0, 0.0); glVertex3f(xpos-10000, ypos, zpos+10); 
	glEnd();

I know all I have to do is put some additional parameters in the glVertex call relating to the xrot, yrot and zrot but I cant figure it out. Any advice? Thanks.

Share this post


Link to post
Share on other sites
I believe you have to call glLoadIdentity() before every object you try to move/rotate otherwise your glRotatef() will just try to hit everything. I could be mistaken. Kind of new at this myself and I don't have my books here at work to look it up.

Share this post


Link to post
Share on other sites

This topic is 3568 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