Advertisement

Duplicating Mouselook?

Started by March 22, 2000 01:36 AM
9 comments, last by paulcoz 24 years, 8 months ago
Does anyone have any ideas about duplicating the ''mouselook'' feature (looking with the mouse )? I am thinking of adding the value of the (mousestate).lY or whichever mouse axis to the rotation values, or maybe seeing how far the mouse has moved and then interpolating the values in between. Any other suggestions? Paulcoz.
Basically you couple the mouse y-axis with the pitch rotation (around the world x-axis) and the mouse x-axis with the yaw rotation (world y-axis). You must also clamp the pitch variable to +/- 90 degrees so that the camera doesn''t get upside down otherwise the yaw rotation will be inversed. Of course you may add some sensitivity by scaling the mouse movement before adding to the rotation values.


Advertisement

Well well, we meet again Paulcoz

Basically I do what Spellbound said, updating the pitch and yaw according to change of relative mouse position.

This is some code I chopped for you that I use to do mouselook in my programs (this happens to be from a VB incarnation, and gets called whenever the mouse is moved. X and Y indicate the current x,y position of the mouse):

deltaX = (X - prevMouseX) * mouseSensitivitydeltaY = (Y - prevMouseY) * mouseSensitivity    viewerHeading = (viewerHeading + deltaX) Mod 360viewerHeadTilt = (viewerHeadTilt + deltaY) Mod 360  '' lock head tilt in range -90 to 90If viewerHeadTilt > 90 Then viewerHeadTilt = 90If viewerHeadTilt < -90 Then viewerHeadTilt = -90    prevMouseX = XprevMouseY = Y 


Before drawing each frame, you simply rotate about the y-axis by ''viewerHeading'' degrees, and around the x-axis by ''viewerHeadTilt'' degrees, and *joy* .... mouselook

Hope that was helpful

-------------
squirrels are a remarkable source of protein...
I thought that was how it would work .

Bad Monkey, which state are you in? (in Australia).

Paulcoz.

I reside in sunny Queensland (yes, yes, 1 hour and 20 years behind the rest of Australia etc etc), in the fine township of Brisbane.

I would like to point out that I DO NOT condone the consumption of XXXX, though

Where abouts are you?
I guess that means I am 50 years behind you - I am in Tasmania.

Paulcoz.
Advertisement
I''ve just decided to resurrect this weeks-old post.

I have mouselook working, only the quality is really poor. When I move the mouse the world seems to stutter across the screen as if it is jumping too far each step. I have programmed it like this:

if (dims.lX != 0)
(
yaw += double(dims.lX) * 0.7
)

I have tried changing the sensitivity so that the yaw changes with smaller increments and larger increments but nothing I do seems to help. Any idea why this looks so bad. Could it be because I update every frame?

Paulcoz.
Me again

If anything, updating the view each frame should make it smoother ... so the only thing I can think of is that you''re hammering the living daylights out of your ''puter by making it draw too much. What''s your framerate like?

-------------
squirrels are a remarkable source of protein...
Interpolating is easy, you just use mouse filtering. Store the last two x and y values of the mouse. After that, in the current frame, average the last two x and y variables with the current one. I think that is what you meant by interpolation.

Also wouldn''t this be faster?:
yaw += dims.lX * 0.7

instead of:
if (dims.lX != 0)
(
yaw += double(dims.lX) * 0.7
)

Also try this:
yaw += dims.lX * SceneTimer

SceneTimer is a variable that tells how long it took to get from the start of your loop to the end of your render loop.
At present I am updating the yaw value every frame, and I am getting an average of 60FPS (monitor refresh). I also tried increasing the refresh to 75 and the FPS jumped up to that then, but I had some other video problems so I put it back.

I don't understand how they make the mouselook in games like Q3 and Unreal so smooth, mine looks so jittery and I can't imagine what is different because their code must rely on the lX and lY values too.

Does anybody know whether there is something else you have to do here to smooth mouselook animation, or is it more likely that some part of my program needs re-working?

Paulcoz.

Edited by - paulcoz on 4/18/00 3:37:25 AM

This topic is closed to new replies.

Advertisement