Game Development Reference
In-Depth Information
incremental rotation, as was done with the orbit camera. An implementation of a
first-person camera is provided in Listing 8.3 .
Listing 8.3 First-person Camera
Click here to view code image
class FirstPersonCamera
// Camera offset from player character position
// For a y-up world, the vector would be (0,
value, 0)
Vector3 verticalOffset
// Target position offset from camera
// For a z-forward world, vector would be (0, 0,
value)
Vector3 targetOffset
// Total yaw and pitch angles
float totalYaw , totalPitch
// Player that the camera is attached to
GameObject Player
// Actual camera matrix
Matrix cameraMatrix
// Initializes all the camera parameters
function Initialize( GameObject myPlayer , Vector3
myVerticalOffset ,
Vector3 myTargetOffset )
player = myPlayer
verticalOffset = myVerticalOffset
targetOffset = myTargetOffset
// Initially, there's no extra yaw or pitch
totalYaw = 0
totalPitch = 0
// Calculate camera matrix
Vector3 eye = player . position + verticalOff-
set
Search WWH ::




Custom Search