coord_system.C

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 #include <archon/math/coord_system.H>
00021 
00022 using namespace std;
00023 
00024 namespace Archon
00025 {
00026   namespace Math
00027   {
00028     CoordSystem3x3 CoordSystem3x3::makeIdentity()
00029     {
00030       return CoordSystem3x3(Vector3::zero(), Matrix3x3::identity());
00031     }
00032 
00033     const CoordSystem3x3 &CoordSystem3x3::identity()
00034     {
00035       static CoordSystem3x3 v = makeIdentity();
00036       return v;
00037     }
00038 
00039     CoordSystem3x3::CoordSystem3x3(const double m[])
00040     {
00041       basis.x[0] = m[0];
00042       basis.x[1] = m[1]; 
00043       basis.x[2] = m[2]; 
00044       basis.y[0] = m[4]; 
00045       basis.y[1] = m[5]; 
00046       basis.y[2] = m[6]; 
00047       basis.z[0] = m[8]; 
00048       basis.z[1] = m[9]; 
00049       basis.z[2] = m[10]; 
00050       origin[0]  = m[12]; 
00051       origin[1]  = m[13]; 
00052       origin[2]  = m[14]; 
00053     }
00054 
00055     void CoordSystem3x3::setOpenGLMatrix(double m[])
00056     {
00057       m[0]  = basis.x[0];
00058       m[1]  = basis.x[1];
00059       m[2]  = basis.x[2];
00060       m[4]  = basis.y[0];
00061       m[5]  = basis.y[1];
00062       m[6]  = basis.y[2];
00063       m[8]  = basis.z[0];
00064       m[9]  = basis.z[1];
00065       m[10] = basis.z[2];
00066       m[12] = origin[0];
00067       m[13] = origin[1];
00068       m[14] = origin[2];
00069       m[3]  = m[7] = m[11] = 0;
00070       m[15] = 1;    
00071     }
00072 
00073     void CoordSystem3x3::minimalTurn(const Vector3 &point)
00074     {
00075       double p, angle;
00076       Vector3 v = point;
00077       v -= origin;
00078       v.normalize();
00079       p = dot(v, basis.z);
00080       if(p == -1) return; // Parallel same direction as negative z-axis
00081       if(p ==  1)         // Parallel opposite direction as negative z-axis
00082       {
00083         v = basis.y;
00084         angle = M_PI;
00085       }
00086       else
00087       {
00088         v *= basis.z;
00089         v.normalize();
00090         angle = acos(-p);
00091       }
00092       basis.rotateRightHandedOrthoNormal(Rotation3(v, angle));
00093     }
00094 
00095     std::ostream &operator<<(std::ostream &out, const CoordSystem3x3 &s)
00096     {
00097       out << "Origin: " << s.origin <<  "\n";
00098       out << "Basis:\n";
00099       out << s.basis;
00100       return out;
00101     }
00102   }
00103 }

Generated on Sun Jul 30 22:55:43 2006 for Archon by  doxygen 1.4.4