Sign in to follow this  

Rotations help

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) {


And my code to draw the rectangle at the bottom is.
	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); 

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

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