# 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.

## 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: 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 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 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 :)

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999965
×