-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransformQ.h
127 lines (98 loc) · 2.99 KB
/
TransformQ.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
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
/****************************************************************************
Copyright (C) 2010-2011 Alexandre Meyer
This file is part of library.
Sime is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Sime is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Sime. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef _TRANSFORMQ_H
#define _TRANSFORMQ_H
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <cmath>
#include <iostream>
#include <vec.h>
/*! \brief
*/
class TransformQ
{
public:
TransformQ() : T(0, 0, 0) {}
TransformQ(const Vector& _T) : T(_T) {}
//! constructor from axis and angle (degree) of rotation
TransformQ(const Vector& axis_rotation, const float angle, const Vector& translation=Vector(0,0,0)) : Q(axis_rotation, angle), T(translation) {}
TransformQ(const Quaternion& _Q, const Vector& _T = Vector(0, 0, 0)) : Q(_Q), T(_T) {}
/*! \brief Tr x Tr */
friend inline TransformQ operator*(const TransformQ& a, const TransformQ& b)
{
// TODO
return TransformQ();
}
friend inline Vector operator*(const TransformQ& a, const Vector& v)
{
// TODO
return Vector(0, 0, 0);
}
friend inline Point operator*(const TransformQ& a, const Point& v)
{
// TODO
return Point(0, 0, 0);
}
inline static TransformQ slerp(const TransformQ& a, const TransformQ& b, float t)
{
// TODO
return TransformQ();
}
void setIdentity()
{
T = Vector(0, 0, 0);
Q.setAxisAngle(Vector(1, 0, 0), 0.f);
}
TransformQ getInverse() const
{
Quaternion NQ = Q.inverse();
return TransformQ(NQ, NQ*Vector(-T.x, -T.y, -T.z));
}
void inverse()
{
*this = getInverse();
}
void setRotation(const Quaternion& _Q) { Q = _Q; }
void setTranslation(const Vector& _T) { T = _T; }
Quaternion& getRotation() { return Q; }
Vector& getTranslation() { return T; }
const Quaternion& getRotation() const { return Q; }
const Vector& getTranslation() const { return T; }
template<typename MAT>
void getMatrix44(MAT& m) const
{
Q.getMatrix44(m);
m[0][3] = T.x;
m[1][3] = T.y;
m[2][3] = T.z;
}
void getMatrix16(float m[16]) const
{
Q.getMatrix16(m);
m[3] = T.x;
m[7] = T.y;
m[11] = T.z;
}
friend inline std::ostream& operator<<(std::ostream& o, const TransformQ& a)
{
o << "Q=" << a.Q << ", T=" << a.T;
return o;
}
protected:
Quaternion Q;
Vector T;
};
#endif