GteBlendTransformController.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>
10 #include <Graphics/GteSpatial.h>
12 using namespace gte;
13 
14 
16  std::shared_ptr<TransformController> const& controller0,
17  std::shared_ptr<TransformController> const& controller1,
18  bool geometricRotation, bool geometricScale)
19  :
20  TransformController(Transform()), // the identity transform
21  mController0(controller0),
22  mController1(controller1),
23  mWeight(0.0f),
24  mGeometricRotation(geometricRotation),
25  mGeometricScale(geometricScale)
26 {
27 }
28 
29 bool BlendTransformController::Update(double applicationTime)
30 {
31  if (!Controller::Update(applicationTime))
32  {
33  return false;
34  }
35 
36  mController0->Update(applicationTime);
37  mController1->Update(applicationTime);
38 
39  Transform const& xfrm0 = mController0->GetTransform();
40  Transform const& xfrm1 = mController1->GetTransform();
41  float oneMinusWeight = 1.0f - mWeight;
42 
43  // Compute the blended translation.
44  Vector4<float> trn0 = xfrm0.GetTranslationW1();
45  Vector4<float> trn1 = xfrm1.GetTranslationW1();
46  Vector4<float> blendTrn = oneMinusWeight * trn0 + mWeight * trn1;
48 
49  // Compute the blended rotation.
50  Matrix4x4<float> const& rot0 = xfrm0.GetRotation();
51  Matrix4x4<float> const& rot1 = xfrm1.GetRotation();
52 
55  if (Dot(quat0, quat1) < 0.0f)
56  {
57  quat1 = -quat1;
58  }
59 
60  Quaternion<float> blendQuat;
62  {
63  blendQuat = Slerp(mWeight, quat0, quat1);
64  }
65  else
66  {
67  blendQuat = oneMinusWeight * quat0 + mWeight * quat1;
68  Normalize(blendQuat);
69  }
70 
71  Matrix4x4<float> blendRot = Rotation<4, float>(blendQuat);
72  mLocalTransform.SetRotation(blendRot);
73 
74  // Compute the blended scale.
75  Vector3<float> sca0 = xfrm0.GetScale();
76  Vector3<float> sca1 = xfrm1.GetScale();
77  Vector3<float> blendSca;
78  if (mGeometricScale)
79  {
80  for (int i = 0; i < 3; ++i)
81  {
82  float s0 = sca0[i], s1 = sca1[i];
83  if (s0 != 0.0f && s1 != 0.0f)
84  {
85  float sign0 = (s0 > 0.0f ? 1.0f : -1.0f);
86  float sign1 = (s1 > 0.0f ? 1.0f : -1.0f);
87  s0 = fabs(s0);
88  s1 = fabs(s1);
89  float pow0 = pow(s0, oneMinusWeight);
90  float pow1 = pow(s1, mWeight);
91  blendSca[i] = sign0 * sign1 * pow0 * pow1;
92  }
93  else
94  {
95  blendSca[i] = 0.0f;
96  }
97  }
98  }
99  else
100  {
101  blendSca = oneMinusWeight * sca0 + mWeight * sca1;
102  }
103  mLocalTransform.SetScale(blendSca);
104 
105  Spatial* spatial = reinterpret_cast<Spatial*>(mObject);
106  spatial->localTransform = mLocalTransform;
107  return true;
108 }
109 
111 {
113  mController0->SetObject(object);
114  mController1->SetObject(object);
115 }
116 
std::shared_ptr< TransformController > mController0
ControlledObject * mObject
Definition: GteController.h:71
std::shared_ptr< TransformController > mController1
Quaternion< Real > Slerp(Real t, Quaternion< Real > const &q0, Quaternion< Real > const &q1)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s0
Definition: glext.h:9013
void SetScale(float s0, float s1, float s2)
virtual bool Update(double applicationTime)
virtual bool Update(double applicationTime)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Matrix4x4< float > const & GetRotation() const
Definition: GteTransform.h:217
Real Normalize(GVector< Real > &v, bool robust=false)
Definition: GteGVector.h:454
Vector3< float > GetScale() const
Definition: GteTransform.h:243
virtual void SetObject(ControlledObject *object)
virtual void SetObject(ControlledObject *object)
BlendTransformController(std::shared_ptr< TransformController > const &controller0, std::shared_ptr< TransformController > const &controller1, bool geometricRotation, bool geometricScale)
GLfloat f
Definition: glcorearb.h:1921
void SetRotation(Matrix4x4< float > const &rotate)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: glext.h:9013
Vector4< float > GetTranslationW1() const
Definition: GteTransform.h:238
void SetTranslation(float x0, float x1, float x2)
Transform localTransform
Definition: GteSpatial.h:49


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