Jump to content
  • Advertisement

Archived

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

xf00f

Annoying trig problem

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

Hmmmm - I''m a bit embarrased to be asking this, but it''s got me stumped. Below is a snippet of code that is wrong, and I don''t know why - any ideas? The idea is that an object is rendered to the screen with openGL, left and right arrows rotate it, up and down arrows make it move forwards and backwards according to it''s bearing. 0deg is facing out of the screen (so forward would increase the z axis value), 90deg is the object facing right (so forward would increase the x axis value) Hope I explained that sufficiently... At certain angles it seems "ok", at other angles the object seems to move perpendicular to what I expect it to (i.e. it moves left and right instead of forwards and backwards.) Holding the up and left arrow tohgether should make the object perform an arc, but it just has a weird fit - jumping around a given location. Any idea where have I made my foolish mistake(s)? Thanks. CODE : int y_rotate; float x_trans,y_trans_z_trans; ..... if (key_buffer[VK_UP]) { x_trans+=sin(y_rotate); z_trans+=cos(y_rotate); } if (key_buffer[VK_DOWN]) { x_trans-=sin(y_rotate); z_trans-=cos(y_rotate); } if (key_buffer[VK_LEFT]) if (--y_rotate < 0) y_rotate = 359; if (key_buffer[VK_RIGHT]) if (++y_rotate > 359) y_rotate = 0; glLoadIdentity(); glTranslatef(x_trans,y_trans,z_trans); glRotatef(y_rotate, 0, 1, 0);

Share this post


Link to post
Share on other sites
Advertisement
You need to pass the angles in radians. To convert from radians to degrees:
radian = degree * ( 3.1415927 / 180 ); // store the constant in an const-variable

edit: bah, gotta get faster...


____________________ ____ ___ __ _
Enselic's Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10. (source available)
CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.

[edited by - Enselic on June 18, 2003 2:07:56 PM]

Share this post


Link to post
Share on other sites
Argh - you''re kidding me! Thanks. Mixing degrees and radians - don''t I get to have some fun?....

Share this post


Link to post
Share on other sites
quote:
Original post by xf00f
Argh - you''re kidding me! Thanks. Mixing degrees and radians - don''t I get to have some fun?....

Haha... Yes, just kidding! Actually, they are measured in Grads!

20: ...Qg2 ++

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!