ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MorphTransform.tpp
Go to the documentation of this file.
1#pragma once
2
3template<size_t maxMorphs>
4MorphTransform<maxMorphs>::MorphTransform(IEasyEaseAnimator* eEA){
5 this->eEA = eEA;
6}
7
8template<size_t maxMorphs>
9void MorphTransform<maxMorphs>::AddMorph(uint16_t dictionaryValue, Vector3D positionOffset){
10 AddMorph(dictionaryValue, positionOffset, Vector3D(1.0f, 1.0f, 1.0f), Vector3D());
11}
12
13template<size_t maxMorphs>
14void MorphTransform<maxMorphs>::AddMorph(uint16_t dictionaryValue, Vector3D positionOffset, Vector3D scaleOffset){
15 AddMorph(dictionaryValue, positionOffset, scaleOffset, Vector3D());
16}
17
18template<size_t maxMorphs>
19void MorphTransform<maxMorphs>::AddMorph(uint16_t dictionaryValue, Vector3D positionOffset, Vector3D scaleOffset, Vector3D rotationOffset){
20 if(currentMorphs < maxMorphs){
21 bool addValue = true;
22
23 for(uint8_t i = 0; i < currentMorphs; i++){
24 if(dictionary[i] == dictionaryValue){
25 addValue = false;
26 break;
27 }
28 }
29
30 if(addValue){
31 positionOffsets[currentMorphs] = positionOffset;
32 scaleOffsets[currentMorphs] = scaleOffset;
33 rotationOffsets[currentMorphs] = rotationOffset;
34
35 dictionary[currentMorphs] = dictionaryValue;
36 currentMorphs++;
37 }
38 }
39}
40
41template<size_t maxMorphs>
42void MorphTransform<maxMorphs>::SetMorphPositionOffset(uint16_t dictionaryValue, Vector3D positionOffset){
43 bool hasIndex = false;
44 uint8_t index = 0;
45
46 for(uint8_t i = 0; i < currentMorphs; i++){
47 if(dictionary[i] == dictionaryValue){
48 hasIndex = true;
49 index = i;
50 break;
51 }
52 }
53
54 if(hasIndex){
55 positionOffsets[index] = positionOffset;
56 }
57}
58
59template<size_t maxMorphs>
60void MorphTransform<maxMorphs>::SetMorphScaleOffset(uint16_t dictionaryValue, Vector3D scaleOffset){
61 bool hasIndex = false;
62 uint8_t index = 0;
63
64 for(uint8_t i = 0; i < currentMorphs; i++){
65 if(dictionary[i] == dictionaryValue){
66 hasIndex = true;
67 index = i;
68 break;
69 }
70 }
71
72 if(hasIndex){
73 scaleOffsets[index] = scaleOffset;
74 }
75}
76
77template<size_t maxMorphs>
78void MorphTransform<maxMorphs>::SetMorphRotationOffset(uint16_t dictionaryValue, Vector3D rotationOffset){
79 bool hasIndex = false;
80 uint8_t index = 0;
81
82 for(uint8_t i = 0; i < currentMorphs; i++){
83 if(dictionary[i] == dictionaryValue){
84 hasIndex = true;
85 index = i;
86 break;
87 }
88 }
89
90 if(hasIndex){
91 rotationOffsets[index] = rotationOffset;
92 }
93}
94
95template<size_t maxMorphs>
96Vector3D MorphTransform<maxMorphs>::GetPositionOffset(){
97 Vector3D positionOffset;
98
99 for(uint8_t i = 0; i < currentMorphs; i++){
100 if (eEA->GetValue(dictionary[i]) > 0.0f){
101 positionOffset += positionOffsets[i] * eEA->GetValue(dictionary[i]);
102 }
103 }
104
105 return positionOffset;
106}
107
108template<size_t maxMorphs>
109Vector3D MorphTransform<maxMorphs>::GetScaleOffset(){
110 Vector3D scaleOffset = Vector3D(1.0f, 1.0f, 1.0f);
111 uint8_t count = 0;
112
113 for(uint8_t i = 0; i < currentMorphs; i++){
114 if (eEA->GetValue(dictionary[i]) > 0.0f){
115 scaleOffset = scaleOffset * Vector3D::LERP(Vector3D(1.0f, 1.0f, 1.0f), scaleOffsets[i], eEA->GetValue(dictionary[i]));
116 count++;
117 }
118 }
119
120 if(count) return scaleOffset;
121 else return Vector3D(1.0f, 1.0f, 1.0f);
122}
123
124template<size_t maxMorphs>
125Vector3D MorphTransform<maxMorphs>::GetRotationOffset(){
126 Vector3D rotationOffset;
127
128 for(uint8_t i = 0; i < currentMorphs; i++){
129 if (eEA->GetValue(dictionary[i]) > 0.0f){
130 rotationOffset += rotationOffsets[i] * eEA->GetValue(dictionary[i]);
131 }
132 }
133
134 return rotationOffset;
135}