quaternion.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Copyright (c) 2001 - 2008 Marcus Boerger.  All rights reserved.
00003 *
00004 * This library is free software; you can redistribute it and/or
00005 * modify it under the terms of the GNU Lesser General Public
00006 * License as published by the Free Software Foundation; either
00007 * version 2.1 of the License, or (at your option) any later version.
00008 *
00009 * This library is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 * Lesser General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU Lesser General Public
00015 * License along with this library; if not, write to the Free Software
00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 * ========================================================================= */
00018 
00019 /* ------------------------------------------------------------------------ */
00030 /* ------------------------------------------------------------------------ */
00031 
00032 #pragma once
00033 
00034 #ifndef _QUATERNION_H_
00035 #define _QUATERNION_H_
00036 
00037 #include "triplet.h"
00038 
00039 namespace mbo
00040 {
00041 
00042 /****************************************************************************/
00043 
00046 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00047 struct quaternion: public triplet<_Ty1, _Ty2, _Ty3>
00048 {
00049     typedef triplet<_Ty1, _Ty2, _Ty3>     _Mybase;
00050     typedef quaternion<_Ty1, _Ty2, _Ty3, _Ty4> _Myt;
00051     typedef _Ty4 forth_type;
00052 
00053     quaternion()
00054         : _Mybase()
00055         , forth()
00056     {
00057     }
00058 
00059     quaternion(const _Ty1& val1, const _Ty2& val2, const _Ty3& val3, const _Ty4& val4)
00060         : _Mybase(val1, val2, val3)
00061         , forth(val4)
00062     {
00063     }
00064 
00065     template<typename _O1, typename _O2, typename _O3, typename _O4>
00066     quaternion(const quaternion<_O1, _O2, _O3, _O4>& rhs)
00067         : _Mybase(rhs.first, rhs.second, rhs.third)
00068         , forth(rhs.forth)
00069     {
00070     }
00071 
00072     void swap(_Myt& rhs)
00073     {
00074         std::swap(first,  rhs.first);
00075         std::swap(second, rhs.second);
00076         std::swap(third,  rhs.third);
00077         std::swap(forth,  rhs.forth);
00078     }
00079 
00080     forth_type   forth;
00081 };
00082 
00083 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00084 inline bool __cdecl operator == (const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& lhs, const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& rhs)
00085 {
00086     return (lhs.first == rhs.first && lsh.second == rhs.second && lsh.third == rhs.third && lsh.forth == rhs.forth);
00087 }
00088 
00089 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00090 inline bool __cdecl operator != (const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& lhs, const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& rhs)
00091 {
00092     return (!(lhs == rhs));
00093 }
00094 
00095 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00096 inline bool __cdecl operator < (const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& lhs, const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& rhs)
00097 {
00098     return lhs::pair < rhs::pair  ||
00099         (!(rhs.first < lhs.first) && lhs.second < rhs.second) ||
00100         (!(rhs.first < lhs.first) && !(rhs.second < lhs.second) && lhs.third < rhs.third) ||
00101         (!(rhs.first < lhs.first) && !(rhs.second < lhs.second) && !(rhs.third < lhs.third) && lhs.forth < rhs.forth)
00102         ;
00103 }
00104 
00105 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00106 inline bool __cdecl operator > (const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& lhs, const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& rhs)
00107 {
00108     return (rhs < lhs);
00109 }
00110 
00111 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00112 inline bool __cdecl operator <= (const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& lhs, const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& rhs)
00113 {
00114     return (!(rhs < lhs));
00115 }
00116 
00117 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00118 inline bool __cdecl operator >= (const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& lhs, const quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& rhs)
00119 {
00120     return (!(lhs < rhs));
00121 }
00122 
00123 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00124 inline quaternion<_Ty1, _Ty2, _Ty3, _Ty4> __cdecl make_quaternion(_Ty1 val1, _Ty2 val2, _Ty3 val3, _Ty4 val4)
00125 {
00126     return (quaternion<_Ty1, _Ty2, _Ty3, _Ty4>(val1, val2, val3, val4));
00127 }
00128 
00129 template<typename _Ty1, typename _Ty2, typename _Ty3, typename _Ty4>
00130 inline void swap(quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& lhs, quaternion<_Ty1, _Ty2, _Ty3, _Ty4>& rhs)
00131 {
00132     lhs.swap(rhs);
00133 }
00134 
00135 } // namespace mbo
00136 
00137 #endif // _QUATERNION_H_

  Hosted on code.google.com  
© Marcus Börger
Generated on Fri Jan 18 21:21:08 2008 for MBO-lib by doxygen 1.5.4