[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Camera thoughts



Hey there,



	I'm implementing a camera system using Euler angles, but I'm not sure
about one thing. Here's a small intro.
	The system is simple: I keep track of the camera's local coordinate
system by applying transforms to it's Up, Right and Direction vectors
(all unit vectors) and also it's Target (just a reference point) and
Position. One operation, for instance, is applying yaw, pitch and
rotate, in this order, using the camera's axis as the axis for the
rotation - yaw rotates Right and Direction vectors about the Up vector,
pitch rotates Up and Direction about the Right vector, and so on.
	When I'm finished transforming the camera, I call gluLookAt, passing as
arguments the camera's position, up vector and target.
	Ok, so this performs as espected, but there's this transform that I
implemented, which goes like this (it's supposed to mimic the behavior
of a FPS camera):

Transform(yaw, pitch)
{
	target -= camera position
	rotate Right, Direction and Target about Up axis (yaw)
	rotate Direction and Target about Right axis (pitch)

	recalculate Right as (Direction x Y_axis) or as (Direction x Z_axis),
if lies along the Y axis (BTW, "x" stands for cross product)

	normalize Right
	recalculate Up as (Right x Direction)
	target += camera position
}


	This seems to work fine, but if, for example, I pitch up, and start
just applying yaw repeatedly, I notice that the camera slowly starts
leveling, canceling the initial pitch. Obviously the Up vector is
getting screwed up, but I can't notice why. Or is my approach just wrong
in the first place?



Many thanks,
Miguel A. Osorio