Jump to content
  • Advertisement
Sign in to follow this  
mpledge52

Rotations help

This topic is 3762 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
Advertisement
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
Thanks very much Ahl, it worked perfectly. I just read up on glLoadIdentity and I found out I was using in the wrong places in my program. Thanks again :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!