Game Development Reference
In-Depth Information
float
range
// (x,y) center of radar on screen
Vector2
position
// Radius of radar on screen
float
radius
// Radar background image
ImageFile
radarImage
// List of all active RadarBlips
List
blips
// Initialize function sets range, center, radi-
us, and image
...
function
Update(
float
deltaTime
)
// Clear out the List of blips from last
frame
blips
.Clear()
// Get the player's position
...
// Convert playerPosition to a 2D coordinate.
// The below assumes a y-up world.
Vector2
playerPos2D
=
Vector2
(
playerPosi-
tion
.
x
,
playerPosition
.
z
)
// Calculate the rotation that may need to be
applied to the blip
// Get the players normalized facing vector
...
// Convert playerFacing to 2D
Vector2
playerFacing2D
=
Vector2
(
playerFa-
cing
.
x
,
playerFacing
.
z
)
// Angle between the player's 2D facing and
radar "forward"
float
angle
= acos(DotProduct(
playerFacing2D
,
Vector2
(0,1)))
// Convert 3D vector so we can perform a
cross product