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;
some problems with mouselook
hello,
i am using the following code to implement the classical FPS-mouselook.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement