GteBillboardNode.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
12 using namespace gte;
13 
14 
15 BillboardNode::BillboardNode(std::shared_ptr<Camera> const& camera)
16  :
17  mCamera(camera)
18 {
19 }
20 
21 void BillboardNode::UpdateWorldData(double applicationTime)
22 {
23  // Compute the billboard's world transforms based on its parent's world
24  // transform and its local transforms. Notice that you should not call
25  // Node::UpdateWorldData since that function updates its children. The
26  // children of a BillboardNode cannot be updated until the billboard is
27  // aligned with the camera.
28  Spatial::UpdateWorldData(applicationTime);
29 
30  if (mCamera)
31  {
32  // Inverse-transform the camera to the model space of the billboard.
33  Matrix4x4<float> const& inverse = worldTransform.GetHInverse();
34 #if defined(GTE_USE_MAT_VEC)
35  Vector4<float> modelPos = inverse * mCamera->GetPosition();
36 #else
37  Vector4<float> modelPos = mCamera->GetPosition() * inverse;
38 #endif
39 
40  // To align the billboard, the projection of the camera to the
41  // xz-plane of the billboard's model space determines the angle of
42  // rotation about the billboard's model y-axis. If the projected
43  // camera is on the model axis (x = 0 and z = 0), ATan2 returns zero
44  // (rather than NaN), so there is no need to trap this degenerate
45  // case and handle it separately.
46  float angle = Function<float>::ATan2(modelPos[0], modelPos[2]);
49 #if defined(GTE_USE_MAT_VEC)
51 #else
53 #endif
54  }
55 
56  // Update the children now that the billboard orientation is known.
57  for (auto& child : mChild)
58  {
59  if (child)
60  {
61  child->Update(applicationTime, false);
62  }
63  }
64 }
65 
BillboardNode(std::shared_ptr< Camera > const &camera)
GLfloat angle
Definition: glext.h:6466
virtual void UpdateWorldData(double applicationTime)
std::shared_ptr< Camera > mCamera
Transform worldTransform
Definition: GteSpatial.h:50
Matrix4x4< float > const & GetRotation() const
Definition: GteTransform.h:217
static Real ATan2(Real const &y, Real const &x)
Definition: GteFunctions.h:383
std::vector< std::shared_ptr< Spatial > > mChild
Definition: GteNode.h:100
virtual void UpdateWorldData(double applicationTime)
Definition: GteSpatial.cpp:59
void SetRotation(Matrix4x4< float > const &rotate)
Matrix4x4< float > const & GetHInverse() const
static Vector Unit(int d)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59