Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

some problems with mouselook

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

hello, i am using the following code to implement the classical FPS-mouselook.
roty = (float) ((oldy - ymouse)*180) * timingspeed;
rotx = (float) ((oldx - xmouse)*180) * timingspeed;

viewVector[0]=viewVector[2]*sin(rotx)+viewVector[0]*cos(rotx);
viewVector[2]=viewVector[2]*cos(rotx)-viewVector[0]*sin(rotx);

normalize(viewVector);

cross(viewVector, upVector, axis);

normalize(axis);

float cosTheta = (float)cos(roty);
float sinTheta = (float)sin(roty);

// Find the new x position for the new rotated point
rotationVector[0]  = (cosTheta + (1 - cosTheta) * axis[0] * axis[0])		* viewVector[0];
rotationVector[0] += ((1 - cosTheta) * axis[0] * axis[1] - axis[2] * sinTheta)	* viewVector[1];
rotationVector[0] += ((1 - cosTheta) * axis[0] * axis[2] + axis[1] * sinTheta)	* viewVector[2];

// Find the new y position for the new rotated point
rotationVector[1]  = ((1 - cosTheta) * axis[0] * axis[1] + axis[2] * sinTheta)	* viewVector[0];
rotationVector[1] += (cosTheta + (1 - cosTheta) * axis[1] * axis[1])		* viewVector[1];
rotationVector[1] += ((1 - cosTheta) * axis[1] * axis[2] - axis[0] * sinTheta)	* viewVector[2];

// Find the new z position for the new rotated point
rotationVector[2]  = ((1 - cosTheta) * axis[0] * axis[2] - axis[1] * sinTheta)	* viewVector[0];
rotationVector[2] += ((1 - cosTheta) * axis[1] * axis[2] + axis[0] * sinTheta)	* viewVector[1];
rotationVector[2] += (cosTheta + (1 - cosTheta) * axis[2] * axis[2])		* viewVector[2];

viewVector[0]=rotationVector[0];
viewVector[1]=rotationVector[1];
viewVector[2]=rotationVector[2];

normalize(viewVector);

oldy=ymouse;
oldx=xmouse;

the problems i have are mainly windows-programming oriented. 1. when i get the cursor out of the window, then it screws up the rotation. if i try to keep the cursor inside the window by setting it to its previous location after each rotation, then i cant move at all, since the cursor position never changes. 2. how can i smooth out the movement a bit? i want a bit of a fading effect towards the final rotation.

Share this post


Link to post
Share on other sites
Advertisement
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!