00001 /* 00002 * This file is part of the "Archon" framework. 00003 * (http://files3d.sourceforge.net) 00004 * 00005 * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen. 00006 * 00007 * Permission to use, copy, modify, and distribute this software and 00008 * its documentation under the terms of the GNU General Public License is 00009 * hereby granted. No representations are made about the suitability of 00010 * this software for any purpose. It is provided "as is" without express 00011 * or implied warranty. See the GNU General Public License 00012 * (http://www.gnu.org/copyleft/gpl.html) for more details. 00013 * 00014 * The characters in this file are ISO8859-1 encoded. 00015 * 00016 * The documentation in this file is in "Doxygen" style 00017 * (http://www.doxygen.org). 00018 */ 00019 00020 #ifndef ARCHON_MATH_COORD_SYSTEM_H 00021 #define ARCHON_MATH_COORD_SYSTEM_H 00022 00023 #include <archon/math/matrix.H> 00024 00025 namespace Archon 00026 { 00027 namespace Math 00028 { 00051 struct CoordSystem3x3 00052 { 00053 Vector3 origin; 00054 Matrix3x3 basis; 00055 00056 static const CoordSystem3x3 &identity(); 00057 00058 CoordSystem3x3() {} 00059 00064 CoordSystem3x3(Vector3 origin, Matrix3x3 basis): origin(origin), basis(basis) {} 00065 00069 CoordSystem3x3(const double openGLMatrix4x4[]); 00070 00071 void setOpenGLMatrix(double openGLMatrix4x4[]); 00072 00076 CoordSystem3x3 &operator*=(const CoordSystem3x3 &s) { origin += basis(s.origin); basis *= s.basis; return *this; } 00077 CoordSystem3x3 &operator/=(const CoordSystem3x3 &s) { CoordSystem3x3 t; t.setInverseOf(s); operator*=(t); return *this; } 00078 00079 CoordSystem3x3 operator*(const CoordSystem3x3 &s) const { CoordSystem3x3 t(*this); return t *= s; } 00080 CoordSystem3x3 operator/(const CoordSystem3x3 &s) const { CoordSystem3x3 t(*this); return t /= s; } 00081 00082 void map(Vector3 &v) const { basis.map(v); v += origin; } 00087 Vector3 operator()(const Vector3 &v) const { Vector3 w(v); map(w); return w; } 00088 Vector3 operator*(const Vector3 &v) const { return operator()(v); } 00089 00096 void translate(const Vector3 &p) 00097 { 00098 Vector3 v = p; 00099 basis.map(v); 00100 origin += v; 00101 } 00102 00106 void setInverseOf(const CoordSystem3x3 &s) 00107 { 00108 basis.setInverseOf(s.basis); 00109 origin = s.origin; 00110 basis.map(origin); 00111 origin.negate(); 00112 } 00113 00126 void minimalTurn(const Vector3 &point); 00127 00128 private: 00129 static CoordSystem3x3 makeIdentity(); 00130 }; 00131 00132 std::ostream &operator<<(std::ostream &, const CoordSystem3x3 &); 00133 } 00134 } 00135 00136 #endif // ARCHON_MATH_COORD_SYSTEM_H