GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/CGLA/Quatf.h
00001 #ifndef __CGLA_QUATF_H__
00002 #define __CGLA_QUATF_H__
00003 
00004 #include "ArithQuat.h"
00005 #include "Vec3f.h"
00006 #include "Vec4f.h"
00007 #include "Mat3x3f.h"
00008 #include "Mat4x4f.h"
00009 
00010 
00011 namespace CGLA {
00012 
00017         class Quatf : public ArithQuat<float,Vec3f,Quatf>
00018   {
00019   public:
00020                 Quatf() : ArithQuat<float, Vec3f, Quatf>() {}
00021 
00023     Quatf(const Vec3f& imaginary, float real = 1.0f) : ArithQuat<float, Vec3f, Quatf>(imaginary, real) {}
00024 
00026     Quatf(float x, float y, float z, float _qw) :  ArithQuat<float, Vec3f, Quatf>(x,y,z,_qw) {}
00027 
00029                 explicit Quatf(const Vec4f& v) : ArithQuat<float, Vec3f, Quatf>(v[0], v[1], v[2], v[3]) {}
00030 
00031         
00033     Mat3x3f get_Mat3x3f() const
00034     {
00035       float s = 2/norm();
00036       // note that the all q_*q_ are used twice (optimize)
00037       return Mat3x3f(Vec3f(1.0 - s*(qv[1]*qv[1] + qv[2]*qv[2]),
00038                                  s*(qv[0]*qv[1] - qw*qv[2]),
00039                                  s*(qv[0]*qv[2] + qw*qv[1])),
00040                      Vec3f(      s*(qv[0]*qv[1] + qw*qv[2]),
00041                            1.0 - s*(qv[0]*qv[0] + qv[2]*qv[2]),
00042                                  s*(qv[1]*qv[2] - qw*qv[0])),
00043                      Vec3f(      s*(qv[0]*qv[2] - qw*qv[1]),
00044                                  s*(qv[1]*qv[2] + qw*qv[0]),
00045                            1.0 - s*(qv[0]*qv[0] + qv[1]*qv[1])));
00046     }
00047 
00049     Mat4x4f get_Mat4x4f() const
00050     {
00051       float s = 2/norm();
00052       // note that the all q_*q_ are used twice (optimize?)
00053       return Mat4x4f(Vec4f(1.0 - s*(qv[1]*qv[1] + qv[2]*qv[2]),
00054                                  s*(qv[0]*qv[1] - qw*qv[2]),
00055                                  s*(qv[0]*qv[2] + qw*qv[1]),
00056                            0.0),
00057                      Vec4f(      s*(qv[0]*qv[1] + qw*qv[2]),
00058                            1.0 - s*(qv[0]*qv[0] + qv[2]*qv[2]),
00059                                  s*(qv[1]*qv[2] - qw*qv[0]),
00060                            0.0),
00061                      Vec4f(      s*(qv[0]*qv[2] - qw*qv[1]),
00062                                  s*(qv[1]*qv[2] + qw*qv[0]),
00063                            1.0 - s*(qv[0]*qv[0] + qv[1]*qv[1]),
00064                            0.0),
00065                      Vec4f(0.0, 0.0, 0.0, 1.0));
00066     }
00067                 
00069   inline Quatf identity_Quatf()
00070   {
00071     return Quatf(Vec3f(0.0));
00072   }
00073 
00074         };
00075 
00076 }
00077 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations