Game Development Reference
In-Depth Information
float
t
// speed is how much t changes per second
float
speed
// Actual camera matrix
Matrix
cameraMatrix
// Calculates the camera matrix given current
index and t
function
ComputeMatrix()
// Eye position is the spline at the current
t/index
Vector3
eye
=
path
.Compute(index, t)
// Get point a little bit further ahead to
get the target point
Vector3
target
= path.Compute(
index
,
t
+
0.05f)
// For y-up world
Vector3
up
=
Vector3
(0, 1, 0)
cameraMatrix
= CreateLookAt(
eye
,
target
,
up
)
end
function
Initialize(
float
mySpeed
)
// The initial index should be 1 (because 0
is P0 initially)
index
= 1
t
= 0.0f
speed
= mySpeed
ComputeMatrix()
end
function
Update(
float
deltaTime
)
t
+=
speed
*
deltaTime
// If t > = 1.0f, we should move to the next
control point
// This code assumes that the speed won't be