Sign in to follow this  

some problems with mouselook

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

This topic is 4340 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.

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