From fbf770bd7b058196552733d000845e69d92912bc Mon Sep 17 00:00:00 2001 From: maxcorsini Date: Mon, 5 Feb 2007 13:55:21 +0000 Subject: [PATCH] add euler angle to quaternion conversion --- vcg/math/quaternion.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/vcg/math/quaternion.h b/vcg/math/quaternion.h index ee53c23b..711c8171 100644 --- a/vcg/math/quaternion.h +++ b/vcg/math/quaternion.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.15 2006/06/22 08:00:26 ganovelli +toMatrix with matrix33 added + Revision 1.14 2005/04/17 21:57:03 ganovelli tolto il const a interpolate @@ -50,6 +53,9 @@ updated access to matrix44 elements through V() instead simple [] Revision 1.6 2004/03/25 14:57:49 ponchio Microerror. ($LOG$ -> $Log: not supported by cvs2svn $ +Microerror. ($LOG$ -> Revision 1.15 2006/06/22 08:00:26 ganovelli +Microerror. ($LOG$ -> toMatrix with matrix33 added +Microerror. ($LOG$ -> Microerror. ($LOG$ -> Revision 1.14 2005/04/17 21:57:03 ganovelli Microerror. ($LOG$ -> tolto il const a interpolate Microerror. ($LOG$ -> @@ -110,7 +116,6 @@ public: void SetIdentity(); - void FromAxis(const S phi, const Point3 &a); void ToAxis(S &phi, Point3 &a ) const; @@ -118,6 +123,8 @@ public: void FromMatrix(Matrix44 &m); void ToMatrix(Matrix44 &m) const; void ToMatrix(Matrix33 &m) const; + + void FromEulerAngles(S alpha, S beta, S gamma); Point3 Rotate(const Point3 vec) const; //duplicated ... because of gcc new confoming to ISO template derived classes @@ -310,6 +317,23 @@ template void Quaternion::FromMatrix(Matrix44 &m) { } } } + +template +void FromEulerAngles(S alpha, S beta, S gamma) +{ + S cosalpha = cos(alpha / 2.0); + S cosbeta = cos(beta / 2.0); + S cosgamma = cos(gamma / 2.0); + S sinalpha = sin(alpha / 2.0); + S sinbeta = sin(beta / 2.0); + S singamma = sin(gamma / 2.0); + + V(0) = cosalpha * cosbeta * cosgamma + sinalpha * sinbeta * singamma; + V(1) = sinalpha * cosbeta * cosgamma - cosalpha * sinbeta * singamma; + V(2) = cosalpha * sinbeta * cosgamma + sinalpha * cosbeta * singamma; + V(3) = cosalpha * cosbeta * singamma - sinalpha * sinbeta * cosgamma; +} + template Quaternion &Invert(Quaternion &m) { m.Invert(); return m;