Game Development Reference
In-Depth Information
y
BillBoard
Score:1234
Camera
ForwardVecProj
cross
Bill2CameraVecProj
x
BillBoardPositionProj
Bill2CameraVecProj
θ
z
ForwardVecProj
CameraPositionProj
Figure 6-2. Billboarding
Listing 6-12. Billboarding Procedure
void SetBillBoardTowardCamera(Camera Cam)
{
// 1. Get Front Vector of Billboard Object projected on xz plane
Vector3 ForwardVecProj = new Vector3(m_Orientation.GetForwardWorldCoords().x, 0,
m_Orientation.GetForwardWorldCoords().z);
// 2. Get The BillBoard Position projected on xz plane
Vector3 BillBoardPositionProj = new Vector3(m_Orientation.GetPosition().x, 0,
m_Orientation.GetPosition().z);
// 3. Get Position of Camera on 2d XZ Plane
Vector3 CameraPositionProj = new Vector3(Cam.GetCameraEye().x, 0, Cam.GetCameraEye().z);
// 4. Calculate Vector from Billboard to Camera
Vector3 Bill2CameraVecProj = Vector3.Subtract(CameraPositionProj , BillBoardPositionProj);
Bill2CameraVecProj.Normalize();
// 5. Find Angle between forward of Billboard object and camera
// P = forwardxy
// Q = Vec_Bill_Camera
// P and Q are normalized Vectors
// P.Q = P*Q*cos(theta)
// P.Q/P*Q = cos(theta)
// acos(P.Q/P*Q) = theta;
// P.Q > 0 then angle between vectors is less than 90 deg
// P.Q < 0 then angle between vectors is greater than 90 deg.
// P.Q = 0 then angle between vector is exactly 90 degs.
Search WWH ::




Custom Search