**1**

# Camera rotation from mouse

Started by Aug 06 2011 03:52 PM

,
3 replies to this topic

###
#1
Members - Reputation: **100**

Posted 06 August 2011 - 03:52 PM

hey, as the title says, ill need to rotate a game camera from the mouse mouvement

i have the mouse movement coords(X, Y)

i have the camera lookat coords

and the camera position coords

all i need is a simple way to rotate the camera using the mouse coords

an easy sample could be useful for me to understand

any help will be appreciated

i have the mouse movement coords(X, Y)

i have the camera lookat coords

and the camera position coords

all i need is a simple way to rotate the camera using the mouse coords

an easy sample could be useful for me to understand

any help will be appreciated

###
#2
Members - Reputation: **225**

Posted 08 August 2011 - 06:35 PM

The easiest way: keep track of a yaw variable and pitch variable. When the mouse moves you increase or decrease the yaw or pitch, based on the X and Y movement, respectively.

If you can't directly set the angle the camera is rotated to (or you haven't programmed it yet), reply and I'll show you how to compute the new look at coordinates based on yaw and pitch, or you can use the frustum building functions of the graphics library you are using to help you out. (Can you give some more details, please?)

If, for some reason, you can't keep track of a yaw and pitch variables yourself (and the camera you are using doesn't let you get or set them) then its possible to take the look at coordinates, compute the current angle, change the angle, and then compute new lookat coords.

If you can't directly set the angle the camera is rotated to (or you haven't programmed it yet), reply and I'll show you how to compute the new look at coordinates based on yaw and pitch, or you can use the frustum building functions of the graphics library you are using to help you out. (Can you give some more details, please?)

If, for some reason, you can't keep track of a yaw and pitch variables yourself (and the camera you are using doesn't let you get or set them) then its possible to take the look at coordinates, compute the current angle, change the angle, and then compute new lookat coords.

*Two things are infinite: the universe and human stupidity; and Im not sure about the universe.*-- Albert Einstein

###
#3
Members - Reputation: **100**

Posted 08 August 2011 - 07:27 PM

the angle is a good idea

i already have the X, Y coords of the camera looka, and i already have an angle counting method from X, Y

but do u know a way to get the X, Y coords from the angle, this method could work i guess

thanks for the reply

i already have the X, Y coords of the camera looka, and i already have an angle counting method from X, Y

but do u know a way to get the X, Y coords from the angle, this method could work i guess

thanks for the reply

###
#4
Members - Reputation: **225**

Posted 08 August 2011 - 08:56 PM

assuming that X goes to the side, Y goes forward, and Z goes up

float pitchCos = Math.Cos(pitch); Vector3 offset; offset.X = Math.Sin(yaw) * pitchCos; offset.Y = Math.Cos(yaw) * pitchCos; offset.Z = Math.Sin(pitch); Vector3 lookat = offset + cameraPos;

*Two things are infinite: the universe and human stupidity; and Im not sure about the universe.*-- Albert Einstein