Game Development Reference
In-Depth Information
Figure 68 - The atan2() function returns the arc tangent of y/x, in the range [-pi, +pi] radians.
We will then use the player angle to create a 2D rotation matrix.
Which we will use to rotate each of our icons into an orientation relative to the player for-
ward angle.
Now,therearetwomainpartsthatweneedtoimplement,thefirstistheplayer'stranslation
over our map, the conversion of world coordinates into map coordinates as the player ex-
plores the world. For the mini map we are implementing we need to know the extents of
the world, even if the world was procedurally generated, we would need to know the size
of the sector we are currently in.
We generally want to draw only a portion of our large mini map texture within the mini
map's space, in order to do this we need to calculate a source rectangle which contains the
coordinates in texels of the texture we wish to draw. We also will calculate a destination
rectangle that is the actual screen real estate our mini map will use.
Our initial source rectangle will contain the width and height of the full map texture di-
vided by some zoom factor. This zoom factor will determine how much of the map we will
capture at a time, where a zoom factor of one means “no zoom” and the higher its value,
the more zoomed in the mini map will be.
vector2 playerPos2D = vector2(playerPosition.x(), -playerPosition.z());
Search WWH ::




Custom Search