From cb348c359832d9934e840e461c114f9c8427aa6b Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Thu, 3 Oct 2013 17:19:28 -0400 Subject: [PATCH] Reappropriate vexlib math headers into FasTC. --- Base/include/Matrix3x3.h | 47 ++++ Base/include/MatrixBase.h | 191 ++++++++++++++++ Base/include/MatrixSquare.h | 46 ++++ Base/include/Vector2.h | 80 +++++++ Base/include/Vector3.h | 124 +++++++++++ Base/include/Vector4.h | 420 ++++++++++++++++++++++++++++++++++++ Base/include/VectorBase.h | 171 +++++++++++++++ 7 files changed, 1079 insertions(+) create mode 100644 Base/include/Matrix3x3.h create mode 100644 Base/include/MatrixBase.h create mode 100644 Base/include/MatrixSquare.h create mode 100644 Base/include/Vector2.h create mode 100644 Base/include/Vector3.h create mode 100644 Base/include/Vector4.h create mode 100644 Base/include/VectorBase.h diff --git a/Base/include/Matrix3x3.h b/Base/include/Matrix3x3.h new file mode 100644 index 0000000..b5d226b --- /dev/null +++ b/Base/include/Matrix3x3.h @@ -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 + class Matrix3x3 : public MatrixSquare { + + public: + + // Constructors + Matrix3x3() { } + Matrix3x3(const MatrixSquare &other) { + for(int i = 0; i < kNumElements; i++) { + mat[i] = other[i]; + } + } + }; +}; + +#endif // BASE_INCLUDE_MATRIX3X3_H_ diff --git a/Base/include/MatrixBase.h b/Base/include/MatrixBase.h new file mode 100644 index 0000000..3182b4b --- /dev/null +++ b/Base/include/MatrixBase.h @@ -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 + class MatrixBase { + protected: + + // Vector representation + static const int kNumElements = nRows * nCols; + T mat[kNumElements]; + + public: + + // Constructors + MatrixBase() { } + MatrixBase(const MatrixBase &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 + MatrixBase operator+(const MatrixBase<_T, nRows, nCols> &m) { + MatrixBase a; + for(int i = 0; i < kNumElements; i++) { + a[i] = mat[i] + m[i]; + } + return a; + } + + template + MatrixBase &operator+=(const MatrixBase<_T, nRows, nCols> &m) { + for(int i = 0; i < kNumElements; i++) { + mat[i] += m[i]; + } + return *this; + } + + template + MatrixBase operator-(const MatrixBase<_T, nRows, nCols> &m) { + MatrixBase a; + for(int i = 0; i < kNumElements; i++) { + a[i] = mat[i] - m[i]; + } + return a; + } + + template + MatrixBase &operator-=(const MatrixBase<_T, nRows, nCols> &m) { + for(int i = 0; i < kNumElements; i++) { + mat[i] -= m[i]; + } + return *this; + } + + template + MatrixBase operator*(_T s) { + MatrixBase a; + for(int i = 0; i < kNumElements; i++) { + a[i] = mat[i] * s; + } + return a; + } + + template + MatrixBase &operator*=(_T s) { + for(int i = 0; i < kNumElements; i++) { + mat[i] *= s; + } + return *this; + } + + template + MatrixBase operator/(_T s) { + MatrixBase a; + for(int i = 0; i < kNumElements; i++) { + a[i] = mat[i] / s; + } + return a; + } + + template + MatrixBase &operator/=(_T s) { + for(int i = 0; i < kNumElements; i++) { + mat[i] /= s; + } + return *this; + } + + // Matrix multiplication + template + MatrixBase operator*(const MatrixBase<_T, nCols, nTarget> &m) { + MatrixBase 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 + VectorBase operator*(const VectorBase<_T, nCols> &v) { + VectorBase 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 + 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 + friend MatrixBase<_T, N, M> OuterProduct( + const VectorBase<_T, N> &a, + const VectorBase<_U, M> &b + ) { + return a ^ b; + } + + // Double dot product + template + 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_ diff --git a/Base/include/MatrixSquare.h b/Base/include/MatrixSquare.h new file mode 100644 index 0000000..7fdfb48 --- /dev/null +++ b/Base/include/MatrixSquare.h @@ -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 + class MatrixSquare : public MatrixBase { + public: + + // Constructors + MatrixSquare() { } + MatrixSquare(const MatrixBase &other) { + for(int i = 0; i < kNumElements; i++) { + mat[i] = other[i]; + } + } + }; +}; + +#endif // BASE_INCLUDE_MATRIXSQUARE_H_ diff --git a/Base/include/Vector2.h b/Base/include/Vector2.h new file mode 100644 index 0000000..2c0edcd --- /dev/null +++ b/Base/include/Vector2.h @@ -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 X##Y() const { return Vector2( X(), Y() ); } +#endif // _VEX_ENABLE_SWIZZLE_ + +namespace FasTC { + + template + class Vector2 : public VectorBase { + 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 + Vector2(const Vector2<_T> &v) : VectorBase(v) { } + + template + Vector2 &operator=(const Vector2<_T> &v) { + VectorBase::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 Vec2f; + typedef Vector2 Vec2d; + typedef Vector2 Vec2i; +}; + +#endif // BASE_INCLUDE_VECTOR2_H_ diff --git a/Base/include/Vector3.h b/Base/include/Vector3.h new file mode 100644 index 0000000..3c32b46 --- /dev/null +++ b/Base/include/Vector3.h @@ -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 X##Y##Z() const { return Vector3( X(), Y(), Z() ); } +#endif // _VEX_ENABLE_SWIZZLE_ + +namespace FasTC { + + template + class Vector3 : public VectorBase { + public: + Vector3() { } + Vector3(T x, T y, T z) { + X() = x; + Y() = y; + Z() = z; + } + + // Overloaded functions + template + Vector3(const Vector3<_T> &v) : VectorBase(v) { } + + template + Vector3 &operator=(const Vector3<_T> &v) { + VectorBase::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 + Vector3 Cross(const Vector3<_T> &v) { + return Vector3( + 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 Vec3f; + typedef Vector3 Vec3d; + typedef Vector3 Vec3i; +}; + +#endif // BASE_INCLUDE_VECTOR3_H_ diff --git a/Base/include/Vector4.h b/Base/include/Vector4.h new file mode 100644 index 0000000..55f06ae --- /dev/null +++ b/Base/include/Vector4.h @@ -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 X##Y##Z##W() const { return Vector4( X(), Y(), Z(), W() ); } +#endif // _VEX_ENABLE_SWIZZLE_ + +namespace FasTC { + + template + class Vector4 : public VectorBase { + public: + Vector4() { } + Vector4(T x, T y, T z, T w) { + X() = x; + Y() = y; + Z() = z; + W() = w; + } + + // Overloaded functions + template + Vector4(const Vector4<_T> &v) : VectorBase(v) { } + + template + Vector4 &operator=(const Vector4<_T> &v) { + VectorBase::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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VEC3_SWIZZLE_DEF(W, W, Y) + _VEX_VEC3_SWIZZLE_DEF(W, W, Z) + _VEX_VEC3_SWIZZLE_DEF(W, W, W) + + _VEX_VEC4_SWIZZLE_DEF(X, X, X, X) + _VEX_VEC4_SWIZZLE_DEF(X, X, X, Y) + _VEX_VEC4_SWIZZLE_DEF(X, X, X, Z) + _VEX_VEC4_SWIZZLE_DEF(X, X, X, W) + _VEX_VEC4_SWIZZLE_DEF(X, X, Y, X) + _VEX_VEC4_SWIZZLE_DEF(X, X, Y, Y) + _VEX_VEC4_SWIZZLE_DEF(X, X, Y, Z) + _VEX_VEC4_SWIZZLE_DEF(X, X, Y, W) + _VEX_VEC4_SWIZZLE_DEF(X, X, Z, X) + _VEX_VEC4_SWIZZLE_DEF(X, X, Z, Y) + _VEX_VEC4_SWIZZLE_DEF(X, X, Z, Z) + _VEX_VEC4_SWIZZLE_DEF(X, X, Z, W) + _VEX_VEC4_SWIZZLE_DEF(X, X, W, X) + _VEX_VEC4_SWIZZLE_DEF(X, X, W, Y) + _VEX_VEC4_SWIZZLE_DEF(X, X, W, Z) + _VEX_VEC4_SWIZZLE_DEF(X, X, W, W) + _VEX_VEC4_SWIZZLE_DEF(X, Y, X, X) + _VEX_VEC4_SWIZZLE_DEF(X, Y, X, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Y, X, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Y, X, W) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Y, X) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Y, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Y, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Y, W) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Z, X) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Z, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Z, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Y, Z, W) + _VEX_VEC4_SWIZZLE_DEF(X, Y, W, X) + _VEX_VEC4_SWIZZLE_DEF(X, Y, W, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Y, W, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Y, W, W) + _VEX_VEC4_SWIZZLE_DEF(X, Z, X, X) + _VEX_VEC4_SWIZZLE_DEF(X, Z, X, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Z, X, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Z, X, W) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Y, X) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Y, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Y, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Y, W) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Z, X) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Z, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Z, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Z, Z, W) + _VEX_VEC4_SWIZZLE_DEF(X, Z, W, X) + _VEX_VEC4_SWIZZLE_DEF(X, Z, W, Y) + _VEX_VEC4_SWIZZLE_DEF(X, Z, W, Z) + _VEX_VEC4_SWIZZLE_DEF(X, Z, W, W) + _VEX_VEC4_SWIZZLE_DEF(X, W, X, X) + _VEX_VEC4_SWIZZLE_DEF(X, W, X, Y) + _VEX_VEC4_SWIZZLE_DEF(X, W, X, Z) + _VEX_VEC4_SWIZZLE_DEF(X, W, X, W) + _VEX_VEC4_SWIZZLE_DEF(X, W, Y, X) + _VEX_VEC4_SWIZZLE_DEF(X, W, Y, Y) + _VEX_VEC4_SWIZZLE_DEF(X, W, Y, Z) + _VEX_VEC4_SWIZZLE_DEF(X, W, Y, W) + _VEX_VEC4_SWIZZLE_DEF(X, W, Z, X) + _VEX_VEC4_SWIZZLE_DEF(X, W, Z, Y) + _VEX_VEC4_SWIZZLE_DEF(X, W, Z, Z) + _VEX_VEC4_SWIZZLE_DEF(X, W, Z, W) + _VEX_VEC4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Z, W, Y, Z) + _VEX_VEC4_SWIZZLE_DEF(Z, W, Y, W) + _VEX_VEC4_SWIZZLE_DEF(Z, W, Z, X) + _VEX_VEC4_SWIZZLE_DEF(Z, W, Z, Y) + _VEX_VEC4_SWIZZLE_DEF(Z, W, Z, Z) + _VEX_VEC4_SWIZZLE_DEF(Z, W, Z, W) + _VEX_VEC4_SWIZZLE_DEF(Z, W, W, X) + _VEX_VEC4_SWIZZLE_DEF(Z, W, W, Y) + _VEX_VEC4_SWIZZLE_DEF(Z, W, W, Z) + _VEX_VEC4_SWIZZLE_DEF(Z, W, W, W) + _VEX_VEC4_SWIZZLE_DEF(W, X, X, X) + _VEX_VEC4_SWIZZLE_DEF(W, X, X, Y) + _VEX_VEC4_SWIZZLE_DEF(W, X, X, Z) + _VEX_VEC4_SWIZZLE_DEF(W, X, X, W) + _VEX_VEC4_SWIZZLE_DEF(W, X, Y, X) + _VEX_VEC4_SWIZZLE_DEF(W, X, Y, Y) + _VEX_VEC4_SWIZZLE_DEF(W, X, Y, Z) + _VEX_VEC4_SWIZZLE_DEF(W, X, Y, W) + _VEX_VEC4_SWIZZLE_DEF(W, X, Z, X) + _VEX_VEC4_SWIZZLE_DEF(W, X, Z, Y) + _VEX_VEC4_SWIZZLE_DEF(W, X, Z, Z) + _VEX_VEC4_SWIZZLE_DEF(W, X, Z, W) + _VEX_VEC4_SWIZZLE_DEF(W, X, W, X) + _VEX_VEC4_SWIZZLE_DEF(W, X, W, Y) + _VEX_VEC4_SWIZZLE_DEF(W, X, W, Z) + _VEX_VEC4_SWIZZLE_DEF(W, X, W, W) + _VEX_VEC4_SWIZZLE_DEF(W, Y, X, X) + _VEX_VEC4_SWIZZLE_DEF(W, Y, X, Y) + _VEX_VEC4_SWIZZLE_DEF(W, Y, X, Z) + _VEX_VEC4_SWIZZLE_DEF(W, Y, X, W) + _VEX_VEC4_SWIZZLE_DEF(W, Y, Y, X) + _VEX_VEC4_SWIZZLE_DEF(W, Y, Y, Y) + _VEX_V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ZZLE_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 Vec4f; + typedef Vector4 Vec4d; + typedef Vector4 Vec4i; +}; + +#endif // BASE_INCLUDE_VECTOR4_H_ diff --git a/Base/include/VectorBase.h b/Base/include/VectorBase.h new file mode 100644 index 0000000..a7d892f --- /dev/null +++ b/Base/include/VectorBase.h @@ -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 + +namespace FasTC { + + template + class VectorBase { + protected: + + // Vector representation + T vec[N]; + + public: + + VectorBase() { } + VectorBase(const VectorBase &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 &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 + operator VectorBase<_T, N>() const { + return VectorBase<_T, N>(vec); + } + + // Operators + template + VectorBase 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 + VectorBase &operator+=(const VectorBase<_T, N> &v) const { + for(int i = 0; i < N; i++) + vec[i] += v(i); + return *this; + } + + template + VectorBase operator-(const VectorBase<_T, N> &v) const { + VectorBase a; + for(int i = 0; i < N; i++) + a(i) = vec[i] - v[i]; + return a; + } + + template + VectorBase &operator-=(const VectorBase<_T, N> &v) const { + for(int i = 0; i < N; i++) { + vec[i] -= v[i]; + } + return *this; + } + + template + VectorBase &operator=(const VectorBase<_T, N> &v) { + for(int i = 0; i < N; i++) + vec[i] = v[i]; + return *this; + } + + template + VectorBase operator*(const _T s) const { + VectorBase a; + for(int i = 0; i < N; i++) + a[i] = vec[i] * s; + return a; + } + + template + friend VectorBase operator*(const _T s, const VectorBase &v) { + VectorBase a; + for(int i = 0; i < N; i++) + a[i] = v[i] * s; + return a; + } + + template + VectorBase operator/(const _T s) const { + VectorBase a; + for(int i = 0; i < N; i++) + a[i] = vec[i] / s; + return a; + } + + template + friend VectorBase operator/(const _T s, const VectorBase &v) { + VectorBase a; + for(int i = 0; i < N; i++) + a[i] = v[i] / s; + return a; + } + + template + void operator*=(const _T s) { + for(int i = 0; i < N; i++) + vec[i] *= s; + } + + template + void operator/=(const _T s) { + for(int i = 0; i < N; i++) + vec[i] /= s; + } + + // Vector operations + template + 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_