summaryrefslogtreecommitdiffstats
path: root/tools/globalcode/utility/transformmatrix.h
blob: 4d0e1755d8369bfcc9a1ade04542b039f3d37a35 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "precompiled/PCH.h"

/*===========================================================================
    transformmatrix.hpp
    Created: October 16, 2000
    Auuthor: Bryan Brandt

    Copyright (c) 2000 Radical Entertainment, Inc.
    All rights reserved.
===========================================================================*/
#ifndef _TRANSFORMMATRIX_HPP
#define _TRANSFORMMATRIX_HPP

#ifdef WORLD_BUILDER
#include "main/toolhack.h"
#endif
#include <toollib.hpp>


class MObject;
class MDagPath;
class MFnTransform;
class MFnIkJoint;
class MTransformationMatrix;


class TransformMatrix
{
public:

    enum RotateOrder
    {
        ORDER_XYZ = 0,
        ORDER_YZX,
        ORDER_ZXY,
        ORDER_XZY,
        ORDER_YXZ,
        ORDER_ZYX
    };

    TransformMatrix();
    TransformMatrix(const MDagPath& dagPath);
    TransformMatrix(const MTransformationMatrix& xform);

    bool Assign(const MDagPath& dagPath);
    bool Assign(const MTransformationMatrix& xform);

    void SetScalePivot(float x, float y, float z);
    void SetScalePivot(const tlPoint& sp);
    void SetScalePivotX(float x);
    void SetScalePivotY(float y);
    void SetScalePivotZ(float z);
    const tlPoint& GetScalePivot() const
        { return scalePivot; }
    float GetScalePivotX() const
        { return scalePivot.x; }
    float GetScalePivotY() const
        { return scalePivot.y; }
    float GetScalePivotZ() const
        { return scalePivot.z; }

    void SetScale(float x, float y, float z);
    void SetScaleX(float x);
    void SetScaleY(float y);
    void SetScaleZ(float z);
    float GetScaleX() const
        { return scaleX; }
    float GetScaleY() const
        { return scaleY; }
    float GetScaleZ() const
        { return scaleZ; }

    void SetShear(float xy, float xz, float yz);
    void SetShearXY(float xy);
    void SetShearXZ(float xz);
    void SetShearYZ(float yz);
    float GetShearXY() const
        { return shearXY; }
    float GetShearXZ() const
        { return shearXZ; }
    float GetShearYZ() const
        { return shearYZ; }

    void SetScalePivotTranslate(float x, float y, float z);
    void SetScalePivotTranslate(const tlPoint& spt);
    void SetScalePivotTranslateX(float x);
    void SetScalePivotTranslateY(float y);
    void SetScalePivotTranslateZ(float z);
    const tlPoint& GetScalePivotTranslate() const
        { return scalePivotTranslate; }
    float GetScalePivotTranslateX() const
        { return scalePivotTranslate.x; }
    float GetScalePivotTranslateY() const
        { return scalePivotTranslate.y; }
    float GetScalePivotTranslateZ() const
        { return scalePivotTranslate.z; }

    void SetRotatePivot(float x, float y, float z);
    void SetRotatePivot(const tlPoint& rp);
    void SetRotatePivotX(float x);
    void SetRotatePivotY(float y);
    void SetRotatePivotZ(float z);
    const tlPoint& GetRotatePivot() const
        { return rotatePivot; }
    float GetRotatePivotX() const
        { return rotatePivot.x; }
    float GetRotatePivotY() const
        { return rotatePivot.y; }
    float GetRotatePivotZ() const
        { return rotatePivot.z; }

    void SetRotateAxis(float x, float y, float z);
    void SetRotateAxisX(float rax);
    void SetRotateAxisY(float ray);
    void SetRotateAxisZ(float raz);
    float GetRotateAxisX() const
        { return rotateAxisX; }
    float GetRotateAxisY() const
        { return rotateAxisY; }
    float GetRotateAxisZ() const
        { return rotateAxisZ; }

