Moving the Camera with the Mouse

Started by
3 comments, last by koniosis 20 years, 3 months ago
Hi, I''m trying to get the camera to move relative to mouse movement, just like in FPS games where you hold-right click and "look around". I''m not sure whats going wrong, I mean I know the difference in mouse position and I can set the "target" for the camera based on this, but the results seem erattic and not like what I was expecting, the camera doesn''t seem to move like in FPS i''ve played Heres what i''ve got so far:

Capture mouse down event
{
   set a boolean so we know
   store the X and Y of mouse
}

Capture mouse movement event
{
   if the right button is down then
   {
      camera target.x += difference between current and previous X
      camera target.y += difference between current and previous Y
      Set the previous mouse X,Y to the current X,Y
   }
}

capture mouse up event
{
   reset boolean to say mouse is up
}
I get the feeling this is totally wrong, but it seems right on paper :/ should I be modifying the Z component also. Thanks, Chris
Advertisement
Oh, I''m working in DirectX using:

device.Transform.View = Matrix.LookAtLH(	Position,		// Position of camera (Vector3)	Target,	// Where the camera is pointing (Vector3)	Up);		// "up" direction of the camera (Vector3)


And changing the components of "Target" when the mouse is moved
Your probably going to have to do some math to figure out what the new coordinates to change to are. Realize that depending on where your looking you might have to only change one coordinate (the other would be barely touched) and in some cases you might have to change both abit. I''m assuimg you already have it where you can turn around (if you haven''t then do that first.) The basic idea (regardless) would be to consider yourself to be the center of a circle, and use some sin/cos to figure out the coordinates of a point around you (have your mouse movement change the angles, not the target coordinates)
Maybe my understanding of how the camera target works is flawed, I thought that if you enter a vector, then the camera will "point" at that vector, so the middle of the view will be that vector. If this is the case then if i want to look "up" i should just increase the Y component of the vector? or is it that as the camera gradually becomes more level with the Z-axis i should be increasing the Z component, but wouldn't setting the Y component to 0 have the same effect as increasing Z.

That being said, all I want to implement i guess is roll-pitch-yaw for the camera, but this seems a strange concept if it's in terms of coordinates and not radians :/

Arghhh lol, this is complicated Any suggestion are welcome,

Cheers

[edited by - koniosis on January 23, 2004 5:22:53 PM]
K, i''ve found out I need to be using Quanternions, reading up on it now, i''ll post my results for those interested.

This topic is closed to new replies.

Advertisement