Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Camera Views

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

Hi all.... I am having trouble with camera view points.... The code I have so far lets me know where I am in the world (grid reference) and what heading I have 360 degrees (bearing). The problem is that when I move around the Y axis the world flips at certain points and I can''t figure out why.. Below I have posted parts of the code so you can see what I am doing... and if anyone can see what I am doing wrong, please let me know. if(heading > 360) { heading -= 360; } if (heading <= 0) { heading += 360; } //---- this keeps my heading true in relation to a compass (if you like... kinda like a reset but not) //---- Below is code that tells me what I am looking at if on a specific angle. (I am using 1 as a standard measurement) So if I am facing 0 degrees then the amount of motion on the x plane is 0 (not looking left or right) and the motion on the z plane is 1, because your looking straight ahead) There is code for 0, 90, 180 and 270 so each has it''s specific set of instructions to follow. if (heading == 0.0) { x_length = 0; z_length = 1; } //---- Below is where I THINK the flaw lies in my program. else if((heading > 0) && (heading < 90)) { x_length = tan(heading); z_length = tan ((90 - heading)); } else if((heading > 90) && (heading < 180)) { x_length = tan((180 - heading)); z_length = tan((heading - 90)); z_length = z_length - (z_length *2); } else if((heading > 180) && (heading < 270)) { x_length = tan((heading - 180)); z_length = tan((270 - heading)); x_length = x_length - (x_length * 2); z_length = z_length - (z_length * 2); } else if((heading > 270) && (heading < 360)) { x_length = tan((360 - heading)); z_length = tan((heading - 270)); x_length = x_length - (x_length *2); } To cut a long story short.... (I hope).... The tan(varaibles) gives me the length of the side I wish to know for z(into and out of the screen) and x(lateral position) Tan = Tangent (just incase you were wondering what it was.... and Tangent gives you the length of the side opposite to the angle you know. You can see that some of it reverses the sign (positive to negative) ... I can''t remember the code for doing it properly x_length = x_length - (x_length *2); x_view = x_pos + x_length; z_view = z_pos + z_length; y_view = y_pos; gluLookAt(x_pos, y_pos, z_pos, x_view, y_view, z_view, 0, 1, 0); This ''should'' make the camera turn to face the new heading.. (Heading is increased and decreased by using a key press) What it actually does is turn round and at some point "Flip" the screen round on the Y axis... but for the life of me I just can''t figure out why. Any offers ?? P.s. how do you post the code so that it is in the scrolling boxes ?? and is there a designated place where I can put the .exe file for people to look at while they are trying to help sort the code. Cheers.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!