Game Development Reference
In-Depth Information
Furthermore, the waypoint arrow must be rendered with z-buffering disabled and
after all the other 3D objects in the world have been rendered. This ensures that
the arrow is always visible, even if there is a 3D object that should technically be
in front of it.
Listing 10.1 Waypoint Arrow
Click here to view code image
class WaypointArrow
// Stores the current facing of the arrow
Vector3 facing
// 2D position of the arrow on screen
Vector2 screenPosition
// Current waypoint the arrow points at
Vector3 waypoint
// World transform matrix used to render the ar-
row
Matrix worldTransform
// Computes world transform matrix from given
position/rotation
function ComputeMatrix( Vector3 worldPosition ,
Quaternion rotation )
// Scale, rotate, translate (but we don't
have a scale this time)
worldTransform = CreateFromQuaternion( rota-
tion ) *
CreateTranslation( worldPosi-
tion )
end
// Gets world position of the 3D arrow based on
screenPosition
function ComputeWorldPosition()
// In order to do the unprojection, we need a
3D vector.
// The z component is the percent between the
Search WWH ::




Custom Search