Game Development Reference
In-Depth Information
The UpdateHUDItem() function updates the HUD item Item using the camera Cam. What this means
is that
1.
The position in the world for this HUD item is calculated based on the
camera's position, orientation, and the local HUD coordinates of the HUD
item. In local HUD coordinates, the x = 0 and y = 0 means the center of
the camera viewpoint. So, local coordinates of (1,2) mean that the HUD
item is placed 1 unit to the right of center and 2 units up above the center.
When z = 0, this means the HUD item is placed at the position of the near
projection plane, which would probably make the item unviewable, so you
require a positive value here, such as 0.5.
2.
If the HUD item is dirty, its billboard texture is updated. That is the billboard
texture associated with the HUDItem object, which is m_HUDImage updated.
First m_HUDImage is cleared by copying a blank texture over it.
3.
If there is an icon associated with this HUD item, it is copied to m_HUDImage .
4.
The numerical value of the HUD item is rendered to m_HUDImage .
5.
6.
If there is a string value associated with the HUD item, then it is rendered to
m_HUDImage .
7.
The HUD item has been updated as “cleaned,” so it is no longer set
to “dirty.”
8.
The HUD item is positioned in the world using the location calculated in the
first step.
The m_HUDImage 's UpdateObject3d() function is then called, so that the
billboard is turned to face the camera.
9.
See Listing 6-33 for the source code.
Listing 6-33. Updating the HUD Item
void UpdateHUDItem(Camera Cam, HUDItem Item)
{
// Update HUDItem position and rotation in the 3d world
// to face the camera.
Vector3 PositionLocal = Item.GetLocalScreenPosition();
Vector3 PositionWorld = new Vector3(0,0,0);
Vector3 CamPos = new Vector3(Cam.GetCameraEye().x, Cam.GetCameraEye().y, Cam.GetCameraEye().z);
Vector3 CameraForward = Cam.GetOrientation().GetForwardWorldCoords();
Vector3 CameraUp = Cam.GetOrientation().GetUpWorldCoords();
Vector3 CameraRight = Cam.GetOrientation().GetRightWorldCoords();
 
Search WWH ::




Custom Search