forked from vixorien/AdvancedDX11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransform.h
59 lines (44 loc) · 1.54 KB
/
Transform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <DirectXMath.h>
#include <vector>
class Transform
{
public:
Transform();
void MoveAbsolute(float x, float y, float z);
void MoveRelative(float x, float y, float z);
void Rotate(float p, float y, float r);
void Scale(float x, float y, float z);
void SetPosition(float x, float y, float z);
void SetRotation(float p, float y, float r);
void SetScale(float x, float y, float z);
void SetTransformsFromMatrix(DirectX::XMFLOAT4X4 worldMatrix);
DirectX::XMFLOAT3 GetPosition();
DirectX::XMFLOAT3 GetPitchYawRoll();
DirectX::XMFLOAT3 GetScale();
DirectX::XMFLOAT4X4 GetWorldMatrix();
DirectX::XMFLOAT4X4 GetWorldInverseTransposeMatrix();
void AddChild(Transform* child, bool makeChildRelative = true);
void RemoveChild(Transform* child, bool applyParentTransform = true);
void SetParent(Transform* newParent, bool makeChildRelative = true);
Transform* GetParent();
Transform* GetChild(unsigned int index);
int IndexOfChild(Transform* child);
unsigned int GetChildCount();
private:
// Raw transformation data
DirectX::XMFLOAT3 position;
DirectX::XMFLOAT3 pitchYawRoll;
DirectX::XMFLOAT3 scale;
// World matrix and inverse transpose of the world matrix
bool matricesDirty;
DirectX::XMFLOAT4X4 worldMatrix;
DirectX::XMFLOAT4X4 worldInverseTransposeMatrix;
Transform* parent;
std::vector<Transform*> children;
// Helper to update both matrices if necessary
void UpdateMatrices();
void MarkChildTransformsDirty();
// Helpers for conversion
DirectX::XMFLOAT3 QuaternionToEuler(DirectX::XMFLOAT4 quaternion);
};