| 17 | } |
| 18 | |
| 19 | void BillboardNode::UpdateWorldData(double applicationTime) |
| 20 | { |
| 21 | // Compute the billboard's world transforms based on its parent's world |
| 22 | // transform and its local transforms. Notice that you should not call |
| 23 | // Node::UpdateWorldData since that function updates its children. The |
| 24 | // children of a BillboardNode cannot be updated until the billboard is |
| 25 | // aligned with the camera. |
| 26 | Spatial::UpdateWorldData(applicationTime); |
| 27 | |
| 28 | if (mCamera) |
| 29 | { |
| 30 | // Inverse-transform the camera to the model space of the billboard. |
| 31 | Matrix4x4<float> const& inverse = worldTransform.GetHInverse(); |
| 32 | #if defined(GTE_USE_VEC_MAT) |
| 33 | Vector4<float> modelPos = mCamera->GetPosition() * inverse; |
| 34 | #else |
| 35 | Vector4<float> modelPos = inverse * mCamera->GetPosition(); |
| 36 | #endif |
| 37 | |
| 38 | // To align the billboard, the projection of the camera to the |
| 39 | // xz-plane of the billboard's model space determines the angle of |
| 40 | // rotation about the billboard's model y-axis. If the projected |
| 41 | // camera is on the model axis (x = 0 and z = 0), atan2 returns zero |
| 42 | // (rather than NaN), so there is no need to trap this degenerate |
| 43 | // case and handle it separately. |
| 44 | float angle = std::atan2(modelPos[0], modelPos[2]); |
| 45 | Matrix4x4<float> orient = |
| 46 | Rotation<4, float>(AxisAngle<4, float>(Vector4<float>::Unit(1), angle)); |
| 47 | #if defined(GTE_USE_VEC_MAT) |
| 48 | worldTransform.SetRotation(orient * worldTransform.GetRotation()); |
| 49 | #else |
| 50 | worldTransform.SetRotation(worldTransform.GetRotation() * orient); |
| 51 | #endif |
| 52 | } |
| 53 | |
| 54 | // Update the children now that the billboard orientation is known. |
| 55 | for (auto& child : mChild) |
| 56 | { |
| 57 | if (child) |
| 58 | { |
| 59 | child->Update(applicationTime, false); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 |
nothing calls this directly
no test coverage detected