Jump to content
  • Advertisement
Sign in to follow this  
adzz182

Rotation/Translation....help, please

This topic is 4230 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, im pretty new to openGL. Ive just started on a little project on the Nintendo DS, and right now im just trying to create a program that will navigate a 3D environment. I am following the methods of navigation found in Tutorial 10 on the NeHe site. I have no Trouble Strafing the 'camera' forwards and backwards, or rotating it left and right, the problems arise when i try to strafe left and right, it seems to move diagonally, ive tried editing the code for hours, and searched the internet but i cant find whats wrong. Here is my (pseudo)code: //Rotate Left if L is pressed then { y_rotate += 1; } //Rotate Right if R is pressed then { y_rotate += 1; } //Move/Strafe forwards if UP is pressed then { xposition += SIN[y_rotate && LUT_MASK] >> 4; zposition -= COS[y_rotate && LUT_MASK] >> 4; } //Move/Strafe Backwards if DOWN is pressed then { xposition -= SIN[y_rotate && LUT_MASK] >> 4; zposition += COS[y_rotate && LUT_MASK] >> 4; } //Move/Strafe Right if RIGHT is pressed then { xposition -= SIN[(y_rotate-90) && LUT_MASK] >> 4; zposition += COS[(y_rotate-90) && LUT_MASK] >> 4; } //Move/Strafe Right if LEFT is pressed then { xposition -= SIN[(y_rotate+90) && LUT_MASK] >> 4; zposition += COS[(y_rotate+90) && LUT_MASK] >> 4; } //Then in my DrawGLScene glRotatef32i((int)(LUT_SIZE - y_rotate),0,(1<<12),0); glTranslate3f32( (int32)(-xposition/), 0.5f, (int32)(-zposition) ); I use this method as opposed to the method in the NeHe example (multiplying by piOver180) as i keep getting error messages when compiling.

Share this post


Link to post
Share on other sites
Advertisement
By "this method" do you mean all the shifts you're doing?

I haven't looked into what NeHe suggests but I did the following to get a FPS style camera

Vectors: position, left, forward.
Flots: pitch, yaw.

The camera is created by specifying position, pitch, and yaw. An UpdateVectors function computes the correct left and forward vectors (assuming a right-handed system (which OpenGL is)). With UpdateVectors, you only need to use cos & sin when you change pitch and yaw. UpdateVectors calculates the left and forward vectors like this


forward = Vec3(cos(rad_pitch)*sin(rad_yaw), sin(rad_pitch), -cos(rad_yaw)*cos(rad_pitch));
left = Vec3(sin(rad_yaw - pi_over_2), 0, -cos(rad_yaw - pi_over_2));




Then when it comes time to position the camera you rotate pitch degrees around the x direction, then yaw degrees around the y direction, then you translate to the camera position. Hoepfully this helps. My source for those vector calculations was Wolfram's Mathworld: Spherical Coordinates

Share this post


Link to post
Share on other sites
do that or take a look at this which is from my current (and old)camera class

void FPS_move_add(float forward, float up, float strafe)
{ ca.x+=((float)sin(-ca.h/(180/3.1415f))*forward)-((float)sin(+(ca.h+90)/(180/3.1415f))*strafe);
ca.y+=((float)sin(ca.p/(180/3.1415f))*forward)+up;
ca.z+=(-((float)cos(-ca.h/(180/3.1415f))*forward))-((float)cos(+(ca.h+90)/(180/3.1415f))*strafe);
}

And by the way, you don't really need all those shifts, jeff put in *0.05 so things wouldn't move that fast, but you shouldn't really do it that way, you should use the deltatime*movespeed value, which varies for every frame.

Share this post


Link to post
Share on other sites
Thanks alot for your help, i have figured it out now,

i was adding/subtracting 90 to the rotation value to change the rotation by 90 degrees. I actually needed to add/subtract 128 to rotate by 90 degrees, because my LUT_MASK was 0x1FF.

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.

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!