Attempting to make similarity compatible with both quaternions and matrix44
This commit is contained in:
parent
f3bddee157
commit
e5258c6aa3
|
@ -203,19 +203,19 @@ template <class S,class RotationType> void Similarity<S,RotationType>::FromMatri
|
||||||
//Computes a t*s*r decomposition
|
//Computes a t*s*r decomposition
|
||||||
S det = m.Determinant();
|
S det = m.Determinant();
|
||||||
assert(det > 0);
|
assert(det > 0);
|
||||||
sca = (S)pow(det, 1/3.0);
|
sca = (S)pow((S)det, (S)(1/3.0));
|
||||||
Matrix44<S> t = m*Matrix44<S>().SetScale(1/sca, 1/sca, 1/sca);
|
Matrix44<S> t = m*Matrix44<S>().SetScale(1/sca, 1/sca, 1/sca);
|
||||||
|
tra[0] = t.ElementAt(0, 3);t[0][3] = 0.0;
|
||||||
|
tra[1] = t.ElementAt(1, 3);t[1][3] = 0.0;
|
||||||
|
tra[2] = t.ElementAt(2, 3);t[2][3] = 0.0;
|
||||||
rot.FromMatrix(t);
|
rot.FromMatrix(t);
|
||||||
tra[0] = t.ElementAt(0, 3);
|
|
||||||
tra[1] = t.ElementAt(1, 3);
|
Invert(t);
|
||||||
tra[2] = t.ElementAt(2, 3);
|
tra = t * tra;
|
||||||
//Compute a s*r*t decomposition
|
tra/= sca;
|
||||||
Quaternion<S> irot = rot;
|
|
||||||
irot.Invert();
|
|
||||||
tra = irot.Rotate(tra);
|
|
||||||
tra /= sca;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class S,class RotationType> Similarity<S,RotationType> &Invert(Similarity<S,RotationType> &a) {
|
template <class S,class RotationType> Similarity<S,RotationType> &Invert(Similarity<S,RotationType> &a) {
|
||||||
a.rot.Invert();
|
a.rot.Invert();
|
||||||
a.sca = 1/a.sca;
|
a.sca = 1/a.sca;
|
||||||
|
@ -238,7 +238,9 @@ template <class S,class RotationType> Similarity<S,RotationType> Interpolate(con
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class S,class RotationType> Point3<S> operator*(const Similarity<S,RotationType> &m, const Point3<S> &p) {
|
template <class S,class RotationType> Point3<S> operator*(const Similarity<S,RotationType> &m, const Point3<S> &p) {
|
||||||
Point3<S> r = m.rot.Rotate(p);
|
Matrix44<S> t;
|
||||||
|
m.rot.ToMatrix(t);
|
||||||
|
Point3<S> r = t*p;
|
||||||
r *= m.sca;
|
r *= m.sca;
|
||||||
r += m.tra;
|
r += m.tra;
|
||||||
return r;
|
return r;
|
||||||
|
|
Loading…
Reference in New Issue