Aether3D Game Engine
TransformComponent.hpp
1 #ifndef TRANSFORM_COMPONENT_H
2 #define TRANSFORM_COMPONENT_H
3 
4 #include <string>
5 #include "Vec3.hpp"
6 #include "Matrix.hpp"
7 #include "Quaternion.hpp"
8 
9 namespace ae3d
10 {
13  {
14  public:
16  const Vec3& GetLocalPosition() const { return localPosition; }
17 
19  const Quaternion& GetLocalRotation() const { return localRotation; }
20 
22  float GetLocalScale() const { return localScale; }
23 
25  class GameObject* GetGameObject() const { return gameObject; }
26 
30  void LookAt( const Vec3& localPosition, const Vec3& center, const Vec3& up );
31 
33  void MoveRight( float amount );
34 
36  void MoveForward( float amount );
37 
39  void MoveUp( float amount );
40 
43  void OffsetRotate( const Vec3& axis, float angleDegrees );
44 
46  void SetLocalPosition( const Vec3& localPos );
47 
49  void SetLocalRotation( const Quaternion& localRotation );
50 
52  void SetLocalScale( float localScale );
53 
55  void SetParent( TransformComponent* parent );
56 
58 #if OCULUS_RIFT
59  const Matrix44& GetVrView() const { return hmdView; }
60 #else
61  const Matrix44& GetVrView() const { return Matrix44::identity; }
62 #endif
63  void SetVrView( const Matrix44& view );
65 
67  const Matrix44& GetLocalMatrix();
68 
70  std::string GetSerialized() const;
71 
73  Vec3 GetViewDirection() const;
74 
75  private:
76  friend class GameObject;
77  friend class Scene;
78 
80  static int Type() { return 2; }
81 
83  static unsigned New();
84 
86  static TransformComponent* Get( unsigned index );
87 
89  static void UpdateLocalMatrices();
90 
91  void SolveLocalMatrix();
92 
93  Vec3 localPosition;
94  Quaternion localRotation;
95  float localScale = 1;
96  Matrix44 localMatrix;
97  TransformComponent* parent = nullptr;
98 #if OCULUS_RIFT
99  Matrix44 hmdView; // For VR
100 #endif
101  GameObject* gameObject = nullptr;
102  };
103 }
104 
105 #endif
void LookAt(const Vec3 &localPosition, const Vec3 &center, const Vec3 &up)
void MoveUp(float amount)
const Vec3 & GetLocalPosition() const
Definition: TransformComponent.hpp:16
Definition: AudioClip.hpp:4
void MoveRight(float amount)
Stores a position and an orientation.
Definition: TransformComponent.hpp:12
void SetParent(TransformComponent *parent)
const Quaternion & GetLocalRotation() const
Definition: TransformComponent.hpp:19
std::string GetSerialized() const
3-component vector.
Definition: Vec3.hpp:12
Vec3 GetViewDirection() const
const Matrix44 & GetVrView() const
Definition: TransformComponent.hpp:61
float GetLocalScale() const
Definition: TransformComponent.hpp:22
void SetLocalScale(float localScale)
void SetVrView(const Matrix44 &view)
GameObject is composed of components that define its behavior.
Definition: GameObject.hpp:9
const Matrix44 & GetLocalMatrix()
void SetLocalPosition(const Vec3 &localPos)
class GameObject * GetGameObject() const
Definition: TransformComponent.hpp:25
void OffsetRotate(const Vec3 &axis, float angleDegrees)
Stores an orientation.
Definition: Quaternion.hpp:12
void SetLocalRotation(const Quaternion &localRotation)
Contains game objects in a transform hierarchy.
Definition: Scene.hpp:17
void MoveForward(float amount)