Game Development Reference
In-Depth Information
// Create a quaternion that rotates about the
world up
Quaternion quatYaw = CreateFromAx-
isAngle( Vector3 (0,1,0), yaw )
// Transform the camera offset and up by this
quaternion
offset = Transform( offset , quatYaw )
up = Transform( up , quatYaw )
// The forward is target.position - (tar-
get.position + offset)
// Which is just -offset
Vector3 forward = - offset
forward .Normalize()
Vector3 left = CrossProduct( up , forward )
left .Normalize()
// Create quaternion that rotates about cam-
era left
Quaternion quatPitch = CreateFromAx-
isAngle( left , pitch )
// Transform camera offset and up by this
quaternion
offset = Transform( offset , quatPitch )
up = Transform( up , quatPitch )
// Now compute the matrix
cameraMatrix = CreateLookAt( target . position +
offset ,
target . position ,
up )
end
end
In some games, it may be desirable to have the spring camera behavior as well as
the ability to manually orbit the camera. Both methods can certainly be combined
Search WWH ::




Custom Search