Game Development Reference
In-Depth Information
ing an orbit camera using spherical coordinates, but I find the approach presented
here a bit easier to follow.
Listing 8.2
Orbit Camera
class
OrbitCamera
// Up vector for camera
Vector3
up
// Offset from target
Vector3
offset
// Target object
GameObject
target
// Final camera matrix
Matrix
cameraMatrix
// Initializes the initial camera state
function
Initialize(
GameObject
myTarget
,
Vector3
myOffset
)
// In a y-up world, the up vector can just be
the Y axis
up
=
Vector3
(0,1,0)
offset
=
myOffset
target
=
myTarget
// CreateLookAt parameters are eye, target,
and up
cameraMatrix
= CreateLookAt(
target
.
position
+
offset
,
target
.
position
,
up
)
end
// Updates based on the incremental yaw/pitch
angles for this frame
function
Update(
float
yaw
,
float
pitch
)