From 5d07b02cf62aac4381c6ce2b3f0d9ff94cff21cc Mon Sep 17 00:00:00 2001 From: ganovelli Date: Thu, 7 Oct 2004 13:55:47 +0000 Subject: [PATCH] templated on the kind of class used to implement rotation (default is QUternion but it can be Matrix44 as well) --- vcg/math/similarity.h | 64 +++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/vcg/math/similarity.h b/vcg/math/similarity.h index e5c6f478..47285e4c 100644 --- a/vcg/math/similarity.h +++ b/vcg/math/similarity.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.9 2004/06/04 13:35:07 cignoni +added InverseMatrix, + Revision 1.8 2004/05/07 10:09:13 cignoni missing final newline @@ -32,6 +35,9 @@ unified to the gl stlyle matix*vector. removed vector*matrix operator Revision 1.6 2004/03/25 14:57:49 ponchio Microerror. ($LOG$ -> $Log: not supported by cvs2svn $ +Microerror. ($LOG$ -> Revision 1.9 2004/06/04 13:35:07 cignoni +Microerror. ($LOG$ -> added InverseMatrix, +Microerror. ($LOG$ -> Microerror. ($LOG$ -> Revision 1.8 2004/05/07 10:09:13 cignoni Microerror. ($LOG$ -> missing final newline Microerror. ($LOG$ -> @@ -50,10 +56,10 @@ Microerror. ($LOG$ -> namespace vcg { -template class Similarity { +template > class Similarity { public: Similarity() {} - Similarity(const Quaternion &q) { SetRotate(q); } + Similarity(const RotationType &q) { SetRotate(q); } Similarity(const Point3 &p) { SetTranslate(p); } Similarity(S s) { SetScale(s); } @@ -67,70 +73,70 @@ public: Similarity &SetTranslate(const Point3 &t); ///use radiants for angle. Similarity &SetRotate(S angle, const Point3 & axis); - Similarity &SetRotate(const Quaternion &q); + Similarity &SetRotate(const RotationType &q); Matrix44 Matrix() const; Matrix44 InverseMatrix() const; void FromMatrix(const Matrix44 &m); - Quaternion rot; + RotationType rot; Point3 tra; S sca; }; -template Similarity &Invert(Similarity &m); -template Similarity Inverse(const Similarity &m); -template Point3 operator*(const Similarity &m, const Point3 &p); +template Similarity &Invert(Similarity &m); +template Similarity Inverse(const Similarity &m); +template Point3 operator*(const Similarity &m, const Point3 &p); -template Similarity Similarity::operator*(const Similarity &a) const { - Similarity r; +template Similarity Similarity::operator*(const Similarity &a) const { + Similarity r; r.rot = rot * a.rot; r.sca = sca * a.sca; r.tra = (rot.Rotate(a.tra)) * sca + tra; return r; } -template Similarity &Similarity::operator*=(const Similarity &a) { +template Similarity &Similarity::operator*=(const Similarity &a) { rot = rot * a.rot; sca = sca * a.sca; tra = (rot.Rotate(a.tra)) * sca + tra; return *this; } -template Similarity &Similarity::SetIdentity() { - rot.FromAxis(0, Point3(1, 0, 0)); +template Similarity &Similarity::SetIdentity() { + rot.SetIdentity(); tra = Point3(0, 0, 0); sca = 1; return *this; } -template Similarity &Similarity::SetScale(const S s) { +template Similarity &Similarity::SetScale(const S s) { SetIdentity(); sca = s; return *this; } -template Similarity &Similarity::SetTranslate(const Point3 &t) { +template Similarity &Similarity::SetTranslate(const Point3 &t) { SetIdentity(); tra = t; return *this; } -template Similarity &Similarity::SetRotate(S angle, const Point3 &axis) { +template Similarity &Similarity::SetRotate(S angle, const Point3 &axis) { SetIdentity(); rot.FromAxis(angle, axis); return *this; } -template Similarity &Similarity::SetRotate(const Quaternion &q) { +template Similarity &Similarity::SetRotate(const RotationType &q) { SetIdentity(); rot = q; return *this; } -template Matrix44 Similarity::Matrix() const { +template Matrix44 Similarity::Matrix() const { Matrix44 r; rot.ToMatrix(r); Matrix44 s = Matrix44().SetScale(sca, sca, sca); @@ -138,12 +144,12 @@ template Matrix44 Similarity::Matrix() const { return s*r*t; // scale * rot * trans } -template Matrix44 Similarity::InverseMatrix() const { +template Matrix44 Similarity::InverseMatrix() const { return Inverse(Matrix()); } -template void Similarity::FromMatrix(const Matrix44 &m) { +template void Similarity::FromMatrix(const Matrix44 &m) { sca = (S)pow(m.Determinant(), 1/3); assert(sca != 0); Matrix44 t = m * Matrix44().SetScale(1/sca, 1/sca, 1/sca); @@ -153,36 +159,40 @@ template void Similarity::FromMatrix(const Matrix44 &m) { tra[2] = t.element(3, 2); } -template Similarity &Invert(Similarity &a) { +template Similarity &Invert(Similarity &a) { a.rot.Invert(); a.sca = 1/a.sca; a.tra = a.rot.Rotate(-a.tra)*a.sca; return a; } -template Similarity Inverse(const Similarity &m) { - Similarity a = m; +template Similarity Inverse(const Similarity &m) { + Similarity a = m; return Invert(a); } -template Similarity Interpolate(const Similarity &a, const Similarity &b, const S t) { - Similarity r; +template Similarity Interpolate(const Similarity &a, const Similarity &b, const S t) { + Similarity r; r.rot = interpolate(a.rot, b.rot, t); r.tra = t * a.tra + (1-t) * b.tra; r.sca = t * a.sca + (1-t) * b.sca; return r; } -template Point3 operator*(const Similarity &m, const Point3 &p) { +template Point3 operator*(const Similarity &m, const Point3 &p) { Point3 r = m.rot.Rotate(p); r *= m.sca; r += m.tra; return r; } -typedef Similarity Similarityf; -typedef SimilaritySimilarityd; +//typedef Similarity Similarityf; +//typedef SimilaritySimilarityd; + +class Similarityf:public Similarity{}; + +class Similarityd:public Similarity{}; } //namespace