#pragma region License /****************************************************************************** This file is part of the PolyVox library Copyright (C) 2006 David Williams This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ******************************************************************************/ #pragma endregion #ifndef __PolyVox_Vector_H__ #define __PolyVox_Vector_H__ #include #include "boost/cstdint.hpp" namespace PolyVox { ///Represents a vector in space. template class Vector { public: ///Constructor. Vector(Type x, Type y) throw(); ///Constructor. Vector(Type x, Type y, Type z) throw(); ///Constructor. Vector(Type x, Type y, Type z, Type w) throw(); ///Constructor Vector(void) throw(); ///Copy Constructor. Vector(const Vector& vector) throw(); ///Copy Constructor which performs casting. template explicit Vector(const Vector& vector) throw(); ///Destructor. ~Vector(void) throw(); ///Assignment Operator. Vector& operator=(const Vector& rhs) throw(); ///Equality Operator. bool operator==(const Vector& rhs) const throw(); ///Comparison Operator. bool operator<(const Vector& rhs) const throw(); ///Addition and Assignment Operator. Vector& operator+=(const Vector &rhs) throw(); ///Subtraction and Assignment Operator. Vector& operator-=(const Vector &rhs) throw(); ///Multiplication and Assignment Operator. Vector& operator*=(const Type& rhs) throw(); ///Division and Assignment Operator. Vector& operator/=(const Type& rhs) throw(); ///Element Access Type getElement(boost::uint32_t index) const throw(); ///Get the x component of the vector. Type getX(void) const throw(); ///Get the y component of the vector. Type getY(void) const throw(); ///Get the z component of the vector. Type getZ(void) const throw(); ///Get the w component of the vector. Type getW(void) const throw(); ///Element Access void setElement(boost::uint32_t index, Type tValue) throw(); ///Set the x component of the vector. void setX(Type tX) throw(); ///Set the y component of the vector. void setY(Type tY) throw(); ///Set the z component of the vector. void setZ(Type tZ) throw(); ///Set the w component of the vector. void setW(Type tW) throw(); ///Get the length of the vector. double length(void) const throw(); ///Get the squared length of the vector. double lengthSquared(void) const throw(); ///Find the angle between this vector and that which is passed as a parameter. double angleTo(const Vector& vector) const throw(); ///Find the cross product between this vector and the vector passed as a parameter. Vector cross(const Vector& vector) const throw(); ///Find the dot product between this vector and the vector passed as a parameter. Type dot(const Vector& rhs) const throw(); ///Normalise the vector. void normalise(void) throw(); private: //Values for the vector Type m_tElements[Size]; }; //Non-member overloaded operators. ///Addition operator. template Vector operator+(const Vector& lhs, const Vector& rhs) throw(); ///Subtraction operator. template Vector operator-(const Vector& lhs, const Vector& rhs) throw(); ///Multiplication operator. template Vector operator*(const Vector& lhs, const Type& rhs) throw(); ///Division operator. template Vector operator/(const Vector& lhs, const Type& rhs) throw(); ///Stream insertion operator. template std::ostream& operator<<(std::ostream& os, const Vector& vector) throw(); //Some handy typedefs ///A 3D Vector of floats. typedef Vector<3,float> Vector3DFloat; ///A 3D Vector of doubles. typedef Vector<3,double> Vector3DDouble; ///A 3D Vector of signed 8-bit values. typedef Vector<3,boost::int8_t> Vector3DInt8; ///A 3D Vector of unsigned 8-bit values. typedef Vector<3,boost::uint8_t> Vector3DUint8; ///A 3D Vector of signed 16-bit values. typedef Vector<3,boost::int16_t> Vector3DInt16; ///A 3D Vector of unsigned 16-bit values. typedef Vector<3,boost::uint16_t> Vector3DUint16; ///A 3D Vector of signed 32-bit values. typedef Vector<3,boost::int32_t> Vector3DInt32; ///A 3D Vector of unsigned 32-bit values. typedef Vector<3,boost::uint32_t> Vector3DUint32; }//namespace Thermite #include "Vector.inl" #endif