-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrigtform.h
79 lines (61 loc) · 1.57 KB
/
rigtform.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
#ifndef RIGTFORM_H
#define RIGTFORM_H
#include <iostream>
#include <cassert>
#include "matrix4.h"
#include "quat.h"
class RigTForm {
Cvec3 t_; // translation component
Quat r_; // rotation component represented as a quaternion
public:
RigTForm() : t_(0) {
assert(norm2(Quat(1,0,0,0) - r_) < CS175_EPS2);
}
RigTForm(const Cvec3& t, const Quat& r) {
t_ = t;
r_ = r;
}
explicit RigTForm(const Cvec3& t) {
t_ = t;
}
explicit RigTForm(const Quat& r) {
r_ = r;
}
Cvec3 getTranslation() const {
return t_;
}
Quat getRotation() const {
return r_;
}
RigTForm& setTranslation(const Cvec3& t) {
t_ = t;
return *this;
}
RigTForm& setRotation(const Quat& r) {
r_ = r;
return *this;
}
Cvec4 operator * (const Cvec4& a) const {
const Cvec4 ans = this->r_ * a + Cvec4(this->t_, 0) ;
return ans ;
}
RigTForm operator * (const RigTForm& a) const {
return RigTForm(this->t_ + Cvec3(this->r_*Cvec4(a.getTranslation())),
this->r_ * a.getRotation());
}
};
inline RigTForm inv(const RigTForm& tform) {
Quat r_inv = inv(tform.getRotation());
return RigTForm(Cvec3(r_inv * -Cvec4(tform.getTranslation(), 1)),
r_inv);
}
inline RigTForm transFact(const RigTForm& tform) {
return RigTForm(tform.getTranslation());
}
inline RigTForm linFact(const RigTForm& tform) {
return RigTForm(tform.getRotation());
}
inline Matrix4 rigTFormToMatrix(const RigTForm& tform) {
return Matrix4::makeTranslation(tform.getTranslation()) * quatToMatrix(tform.getRotation());
}
#endif