00001 ////////////////////////////////////////////////////////////////////// 00002 // Copyright (c) 2001-2003 David Pritchard <drpritch@alumni.uwaterloo.ca> 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either 00007 // version 2 of the License, or (at your option) any later 00008 // 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 Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 00019 #include <freecloth/geom/geVector.h> 00020 #include <freecloth/geom/gePoint.h> 00021 00022 //////////////////////////////////////////////////////////////////////////////// 00023 // LOCAL DECLARATIONS 00024 00025 FREECLOTH_NAMESPACE_START 00026 00027 //////////////////////////////////////////////////////////////////////////////// 00028 // CLASS GeVector 00029 00030 const GeVector GeVector::ZERO( 0, 0, 0 ); 00031 const GeVector GeVector::X( 1, 0, 0 ); 00032 const GeVector GeVector::Y( 0, 1, 0 ); 00033 const GeVector GeVector::Z( 0, 0, 1 ); 00034 00035 //------------------------------------------------------------------------------ 00036 00037 GeVector::GeVector( const GePoint& p1, const GePoint& p2 ) 00038 : _x( p2._x - p1._x ), _y( p2._y - p1._y), _z( p2._z - p1._z ) 00039 {} 00040 00041 //------------------------------------------------------------------------------ 00042 00043 Float GeVector::getAngle( const GeVector& rhs ) const 00044 { 00045 // This one's actually probably better.. revisit someday. 00046 #if 0 00047 const GeVector lunit( getUnit() ); 00048 const GeVector runit( rhs.getUnit() ); 00049 Float costheta = lunit.dot( runit ); 00050 Float sintheta = lunit.cross( runit ); 00051 return BaMath::arctan2( sintheta, costheta ); 00052 #endif 00053 Float th1 = BaMath::arctan2( _y, _x ); 00054 Float th2 = BaMath::arctan2( rhs._y, rhs._x ); 00055 Float result = th2 - th1; 00056 while ( BaMath::isLess( result, 0 ) ) result += 2 * M_PI; 00057 while ( BaMath::isGreater( result, 2 * M_PI ) ) result -= 2 * M_PI; 00058 return result; 00059 } 00060 00061 00062 //////////////////////////////////////////////////////////////////////////////// 00063 // GLOBAL FUNCTIONS 00064 // 00065 00066 //------------------------------------------------------------------------------ 00067 00068 std::ostream& operator<<( std::ostream& os, const GeVector& v ) 00069 { 00070 os << "v(" << v._x << "," << v._y << "," << v._z << ")"; 00071 return os; 00072 } 00073 00074 FREECLOTH_NAMESPACE_END
1.2.14 written by Dimitri van Heesch,
© 1997-2002