00001 /* 00002 Sheep - A Rigid Body Dynamics Engine 00003 Copyright (C) 2001-2004 Francois Beaune 00004 Contact: http://toxicengine.sourceforge.net/ 00005 00006 This file is part of Sheep. 00007 00008 Sheep is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 Sheep is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Sheep; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef SHEEP_MATH_VECTOR_H 00024 #define SHEEP_MATH_VECTOR_H 00025 00026 #include "common/misc/htmlstream.h" 00027 #include "real.h" 00028 00029 #include <cassert> 00030 #include <cmath> // std::sqrt() 00031 00032 namespace sheep { 00033 00034 class Vector { 00035 public: 00036 //! Constructors. 00037 Vector(int d); 00038 Vector(int d, Real r); 00039 Vector(const Vector &v); 00040 00041 //! Destructor. 00042 virtual ~Vector(); 00043 00044 //! Assignment operators. 00045 Vector &operator=(Real r); 00046 Vector &operator=(const Vector &v); 00047 00048 //! Vector dimension. 00049 int GetDimension() const; 00050 00051 //! Basic operations. 00052 Vector operator+(const Vector &v) const; 00053 Vector operator-(const Vector &v) const; 00054 Vector operator-() const; 00055 Vector operator*(Real r) const; 00056 Vector operator/(Real r) const; 00057 Vector &operator+=(const Vector &v); 00058 Vector &operator-=(const Vector &v); 00059 Vector &operator*=(Real r); 00060 Vector &operator/=(Real r); 00061 00062 //! Array subscripting. 00063 Real &operator[](int i); 00064 const Real &operator[](int i) const; 00065 00066 //! Direct access to vector coefficients. 00067 Real *GetData(); 00068 00069 //! Square of the vector length. 00070 Real SquareNorm() const; 00071 00072 //! Vector length. 00073 Real Norm() const; 00074 00075 //! Normalized vector. Performance warning! 00076 Vector Normalized() const; 00077 00078 //! Normalize the vector. 00079 void Normalize(); 00080 00081 //! Returns true if the vector is (approximately) unit-length. 00082 bool IsUnitLength(Real e = EPS) const; 00083 00084 private: 00085 int m_d; //!< Vector dimension. 00086 Real *m_v; //!< Vector coefficients. 00087 }; 00088 00089 //! Product of a real by a vector. 00090 Vector operator*(Real r, const Vector &v); 00091 00092 //! Deprecated. 00093 htmlstream& operator<<(htmlstream &s, const Vector &v); 00094 00095 #include "vector.inl" 00096 00097 } 00098 00099 #endif // !SHEEP_MATH_VECTOR_H
1.3.6