# some problems with mouselook

This topic is 4647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
anyone? :-)

some code for other mouselook implementations would be helpful too!

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 9
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009388
• ### Who's Online (See full list)

There are no registered users currently online

×