Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

quat.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 2000, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  */
00023 #ifndef QUAT_HEADER
00024 #define QUAT_HEADER
00025 
00026 #include "std/config.H"
00027 #include "mlib/global.H"
00028 
00029 template <class QUAT, class T, class P, class V, class L>
00030 class _quat
00031 {
00032 protected:
00033    V            _v;
00034    Greal       _w;
00035    
00036 public:
00037    
00038    _quat() : _v(), _w(1) {}
00039    _quat(const V& v, Greal w)  : _v(v), _w(w) {}
00040    _quat(Greal w)   : _w(w) {}
00041    _quat(const V& v) : _v(v), _w(0) {}
00042    
00043    //create quaternion from rotation matrix
00044    _quat(const T& t);
00045    
00046    //create quaternion to rotate from v1 to v2
00047    _quat(const V& v1, const V& v2);
00048    
00049    const V&     v()  const              { return _v; }
00050    V&           v()                     { return _v; }
00051    Greal       w()  const              { return _w; }
00052    Greal&      w()                     { return _w; }
00053 
00054    Greal       norm()      const       { return _v.lengthSqrd() + _w*_w; }
00055 
00056    QUAT         conjugate() const       { return QUAT(-_v, _w); }
00057    QUAT         inverse()   const       { return conjugate()/norm(); }
00058    
00059    QUAT         operator+(QUAT q) const { return QUAT(v()+q.v(), w()+q.w()); }
00060    QUAT         operator*(QUAT q) const { return QUAT(cross(v(), q.v()) 
00061                                                        + w()*q.v() + q.w()*v(), 
00062                                                       w()*q.w() - v()*q.v()); } 
00063    QUAT         operator/(QUAT q) const { return operator*(q.inverse()); }
00064 
00065    static QUAT  slerp(const QUAT& q1, const QUAT& q2, Greal u);
00066 }; 
00067 
00068 template <class QUAT, class T, class P, class V, class L>
00069 inline ostream &
00070 operator<<(ostream &os, const _quat<QUAT,T,P,V,L> &p) 
00071 { 
00072    return os << "<" << p.v() << ", " << p.w() << ">";
00073 }
00074 
00075 #ifdef GLUE_NEEDS_TEMPLATES_IN_H_FILE
00076 #include "quat.C"
00077 #endif
00078 #endif

Generated on Mon Sep 15 16:25:57 2003 for gluebase by doxygen1.2.18