    void SetRotateOrder(RotateOrder ro);
    RotateOrder GetRotateOrder() const
        { return rotateOrder; }

    void SetRotate(float x, float y, float z);
    void SetRotateX(float x);
    void SetRotateY(float y);
    void SetRotateZ(float z);
    float GetRotateX() const
        { return rotateX; }
    float GetRotateY() const
        { return rotateY; }
    float GetRotateZ() const
        { return rotateZ; }

    void SetRotatePivotTranslate(float x, float y, float z);
    void SetRotatePivotTranslate(const tlPoint& rpt);
    void SetRotatePivotTranslateX(float x);
    void SetRotatePivotTranslateY(float y);
    void SetRotatePivotTranslateZ(float z);
    const tlPoint& GetRotatePivotTranslate() const
        { return rotatePivotTranslate; }
    float GetRotatePivotTranslateX() const
        { return rotatePivotTranslate.x; }
    float GetRotatePivotTranslateY() const
        { return rotatePivotTranslate.y; }
    float GetRotatePivotTranslateZ() const
        { return rotatePivotTranslate.z; }

    void SetJointOrient(float x, float y, float z);
    void SetJointOrientX(float x);
    void SetJointOrientY(float y);
    void SetJointOrientZ(float z);
    float GetJointOrientX() const
        { return jointOrientX; }
    float GetJointOrientY() const
        { return jointOrientY; }
    float GetJointOrientZ() const
        { return jointOrientZ; }

    void SetInverseScale(float x, float y, float z);
    void SetInverseScaleX(float x);
    void SetInverseScaleY(float y);
    void SetInverseScaleZ(float z);
    float GetInverseScaleX() const
        { return inverseScaleX; }
    float GetInverseScaleY() const
        { return inverseScaleY; }
    float GetInverseScaleZ() const
        { return inverseScaleZ; }

    void SetTranslate(float x, float y, float z);
    void SetTranslate(const tlPoint& t);
    void SetTranslateX(float x);
    void SetTranslateY(float y);
    void SetTranslateZ(float z);
    const tlPoint& GetTranslate() const
        { return translate; }
    float GetTranslateX() const
        { return translate.x; }
    float GetTranslateY() const
        { return translate.y; }
    float GetTranslateZ() const
        { return translate.z; }

    void SetScaleMatrixIdentity();
    void SetHierarchyMatrixIdentity();
    void SetIdentity();

    // these are the outputs of this class:
    //    scale matrix - to be baked into the mesh
    //    hierarchy matrix - stored in the skeleton
    const tlMatrix& GetScaleMatrix() const;
    const tlMatrix& GetHierarchyMatrix() const;

    // routines for extracting the above matrices,
    // except with an option to change coordinate systems
    //
    void GetScaleMatrixLHS(tlMatrix& matrix) const;
    void GetHierarchyMatrixLHS(tlMatrix& matrix) const;
    void GetScaleMatrixRHS(tlMatrix& matrix) const;
    void GetHierarchyMatrixRHS(tlMatrix& matrix) const;

private:

    bool AssignJoint(MDagPath& dagPath, MObject& jointNode);

    void ComputeScaleMatrix();
    void ComputeHierarchyMatrix();

    tlPoint scalePivot;
    float scaleX;
    float scaleY;
    float scaleZ;
    float shearXY;
    float shearXZ;
    float shearYZ;
    tlPoint scalePivotTranslate;
    tlPoint rotatePivot;
    float rotateAxisX;
    float rotateAxisY;
    float rotateAxisZ;
    RotateOrder rotateOrder;
    float rotateX;
    float rotateY;
    float rotateZ;
    tlPoint rotatePivotTranslate;
    float jointOrientX;
    float jointOrientY;
    float jointOrientZ;
    float inverseScaleX;
    float inverseScaleY;
    float inverseScaleZ;
    tlPoint translate;

    bool scaleDirty;
    bool hierarchyDirty;

    tlMatrix scaleMatrix;
    tlMatrix hierarchyMatrix;
};


#endif // _TRANSFORMMATRIX_HPP