This is a collection of commits which were supposed to be part of a feature branch... but I got in a mess with Git and so am committing them all together.
This commit is contained in:
parent
3e79e0bfaa
commit
d28c2aa61d
@ -26,6 +26,8 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "Impl/TypeDef.h"
|
#include "Impl/TypeDef.h"
|
||||||
|
|
||||||
|
#include "PolyVoxForwardDeclarations.h"
|
||||||
|
|
||||||
#include "PolyVoxCore/Array.h"
|
#include "PolyVoxCore/Array.h"
|
||||||
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
#include "PolyVoxCore/DefaultIsQuadNeeded.h"
|
||||||
#include "PolyVoxCore/SurfaceMesh.h"
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
@ -73,7 +75,7 @@ namespace PolyVox
|
|||||||
///
|
///
|
||||||
/// Another scenario which sometimes results in confusion is when you wish to extract a region which corresponds to the whole volume, partcularly when solid voxels extend right to the edge of the volume.
|
/// Another scenario which sometimes results in confusion is when you wish to extract a region which corresponds to the whole volume, partcularly when solid voxels extend right to the edge of the volume.
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
class CubicSurfaceExtractor
|
class CubicSurfaceExtractor
|
||||||
{
|
{
|
||||||
struct IndexAndMaterial
|
struct IndexAndMaterial
|
||||||
|
@ -63,7 +63,7 @@ namespace PolyVox
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// CubicSurfaceExtractor
|
// CubicSurfaceExtractor
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template< typename VolumeType> class CubicSurfaceExtractor;
|
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> > class CubicSurfaceExtractor;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Density
|
// Density
|
||||||
@ -139,15 +139,34 @@ namespace PolyVox
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Vector
|
// Vector
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template <uint32_t Size, typename Type> class Vector;
|
template <uint32_t Size, typename StorageType, typename OperationType = StorageType> class Vector;
|
||||||
typedef Vector<3,float> Vector3DFloat;
|
|
||||||
typedef Vector<3,double> Vector3DDouble;
|
typedef Vector<2,float,float> Vector2DFloat;
|
||||||
typedef Vector<3,int8_t> Vector3DInt8;
|
typedef Vector<2,double,double> Vector2DDouble;
|
||||||
typedef Vector<3,uint8_t> Vector3DUint8;
|
typedef Vector<2,int8_t,int32_t> Vector2DInt8;
|
||||||
typedef Vector<3,int16_t> Vector3DInt16;
|
typedef Vector<2,uint8_t,int32_t> Vector2DUint8;
|
||||||
typedef Vector<3,uint16_t> Vector3DUint16;
|
typedef Vector<2,int16_t,int32_t> Vector2DInt16;
|
||||||
typedef Vector<3,int32_t> Vector3DInt32;
|
typedef Vector<2,uint16_t,int32_t> Vector2DUint16;
|
||||||
typedef Vector<3,uint32_t> Vector3DUint32;
|
typedef Vector<2,int32_t,int32_t> Vector2DInt32;
|
||||||
|
typedef Vector<2,uint32_t,int32_t> Vector2DUint32;
|
||||||
|
|
||||||
|
typedef Vector<3,float,float> Vector3DFloat;
|
||||||
|
typedef Vector<3,double,double> Vector3DDouble;
|
||||||
|
typedef Vector<3,int8_t,int32_t> Vector3DInt8;
|
||||||
|
typedef Vector<3,uint8_t,int32_t> Vector3DUint8;
|
||||||
|
typedef Vector<3,int16_t,int32_t> Vector3DInt16;
|
||||||
|
typedef Vector<3,uint16_t,int32_t> Vector3DUint16;
|
||||||
|
typedef Vector<3,int32_t,int32_t> Vector3DInt32;
|
||||||
|
typedef Vector<3,uint32_t,int32_t> Vector3DUint32;
|
||||||
|
|
||||||
|
typedef Vector<4,float,float> Vector4DFloat;
|
||||||
|
typedef Vector<4,double,double> Vector4DDouble;
|
||||||
|
typedef Vector<4,int8_t,int32_t> Vector4DInt8;
|
||||||
|
typedef Vector<4,uint8_t,int32_t> Vector4DUint8;
|
||||||
|
typedef Vector<4,int16_t,int32_t> Vector4DInt16;
|
||||||
|
typedef Vector<4,uint16_t,int32_t> Vector4DUint16;
|
||||||
|
typedef Vector<4,int32_t,int32_t> Vector4DInt32;
|
||||||
|
typedef Vector<4,uint32_t,int32_t> Vector4DUint32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -26,6 +26,8 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
#include "Impl/TypeDef.h"
|
#include "Impl/TypeDef.h"
|
||||||
|
|
||||||
|
#include "PolyVoxForwardDeclarations.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -58,133 +60,169 @@ namespace PolyVox
|
|||||||
Vector2DInt4 test(1,2); //Declares a 2 dimensional Vector of type int4.
|
Vector2DInt4 test(1,2); //Declares a 2 dimensional Vector of type int4.
|
||||||
\endcode
|
\endcode
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
class Vector
|
class Vector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///Constructor.
|
|
||||||
Vector(Type x, Type y);
|
|
||||||
///Constructor.
|
|
||||||
Vector(Type x, Type y, Type z);
|
|
||||||
///Constructor.
|
|
||||||
Vector(Type x, Type y, Type z, Type w);
|
|
||||||
///Constructor
|
///Constructor
|
||||||
Vector(void);
|
Vector(void);
|
||||||
|
///Constructor.
|
||||||
|
Vector(StorageType tFillValue);
|
||||||
|
///Constructor.
|
||||||
|
Vector(StorageType x, StorageType y);
|
||||||
|
///Constructor.
|
||||||
|
Vector(StorageType x, StorageType y, StorageType z);
|
||||||
|
///Constructor.
|
||||||
|
Vector(StorageType x, StorageType y, StorageType z, StorageType w);
|
||||||
///Copy Constructor.
|
///Copy Constructor.
|
||||||
Vector(const Vector<Size,Type>& vector);
|
Vector(const Vector<Size,StorageType,OperationType>& vector);
|
||||||
///Copy Constructor which performs casting.
|
///Copy Constructor which performs casting.
|
||||||
template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector);
|
template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector);
|
||||||
///Destructor.
|
///Destructor.
|
||||||
~Vector(void);
|
~Vector(void);
|
||||||
|
|
||||||
///Assignment Operator.
|
///Assignment Operator.
|
||||||
Vector<Size,Type>& operator=(const Vector<Size,Type>& rhs);
|
Vector<Size,StorageType,OperationType>& operator=(const Vector<Size,StorageType,OperationType>& rhs);
|
||||||
///Equality Operator.
|
///Equality Operator.
|
||||||
bool operator==(const Vector<Size,Type>& rhs) const;
|
bool operator==(const Vector<Size,StorageType,OperationType>& rhs) const;
|
||||||
///Inequality Operator.
|
///Inequality Operator.
|
||||||
bool operator!=(const Vector<Size,Type>& rhs) const;
|
bool operator!=(const Vector<Size,StorageType,OperationType>& rhs) const;
|
||||||
///Comparison Operator.
|
///Comparison Operator.
|
||||||
bool operator<(const Vector<Size,Type>& rhs) const;
|
bool operator<(const Vector<Size,StorageType,OperationType>& rhs) const;
|
||||||
///Addition and Assignment Operator.
|
///Addition and Assignment Operator.
|
||||||
Vector<Size,Type>& operator+=(const Vector<Size,Type> &rhs);
|
Vector<Size,StorageType,OperationType>& operator+=(const Vector<Size,StorageType,OperationType> &rhs);
|
||||||
///Subtraction and Assignment Operator.
|
///Subtraction and Assignment Operator.
|
||||||
Vector<Size,Type>& operator-=(const Vector<Size,Type> &rhs);
|
Vector<Size,StorageType,OperationType>& operator-=(const Vector<Size,StorageType,OperationType> &rhs);
|
||||||
///Multiplication and Assignment Operator.
|
///Multiplication and Assignment Operator.
|
||||||
Vector<Size,Type>& operator*=(const Vector<Size,Type> &rhs);
|
Vector<Size,StorageType,OperationType>& operator*=(const Vector<Size,StorageType,OperationType> &rhs);
|
||||||
///Division and Assignment Operator.
|
///Division and Assignment Operator.
|
||||||
Vector<Size,Type>& operator/=(const Vector<Size,Type> &rhs);
|
Vector<Size,StorageType,OperationType>& operator/=(const Vector<Size,StorageType,OperationType> &rhs);
|
||||||
///Multiplication and Assignment Operator.
|
///Multiplication and Assignment Operator.
|
||||||
Vector<Size,Type>& operator*=(const Type& rhs);
|
Vector<Size,StorageType,OperationType>& operator*=(const StorageType& rhs);
|
||||||
///Division and Assignment Operator.
|
///Division and Assignment Operator.
|
||||||
Vector<Size,Type>& operator/=(const Type& rhs);
|
Vector<Size,StorageType,OperationType>& operator/=(const StorageType& rhs);
|
||||||
|
|
||||||
///Element Access.
|
///Element Access.
|
||||||
Type getElement(uint32_t index) const;
|
StorageType getElement(uint32_t index) const;
|
||||||
///Get the x component of the vector.
|
///Get the x component of the vector.
|
||||||
Type getX(void) const;
|
StorageType getX(void) const;
|
||||||
///Get the y component of the vector.
|
///Get the y component of the vector.
|
||||||
Type getY(void) const;
|
StorageType getY(void) const;
|
||||||
///Get the z component of the vector.
|
///Get the z component of the vector.
|
||||||
Type getZ(void) const;
|
StorageType getZ(void) const;
|
||||||
///Get the w component of the vector.
|
///Get the w component of the vector.
|
||||||
Type getW(void) const;
|
StorageType getW(void) const;
|
||||||
|
|
||||||
///Element Access.
|
///Element Access.
|
||||||
void setElement(uint32_t index, Type tValue);
|
void setElement(uint32_t index, StorageType tValue);
|
||||||
///Element Access.
|
///Element Access.
|
||||||
void setElements(Type x, Type y);
|
void setElements(StorageType x, StorageType y);
|
||||||
///Element Access.
|
///Element Access.
|
||||||
void setElements(Type x, Type y, Type z);
|
void setElements(StorageType x, StorageType y, StorageType z);
|
||||||
///Element Access.
|
///Element Access.
|
||||||
void setElements(Type x, Type y, Type z, Type w);
|
void setElements(StorageType x, StorageType y, StorageType z, StorageType w);
|
||||||
///Set the x component of the vector.
|
///Set the x component of the vector.
|
||||||
void setX(Type tX);
|
void setX(StorageType tX);
|
||||||
///Set the y component of the vector.
|
///Set the y component of the vector.
|
||||||
void setY(Type tY);
|
void setY(StorageType tY);
|
||||||
///Set the z component of the vector.
|
///Set the z component of the vector.
|
||||||
void setZ(Type tZ);
|
void setZ(StorageType tZ);
|
||||||
///Set the w component of the vector.
|
///Set the w component of the vector.
|
||||||
void setW(Type tW);
|
void setW(StorageType tW);
|
||||||
|
|
||||||
///Get the length of the vector.
|
///Get the length of the vector.
|
||||||
double length(void) const;
|
double length(void) const;
|
||||||
///Get the squared length of the vector.
|
///Get the squared length of the vector.
|
||||||
double lengthSquared(void) const;
|
double lengthSquared(void) const;
|
||||||
///Find the angle between this vector and that which is passed as a parameter.
|
///Find the angle between this vector and that which is passed as a parameter.
|
||||||
double angleTo(const Vector<Size,Type>& vector) const;
|
double angleTo(const Vector<Size,StorageType,OperationType>& vector) const;
|
||||||
///Find the cross product between this vector and the vector passed as a parameter.
|
///Find the cross product between this vector and the vector passed as a parameter.
|
||||||
Vector<Size,Type> cross(const Vector<Size,Type>& vector) const;
|
Vector<Size,StorageType,OperationType> cross(const Vector<Size,StorageType,OperationType>& vector) const;
|
||||||
///Find the dot product between this vector and the vector passed as a parameter.
|
///Find the dot product between this vector and the vector passed as a parameter.
|
||||||
Type dot(const Vector<Size,Type>& rhs) const;
|
StorageType dot(const Vector<Size,StorageType,OperationType>& rhs) const;
|
||||||
///Normalise the vector.
|
///Normalise the vector.
|
||||||
void normalise(void);
|
void normalise(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//Values for the vector
|
//Values for the vector
|
||||||
Type m_tElements[Size];
|
StorageType m_tElements[Size];
|
||||||
};
|
};
|
||||||
|
|
||||||
//Non-member overloaded operators.
|
//Non-member overloaded operators.
|
||||||
///Addition operator.
|
///Addition operator.
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType,typename OperationType>
|
||||||
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs);
|
Vector<Size,StorageType,OperationType> operator+(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
|
||||||
///Subtraction operator.
|
///Subtraction operator.
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType,typename OperationType>
|
||||||
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs);
|
Vector<Size,StorageType,OperationType> operator-(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
|
||||||
///Multiplication operator.
|
///Multiplication operator.
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType,typename OperationType>
|
||||||
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs);
|
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
|
||||||
///Division operator.
|
///Division operator.
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType,typename OperationType>
|
||||||
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs);
|
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs);
|
||||||
///Multiplication operator.
|
///Multiplication operator.
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType,typename OperationType>
|
||||||
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs);
|
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs);
|
||||||
///Division operator.
|
///Division operator.
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType,typename OperationType>
|
||||||
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs);
|
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs);
|
||||||
///Stream insertion operator.
|
///Stream insertion operator.
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType,typename OperationType>
|
||||||
std::ostream& operator<<(std::ostream& os, const Vector<Size,Type>& vector);
|
std::ostream& operator<<(std::ostream& os, const Vector<Size,StorageType,OperationType>& vector);
|
||||||
|
|
||||||
//Some handy typedefs
|
//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,int8_t> Vector3DInt8;
|
|
||||||
///A 3D Vector of unsigned 8-bit values.
|
|
||||||
typedef Vector<3,uint8_t> Vector3DUint8;
|
|
||||||
///A 3D Vector of signed 16-bit values.
|
|
||||||
typedef Vector<3,int16_t> Vector3DInt16;
|
|
||||||
///A 3D Vector of unsigned 16-bit values.
|
|
||||||
typedef Vector<3,uint16_t> Vector3DUint16;
|
|
||||||
///A 3D Vector of signed 32-bit values.
|
|
||||||
typedef Vector<3,int32_t> Vector3DInt32;
|
|
||||||
///A 3D Vector of unsigned 32-bit values.
|
|
||||||
typedef Vector<3,uint32_t> Vector3DUint32;
|
|
||||||
|
|
||||||
|
///A 2D Vector of floats.
|
||||||
|
typedef Vector<2,float,float> Vector2DFloat;
|
||||||
|
///A 2D Vector of doubles.
|
||||||
|
typedef Vector<2,double,double> Vector2DDouble;
|
||||||
|
///A 2D Vector of signed 8-bit values.
|
||||||
|
typedef Vector<2,int8_t,int32_t> Vector2DInt8;
|
||||||
|
///A 2D Vector of unsigned 8-bit values.
|
||||||
|
typedef Vector<2,uint8_t,int32_t> Vector2DUint8;
|
||||||
|
///A 2D Vector of signed 16-bit values.
|
||||||
|
typedef Vector<2,int16_t,int32_t> Vector2DInt16;
|
||||||
|
///A 2D Vector of unsigned 16-bit values.
|
||||||
|
typedef Vector<2,uint16_t,int32_t> Vector2DUint16;
|
||||||
|
///A 2D Vector of signed 32-bit values.
|
||||||
|
typedef Vector<2,int32_t,int32_t> Vector2DInt32;
|
||||||
|
///A 2D Vector of unsigned 32-bit values.
|
||||||
|
typedef Vector<2,uint32_t,int32_t> Vector2DUint32;
|
||||||
|
|
||||||
|
///A 3D Vector of floats.
|
||||||
|
typedef Vector<3,float,float> Vector3DFloat;
|
||||||
|
///A 3D Vector of doubles.
|
||||||
|
typedef Vector<3,double,double> Vector3DDouble;
|
||||||
|
///A 3D Vector of signed 8-bit values.
|
||||||
|
typedef Vector<3,int8_t,int32_t> Vector3DInt8;
|
||||||
|
///A 3D Vector of unsigned 8-bit values.
|
||||||
|
typedef Vector<3,uint8_t,int32_t> Vector3DUint8;
|
||||||
|
///A 3D Vector of signed 16-bit values.
|
||||||
|
typedef Vector<3,int16_t,int32_t> Vector3DInt16;
|
||||||
|
///A 3D Vector of unsigned 16-bit values.
|
||||||
|
typedef Vector<3,uint16_t,int32_t> Vector3DUint16;
|
||||||
|
///A 3D Vector of signed 32-bit values.
|
||||||
|
typedef Vector<3,int32_t,int32_t> Vector3DInt32;
|
||||||
|
///A 3D Vector of unsigned 32-bit values.
|
||||||
|
typedef Vector<3,uint32_t,int32_t> Vector3DUint32;
|
||||||
|
|
||||||
|
///A 4D Vector of floats.
|
||||||
|
typedef Vector<4,float,float> Vector4DFloat;
|
||||||
|
///A 4D Vector of doubles.
|
||||||
|
typedef Vector<4,double,double> Vector4DDouble;
|
||||||
|
///A 4D Vector of signed 8-bit values.
|
||||||
|
typedef Vector<4,int8_t,int32_t> Vector4DInt8;
|
||||||
|
///A 4D Vector of unsigned 8-bit values.
|
||||||
|
typedef Vector<4,uint8_t,int32_t> Vector4DUint8;
|
||||||
|
///A 4D Vector of signed 16-bit values.
|
||||||
|
typedef Vector<4,int16_t,int32_t> Vector4DInt16;
|
||||||
|
///A 4D Vector of unsigned 16-bit values.
|
||||||
|
typedef Vector<4,uint16_t,int32_t> Vector4DUint16;
|
||||||
|
///A 4D Vector of signed 32-bit values.
|
||||||
|
typedef Vector<4,int32_t,int32_t> Vector4DInt32;
|
||||||
|
///A 4D Vector of unsigned 32-bit values.
|
||||||
|
typedef Vector<4,uint32_t,int32_t> Vector4DUint32;
|
||||||
|
|
||||||
|
|
||||||
}//namespace PolyVox
|
}//namespace PolyVox
|
||||||
|
@ -24,17 +24,41 @@ freely, subject to the following restrictions:
|
|||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
//-------------------------- Constructors, etc ---------------------------------
|
//-------------------------- Constructors, etc ---------------------------------
|
||||||
|
/**
|
||||||
|
Creates a Vector object but does not initialise it.
|
||||||
|
*/
|
||||||
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
|
Vector<Size, StorageType, OperationType>::Vector(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a Vector object and initialises it with given values.
|
||||||
|
\param x x component to set.
|
||||||
|
*/
|
||||||
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
|
Vector<Size,StorageType,OperationType>::Vector(StorageType tFillValue)
|
||||||
|
{
|
||||||
|
for(uint32_t ct = 0; ct < Size; ct++)
|
||||||
|
{
|
||||||
|
m_tElements[ct] = tFillValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a Vector object and initialises it with given values.
|
Creates a Vector object and initialises it with given values.
|
||||||
\param x x component to set.
|
\param x x component to set.
|
||||||
\param y y component to set.
|
\param y y component to set.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type>::Vector(Type x, Type y)
|
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y)
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size == 2, "This constructor should only be used for vectors with two elements.");
|
||||||
|
#endif
|
||||||
|
|
||||||
m_tElements[0] = x;
|
m_tElements[0] = x;
|
||||||
m_tElements[1] = y;
|
m_tElements[1] = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,9 +67,13 @@ namespace PolyVox
|
|||||||
\param y y component to set.
|
\param y y component to set.
|
||||||
\param z z component to set.
|
\param z z component to set.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type>::Vector(Type x, Type y, Type z)
|
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y, StorageType z)
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size == 3, "This constructor should only be used for vectors with three elements.");
|
||||||
|
#endif
|
||||||
|
|
||||||
m_tElements[0] = x;
|
m_tElements[0] = x;
|
||||||
m_tElements[1] = y;
|
m_tElements[1] = y;
|
||||||
m_tElements[2] = z;
|
m_tElements[2] = z;
|
||||||
@ -59,31 +87,27 @@ namespace PolyVox
|
|||||||
\param z z component to set.
|
\param z z component to set.
|
||||||
\param w w component to set.
|
\param w w component to set.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type>::Vector(Type x, Type y, Type z, Type w)
|
Vector<Size,StorageType,OperationType>::Vector(StorageType x, StorageType y, StorageType z, StorageType w)
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all constructors, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size == 4, "This constructor should only be used for vectors with four elements.");
|
||||||
|
#endif
|
||||||
|
|
||||||
m_tElements[0] = x;
|
m_tElements[0] = x;
|
||||||
m_tElements[1] = y;
|
m_tElements[1] = y;
|
||||||
m_tElements[2] = z;
|
m_tElements[2] = z;
|
||||||
m_tElements[3] = w;
|
m_tElements[3] = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Creates a Vector object but does not initialise it.
|
|
||||||
*/
|
|
||||||
template <uint32_t Size, typename Type>
|
|
||||||
Vector<Size, Type>::Vector(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Copy constructor builds object based on object passed as parameter.
|
Copy constructor builds object based on object passed as parameter.
|
||||||
\param vector A reference to the Vector to be copied.
|
\param vector A reference to the Vector to be copied.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
Vector<Size, Type>::Vector(const Vector<Size, Type>& vector)
|
Vector<Size, StorageType, OperationType>::Vector(const Vector<Size, StorageType, OperationType>& vector)
|
||||||
{
|
{
|
||||||
std::memcpy(m_tElements, vector.m_tElements, sizeof(Type) * Size);
|
std::memcpy(m_tElements, vector.m_tElements, sizeof(StorageType) * Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,22 +119,30 @@ namespace PolyVox
|
|||||||
|
|
||||||
\param vector A reference to the Vector to be copied.
|
\param vector A reference to the Vector to be copied.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
template <typename CastType>
|
template <typename CastType>
|
||||||
Vector<Size, Type>::Vector(const Vector<Size, CastType>& vector)
|
Vector<Size, StorageType, OperationType>::Vector(const Vector<Size, CastType>& vector)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
m_tElements[ct] = static_cast<Type>(vector.getElement(ct));
|
m_tElements[ct] = static_cast<StorageType>(vector.getElement(ct));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Destroys the Vector.
|
Destroys the Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
Vector<Size, Type>::~Vector(void)
|
Vector<Size, StorageType, OperationType>::~Vector(void)
|
||||||
{
|
{
|
||||||
|
// We put the static_asserts in the destructor because there is one one of these,
|
||||||
|
// where as there are multiple constructors.
|
||||||
|
|
||||||
|
// Force a vector to have a length greater than one. There is no need for a
|
||||||
|
// vector with one element, and supporting this would cause confusion over the
|
||||||
|
// behaviour of the constructor taking a single value, as this fills all elements
|
||||||
|
// to that value rather than just the first one.
|
||||||
|
static_assert(Size > 1, "Vector must have a length greater than one.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,14 +150,14 @@ namespace PolyVox
|
|||||||
\param rhs Vector to assign to.
|
\param rhs Vector to assign to.
|
||||||
\return A reference to the result to allow chaining.
|
\return A reference to the result to allow chaining.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
Vector<Size, Type>& Vector<Size, Type>::operator=(const Vector<Size, Type>& rhs)
|
Vector<Size, StorageType, OperationType>& Vector<Size, StorageType, OperationType>::operator=(const Vector<Size, StorageType, OperationType>& rhs)
|
||||||
{
|
{
|
||||||
if(this == &rhs)
|
if(this == &rhs)
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
std::memcpy(m_tElements, rhs.m_tElements, sizeof(Type) * Size);
|
std::memcpy(m_tElements, rhs.m_tElements, sizeof(StorageType) * Size);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +167,8 @@ namespace PolyVox
|
|||||||
\return true if the Vectors match.
|
\return true if the Vectors match.
|
||||||
\see operator!=
|
\see operator!=
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline bool Vector<Size, Type>::operator==(const Vector<Size, Type> &rhs) const
|
inline bool Vector<Size, StorageType, OperationType>::operator==(const Vector<Size, StorageType, OperationType> &rhs) const
|
||||||
{
|
{
|
||||||
bool equal = true;
|
bool equal = true;
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
@ -156,8 +188,8 @@ namespace PolyVox
|
|||||||
\return true if the Vectors do not match.
|
\return true if the Vectors do not match.
|
||||||
\see operator==
|
\see operator==
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline bool Vector<Size, Type>::operator!=(const Vector<Size, Type> &rhs) const
|
inline bool Vector<Size, StorageType, OperationType>::operator!=(const Vector<Size, StorageType, OperationType> &rhs) const
|
||||||
{
|
{
|
||||||
return !(*this == rhs); //Just call equality operator and invert the result.
|
return !(*this == rhs); //Just call equality operator and invert the result.
|
||||||
}
|
}
|
||||||
@ -169,8 +201,8 @@ namespace PolyVox
|
|||||||
\return true if this is less than the parameter
|
\return true if this is less than the parameter
|
||||||
\see operator!=
|
\see operator!=
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline bool Vector<Size, Type>::operator<(const Vector<Size, Type> &rhs) const
|
inline bool Vector<Size, StorageType, OperationType>::operator<(const Vector<Size, StorageType, OperationType> &rhs) const
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
@ -187,8 +219,8 @@ namespace PolyVox
|
|||||||
\param rhs Vector to add
|
\param rhs Vector to add
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Vector<Size, Type>& Vector<Size, Type>::operator+=(const Vector<Size, Type>& rhs)
|
inline Vector<Size, StorageType, OperationType>& Vector<Size, StorageType, OperationType>::operator+=(const Vector<Size, StorageType, OperationType>& rhs)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
@ -202,8 +234,8 @@ namespace PolyVox
|
|||||||
\param rhs Vector to subtract
|
\param rhs Vector to subtract
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Vector<Size, Type>& Vector<Size, Type>::operator-=(const Vector<Size, Type>& rhs)
|
inline Vector<Size, StorageType, OperationType>& Vector<Size, StorageType, OperationType>::operator-=(const Vector<Size, StorageType, OperationType>& rhs)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
@ -217,8 +249,8 @@ namespace PolyVox
|
|||||||
\param rhs Vector to multiply by
|
\param rhs Vector to multiply by
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Vector<Size, Type>& Vector<Size, Type>::operator*=(const Vector<Size, Type>& rhs)
|
inline Vector<Size, StorageType, OperationType>& Vector<Size, StorageType, OperationType>::operator*=(const Vector<Size, StorageType, OperationType>& rhs)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
@ -232,8 +264,8 @@ namespace PolyVox
|
|||||||
\param rhs Vector to divide by
|
\param rhs Vector to divide by
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Vector<Size, Type>& Vector<Size, Type>::operator/=(const Vector<Size, Type>& rhs)
|
inline Vector<Size, StorageType, OperationType>& Vector<Size, StorageType, OperationType>::operator/=(const Vector<Size, StorageType, OperationType>& rhs)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
@ -247,8 +279,8 @@ namespace PolyVox
|
|||||||
\param rhs the number the Vector is multiplied by.
|
\param rhs the number the Vector is multiplied by.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Vector<Size, Type>& Vector<Size, Type>::operator*=(const Type& rhs)
|
inline Vector<Size, StorageType, OperationType>& Vector<Size, StorageType, OperationType>::operator*=(const StorageType& rhs)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
@ -262,8 +294,8 @@ namespace PolyVox
|
|||||||
\param rhs the number the Vector is divided by.
|
\param rhs the number the Vector is divided by.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Vector<Size, Type>& Vector<Size, Type>::operator/=(const Type& rhs)
|
inline Vector<Size, StorageType, OperationType>& Vector<Size, StorageType, OperationType>::operator/=(const StorageType& rhs)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
@ -278,10 +310,10 @@ namespace PolyVox
|
|||||||
\param rhs Vector to add.
|
\param rhs Vector to add.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs)
|
Vector<Size,StorageType,OperationType> operator+(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs)
|
||||||
{
|
{
|
||||||
Vector<Size,Type> result = lhs;
|
Vector<Size,StorageType,OperationType> result = lhs;
|
||||||
result += rhs;
|
result += rhs;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -292,10 +324,10 @@ namespace PolyVox
|
|||||||
\param rhs Vector to subtract.
|
\param rhs Vector to subtract.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs)
|
Vector<Size,StorageType,OperationType> operator-(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs)
|
||||||
{
|
{
|
||||||
Vector<Size,Type> result = lhs;
|
Vector<Size,StorageType,OperationType> result = lhs;
|
||||||
result -= rhs;
|
result -= rhs;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -306,10 +338,10 @@ namespace PolyVox
|
|||||||
\param rhs Vector to multiply by.
|
\param rhs Vector to multiply by.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs)
|
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs)
|
||||||
{
|
{
|
||||||
Vector<Size,Type> result = lhs;
|
Vector<Size,StorageType,OperationType> result = lhs;
|
||||||
result *= rhs;
|
result *= rhs;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -320,10 +352,10 @@ namespace PolyVox
|
|||||||
\param rhs Vector to divide by.
|
\param rhs Vector to divide by.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs)
|
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const Vector<Size,StorageType,OperationType>& rhs)
|
||||||
{
|
{
|
||||||
Vector<Size,Type> result = lhs;
|
Vector<Size,StorageType,OperationType> result = lhs;
|
||||||
result /= rhs;
|
result /= rhs;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -334,10 +366,10 @@ namespace PolyVox
|
|||||||
\param rhs the number the Vector is multiplied by.
|
\param rhs the number the Vector is multiplied by.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs)
|
Vector<Size,StorageType,OperationType> operator*(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs)
|
||||||
{
|
{
|
||||||
Vector<Size,Type> result = lhs;
|
Vector<Size,StorageType,OperationType> result = lhs;
|
||||||
result *= rhs;
|
result *= rhs;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -348,10 +380,10 @@ namespace PolyVox
|
|||||||
\param rhs the number the Vector is divided by.
|
\param rhs the number the Vector is divided by.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs)
|
Vector<Size,StorageType,OperationType> operator/(const Vector<Size,StorageType,OperationType>& lhs, const StorageType& rhs)
|
||||||
{
|
{
|
||||||
Vector<Size,Type> result = lhs;
|
Vector<Size,StorageType,OperationType> result = lhs;
|
||||||
result /= rhs;
|
result /= rhs;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -362,8 +394,8 @@ namespace PolyVox
|
|||||||
\param vector The Vector to write to the stream.
|
\param vector The Vector to write to the stream.
|
||||||
\return A reference to the output stream to allow chaining.
|
\return A reference to the output stream to allow chaining.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
std::ostream& operator<<(std::ostream& os, const Vector<Size, Type>& vector)
|
std::ostream& operator<<(std::ostream& os, const Vector<Size, StorageType, OperationType>& vector)
|
||||||
{
|
{
|
||||||
os << "(";
|
os << "(";
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
@ -383,45 +415,54 @@ namespace PolyVox
|
|||||||
\param index The index of the element to return.
|
\param index The index of the element to return.
|
||||||
\return The element.
|
\return The element.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Type Vector<Size, Type>::getElement(uint32_t index) const
|
inline StorageType Vector<Size, StorageType, OperationType>::getElement(uint32_t index) const
|
||||||
{
|
{
|
||||||
|
assert(index < Size);
|
||||||
return m_tElements[index];
|
return m_tElements[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\return A const reference to the X component of a 1, 2, 3, or 4 dimensional Vector.
|
\return A const reference to the X component of a 1, 2, 3, or 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Type Vector<Size, Type>::getX(void) const
|
inline StorageType Vector<Size, StorageType, OperationType>::getX(void) const
|
||||||
{
|
{
|
||||||
return m_tElements[0];
|
return m_tElements[0]; // This is fine, a Vector always contains at least two elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\return A const reference to the Y component of a 2, 3, or 4 dimensional Vector.
|
\return A const reference to the Y component of a 2, 3, or 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Type Vector<Size, Type>::getY(void) const
|
inline StorageType Vector<Size, StorageType, OperationType>::getY(void) const
|
||||||
{
|
{
|
||||||
return m_tElements[1];
|
return m_tElements[1]; // This is fine, a Vector always contains at least two elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\return A const reference to the Z component of a 3 or 4 dimensional Vector.
|
\return A const reference to the Z component of a 3 or 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Type Vector<Size, Type>::getZ(void) const
|
inline StorageType Vector<Size, StorageType, OperationType>::getZ(void) const
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size >= 3, "You can only get the 'z' component from a vector with at least three elements.");
|
||||||
|
#endif
|
||||||
|
|
||||||
return m_tElements[2];
|
return m_tElements[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\return A const reference to the W component of a 4 dimensional Vector.
|
\return A const reference to the W component of a 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Type Vector<Size, Type>::getW(void) const
|
inline StorageType Vector<Size, StorageType, OperationType>::getW(void) const
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all getters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size >= 4, "You can only get the 'w' component from a vector with at least four elements.");
|
||||||
|
#endif
|
||||||
|
|
||||||
return m_tElements[3];
|
return m_tElements[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,9 +470,10 @@ namespace PolyVox
|
|||||||
\param index The index of the element to set.
|
\param index The index of the element to set.
|
||||||
\param tValue The new value for the element.
|
\param tValue The new value for the element.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size, Type>::setElement(uint32_t index, Type tValue)
|
inline void Vector<Size, StorageType, OperationType>::setElement(uint32_t index, StorageType tValue)
|
||||||
{
|
{
|
||||||
|
assert(index < Size);
|
||||||
m_tElements[index] = tValue;
|
m_tElements[index] = tValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,12 +482,12 @@ namespace PolyVox
|
|||||||
\param x x component to set.
|
\param x x component to set.
|
||||||
\param y y component to set.
|
\param y y component to set.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size,Type>::setElements(Type x, Type y)
|
inline void Vector<Size,StorageType,OperationType>::setElements(StorageType x, StorageType y)
|
||||||
{
|
{
|
||||||
|
// This is fine, a Vector always contains at least two elements.
|
||||||
m_tElements[0] = x;
|
m_tElements[0] = x;
|
||||||
m_tElements[1] = y;
|
m_tElements[1] = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -454,13 +496,15 @@ namespace PolyVox
|
|||||||
\param y y component to set.
|
\param y y component to set.
|
||||||
\param z z component to set.
|
\param z z component to set.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size,Type>::setElements(Type x, Type y, Type z)
|
inline void Vector<Size,StorageType,OperationType>::setElements(StorageType x, StorageType y, StorageType z)
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size >= 3, "You can only use this version of setElements() on a vector with at least three elements.");
|
||||||
|
#endif
|
||||||
m_tElements[0] = x;
|
m_tElements[0] = x;
|
||||||
m_tElements[1] = y;
|
m_tElements[1] = y;
|
||||||
m_tElements[2] = z;
|
m_tElements[2] = z;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,9 +514,12 @@ namespace PolyVox
|
|||||||
\param z z component to set.
|
\param z z component to set.
|
||||||
\param w w component to set.
|
\param w w component to set.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size,typename Type>
|
template <uint32_t Size,typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size,Type>::setElements(Type x, Type y, Type z, Type w)
|
inline void Vector<Size,StorageType,OperationType>::setElements(StorageType x, StorageType y, StorageType z, StorageType w)
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size >= 4, "You can only use this version of setElements() on a vector with at least four elements.");
|
||||||
|
#endif
|
||||||
m_tElements[0] = x;
|
m_tElements[0] = x;
|
||||||
m_tElements[1] = y;
|
m_tElements[1] = y;
|
||||||
m_tElements[2] = z;
|
m_tElements[2] = z;
|
||||||
@ -482,36 +529,42 @@ namespace PolyVox
|
|||||||
/**
|
/**
|
||||||
\param tX The new value for the X component of a 1, 2, 3, or 4 dimensional Vector.
|
\param tX The new value for the X component of a 1, 2, 3, or 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size, Type>::setX(Type tX)
|
inline void Vector<Size, StorageType, OperationType>::setX(StorageType tX)
|
||||||
{
|
{
|
||||||
m_tElements[0] = tX;
|
m_tElements[0] = tX; // This is fine, a Vector always contains at least two elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\param tY The new value for the Y component of a 2, 3, or 4 dimensional Vector.
|
\param tY The new value for the Y component of a 2, 3, or 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size, Type>::setY(Type tY)
|
inline void Vector<Size, StorageType, OperationType>::setY(StorageType tY)
|
||||||
{
|
{
|
||||||
m_tElements[1] = tY;
|
m_tElements[1] = tY; // This is fine, a Vector always contains at least two elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\param tZ The new value for the Z component of a 3 or 4 dimensional Vector.
|
\param tZ The new value for the Z component of a 3 or 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size, Type>::setZ(Type tZ)
|
inline void Vector<Size, StorageType, OperationType>::setZ(StorageType tZ)
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size >= 3, "You can only set the 'w' component from a vector with at least three elements.");
|
||||||
|
#endif
|
||||||
m_tElements[2] = tZ;
|
m_tElements[2] = tZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\param tW The new value for the W component of a 4 dimensional Vector.
|
\param tW The new value for the W component of a 4 dimensional Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size, Type>::setW(Type tW)
|
inline void Vector<Size, StorageType, OperationType>::setW(StorageType tW)
|
||||||
{
|
{
|
||||||
|
#ifndef SWIGPYTHON // SWIG instantiates all setters, unless we can find a way around that. Should we use SWIGIMPORT here, and then %import this file rather then %include it?
|
||||||
|
static_assert(Size >= 4, "You can only set the 'w' component from a vector with at least four elements.");
|
||||||
|
#endif
|
||||||
m_tElements[3] = tW;
|
m_tElements[3] = tW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,8 +572,8 @@ namespace PolyVox
|
|||||||
\note This function does not make much sense on integer Vectors.
|
\note This function does not make much sense on integer Vectors.
|
||||||
\return Length of the Vector.
|
\return Length of the Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline double Vector<Size, Type>::length(void) const
|
inline double Vector<Size, StorageType, OperationType>::length(void) const
|
||||||
{
|
{
|
||||||
return sqrt(lengthSquared());
|
return sqrt(lengthSquared());
|
||||||
}
|
}
|
||||||
@ -528,8 +581,8 @@ namespace PolyVox
|
|||||||
/**
|
/**
|
||||||
\return Squared length of the Vector.
|
\return Squared length of the Vector.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline double Vector<Size, Type>::lengthSquared(void) const
|
inline double Vector<Size, StorageType, OperationType>::lengthSquared(void) const
|
||||||
{
|
{
|
||||||
double result = 0.0f;
|
double result = 0.0f;
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
@ -548,8 +601,8 @@ namespace PolyVox
|
|||||||
\param vector The Vector to find the angle to.
|
\param vector The Vector to find the angle to.
|
||||||
\return The angle between them in radians.
|
\return The angle between them in radians.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline double Vector<Size, Type>::angleTo(const Vector<Size, Type>& vector) const
|
inline double Vector<Size, StorageType, OperationType>::angleTo(const Vector<Size, StorageType, OperationType>& vector) const
|
||||||
{
|
{
|
||||||
return acos(dot(vector) / (vector.length() * this->length()));
|
return acos(dot(vector) / (vector.length() * this->length()));
|
||||||
}
|
}
|
||||||
@ -566,13 +619,13 @@ namespace PolyVox
|
|||||||
\return The value of the cross product.
|
\return The value of the cross product.
|
||||||
\see dot()
|
\see dot()
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Vector<Size, Type> Vector<Size, Type>::cross(const Vector<Size, Type>& vector) const
|
inline Vector<Size, StorageType, OperationType> Vector<Size, StorageType, OperationType>::cross(const Vector<Size, StorageType, OperationType>& vector) const
|
||||||
{
|
{
|
||||||
Type i = vector.getZ() * this->getY() - vector.getY() * this->getZ();
|
StorageType i = vector.getZ() * this->getY() - vector.getY() * this->getZ();
|
||||||
Type j = vector.getX() * this->getZ() - vector.getZ() * this->getX();
|
StorageType j = vector.getX() * this->getZ() - vector.getZ() * this->getX();
|
||||||
Type k = vector.getY() * this->getX() - vector.getX() * this->getY();
|
StorageType k = vector.getY() * this->getX() - vector.getX() * this->getY();
|
||||||
return Vector<Size, Type>(i,j,k);
|
return Vector<Size, StorageType, OperationType>(i,j,k);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -582,10 +635,10 @@ namespace PolyVox
|
|||||||
\return The value of the dot product.
|
\return The value of the dot product.
|
||||||
\see cross()
|
\see cross()
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline Type Vector<Size, Type>::dot(const Vector<Size, Type>& rhs) const
|
inline StorageType Vector<Size, StorageType, OperationType>::dot(const Vector<Size, StorageType, OperationType>& rhs) const
|
||||||
{
|
{
|
||||||
Type dotProduct = static_cast<Type>(0);
|
StorageType dotProduct = static_cast<StorageType>(0);
|
||||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||||
{
|
{
|
||||||
dotProduct += m_tElements[ct] * rhs.m_tElements[ct];
|
dotProduct += m_tElements[ct] * rhs.m_tElements[ct];
|
||||||
@ -598,10 +651,10 @@ namespace PolyVox
|
|||||||
|
|
||||||
\note This function does not make much sense on integer Vectors.
|
\note This function does not make much sense on integer Vectors.
|
||||||
*/
|
*/
|
||||||
template <uint32_t Size, typename Type>
|
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||||
inline void Vector<Size, Type>::normalise(void)
|
inline void Vector<Size, StorageType, OperationType>::normalise(void)
|
||||||
{
|
{
|
||||||
Type tLength = static_cast<Type>(this->length());
|
StorageType tLength = static_cast<StorageType>(this->length());
|
||||||
//FIXME - throw div by zero exception?
|
//FIXME - throw div by zero exception?
|
||||||
if(tLength < 0.0001f)
|
if(tLength < 0.0001f)
|
||||||
{
|
{
|
||||||
|
@ -22,25 +22,25 @@ PROPERTY(PolyVox::Vector, z, getZ, setZ)
|
|||||||
PolyVox::Vector __div__(const PolyVox::Vector& rhs) {
|
PolyVox::Vector __div__(const PolyVox::Vector& rhs) {
|
||||||
return *$self / rhs;
|
return *$self / rhs;
|
||||||
}
|
}
|
||||||
PolyVox::Vector __div__(const Type& rhs) {
|
PolyVox::Vector __div__(const StorageType& rhs) {
|
||||||
return *$self / rhs;
|
return *$self / rhs;
|
||||||
}
|
}
|
||||||
PolyVox::Vector __mul__(const PolyVox::Vector& rhs) {
|
PolyVox::Vector __mul__(const PolyVox::Vector& rhs) {
|
||||||
return *$self * rhs;
|
return *$self * rhs;
|
||||||
}
|
}
|
||||||
PolyVox::Vector __mul__(const Type& rhs) {
|
PolyVox::Vector __mul__(const StorageType& rhs) {
|
||||||
return *$self * rhs;
|
return *$self * rhs;
|
||||||
}
|
}
|
||||||
STR()
|
STR()
|
||||||
};
|
};
|
||||||
|
|
||||||
%template(Vector3DFloat) PolyVox::Vector<3,float>;
|
%template(Vector3DFloat) PolyVox::Vector<3,float,float>;
|
||||||
%template(Vector3DDouble) PolyVox::Vector<3,double>;
|
%template(Vector3DDouble) PolyVox::Vector<3,double,double>;
|
||||||
%template(Vector3DInt8) PolyVox::Vector<3,int8_t>;
|
%template(Vector3DInt8) PolyVox::Vector<3,int8_t,int32_t>;
|
||||||
%template(Vector3DUint8) PolyVox::Vector<3,uint8_t>;
|
%template(Vector3DUint8) PolyVox::Vector<3,uint8_t,int32_t>;
|
||||||
%template(Vector3DInt16) PolyVox::Vector<3,int16_t>;
|
%template(Vector3DInt16) PolyVox::Vector<3,int16_t,int32_t>;
|
||||||
%template(Vector3DUint16) PolyVox::Vector<3,uint16_t>;
|
%template(Vector3DUint16) PolyVox::Vector<3,uint16_t,int32_t>;
|
||||||
%template(Vector3DInt32) PolyVox::Vector<3,int32_t>;
|
%template(Vector3DInt32) PolyVox::Vector<3,int32_t,int32_t>;
|
||||||
%template(Vector3DUint32) PolyVox::Vector<3,uint32_t>;
|
%template(Vector3DUint32) PolyVox::Vector<3,uint32_t,int32_t>;
|
||||||
|
|
||||||
//%rename(assign) Vector3DFloat::operator=;
|
//%rename(assign) Vector3DFloat::operator=;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user