mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-28 02:04:17 +01:00
Reappropriate vexlib math headers into FasTC.
This commit is contained in:
parent
63a235958d
commit
cb348c3598
47
Base/include/Matrix3x3.h
Normal file
47
Base/include/Matrix3x3.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pavel Krajcevski
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef BASE_INCLUDE_MATRIX3X3_H_
|
||||
#define BASE_INCLUDE_MATRIX3X3_H_
|
||||
|
||||
#include "MatrixSquare.h"
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
template <typename T>
|
||||
class Matrix3x3 : public MatrixSquare<T, 3> {
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
Matrix3x3() { }
|
||||
Matrix3x3(const MatrixSquare<T, 3> &other) {
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
mat[i] = other[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BASE_INCLUDE_MATRIX3X3_H_
|
191
Base/include/MatrixBase.h
Normal file
191
Base/include/MatrixBase.h
Normal file
@ -0,0 +1,191 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pavel Krajcevski
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef BASE_INCLUDE_MATRIXBASE_H__
|
||||
#define BASE_INCLUDE_MATRIXBASE_H__
|
||||
|
||||
#include "VectorBase.h"
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
template <typename T, const int nRows, const int nCols>
|
||||
class MatrixBase {
|
||||
protected:
|
||||
|
||||
// Vector representation
|
||||
static const int kNumElements = nRows * nCols;
|
||||
T mat[kNumElements];
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
MatrixBase() { }
|
||||
MatrixBase(const MatrixBase<T, nRows, nCols> &other) {
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
mat[i] = other[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Accessors
|
||||
T &operator()(int idx) { return mat[idx]; }
|
||||
const T &operator()(int idx) const { return mat[idx]; }
|
||||
T &operator()(int r, int c) { return mat[r * nCols + c]; }
|
||||
const T &operator() const (int r, int c) { return mat[r * nCols + c]; }
|
||||
|
||||
T &operator[](int idx) { return mat[idx]; }
|
||||
const T &operator[](int idx) const { return mat[idx]; }
|
||||
|
||||
// Operators
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> operator+(const MatrixBase<_T, nRows, nCols> &m) {
|
||||
MatrixBase<T, nRows, nCols> a;
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
a[i] = mat[i] + m[i];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> &operator+=(const MatrixBase<_T, nRows, nCols> &m) {
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
mat[i] += m[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> operator-(const MatrixBase<_T, nRows, nCols> &m) {
|
||||
MatrixBase<T, nRows, nCols> a;
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
a[i] = mat[i] - m[i];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> &operator-=(const MatrixBase<_T, nRows, nCols> &m) {
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
mat[i] -= m[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> operator*(_T s) {
|
||||
MatrixBase<T, nRows, nCols> a;
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
a[i] = mat[i] * s;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> &operator*=(_T s) {
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
mat[i] *= s;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> operator/(_T s) {
|
||||
MatrixBase<T, nRows, nCols> a;
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
a[i] = mat[i] / s;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
MatrixBase<T, nRows, nCols> &operator/=(_T s) {
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
mat[i] /= s;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Matrix multiplication
|
||||
template<typename _T, const int nTarget>
|
||||
MatrixBase<T, nRows, nTarget> operator*(const MatrixBase<_T, nCols, nTarget> &m) {
|
||||
MatrixBase<T, nRows, nTarget> result;
|
||||
for(int r = 0; r < nRows; r++)
|
||||
for(int c = 0; c < nTarget; c++) {
|
||||
result(r, c) = 0;
|
||||
for(int j = 0; j < nCols; j++) {
|
||||
result(r, c) += (*this)(r, j) * m(j, c);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Vector multiplication -- treat vectors as Nx1 matrices...
|
||||
template<typename _T>
|
||||
VectorBase<T, nCols> operator*(const VectorBase<_T, nCols> &v) {
|
||||
VectorBase<T, nCols> result;
|
||||
for(int r = 0; r < nRows; r++) {
|
||||
result(r) = 0;
|
||||
for(int j = 0; j < nCols; j++) {
|
||||
result(r) += (*this)(r, j) * v(j);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Outer product...
|
||||
template<typename _T, typename _U, const int N, const int M>
|
||||
friend MatrixBase<_T, N, M> operator^(
|
||||
const VectorBase<_T, N> &a,
|
||||
const VectorBase<_U, M> &b
|
||||
) {
|
||||
MatrixBase<_T, N, M> result;
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
for(int j = 0; j < M; j++)
|
||||
result(i, j) = a[i] * b[j];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename _T, typename _U, const int N, const int M>
|
||||
friend MatrixBase<_T, N, M> OuterProduct(
|
||||
const VectorBase<_T, N> &a,
|
||||
const VectorBase<_U, M> &b
|
||||
) {
|
||||
return a ^ b;
|
||||
}
|
||||
|
||||
// Double dot product
|
||||
template<typename _T>
|
||||
T DDot(const MatrixBase<_T, nRows, nCols> &m) {
|
||||
T result = 0;
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
result += mat[i] * m[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BASE_INCLUDE_MATRIXBASE_H_
|
46
Base/include/MatrixSquare.h
Normal file
46
Base/include/MatrixSquare.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pavel Krajcevski
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef BASE_INCLUDE_MATRIXSQUARE_H_
|
||||
#define BASE_INCLUDE_MATRIXSQUARE_H_
|
||||
|
||||
#include "MatrixBase.h"
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
template <typename T, const int N>
|
||||
class MatrixSquare : public MatrixBase<T, N, N> {
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
MatrixSquare() { }
|
||||
MatrixSquare(const MatrixBase<T, N, N> &other) {
|
||||
for(int i = 0; i < kNumElements; i++) {
|
||||
mat[i] = other[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BASE_INCLUDE_MATRIXSQUARE_H_
|
80
Base/include/Vector2.h
Normal file
80
Base/include/Vector2.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pavel Krajcevski
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef BASE_INCLUDE_VECTOR2_H_
|
||||
#define BASE_INCLUDE_VECTOR2_H_
|
||||
|
||||
#include "VectorBase.h"
|
||||
|
||||
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||
# define _VEX_VEC2_SWIZZLE_DEF(X, Y) \
|
||||
Vector2<T> X##Y() const { return Vector2<T>( X(), Y() ); }
|
||||
#endif // _VEX_ENABLE_SWIZZLE_
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
template<typename T>
|
||||
class Vector2 : public VectorBase<T, 2> {
|
||||
public:
|
||||
// Ideally, we would be able to do this with initialization
|
||||
// lists, but I'm not really sure how to do that without gross
|
||||
// code duplication.
|
||||
Vector2() { }
|
||||
Vector2(T x, T y) {
|
||||
X() = x;
|
||||
Y() = y;
|
||||
}
|
||||
|
||||
// Overloaded functions
|
||||
template<typename _T>
|
||||
Vector2(const Vector2<_T> &v) : VectorBase<T, 2>(v) { }
|
||||
|
||||
template<typename _T>
|
||||
Vector2<T> &operator=(const Vector2<_T> &v) {
|
||||
VectorBase<T, 2>::operator=(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Accessors
|
||||
T &X() { return (*this)[0]; }
|
||||
const T &X() const { return (*this)[0]; }
|
||||
|
||||
T &Y() { return (*this)[1]; }
|
||||
const T &Y() const { return (*this)[1]; }
|
||||
|
||||
// Swizzle
|
||||
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, Y)
|
||||
#endif //_VEX_ENABLE_SWIZZLE_
|
||||
};
|
||||
|
||||
typedef Vector2<float> Vec2f;
|
||||
typedef Vector2<double> Vec2d;
|
||||
typedef Vector2<int> Vec2i;
|
||||
};
|
||||
|
||||
#endif // BASE_INCLUDE_VECTOR2_H_
|
124
Base/include/Vector3.h
Normal file
124
Base/include/Vector3.h
Normal file
@ -0,0 +1,124 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pavel Krajcevski
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef BASE_INCLUDE_VECTOR3_H_
|
||||
#define BASE_INCLUDE_VECTOR3_H_
|
||||
|
||||
#include "Vector2.h"
|
||||
|
||||
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||
# define _VEX_VEC3_SWIZZLE_DEF(X, Y, Z) \
|
||||
Vector3<T> X##Y##Z() const { return Vector3<T>( X(), Y(), Z() ); }
|
||||
#endif // _VEX_ENABLE_SWIZZLE_
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
template <typename T>
|
||||
class Vector3 : public VectorBase<T, 3> {
|
||||
public:
|
||||
Vector3() { }
|
||||
Vector3(T x, T y, T z) {
|
||||
X() = x;
|
||||
Y() = y;
|
||||
Z() = z;
|
||||
}
|
||||
|
||||
// Overloaded functions
|
||||
template<typename _T>
|
||||
Vector3(const Vector3<_T> &v) : VectorBase<T, 3>(v) { }
|
||||
|
||||
template<typename _T>
|
||||
Vector3<T> &operator=(const Vector3<_T> &v) {
|
||||
VectorBase<T, 3>::operator=(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Accessors
|
||||
T &X() { return (*this)[0]; }
|
||||
const T &X() const { return (*this)[0]; }
|
||||
|
||||
T &Y() { return (*this)[1]; }
|
||||
const T &Y() const { return (*this)[1]; }
|
||||
|
||||
T &Z() { return (*this)[2]; }
|
||||
const T &Z() const { return (*this)[2]; }
|
||||
|
||||
// Vector operations
|
||||
template<typename _T>
|
||||
Vector3<T> Cross(const Vector3<_T> &v) {
|
||||
return Vector3<T>(
|
||||
Y() * v.Z() - v.Y() * Z(),
|
||||
Z() * v.X() - v.Z() * X(),
|
||||
X() * v.Y() - v.X() * Y()
|
||||
);
|
||||
}
|
||||
|
||||
// Swizzle
|
||||
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, Z)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, Z)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Z, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Z, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Z, Z)
|
||||
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, X, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, X, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, X, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Y, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Y, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Y, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Z, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Z, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Z, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, X, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, X, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, X, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, Y, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, Y, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, Y, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, Z, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, Z, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Y, Z, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, X, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, X, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, X, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, Y, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, Y, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, Y, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, Z, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, Z, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(Z, Z, Z)
|
||||
#endif // _VEX_ENABLE_SWIZZLE_
|
||||
};
|
||||
|
||||
typedef Vector3<float> Vec3f;
|
||||
typedef Vector3<double> Vec3d;
|
||||
typedef Vector3<int> Vec3i;
|
||||
};
|
||||
|
||||
#endif // BASE_INCLUDE_VECTOR3_H_
|
420
Base/include/Vector4.h
Normal file
420
Base/include/Vector4.h
Normal file
@ -0,0 +1,420 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pavel Krajcevski
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef BASE_INCLUDE_VECTOR4_H_
|
||||
#define BASE_INCLUDE_VECTOR4_H_
|
||||
|
||||
#include "TexCompTypes.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||
#define _VEX_VEC4_SWIZZLE_DEF(X, Y, Z, W) \
|
||||
Vector4<T> X##Y##Z##W() const { return Vector4<T>( X(), Y(), Z(), W() ); }
|
||||
#endif // _VEX_ENABLE_SWIZZLE_
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
template <typename T>
|
||||
class Vector4 : public VectorBase<T, 4> {
|
||||
public:
|
||||
Vector4() { }
|
||||
Vector4(T x, T y, T z, T w) {
|
||||
X() = x;
|
||||
Y() = y;
|
||||
Z() = z;
|
||||
W() = w;
|
||||
}
|
||||
|
||||
// Overloaded functions
|
||||
template<typename _T>
|
||||
Vector4(const Vector4<_T> &v) : VectorBase<T, 4>(v) { }
|
||||
|
||||
template<typename _T>
|
||||
Vector4<T> &operator=(const Vector4<_T> &v) {
|
||||
VectorBase<T, 4>::operator=(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Accessors
|
||||
T &X() { return (*this)[0]; }
|
||||
const T &X() const { return (*this)[0]; }
|
||||
|
||||
T &Y() { return (*this)[1]; }
|
||||
const T &Y() const { return (*this)[1]; }
|
||||
|
||||
T &Z() { return (*this)[2]; }
|
||||
const T &Z() const { return (*this)[2]; }
|
||||
|
||||
T &W() { return (*this)[3]; }
|
||||
const T &W() const { return (*this)[3]; }
|
||||
|
||||
// Swizzle
|
||||
#ifdef _VEX_ENABLE_SWIZZLE_
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, Z)
|
||||
_VEX_VEC2_SWIZZLE_DEF(X, W)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, Z)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Y, W)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Z, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Z, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Z, Z)
|
||||
_VEX_VEC2_SWIZZLE_DEF(Z, W)
|
||||
_VEX_VEC2_SWIZZLE_DEF(W, X)
|
||||
_VEX_VEC2_SWIZZLE_DEF(W, Y)
|
||||
_VEX_VEC2_SWIZZLE_DEF(W, Z)
|
||||
_VEX_VEC2_SWIZZLE_DEF(W, W)
|
||||
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, X, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, X, Y)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, X, Z)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, X, W)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Y, X)
|
||||
_VEX_VEC3_SWIZZLE_DEF(X, Y,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LE_DEF(W, W, X, Y)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, X, Z)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, X, W)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, X)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, Y)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, Z)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Y, W)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, X)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, Y)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, Z)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, Z, W)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, W, X)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, W, Y)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, W, Z)
|
||||
_VEX_VEC4_SWIZZLE_DEF(W, W, W, W)
|
||||
#endif // _VEX_ENABLE_SWIZZLE_
|
||||
};
|
||||
|
||||
typedef Vector4<float> Vec4f;
|
||||
typedef Vector4<double> Vec4d;
|
||||
typedef Vector4<uint32> Vec4i;
|
||||
};
|
||||
|
||||
#endif // BASE_INCLUDE_VECTOR4_H_
|
171
Base/include/VectorBase.h
Normal file
171
Base/include/VectorBase.h
Normal file
@ -0,0 +1,171 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 Pavel Krajcevski
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef BASE_INCLUDE_VECTORBASE_H_
|
||||
#define BASE_INCLUDE_VECTORBASE_H_
|
||||
|
||||
// !FIXME! For sqrt function. This increases compilation time by a LOT
|
||||
// but I couldn't guarantee any faster general-purpose implementation
|
||||
#include <cmath>
|
||||
|
||||
namespace FasTC {
|
||||
|
||||
template <typename T, const int N>
|
||||
class VectorBase {
|
||||
protected:
|
||||
|
||||
// Vector representation
|
||||
T vec[N];
|
||||
|
||||
public:
|
||||
|
||||
VectorBase() { }
|
||||
VectorBase(const VectorBase<T, N> &other) {
|
||||
for(int i = 0; i < N; i++) vec[i] = other[i];
|
||||
}
|
||||
|
||||
explicit VectorBase(T *_vec) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
vec[i] = _vec[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Accessors
|
||||
T &operator()(int idx) { return vec[idx]; }
|
||||
T &operator[](int idx) { return vec[idx]; }
|
||||
const T &operator()(int idx) const { return vec[idx]; }
|
||||
const T &operator[](int idx) const { return vec[idx]; }
|
||||
|
||||
// Allow casts to the respective array representation...
|
||||
operator T *() const { return vec; }
|
||||
VectorBase<T, N> &operator=(const T *v) {
|
||||
for(int i = 0; i < N; i++)
|
||||
vec[i] = v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Allows casting to other vector types if the underlying type system does as well...
|
||||
template<typename _T>
|
||||
operator VectorBase<_T, N>() const {
|
||||
return VectorBase<_T, N>(vec);
|
||||
}
|
||||
|
||||
// Operators
|
||||
template<typename _T>
|
||||
VectorBase<T, N> operator+(const VectorBase<_T, N> &v) const {
|
||||
VectorBase a;
|
||||
for(int i = 0; i < N; i++)
|
||||
a.vec[i] = v(i) + vec[i];
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
VectorBase<T, N> &operator+=(const VectorBase<_T, N> &v) const {
|
||||
for(int i = 0; i < N; i++)
|
||||
vec[i] += v(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
VectorBase<T, N> operator-(const VectorBase<_T, N> &v) const {
|
||||
VectorBase<T, N> a;
|
||||
for(int i = 0; i < N; i++)
|
||||
a(i) = vec[i] - v[i];
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
VectorBase<T, N> &operator-=(const VectorBase<_T, N> &v) const {
|
||||
for(int i = 0; i < N; i++) {
|
||||
vec[i] -= v[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
VectorBase<T, N> &operator=(const VectorBase<_T, N> &v) {
|
||||
for(int i = 0; i < N; i++)
|
||||
vec[i] = v[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
VectorBase<T, N> operator*(const _T s) const {
|
||||
VectorBase<T, N> a;
|
||||
for(int i = 0; i < N; i++)
|
||||
a[i] = vec[i] * s;
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
friend VectorBase<T, N> operator*(const _T s, const VectorBase<T, N> &v) {
|
||||
VectorBase<T, N> a;
|
||||
for(int i = 0; i < N; i++)
|
||||
a[i] = v[i] * s;
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
VectorBase<T, N> operator/(const _T s) const {
|
||||
VectorBase<T, N> a;
|
||||
for(int i = 0; i < N; i++)
|
||||
a[i] = vec[i] / s;
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
friend VectorBase<T, N> operator/(const _T s, const VectorBase<T, N> &v) {
|
||||
VectorBase<T, N> a;
|
||||
for(int i = 0; i < N; i++)
|
||||
a[i] = v[i] / s;
|
||||
return a;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
void operator*=(const _T s) {
|
||||
for(int i = 0; i < N; i++)
|
||||
vec[i] *= s;
|
||||
}
|
||||
|
||||
template<typename _T>
|
||||
void operator/=(const _T s) {
|
||||
for(int i = 0; i < N; i++)
|
||||
vec[i] /= s;
|
||||
}
|
||||
|
||||
// Vector operations
|
||||
template<typename _T>
|
||||
T Dot(const VectorBase<_T, N> &v) const {
|
||||
T sum = 0;
|
||||
for(int i = 0; i < N; i++)
|
||||
sum += vec[i] * v[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
T LengthSq() const { return this->Dot(*this); }
|
||||
T Length() const { return sqrt(LengthSq()); }
|
||||
};
|
||||
};
|
||||
|
||||
#endif // BASE_INCLUDE_VECTORBASE_H_
|
Loading…
Reference in New Issue
Block a user