PDA

View Full Version : Constraining a vector?



MarkS
09-04-2009, 10:14 PM
I am at a total loss as to how to code this. I'm not even sure what avenue to pursue.

I am trying to get some FPS mouse control code to work correctly. The way the code is right now, there are no constraints. You can rotate the view in any direction. This is obviously not realistic in a FPS setting. Maybe a space simulator, but not a FPS. I need to constrain the camera's look vector so that when the player looks straight up or down, the camera stops moving. In other words, the player shouldn't be able to move the mouse so far up or down that they are looking back. The look vector need to be constrained between (0,1,0) and (0,-1,0). To look back, you need to pan the camera.

I've tried constraining the mouse, constraining the angle and a very naive attempt to constrain the vector.

I am at a total loss and am about to chunk my computer through a window. I simply do not know what path to take nor how to code it. I did not figure that this would be so hard. The camera can only rotate about the y and x axis (cannot roll).

Here is the source: http://www.filefactory.com/file/ah5951d/n/Demo_src_zip
It is modified from this: http://www.codesampler.com/oglsrc/oglsrc_5.htm#ogl_fps_controls

Here is the binary with angular constraints: http://www.filefactory.com/file/ah595fa/n/Demo_zip
If you move the cursor around the screen (inside and outside the window) rapidly, the constraint breaks.

Why is this so hard? What am I doing wrong?

MarkS
09-05-2009, 09:41 AM
Never mind... I got it to work and it was easier than I thought. One of those "off by one errors". Constraining the mouse to the window worked just fine, after I set ClipCursor to the correct rectangle. I forgot to use ScreenToClient to adjust the rectangle.

Since this is no longer a math problem, this thread is in the wrong forum...