HyperspaceExplorer 0.7.1
|
00001 /* 00002 Hyperspace Explorer - vizualizing higher-dimensional geometry 00003 Copyright (C) 2010 Lene Preuss <lene.preuss@gmail.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 */ 00020 00021 #ifndef ROTATION_IMPL_H 00022 #define ROTATION_IMPL_H 00023 00024 #include "Rotation.h" 00025 00026 #include "Matrix.impl.h" 00027 00028 namespace VecMath { 00029 00036 template <unsigned D> 00037 unsigned RotationAxes<D>::axis(unsigned which, unsigned index) { 00038 throw NotYetImplementedException("RotationAxes<"+Util::itoa(D)+">::axis("+ 00039 Util::itoa(which)+", "+Util::itoa(index)+")"); 00040 } 00041 00042 template <unsigned D, typename N> 00043 Rotation<D, N>::Rotation(): axis() { } 00044 00048 template <unsigned D, typename N> 00049 Rotation<D, N>::Rotation (N r0, ... ): axis() { 00050 00051 axis[0] = r0; 00052 va_list argp; 00053 va_start (argp, r0); 00054 for (unsigned i = 1; i < NumAxes<D>::num; i++) { 00055 axis[i] = va_arg (argp, N); 00056 } 00057 va_end (argp); 00058 } 00062 template <unsigned D, typename N> 00063 N &Rotation<D, N>::operator[] (unsigned i) { 00064 assert(i < NumAxes<D>::num); 00065 return axis[i]; 00066 } 00067 00071 template <unsigned D, typename N> 00072 N Rotation<D, N>::operator[] (unsigned i) const { 00073 assert(i < NumAxes<D>::num); 00074 return axis[i]; 00075 } 00076 00081 template <unsigned D, typename N> 00082 Rotation<D, N>::operator Matrix<D, N>() const { 00083 Matrix<D, N> R; 00084 for (unsigned i = 0; i < NumAxes<D>::num; i++) { 00085 if (operator[](i)) { 00086 R *= Matrix<D, N>(RotationAxes<D>::axis(0, i), 00087 RotationAxes<D>::axis(1, i), 00088 operator[](i)); 00089 } 00090 } 00091 return R; 00092 } 00093 00097 template <unsigned D, typename N> 00098 Rotation<D, N> &Rotation<D, N>::operator +=(const Rotation<D, N>& that) { 00099 axis += that.axis; 00100 return *this; 00101 } 00102 00104 template <unsigned D, typename N> 00105 Rotation<D, N>::operator bool() const { 00106 return sqnorm(axis) != 0.; 00107 } 00108 00109 template <unsigned D, typename N> 00110 const Vector<NumAxes<D>::num, N> &Rotation<D, N>::r() const { 00111 return axis; 00112 } 00113 00114 template <unsigned D, typename N> 00115 Vector<NumAxes<D>::num, N> &Rotation<D, N>::r() { 00116 return axis; 00117 } 00118 00119 template <unsigned D, typename N> 00120 std::string Rotation<D, N>::toString() const { 00121 return axis.toString(); 00122 } 00123 00128 template <unsigned D, typename N> 00129 Rotation<D, N> operator+ (const Rotation<D, N> &A, const Rotation<D, N> &B) { 00130 Rotation<D, N> C(A); 00131 return (C += B); 00132 } 00133 00138 template <unsigned D, typename N> 00139 std::ostream &operator << (std::ostream &o, const Rotation<D, N> &v) { 00140 o << v.r(); 00141 return o; 00142 } 00143 00149 template <unsigned D, typename N> 00150 std::istringstream &operator >> (std::istringstream &in, Rotation<D, N> &v) { 00151 in >> v.r(); 00152 return in; 00153 } 00154 00155 template <typename N> 00156 Rotation<3, N> makeRotation(N const &r0, N const &r1, N const &r2) { 00157 00158 Rotation<3, N> r; 00159 00160 r[0] = r0; 00161 r[1] = r1; 00162 r[2] = r2; 00163 00164 return r; 00165 } 00166 00167 template <typename N> 00168 Rotation<4, N> makeRotation(N const &r0, N const &r1, N const &r2, 00169 N const &r3, N const &r4, N const &r5) { 00170 00171 Rotation<4, N> r; 00172 00173 r[0] = r0; 00174 r[1] = r1; 00175 r[2] = r2; 00176 r[3] = r3; 00177 r[4] = r4; 00178 r[5] = r5; 00179 00180 return r; 00181 } 00182 00183 } 00184 00185 #endif