From: chsieh Date: Thu, 23 Dec 2010 19:10:02 +0000 (-0800) Subject: Interim code. Integrating cocos2d. X-Git-Tag: box2d-testbed~32 X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=1b05afc7bed0e2ac55f61a6b6bfae65856aeee75;p=tanks-ios.git Interim code. Integrating cocos2d. --- diff --git a/Classes/Foundation/Common/GlobalDefines.h b/Classes/Foundation/Common/GlobalDefines.h index 7dde617..14712b2 100755 --- a/Classes/Foundation/Common/GlobalDefines.h +++ b/Classes/Foundation/Common/GlobalDefines.h @@ -70,9 +70,9 @@ //---------------------------------------------------------------------------------------- // alignment macros #if defined(__WINDOWS__) -#define ALIGN(N) __declspec(align(N)) +#define MEM_ALIGN(N) __declspec(align(N)) #elif defined(__iOS__) -#define ALIGN(N) __attribute__((aligned (N))) +#define MEM_ALIGN(N) __attribute__((aligned (N))) #endif #define IS_POWER_OF_TWO(x) ( ((x) & -(x)) == (x) ) diff --git a/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.h b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.h new file mode 100644 index 0000000..ba50ba9 --- /dev/null +++ b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.h @@ -0,0 +1,27 @@ +#pragma once + +#include "Foundation/Common/GlobalInclude.h" +#include "Foundation/Math/MathInclude.h" + +//#include +#include + +//---------------------------------------------------------------------------------------- +struct Basic2DPrimitive +{ +protected: + Basic2DPrimitive(); // Only the children classes can call this. + ~Basic2DPrimitive(); + + GLuint mVertexBuffer; + uint16_t mX, mY; +}; + +//---------------------------------------------------------------------------------------- +struct Rectangle : public Basic2DPrimitive +{ +public: + GLuint mWidth, mHeight; + + Rectangle( uint16_t width, uint16_t height, uint16_t anchorX, uint16_t anchorY ); +}; diff --git a/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.mm b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.mm new file mode 100644 index 0000000..4cc9da1 --- /dev/null +++ b/Classes/Foundation/GraphicsServices/Geometry/BasicPrimitives.mm @@ -0,0 +1,26 @@ +#include "BasicPrimitives.h" + +//---------------------------------------------------------------------------------------- +Basic2DPrimitive::Basic2DPrimitive() : mVertexBuffer(0), mX(0), mY(0) +{ + glGenBuffers( 1, &mVertexBuffer ); +} + +//---------------------------------------------------------------------------------------- +Basic2DPrimitive::~Basic2DPrimitive() +{ + glDeleteBuffers( 1, &mVertexBuffer ); +} + +//---------------------------------------------------------------------------------------- +Rectangle::Rectangle( uint16_t width, uint16_t height, uint16_t anchorX, uint16_t anchorY ) : Basic2DPrimitive() +{ + Assert( mVertexBuffer ); + glBindBuffer( GL_ARRAY_BUFFER, mVertexBuffer ); + + mWidth = width; + mHeight = height; + + uint16_t values[4 * 2] = {-anchorX, height + anchorY, -anchorX, }; + glBufferData( GL_ARRAY_BUFFER, 4 * 2 * sizeof(uint16_t), values, GL_STATIC_DRAW ); +} diff --git a/Classes/Foundation/GraphicsServices/OpenGLServices.h b/Classes/Foundation/GraphicsServices/OpenGLServices.h index 819ba12..deadd57 100644 --- a/Classes/Foundation/GraphicsServices/OpenGLServices.h +++ b/Classes/Foundation/GraphicsServices/OpenGLServices.h @@ -10,8 +10,8 @@ * we should never need to set context other than during startup or shutdown. *****************************************************************************************/ -#include -#include +//#include +//#include #include #include diff --git a/Classes/Foundation/GraphicsServices/OpenGLServices.mm b/Classes/Foundation/GraphicsServices/OpenGLServices.mm index 236059e..9c1f7a2 100644 --- a/Classes/Foundation/GraphicsServices/OpenGLServices.mm +++ b/Classes/Foundation/GraphicsServices/OpenGLServices.mm @@ -22,16 +22,21 @@ bool OpenGLServices::init( EAGLContext* mainContext ) initScratchMem(); - // Enable some common states. + // Enable some common states and set their parameters. glEnable( GL_TEXTURE_2D ); - glEnable( GL_BLEND ); - // We will premultiply alpha into the color channels of all textures (so no alpha animation). // This is basically the A over B alpha scheme. glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); - glEnable( GL_DEPTH_TEST ); + glDepthFunc( GL_LEQUAL ); + glFrontFace( GL_CCW ); + glCullFace( GL_BACK ); + + // Disable unused stuff. + glDisable( GL_STENCIL_TEST ); + glDisable( GL_SCISSOR_TEST ); + glDisable( GL_DITHER ); return true; } diff --git a/Classes/Foundation/Math/MathTypes.h b/Classes/Foundation/Math/MathTypes.h index c16a44e..379bf16 100755 --- a/Classes/Foundation/Math/MathTypes.h +++ b/Classes/Foundation/Math/MathTypes.h @@ -4,16 +4,16 @@ #include "Foundation/Math/MathOperations.h" //---------------------------------------------------------------------------------------- -struct Vector2 +struct Vec2 { float x; float y; - slInline explicit Vector2() {} - slInline explicit Vector2(const float xy) {x = xy; y = xy;} - slInline explicit Vector2(const float ix, const float iy) {x = ix; y = iy;} + slInline explicit Vec2() {} + slInline explicit Vec2(const float xy) {x = xy; y = xy;} + slInline explicit Vec2(const float ix, const float iy) {x = ix; y = iy;} - slInline Vector2(const Vector2& v) {x = v.x; y = v.y;} // copy constructor + slInline Vec2(const Vec2& v) {x = v.x; y = v.y;} // copy constructor slInline float* AsFloatArray() {return &x;} slInline const float* AsFloatArray() const {return &x;} @@ -23,21 +23,21 @@ struct Vector2 //---------------------------------------------------------------------------------------- -struct Vector3 +struct Vec3 { float x; float y; float z; - slInline explicit Vector3() {} - slInline explicit Vector3(const float xyz) {x = xyz; y = xyz; z = xyz;} - slInline explicit Vector3(const float ix, const float iy, const float iz) {x = ix; y = iy; z = iz;} + slInline explicit Vec3() {} + slInline explicit Vec3(const float xyz) {x = xyz; y = xyz; z = xyz;} + slInline explicit Vec3(const float ix, const float iy, const float iz) {x = ix; y = iy; z = iz;} - slInline explicit Vector3(const Vector2& v, const float iz) {x = v.x; y = v.y; z = iz;} + slInline explicit Vec3(const Vec2& v, const float iz) {x = v.x; y = v.y; z = iz;} - slInline Vector3(const Vector3& v) {x = v.x; y = v.y; z = v.z;} // copy constructor + slInline Vec3(const Vec3& v) {x = v.x; y = v.y; z = v.z;} // copy constructor - slInline Vector2 AsVector2() const {return Vector2(x, y);} + slInline Vec2 AsVec2() const {return Vec2(x, y);} slInline float* AsFloatArray() {return &x;} slInline const float* AsFloatArray() const {return &x;} @@ -47,27 +47,27 @@ struct Vector3 //---------------------------------------------------------------------------------------- -struct Vector4 +struct Vec4 { float x; float y; float z; float w; - slInline explicit Vector4() {} - slInline explicit Vector4(const float xyzw) {x = xyzw; y = xyzw; z = xyzw; w = xyzw;} - slInline explicit Vector4(const float xyz, const float iw) {x = xyz; y = xyz; z = xyz; w = iw;} - slInline explicit Vector4(const float ix, const float iy, const float iz, const float iw) {x = ix; y = iy; z = iz; w = iw;} + slInline explicit Vec4() {} + slInline explicit Vec4(const float xyzw) {x = xyzw; y = xyzw; z = xyzw; w = xyzw;} + slInline explicit Vec4(const float xyz, const float iw) {x = xyz; y = xyz; z = xyz; w = iw;} + slInline explicit Vec4(const float ix, const float iy, const float iz, const float iw) {x = ix; y = iy; z = iz; w = iw;} - slInline explicit Vector4(const Vector2& u, const Vector2& v) {x = u.x; y = u.y; z = v.x; w = v.y;} - slInline explicit Vector4(const Vector2& v, const float iz, const float iw) {x = v.x; y = v.y; z = iz; w = iw;} + slInline explicit Vec4(const Vec2& u, const Vec2& v) {x = u.x; y = u.y; z = v.x; w = v.y;} + slInline explicit Vec4(const Vec2& v, const float iz, const float iw) {x = v.x; y = v.y; z = iz; w = iw;} - slInline explicit Vector4(const Vector3& v, const float iw) {x = v.x; y = v.y; z = v.z; w = iw;} + slInline explicit Vec4(const Vec3& v, const float iw) {x = v.x; y = v.y; z = v.z; w = iw;} - slInline Vector4(const Vector4& v) {x = v.x; y = v.y; z = v.z; w = v.w;} // copy constructor + slInline Vec4(const Vec4& v) {x = v.x; y = v.y; z = v.z; w = v.w;} // copy constructor - slInline Vector2 AsVector2() const {return Vector2(x, y);} - slInline Vector3 AsVector3() const {return Vector3(x, y, z);} + slInline Vec2 AsVec2() const {return Vec2(x, y);} + slInline Vec3 AsVec3() const {return Vec3(x, y, z);} slInline float* AsFloatArray() {return &x;} slInline const float* AsFloatArray() const {return &x;} @@ -85,43 +85,43 @@ struct Quaternion float s; slInline explicit Quaternion() {} - explicit Quaternion(const float angle, const Vector3& normalized_axis); + explicit Quaternion(const float angle, const Vec3& normalized_axis); explicit Quaternion(const float angle, const float x, const float y, const float z); slInline Quaternion(const Quaternion& q) {i = q.i; j = q.j; k = q.k; s = q.s;} - Vector4 AsVector4(); + Vec4 AsVec4(); slInline float* AsFloatArray() {return &i;} - Vector3 GetImaginary(); + Vec3 GetImaginary(); slInline float GetReal() {return s;} }; -slInline Quaternion::Quaternion(const float angle, const Vector3& normalized_axis) +slInline Quaternion::Quaternion(const float angle, const Vec3& normalized_axis) { - Assert( EpsilonEquals(LengthVector3(normalized_axis), 1.0f, kEpsilon) ); + Assert( EpsilonEquals(normalized_axis.x * normalized_axis.x + normalized_axis.y * normalized_axis.y + normalized_axis.z * normalized_axis.z, 1.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); i = normalized_axis.x * sin_half_angle; j = normalized_axis.y * sin_half_angle; k = normalized_axis.z * sin_half_angle; - s = Cosf(half_angle); + s = (float)Cosf(half_angle); } slInline Quaternion::Quaternion(const float angle, const float x, const float y, const float z) { Assert( EpsilonEquals(x * x + y * y + z * z, 1.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); i = x * sin_half_angle; j = y * sin_half_angle; k = z * sin_half_angle; - s = Cosf(half_angle); + s = (float)Cosf(half_angle); } -Vector4 Quaternion::AsVector4() +Vec4 Quaternion::AsVec4() { - Vector4 r; + Vec4 r; r.x = i; r.y = j; r.z = k; @@ -129,9 +129,9 @@ Vector4 Quaternion::AsVector4() return r; } -Vector3 Quaternion::GetImaginary() +Vec3 Quaternion::GetImaginary() { - Vector3 r; + Vec3 r; r.x = i; r.y = j; r.z = k; @@ -140,35 +140,35 @@ Vector3 Quaternion::GetImaginary() //---------------------------------------------------------------------------------------- -struct Matrix3 +struct Mat3 { - Vector3 v[3]; + Vec3 v[3]; - slInline explicit Matrix3() {} - explicit Matrix3(const Vector3& v0, const Vector3& v1, const Vector3& v2); - explicit Matrix3(const float v00, const float v01, const float v02, - const float v10, const float v11, const float v12, - const float v20, const float v21, const float v22); - Matrix3(Matrix3& m); // copy constructor + slInline explicit Mat3() {} + explicit Mat3(const Vec3& v0, const Vec3& v1, const Vec3& v2); + explicit Mat3(const float v00, const float v01, const float v02, + const float v10, const float v11, const float v12, + const float v20, const float v21, const float v22); + Mat3(const Mat3& m); // copy constructor float* AsFloatArray() {return &v[0].x;} }; -slInline Matrix3::Matrix3(const Vector3& v0, const Vector3& v1, const Vector3& v2) +slInline Mat3::Mat3(const Vec3& v0, const Vec3& v1, const Vec3& v2) { v[0] = v0; v[1] = v1; v[2] = v2; } -slInline Matrix3::Matrix3(const float v00, const float v01, const float v02, const float v10, const float v11, const float v12, const float v20, const float v21, const float v22) +slInline Mat3::Mat3(const float v00, const float v01, const float v02, const float v10, const float v11, const float v12, const float v20, const float v21, const float v22) { v[0].x = v00; v[0].y = v01; v[0].z = v02; v[1].x = v10; v[1].y = v11; v[1].z = v12; v[2].x = v20; v[2].y = v21; v[2].z = v22; } -slInline Matrix3::Matrix3(Matrix3& m) +slInline Mat3::Mat3(const Mat3& m) { v[0] = m.v[0]; v[1] = m.v[1]; @@ -177,23 +177,23 @@ slInline Matrix3::Matrix3(Matrix3& m) //---------------------------------------------------------------------------------------- -struct Matrix4 +struct Mat4 { - Vector4 v[4]; + Vec4 v[4]; - slInline explicit Matrix4() {} - explicit Matrix4(const Vector4& v0, const Vector4& v1, const Vector4& v2, const Vector4& v3); - explicit Matrix4(const float v00, const float v01, const float v02, const float v03, - const float v10, const float v11, const float v12, const float v13, - const float v20, const float v21, const float v22, const float v23, - const float v30, const float v31, const float v32, const float v33); - explicit Matrix4(const Matrix3& m); - Matrix4(const Matrix4& m); // copy constructor + slInline explicit Mat4() {} + explicit Mat4(const Vec4& v0, const Vec4& v1, const Vec4& v2, const Vec4& v3); + explicit Mat4(const float v00, const float v01, const float v02, const float v03, + const float v10, const float v11, const float v12, const float v13, + const float v20, const float v21, const float v22, const float v23, + const float v30, const float v31, const float v32, const float v33); + explicit Mat4(const Mat3& m); + Mat4(const Mat4& m); // copy constructor float* AsFloatArray() {return &v[0].x;} }; -slInline Matrix4::Matrix4(const Vector4& v0, const Vector4& v1, const Vector4& v2, const Vector4& v3) +slInline Mat4::Mat4(const Vec4& v0, const Vec4& v1, const Vec4& v2, const Vec4& v3) { v[0] = v0; v[1] = v1; @@ -201,7 +201,7 @@ slInline Matrix4::Matrix4(const Vector4& v0, const Vector4& v1, const Vector4& v v[3] = v3; } -slInline Matrix4::Matrix4(const float v00, const float v01, const float v02, const float v03, const float v10, const float v11, const float v12, const float v13, const float v20, const float v21, const float v22, const float v23, const float v30, const float v31, const float v32, const float v33) +slInline Mat4::Mat4(const float v00, const float v01, const float v02, const float v03, const float v10, const float v11, const float v12, const float v13, const float v20, const float v21, const float v22, const float v23, const float v30, const float v31, const float v32, const float v33) { v[0].x = v00; v[0].y = v01; v[0].z = v02; v[0].w = v03; v[1].x = v10; v[1].y = v11; v[1].z = v12; v[1].w = v13; @@ -209,7 +209,7 @@ slInline Matrix4::Matrix4(const float v00, const float v01, const float v02, con v[3].x = v30; v[3].y = v31; v[3].z = v32; v[3].w = v33; } -slInline Matrix4::Matrix4(const Matrix3& m) +slInline Mat4::Mat4(const Mat3& m) { v[0].x = m.v[0].x; v[0].y = m.v[0].y; v[0].z = m.v[0].z; v[0].w = 0.0f; v[1].x = m.v[1].x; v[1].y = m.v[1].y; v[1].z = m.v[1].z; v[1].w = 0.0f; @@ -217,7 +217,7 @@ slInline Matrix4::Matrix4(const Matrix3& m) v[3].x = 0.0f; v[3].y = 0.0f; v[3].z = 0.0f; v[3].w = 1.0f; } -slInline Matrix4::Matrix4(const Matrix4& m) +slInline Mat4::Mat4(const Mat4& m) { v[0] = m.v[0]; v[1] = m.v[1]; @@ -227,18 +227,18 @@ slInline Matrix4::Matrix4(const Matrix4& m) //---------------------------------------------------------------------------------------- -typedef ALIGN(8) Vector2 AlignedVector2; -typedef ALIGN(16) Vector3 AlignedVector3; -typedef ALIGN(16) Vector4 AlignedVector4; +typedef MEM_ALIGN(8) Vec2 AlignedVec2; +typedef MEM_ALIGN(16) Vec3 AlignedVec3; +typedef MEM_ALIGN(16) Vec4 AlignedVec4; -typedef ALIGN(64) Matrix3 AlignedMatrix3; -typedef ALIGN(64) Matrix4 AlignedMatrix4; +typedef MEM_ALIGN(64) Mat3 AlignedMat3; +typedef MEM_ALIGN(64) Mat4 AlignedMat4; //---------------------------------------------------------------------------------------- // SIMD Structures //---------------------------------------------------------------------------------------- -struct Vector2SOA +struct Vec2SOA { uint32_t m_Count; uint32_t m_MaxCount; @@ -246,13 +246,13 @@ struct Vector2SOA float* m_X; float* m_Y; - slInline explicit Vector2SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL;} - bool InitVector2SOA(float* buffer, uint32_t buffer_size); + slInline explicit Vec2SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL;} + bool InitVec2SOA(float* buffer, uint32_t buffer_size); - void GetVector2AtIndex(Vector2& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index];} + void GetVec2AtIndex(Vec2& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index];} }; -slInline bool Vector2SOA::InitVector2SOA(float* buffer, uint32_t max_count) +slInline bool Vec2SOA::InitVec2SOA(float* buffer, uint32_t max_count) { m_Count = 0; @@ -280,17 +280,17 @@ slInline bool Vector2SOA::InitVector2SOA(float* buffer, uint32_t max_count) //---------------------------------------------------------------------------------------- -struct Vector3SOA : public Vector2SOA +struct Vec3SOA : public Vec2SOA { float* m_Z; - slInline explicit Vector3SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL;} - bool InitVector3SOA(float* buffer, uint32_t buffer_size); + slInline explicit Vec3SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL;} + bool InitVec3SOA(float* buffer, uint32_t buffer_size); - void GetVector3AtIndex(Vector3& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index];} + void GetVec3AtIndex(Vec3& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index];} }; -slInline bool Vector3SOA::InitVector3SOA(float* buffer, uint32_t max_count) +slInline bool Vec3SOA::InitVec3SOA(float* buffer, uint32_t max_count) { m_Count = 0; @@ -321,17 +321,17 @@ slInline bool Vector3SOA::InitVector3SOA(float* buffer, uint32_t max_count) //---------------------------------------------------------------------------------------- -struct Vector4SOA : public Vector3SOA +struct Vec4SOA : public Vec3SOA { float* m_W; - slInline explicit Vector4SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL; m_W = NULL;} - bool InitVector4SOA(float* buffer, uint32_t buffer_size); + slInline explicit Vec4SOA() {m_Count = 0; m_MaxCount = 0; m_X = NULL; m_Y = NULL; m_Z = NULL; m_W = NULL;} + bool InitVec4SOA(float* buffer, uint32_t buffer_size); - void GetVector4AtIndex(Vector4& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index]; v.w = m_W[index];} + void GetVec4AtIndex(Vec4& v, uint32_t index) {Assert(index < m_Count); v.x = m_X[index]; v.y = m_Y[index]; v.z = m_Z[index]; v.w = m_W[index];} }; -slInline bool Vector4SOA::InitVector4SOA(float* buffer, uint32_t max_count) +slInline bool Vec4SOA::InitVec4SOA(float* buffer, uint32_t max_count) { m_Count = 0; diff --git a/Classes/Foundation/Math/Matrix.h b/Classes/Foundation/Math/Matrix.h index 37e5362..40e2a70 100755 --- a/Classes/Foundation/Math/Matrix.h +++ b/Classes/Foundation/Math/Matrix.h @@ -21,36 +21,36 @@ //---------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------- -// Matrix3 +// Mat3 //---------------------------------------------------------------------------------------- -void SetMatrix3(Matrix3& r, const Matrix3& a); -void SetMatrix3(Matrix3& r, const Vector3& v0, const Vector3& v1, const Vector3& v2); +void SetMat3(Mat3& r, const Mat3& a); +void SetMat3(Mat3& r, const Vec3& v0, const Vec3& v1, const Vec3& v2); -void ScaleMatrix3(Matrix3& r, const float s, const Matrix3& a); -Matrix3 ScaleMatrix3(const float s, const Matrix3& a); +void ScaleMat3(Mat3& r, const float s, const Mat3& a); +Mat3 ScaleMat3(const float s, const Mat3& a); -float DeterminantOfMatrix3(const Matrix3& a); +float DeterminantOfMat3(const Mat3& a); -void TransposeMatrix3(Matrix3& r, const Matrix3& a); -Matrix3 TransposeMatrix3(const Matrix3& a); +void TransposeMat3(Mat3& r, const Mat3& a); +Mat3 TransposeMat3(const Mat3& a); -void InvertAffineMatrix3(Matrix3& r, const Matrix3& a); -Matrix3 InvertAffineMatrix3(const Matrix3& a); +void InvertAffineMat3(Mat3& r, const Mat3& a); +Mat3 InvertAffineMat3(const Mat3& a); -void InvertGeneralMatrix3(Matrix3& r, const Matrix3& a); -Matrix3 InvertGeneralMatrix3(const Matrix3& a); +void InvertGeneralMat3(Mat3& r, const Mat3& a); +Mat3 InvertGeneralMat3(const Mat3& a); -void MulMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b); -Matrix3 MulMatrix3(const Matrix3& a, const Matrix3& b); +void MulMat3(Mat3& r, const Mat3& a, const Mat3& b); +Mat3 MulMat3(const Mat3& a, const Mat3& b); -void MulMatrix3ByTransposedMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b); -Matrix3 MulMatrix3ByTransposedMatrix3(const Matrix3& a, const Matrix3& b); +void MulMat3ByTransposedMat3(Mat3& r, const Mat3& a, const Mat3& b); +Mat3 MulMat3ByTransposedMat3(const Mat3& a, const Mat3& b); -void MulVector3ByMatrix3(Vector3& r, const Vector3& v, const Matrix3& a); -Vector3 MulVector3ByMatrix3(const Vector3& v, const Matrix3& a); +void MulVec3ByMat3(Vec3& r, const Vec3& v, const Mat3& a); +Vec3 MulVec3ByMat3(const Vec3& v, const Mat3& a); //---------------------------------------------------------------------------------------- -slInline void SetMatrix3(Matrix3& r, const Matrix3& a) +slInline void SetMat3(Mat3& r, const Mat3& a) { r.v[0] = a.v[0]; r.v[1] = a.v[1]; @@ -58,7 +58,7 @@ slInline void SetMatrix3(Matrix3& r, const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline void SetMatrix3(Matrix3& r, const Vector3& v0, const Vector3& v1, const Vector3& v2) +slInline void SetMat3(Mat3& r, const Vec3& v0, const Vec3& v1, const Vec3& v2) { r.v[0] = v0; r.v[1] = v1; @@ -66,25 +66,25 @@ slInline void SetMatrix3(Matrix3& r, const Vector3& v0, const Vector3& v1, const } //---------------------------------------------------------------------------------------- -slInline void ScaleMatrix3(Matrix3& r, const float s, const Matrix3& a) +slInline void ScaleMat3(Mat3& r, const float s, const Mat3& a) { - ScaleVector3(r.v[0], s, a.v[0]); - ScaleVector3(r.v[1], s, a.v[1]); - ScaleVector3(r.v[2], s, a.v[2]); + ScaleVec3(r.v[0], s, a.v[0]); + ScaleVec3(r.v[1], s, a.v[1]); + ScaleVec3(r.v[2], s, a.v[2]); } //---------------------------------------------------------------------------------------- -slInline Matrix3 ScaleMatrix3(const float s, const Matrix3& a) +slInline Mat3 ScaleMat3(const float s, const Mat3& a) { - Matrix3 r; - ScaleVector3(r.v[0], s, a.v[0]); - ScaleVector3(r.v[1], s, a.v[1]); - ScaleVector3(r.v[2], s, a.v[2]); + Mat3 r; + ScaleVec3(r.v[0], s, a.v[0]); + ScaleVec3(r.v[1], s, a.v[1]); + ScaleVec3(r.v[2], s, a.v[2]); return r; } //---------------------------------------------------------------------------------------- -slInline float DeterminantOfMatrix3(const Matrix3& a) +slInline float DeterminantOfMat3(const Mat3& a) { return a.v[0].x * (a.v[1].y * a.v[2].z - a.v[1].z * a.v[2].y) + a.v[0].y * (a.v[1].z * a.v[2].x - a.v[1].x * a.v[2].z) @@ -92,7 +92,7 @@ slInline float DeterminantOfMatrix3(const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline void TransposeMatrix3(Matrix3& r, const Matrix3& a) +slInline void TransposeMat3(Mat3& r, const Mat3& a) { // a might be the same as r r.v[0].x = a.v[0].x; @@ -114,9 +114,9 @@ slInline void TransposeMatrix3(Matrix3& r, const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline Matrix3 TransposeMatrix3(const Matrix3& a) +slInline Mat3 TransposeMat3(const Mat3& a) { - Matrix3 r; + Mat3 r; r.v[0].x = a.v[0].x; r.v[0].y = a.v[1].x; r.v[0].z = a.v[2].x; r.v[1].x = a.v[0].y; r.v[1].y = a.v[1].y; r.v[1].z = a.v[2].y; r.v[2].x = a.v[0].z; r.v[2].y = a.v[1].z; r.v[2].z = a.v[2].z; @@ -124,139 +124,139 @@ slInline Matrix3 TransposeMatrix3(const Matrix3& a) } //---------------------------------------------------------------------------------------- -slInline void InvertAffineMatrix3(Matrix3& r, const Matrix3& a) +slInline void InvertAffineMat3(Mat3& r, const Mat3& a) { - TransposeMatrix3(r, a); + TransposeMat3(r, a); } //---------------------------------------------------------------------------------------- -slInline Matrix3 InvertAffineMatrix3(const Matrix3& a) +slInline Mat3 InvertAffineMat3(const Mat3& a) { - return TransposeMatrix3(a); + return TransposeMat3(a); } //---------------------------------------------------------------------------------------- -slInline void InvertGeneralMatrix3(Matrix3& r, const Matrix3& a) +slInline void InvertGeneralMat3(Mat3& r, const Mat3& a) { - float inv_determinant = 1.0f / DeterminantOfMatrix3(a); + float inv_determinant = 1.0f / DeterminantOfMat3(a); - Matrix3 a_T; - TransposeMatrix3(a_T, a); - CrossVector3(r.v[0], a_T.v[1], a_T.v[2]); - CrossVector3(r.v[1], a_T.v[2], a_T.v[0]); - CrossVector3(r.v[2], a_T.v[0], a_T.v[1]); + Mat3 a_T; + TransposeMat3(a_T, a); + CrossVec3(r.v[0], a_T.v[1], a_T.v[2]); + CrossVec3(r.v[1], a_T.v[2], a_T.v[0]); + CrossVec3(r.v[2], a_T.v[0], a_T.v[1]); - ScaleMatrix3(r, inv_determinant, r); + ScaleMat3(r, inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline Matrix3 InvertGeneralMatrix3(const Matrix3& a) +slInline Mat3 InvertGeneralMat3(const Mat3& a) { - float inv_determinant = 1.0f / DeterminantOfMatrix3(a); + float inv_determinant = 1.0f / DeterminantOfMat3(a); - Matrix3 r; - Matrix3 a_T = TransposeMatrix3(a); - CrossVector3(r.v[0], a_T.v[1], a_T.v[2]); - CrossVector3(r.v[1], a_T.v[2], a_T.v[0]); - CrossVector3(r.v[2], a_T.v[0], a_T.v[1]); + Mat3 r; + Mat3 a_T = TransposeMat3(a); + CrossVec3(r.v[0], a_T.v[1], a_T.v[2]); + CrossVec3(r.v[1], a_T.v[2], a_T.v[0]); + CrossVec3(r.v[2], a_T.v[0], a_T.v[1]); - return ScaleMatrix3(inv_determinant, r); + return ScaleMat3(inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline void MulMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b) +slInline void MulMat3(Mat3& r, const Mat3& a, const Mat3& b) { - Matrix3 temp; + Mat3 temp; - temp.v[0].x = DotVector3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); - temp.v[0].y = DotVector3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); - temp.v[0].z = DotVector3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); + temp.v[0].x = DotVec3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); + temp.v[0].y = DotVec3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); + temp.v[0].z = DotVec3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); - temp.v[1].x = DotVector3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); - temp.v[1].y = DotVector3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); - temp.v[1].z = DotVector3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); + temp.v[1].x = DotVec3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); + temp.v[1].y = DotVec3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); + temp.v[1].z = DotVec3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); - temp.v[2].x = DotVector3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); - temp.v[2].y = DotVector3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); - temp.v[2].z = DotVector3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); + temp.v[2].x = DotVec3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); + temp.v[2].y = DotVec3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); + temp.v[2].z = DotVec3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); - SetMatrix3(r, temp); + SetMat3(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix3 MulMatrix3(const Matrix3& a, const Matrix3& b) +slInline Mat3 MulMat3(const Mat3& a, const Mat3& b) { - Matrix3 r; + Mat3 r; - r.v[0].x = DotVector3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); - r.v[0].y = DotVector3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); - r.v[0].z = DotVector3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); + r.v[0].x = DotVec3(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x); + r.v[0].y = DotVec3(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y); + r.v[0].z = DotVec3(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z); - r.v[1].x = DotVector3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); - r.v[1].y = DotVector3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); - r.v[1].z = DotVector3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); + r.v[1].x = DotVec3(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x); + r.v[1].y = DotVec3(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y); + r.v[1].z = DotVec3(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z); - r.v[2].x = DotVector3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); - r.v[2].y = DotVector3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); - r.v[2].z = DotVector3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); + r.v[2].x = DotVec3(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x); + r.v[2].y = DotVec3(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y); + r.v[2].z = DotVec3(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z); return r; } //---------------------------------------------------------------------------------------- -slInline void MulMatrix3ByTransposedMatrix3(Matrix3& r, const Matrix3& a, const Matrix3& b) +slInline void MulMat3ByTransposedMat3(Mat3& r, const Mat3& a, const Mat3& b) { - Matrix3 temp; + Mat3 temp; - temp.v[0].x = DotVector3(a.v[0], b.v[0]); - temp.v[0].y = DotVector3(a.v[0], b.v[1]); - temp.v[0].z = DotVector3(a.v[0], b.v[2]); + temp.v[0].x = DotVec3(a.v[0], b.v[0]); + temp.v[0].y = DotVec3(a.v[0], b.v[1]); + temp.v[0].z = DotVec3(a.v[0], b.v[2]); - temp.v[1].x = DotVector3(a.v[1], b.v[0]); - temp.v[1].y = DotVector3(a.v[1], b.v[1]); - temp.v[1].z = DotVector3(a.v[1], b.v[2]); + temp.v[1].x = DotVec3(a.v[1], b.v[0]); + temp.v[1].y = DotVec3(a.v[1], b.v[1]); + temp.v[1].z = DotVec3(a.v[1], b.v[2]); - temp.v[2].x = DotVector3(a.v[2], b.v[0]); - temp.v[2].y = DotVector3(a.v[2], b.v[1]); - temp.v[2].z = DotVector3(a.v[2], b.v[2]); + temp.v[2].x = DotVec3(a.v[2], b.v[0]); + temp.v[2].y = DotVec3(a.v[2], b.v[1]); + temp.v[2].z = DotVec3(a.v[2], b.v[2]); - SetMatrix3(r, temp); + SetMat3(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix3 MulMatrix3ByTransposedMatrix3(const Matrix3& a, const Matrix3& b) +slInline Mat3 MulMat3ByTransposedMat3(const Mat3& a, const Mat3& b) { - Matrix3 r; + Mat3 r; - r.v[0].x = DotVector3(a.v[0], b.v[0]); - r.v[0].y = DotVector3(a.v[0], b.v[1]); - r.v[0].z = DotVector3(a.v[0], b.v[2]); + r.v[0].x = DotVec3(a.v[0], b.v[0]); + r.v[0].y = DotVec3(a.v[0], b.v[1]); + r.v[0].z = DotVec3(a.v[0], b.v[2]); - r.v[1].x = DotVector3(a.v[1], b.v[0]); - r.v[1].y = DotVector3(a.v[1], b.v[1]); - r.v[1].z = DotVector3(a.v[1], b.v[2]); + r.v[1].x = DotVec3(a.v[1], b.v[0]); + r.v[1].y = DotVec3(a.v[1], b.v[1]); + r.v[1].z = DotVec3(a.v[1], b.v[2]); - r.v[2].x = DotVector3(a.v[2], b.v[0]); - r.v[2].y = DotVector3(a.v[2], b.v[1]); - r.v[2].z = DotVector3(a.v[2], b.v[2]); + r.v[2].x = DotVec3(a.v[2], b.v[0]); + r.v[2].y = DotVec3(a.v[2], b.v[1]); + r.v[2].z = DotVec3(a.v[2], b.v[2]); return r; } //---------------------------------------------------------------------------------------- // do NOT pass in components of a as the r vector -slInline void MulVector3ByMatrix3(Vector3& r, const Vector3& v, const Matrix3& a) +slInline void MulVec3ByMat3(Vec3& r, const Vec3& v, const Mat3& a) { float x = v.x * a.v[0].x + v.y * a.v[1].x + v.z * a.v[2].x; float y = v.x * a.v[0].y + v.y * a.v[1].y + v.z * a.v[2].y; float z = v.x * a.v[0].z + v.y * a.v[1].z + v.z * a.v[2].z; - SetVector3(r, x, y, z); + SetVec3(r, x, y, z); } //---------------------------------------------------------------------------------------- -slInline Vector3 MulVector3ByMatrix3(const Vector3& v, const Matrix3& a) +slInline Vec3 MulVec3ByMat3(const Vec3& v, const Mat3& a) { - Vector3 r; + Vec3 r; r.x = v.x * a.v[0].x + v.y * a.v[1].x + v.z * a.v[2].x; r.y = v.x * a.v[0].y + v.y * a.v[1].y + v.z * a.v[2].y; r.z = v.x * a.v[0].z + v.y * a.v[1].z + v.z * a.v[2].z; @@ -266,46 +266,46 @@ slInline Vector3 MulVector3ByMatrix3(const Vector3& v, const Matrix3& a) //---------------------------------------------------------------------------------------- -// Matrix4 +// Mat4 //---------------------------------------------------------------------------------------- -void SetMatrix4(Matrix4& r, const Matrix4& a); -void SetMatrix4(Matrix4& r, const Matrix3& a); -void SetMatrix4(Matrix4& r, const Matrix3& a, const Vector3& position); +void SetMat4(Mat4& r, const Mat4& a); +void SetMat4(Mat4& r, const Mat3& a); +void SetMat4(Mat4& r, const Mat3& a, const Vec3& position); -void ScaleMatrix4(Matrix4& r, const float s, const Matrix4& a); -Matrix4 ScaleMatrix4(const float s, const Matrix4& a); +void ScaleMat4(Mat4& r, const float s, const Mat4& a); +Mat4 ScaleMat4(const float s, const Mat4& a); -float DeterminantOfMatrix4(const Matrix4& a); +float DeterminantOfMat4(const Mat4& a); -void TransposeMatrix4(Matrix4& r, const Matrix4& a); -Matrix4 TransposeMatrix4(const Matrix4& a); +void TransposeMat4(Mat4& r, const Mat4& a); +Mat4 TransposeMat4(const Mat4& a); -void InvertAffineMatrix4(Matrix4& r, const Matrix4& a); -Matrix4 InvertAffineMatrix4(const Matrix4& a); +void InvertAffineMat4(Mat4& r, const Mat4& a); +Mat4 InvertAffineMat4(const Mat4& a); -void InvertGeneralMatrix4(Matrix4& r, const Matrix4& a); -Matrix4 InvertGeneralMatrix4(const Matrix4& a); +void InvertGeneralMat4(Mat4& r, const Mat4& a); +Mat4 InvertGeneralMat4(const Mat4& a); -void MulMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& b); -Matrix4 MulMatrix4(const Matrix4& a, const Matrix4& b); +void MulMat4(Mat4& r, const Mat4& a, const Mat4& b); +Mat4 MulMat4(const Mat4& a, const Mat4& b); -void MulMatrix4ByTransposedMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& t); -Matrix4 MulMatrix4ByTransposedMatrix4(const Matrix4& a, Matrix4& t); +void MulMat4ByTransposedMat4(Mat4& r, const Mat4& a, const Mat4& t); +Mat4 MulMat4ByTransposedMat4(const Mat4& a, Mat4& t); -void MulVector4ByMatrix4(Vector4& r, const Vector4& v, const Matrix4& a); -Vector4 MulVector4ByMatrix4(const Vector4& v, const Matrix4& a); +void MulVec4ByMat4(Vec4& r, const Vec4& v, const Mat4& a); +Vec4 MulVec4ByMat4(const Vec4& v, const Mat4& a); -void MulVector3ByMatrix4(Vector4& r, const Vector3& v, const float w, const Matrix4& a); -Vector4 MulVector3ByMatrix4(const Vector3& v, const float w, const Matrix4& a); +void MulVec3ByMat4(Vec4& r, const Vec3& v, const float w, const Mat4& a); +Vec4 MulVec3ByMat4(const Vec3& v, const float w, const Mat4& a); -void MulVector4ByTransposedMatrix4(Vector4& r, const Vector4& v, const Matrix4& t); -Vector4 MulVector4ByTransposedMatrix4(const Vector4& v, const Matrix4& t); +void MulVec4ByTransposedMat4(Vec4& r, const Vec4& v, const Mat4& t); +Vec4 MulVec4ByTransposedMat4(const Vec4& v, const Mat4& t); -void MulVector3ByTransposedMatrix4(Vector4& r, const Vector3& v, const float w, const Matrix4& t); -Vector4 MulVector3ByTransposedMatrix4(const Vector3& v, const float w, const Matrix4& t); +void MulVec3ByTransposedMat4(Vec4& r, const Vec3& v, const float w, const Mat4& t); +Vec4 MulVec3ByTransposedMat4(const Vec3& v, const float w, const Mat4& t); //---------------------------------------------------------------------------------------- -slInline void SetMatrix4(Matrix4& r, const Matrix4& a) +slInline void SetMat4(Mat4& r, const Mat4& a) { r.v[0] = a.v[0]; r.v[1] = a.v[1]; @@ -314,54 +314,54 @@ slInline void SetMatrix4(Matrix4& r, const Matrix4& a) } //---------------------------------------------------------------------------------------- -slInline void SetMatrix4(Matrix4& r, const Matrix3& a) +slInline void SetMat4(Mat4& r, const Mat3& a) { - SetVector4(r.v[0], a.v[0], 0.0f); - SetVector4(r.v[1], a.v[1], 0.0f); - SetVector4(r.v[2], a.v[2], 0.0f); - SetVector4(r.v[3], 0.0f, 0.0f, 0.0f, 1.0f); + SetVec4(r.v[0], a.v[0], 0.0f); + SetVec4(r.v[1], a.v[1], 0.0f); + SetVec4(r.v[2], a.v[2], 0.0f); + SetVec4(r.v[3], 0.0f, 0.0f, 0.0f, 1.0f); } //---------------------------------------------------------------------------------------- -slInline void SetMatrix4(Matrix4& r, const Matrix3& a, const Vector3& position) +slInline void SetMat4(Mat4& r, const Mat3& a, const Vec3& position) { - SetVector4(r.v[0], a.v[0], 0.0f); - SetVector4(r.v[1], a.v[1], 0.0f); - SetVector4(r.v[2], a.v[2], 0.0f); - SetVector4(r.v[3], position, 1.0f); + SetVec4(r.v[0], a.v[0], 0.0f); + SetVec4(r.v[1], a.v[1], 0.0f); + SetVec4(r.v[2], a.v[2], 0.0f); + SetVec4(r.v[3], position, 1.0f); } //---------------------------------------------------------------------------------------- -slInline void ScaleMatrix4(Matrix4& r, const float s, const Matrix4& a) +slInline void ScaleMat4(Mat4& r, const float s, const Mat4& a) { - ScaleVector4(r.v[0], s, a.v[0]); - ScaleVector4(r.v[1], s, a.v[1]); - ScaleVector4(r.v[2], s, a.v[2]); - ScaleVector4(r.v[3], s, a.v[3]); + ScaleVec4(r.v[0], s, a.v[0]); + ScaleVec4(r.v[1], s, a.v[1]); + ScaleVec4(r.v[2], s, a.v[2]); + ScaleVec4(r.v[3], s, a.v[3]); } //---------------------------------------------------------------------------------------- -slInline Matrix4 ScaleMatrix4(const float s, const Matrix4& a) +slInline Mat4 ScaleMat4(const float s, const Mat4& a) { - Matrix4 r; - ScaleVector4(r.v[0], s, a.v[0]); - ScaleVector4(r.v[1], s, a.v[1]); - ScaleVector4(r.v[2], s, a.v[2]); - ScaleVector4(r.v[3], s, a.v[3]); + Mat4 r; + ScaleVec4(r.v[0], s, a.v[0]); + ScaleVec4(r.v[1], s, a.v[1]); + ScaleVec4(r.v[2], s, a.v[2]); + ScaleVec4(r.v[3], s, a.v[3]); return r; } //---------------------------------------------------------------------------------------- -slInline float DeterminantOfMatrix4(const Matrix4& a) +slInline float DeterminantOfMat4(const Mat4& a) { // is this correct? - Vector4 cross_product; - CrossVector4(cross_product, a.v[1], a.v[2], a.v[3]); - return DotVector4(a.v[0], cross_product); + Vec4 cross_product; + CrossVec4(cross_product, a.v[1], a.v[2], a.v[3]); + return DotVec4(a.v[0], cross_product); } //---------------------------------------------------------------------------------------- -slInline void TransposeMatrix4(Matrix4& r, const Matrix4& a) +slInline void TransposeMat4(Mat4& r, const Mat4& a) { // a might be the same as r r.v[0].x = a.v[0].x; @@ -396,9 +396,9 @@ slInline void TransposeMatrix4(Matrix4& r, const Matrix4& a) } //---------------------------------------------------------------------------------------- -slInline Matrix4 TransposeMatrix4(const Matrix4& a) +slInline Mat4 TransposeMat4(const Mat4& a) { - Matrix4 r; + Mat4 r; r.v[0].x = a.v[0].x; r.v[0].y = a.v[1].x; r.v[0].z = a.v[2].x; r.v[0].w = a.v[3].x; r.v[1].x = a.v[0].y; r.v[1].y = a.v[1].y; r.v[1].z = a.v[2].y; r.v[1].w = a.v[3].y; r.v[2].x = a.v[0].z; r.v[2].y = a.v[1].z; r.v[2].z = a.v[2].z; r.v[2].w = a.v[3].z; @@ -407,254 +407,254 @@ slInline Matrix4 TransposeMatrix4(const Matrix4& a) } //---------------------------------------------------------------------------------------- -slInline void InvertAffineMatrix4(Matrix4& r, const Matrix4& a) +slInline void InvertAffineMat4(Mat4& r, const Mat4& a) { // this may not be correct... - Matrix3 a3_T(a.v[0].AsVector3(), a.v[1].AsVector3(), a.v[2].AsVector3()); - InvertAffineMatrix3(a3_T, a3_T); + Mat3 a3_T(a.v[0].AsVec3(), a.v[1].AsVec3(), a.v[2].AsVec3()); + InvertAffineMat3(a3_T, a3_T); - Vector3 transpose; - MulVector3ByMatrix3(transpose, a.v[3].AsVector3(), a3_T); + Vec3 transpose; + MulVec3ByMat3(transpose, a.v[3].AsVec3(), a3_T); - SetMatrix4(r, a3_T, transpose); + SetMat4(r, a3_T, transpose); } //---------------------------------------------------------------------------------------- -slInline Matrix4 InvertAffineMatrix4(const Matrix4& a) +slInline Mat4 InvertAffineMat4(const Mat4& a) { - Matrix4 r; + Mat4 r; // this may not be correct... - Matrix3 a3_T(a.v[0].AsVector3(), a.v[1].AsVector3(), a.v[2].AsVector3()); - InvertAffineMatrix3(a3_T, a3_T); + Mat3 a3_T(a.v[0].AsVec3(), a.v[1].AsVec3(), a.v[2].AsVec3()); + InvertAffineMat3(a3_T, a3_T); - Vector3 transpose; - MulVector3ByMatrix3(transpose, a.v[3].AsVector3(), a3_T); + Vec3 transpose; + MulVec3ByMat3(transpose, a.v[3].AsVec3(), a3_T); - SetMatrix4(r, a3_T, transpose); + SetMat4(r, a3_T, transpose); return r; } //---------------------------------------------------------------------------------------- -slInline void InvertGeneralMatrix4(Matrix4& r, const Matrix4& a) +slInline void InvertGeneralMat4(Mat4& r, const Mat4& a) { // does this work? - float inv_determinant = 1.0f / DeterminantOfMatrix4(a); + float inv_determinant = 1.0f / DeterminantOfMat4(a); - Matrix4 a_T; - TransposeMatrix4(a_T, a); - CrossVector4(r.v[0], a_T.v[1], a_T.v[2], a_T.v[3]); - CrossVector4(r.v[1], a_T.v[2], a_T.v[3], a_T.v[0]); - CrossVector4(r.v[2], a_T.v[3], a_T.v[0], a_T.v[1]); - CrossVector4(r.v[3], a_T.v[0], a_T.v[1], a_T.v[2]); + Mat4 a_T; + TransposeMat4(a_T, a); + CrossVec4(r.v[0], a_T.v[1], a_T.v[2], a_T.v[3]); + CrossVec4(r.v[1], a_T.v[2], a_T.v[3], a_T.v[0]); + CrossVec4(r.v[2], a_T.v[3], a_T.v[0], a_T.v[1]); + CrossVec4(r.v[3], a_T.v[0], a_T.v[1], a_T.v[2]); - ScaleMatrix4(r, inv_determinant, r); + ScaleMat4(r, inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline Matrix4 InvertGeneralMatrix4(const Matrix4& a) +slInline Mat4 InvertGeneralMat4(const Mat4& a) { // does this work? - Matrix4 r; - float inv_determinant = 1.0f / DeterminantOfMatrix4(a); + Mat4 r; + float inv_determinant = 1.0f / DeterminantOfMat4(a); - Matrix4 a_T; - TransposeMatrix4(a_T, a); - r.v[0] = CrossVector4(a_T.v[1], a_T.v[2], a_T.v[3]); - r.v[1] = CrossVector4(a_T.v[2], a_T.v[3], a_T.v[0]); - r.v[2] = CrossVector4(a_T.v[3], a_T.v[0], a_T.v[1]); - r.v[3] = CrossVector4(a_T.v[0], a_T.v[1], a_T.v[2]); + Mat4 a_T; + TransposeMat4(a_T, a); + r.v[0] = CrossVec4(a_T.v[1], a_T.v[2], a_T.v[3]); + r.v[1] = CrossVec4(a_T.v[2], a_T.v[3], a_T.v[0]); + r.v[2] = CrossVec4(a_T.v[3], a_T.v[0], a_T.v[1]); + r.v[3] = CrossVec4(a_T.v[0], a_T.v[1], a_T.v[2]); - return ScaleMatrix4(inv_determinant, r); + return ScaleMat4(inv_determinant, r); } //---------------------------------------------------------------------------------------- -slInline void MulMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& b) +slInline void MulMat4(Mat4& r, const Mat4& a, const Mat4& b) { - Matrix4 temp; + Mat4 temp; - temp.v[0].x = DotVector4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[0].y = DotVector4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[0].z = DotVector4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[0].w = DotVector4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[0].x = DotVec4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[0].y = DotVec4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[0].z = DotVec4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[0].w = DotVec4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - temp.v[1].x = DotVector4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[1].y = DotVector4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[1].z = DotVector4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[1].w = DotVector4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[1].x = DotVec4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[1].y = DotVec4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[1].z = DotVec4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[1].w = DotVec4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - temp.v[2].x = DotVector4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[2].y = DotVector4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[2].z = DotVector4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[2].w = DotVector4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[2].x = DotVec4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[2].y = DotVec4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[2].z = DotVec4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[2].w = DotVec4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - temp.v[3].x = DotVector4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - temp.v[3].y = DotVector4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - temp.v[3].z = DotVector4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - temp.v[3].w = DotVector4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + temp.v[3].x = DotVec4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + temp.v[3].y = DotVec4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + temp.v[3].z = DotVec4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + temp.v[3].w = DotVec4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - SetMatrix4(r, temp); + SetMat4(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix4 MulMatrix4(const Matrix4& a, const Matrix4& b) +slInline Mat4 MulMat4(const Mat4& a, const Mat4& b) { - Matrix4 r; + Mat4 r; - r.v[0].x = DotVector4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[0].y = DotVector4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[0].z = DotVector4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[0].w = DotVector4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[0].x = DotVec4(a.v[0], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[0].y = DotVec4(a.v[0], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[0].z = DotVec4(a.v[0], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[0].w = DotVec4(a.v[0], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - r.v[1].x = DotVector4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[1].y = DotVector4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[1].z = DotVector4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[1].w = DotVector4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[1].x = DotVec4(a.v[1], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[1].y = DotVec4(a.v[1], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[1].z = DotVec4(a.v[1], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[1].w = DotVec4(a.v[1], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - r.v[2].x = DotVector4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[2].y = DotVector4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[2].z = DotVector4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[2].w = DotVector4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[2].x = DotVec4(a.v[2], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[2].y = DotVec4(a.v[2], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[2].z = DotVec4(a.v[2], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[2].w = DotVec4(a.v[2], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); - r.v[3].x = DotVector4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); - r.v[3].y = DotVector4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); - r.v[3].z = DotVector4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); - r.v[3].w = DotVector4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); + r.v[3].x = DotVec4(a.v[3], b.v[0].x, b.v[1].x, b.v[2].x, b.v[3].x); + r.v[3].y = DotVec4(a.v[3], b.v[0].y, b.v[1].y, b.v[2].y, b.v[3].y); + r.v[3].z = DotVec4(a.v[3], b.v[0].z, b.v[1].z, b.v[2].z, b.v[3].z); + r.v[3].w = DotVec4(a.v[3], b.v[0].w, b.v[1].w, b.v[2].w, b.v[3].w); return r; } //---------------------------------------------------------------------------------------- -slInline void MulMatrix4ByTransposedMatrix4(Matrix4& r, const Matrix4& a, const Matrix4& t) +slInline void MulMat4ByTransposedMat4(Mat4& r, const Mat4& a, const Mat4& t) { - Matrix4 temp; + Mat4 temp; - temp.v[0].x = DotVector4(a.v[0], b.v[0]); - temp.v[0].y = DotVector4(a.v[0], b.v[1]); - temp.v[0].z = DotVector4(a.v[0], b.v[2]); - temp.v[0].w = DotVector4(a.v[0], b.v[3]); + temp.v[0].x = DotVec4(a.v[0], t.v[0]); + temp.v[0].y = DotVec4(a.v[0], t.v[1]); + temp.v[0].z = DotVec4(a.v[0], t.v[2]); + temp.v[0].w = DotVec4(a.v[0], t.v[3]); - temp.v[1].x = DotVector4(a.v[1], b.v[0]); - temp.v[1].y = DotVector4(a.v[1], b.v[1]); - temp.v[1].z = DotVector4(a.v[1], b.v[2]); - temp.v[1].w = DotVector4(a.v[1], b.v[3]); + temp.v[1].x = DotVec4(a.v[1], t.v[0]); + temp.v[1].y = DotVec4(a.v[1], t.v[1]); + temp.v[1].z = DotVec4(a.v[1], t.v[2]); + temp.v[1].w = DotVec4(a.v[1], t.v[3]); - temp.v[2].x = DotVector4(a.v[2], b.v[0]); - temp.v[2].y = DotVector4(a.v[2], b.v[1]); - temp.v[2].z = DotVector4(a.v[2], b.v[2]); - temp.v[2].w = DotVector4(a.v[2], b.v[3]); + temp.v[2].x = DotVec4(a.v[2], t.v[0]); + temp.v[2].y = DotVec4(a.v[2], t.v[1]); + temp.v[2].z = DotVec4(a.v[2], t.v[2]); + temp.v[2].w = DotVec4(a.v[2], t.v[3]); - temp.v[3].x = DotVector4(a.v[3], b.v[0]); - temp.v[3].y = DotVector4(a.v[3], b.v[1]); - temp.v[3].z = DotVector4(a.v[3], b.v[2]); - temp.v[3].w = DotVector4(a.v[3], b.v[3]); + temp.v[3].x = DotVec4(a.v[3], t.v[0]); + temp.v[3].y = DotVec4(a.v[3], t.v[1]); + temp.v[3].z = DotVec4(a.v[3], t.v[2]); + temp.v[3].w = DotVec4(a.v[3], t.v[3]); - SetMatrix4(r, temp); + SetMat4(r, temp); } //---------------------------------------------------------------------------------------- -slInline Matrix4 MulMatrix4ByTransposedMatrix4(const Matrix4& a, const Matrix4& t) +slInline Mat4 MulMat4ByTransposedMat4(const Mat4& a, const Mat4& t) { - Matrix4 r; + Mat4 r; - r.v[0].x = DotVector4(a.v[0], b.v[0]); - r.v[0].y = DotVector4(a.v[0], b.v[1]); - r.v[0].z = DotVector4(a.v[0], b.v[2]); - r.v[0].w = DotVector4(a.v[0], b.v[3]); + r.v[0].x = DotVec4(a.v[0], t.v[0]); + r.v[0].y = DotVec4(a.v[0], t.v[1]); + r.v[0].z = DotVec4(a.v[0], t.v[2]); + r.v[0].w = DotVec4(a.v[0], t.v[3]); - r.v[1].x = DotVector4(a.v[1], b.v[0]); - r.v[1].y = DotVector4(a.v[1], b.v[1]); - r.v[1].z = DotVector4(a.v[1], b.v[2]); - r.v[1].w = DotVector4(a.v[1], b.v[3]); + r.v[1].x = DotVec4(a.v[1], t.v[0]); + r.v[1].y = DotVec4(a.v[1], t.v[1]); + r.v[1].z = DotVec4(a.v[1], t.v[2]); + r.v[1].w = DotVec4(a.v[1], t.v[3]); - r.v[2].x = DotVector4(a.v[2], b.v[0]); - r.v[2].y = DotVector4(a.v[2], b.v[1]); - r.v[2].z = DotVector4(a.v[2], b.v[2]); - r.v[2].w = DotVector4(a.v[2], b.v[3]); + r.v[2].x = DotVec4(a.v[2], t.v[0]); + r.v[2].y = DotVec4(a.v[2], t.v[1]); + r.v[2].z = DotVec4(a.v[2], t.v[2]); + r.v[2].w = DotVec4(a.v[2], t.v[3]); - r.v[3].x = DotVector4(a.v[3], b.v[0]); - r.v[3].y = DotVector4(a.v[3], b.v[1]); - r.v[3].z = DotVector4(a.v[3], b.v[2]); - r.v[3].w = DotVector4(a.v[3], b.v[3]); + r.v[3].x = DotVec4(a.v[3], t.v[0]); + r.v[3].y = DotVec4(a.v[3], t.v[1]); + r.v[3].z = DotVec4(a.v[3], t.v[2]); + r.v[3].w = DotVec4(a.v[3], t.v[3]); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector4ByMatrix4(Vector4& r, const Vector4& v, const Matrix4& a) +slInline void MulVec4ByMat4(Vec4& r, const Vec4& v, const Mat4& a) { - Vector4 result; - ScaleVector4(result, v.x, a.v[0]); - ScaleAddVector4(result, v.y, a.v[1], result); - ScaleAddVector4(result, v.z, a.v[2], result); - ScaleAddVector4(result, v.w, a.v[3], result); - SetVector4(r, result); + Vec4 result; + ScaleVec4(result, v.x, a.v[0]); + ScaleAddVec4(result, v.y, a.v[1], result); + ScaleAddVec4(result, v.z, a.v[2], result); + ScaleAddVec4(result, v.w, a.v[3], result); + SetVec4(r, result); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector4ByMatrix4(const Vector4& v, const Matrix4& a) +slInline Vec4 MulVec4ByMat4(const Vec4& v, const Mat4& a) { - Vector4 r; - ScaleVector4(r, v.x, a.v[0]); - ScaleAddVector4(r, v.y, a.v[1], r); - ScaleAddVector4(r, v.z, a.v[2], r); - ScaleAddVector4(r, v.w, a.v[3], r); + Vec4 r; + ScaleVec4(r, v.x, a.v[0]); + ScaleAddVec4(r, v.y, a.v[1], r); + ScaleAddVec4(r, v.z, a.v[2], r); + ScaleAddVec4(r, v.w, a.v[3], r); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector3ByMatrix4(Vector4& r, const Vector3& v, const float iw, const Matrix4& a) +slInline void MulVec3ByMat4(Vec4& r, const Vec3& v, const float iw, const Mat4& a) { - Vector4 result; - ScaleVector4(result, v.x, a.v[0]); - ScaleAddVector4(result, v.y, a.v[1], result); - ScaleAddVector4(result, v.z, a.v[2], result); - ScaleAddVector4(result, iw, a.v[3], result); - SetVector4(r, result); + Vec4 result; + ScaleVec4(result, v.x, a.v[0]); + ScaleAddVec4(result, v.y, a.v[1], result); + ScaleAddVec4(result, v.z, a.v[2], result); + ScaleAddVec4(result, iw, a.v[3], result); + SetVec4(r, result); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector3ByMatrix4(const Vector3& v, const float iw, const Matrix4& a) +slInline Vec4 MulVec3ByMat4(const Vec3& v, const float iw, const Mat4& a) { - Vector4 r; - ScaleVector4(r, v.x, a.v[0]); - ScaleAddVector4(r, v.y, a.v[1], r); - ScaleAddVector4(r, v.z, a.v[2], r); - ScaleAddVector4(r, iw, a.v[3], r); + Vec4 r; + ScaleVec4(r, v.x, a.v[0]); + ScaleAddVec4(r, v.y, a.v[1], r); + ScaleAddVec4(r, v.z, a.v[2], r); + ScaleAddVec4(r, iw, a.v[3], r); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector4ByTransposedMatrix4(Vector4& r, const Vector4& v, const Matrix4& t) +slInline void MulVec4ByTransposedMat4(Vec4& r, const Vec4& v, const Mat4& t) { - float x = DotVector4(v, t.v[0]); - float y = DotVector4(v, t.v[1]); - float z = DotVector4(v, t.v[2]); - float w = DotVector4(v, t.v[3]); - SetVector4(r, x, y, z, w); + float x = DotVec4(v, t.v[0]); + float y = DotVec4(v, t.v[1]); + float z = DotVec4(v, t.v[2]); + float w = DotVec4(v, t.v[3]); + SetVec4(r, x, y, z, w); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector4ByTransposedMatrix4(const Vector4& v, const Matrix4& t) +slInline Vec4 MulVec4ByTransposedMat4(const Vec4& v, const Mat4& t) { - Vector4 r; - r.x = DotVector4(v, t.v[0]); - r.y = DotVector4(v, t.v[1]); - r.z = DotVector4(v, t.v[2]); - r.w = DotVector4(v, t.v[3]); + Vec4 r; + r.x = DotVec4(v, t.v[0]); + r.y = DotVec4(v, t.v[1]); + r.z = DotVec4(v, t.v[2]); + r.w = DotVec4(v, t.v[3]); return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector3ByTransposedMatrix4(Vector4& r, const Vector3& v, const float w, const Matrix4& t) +slInline void MulVec3ByTransposedMat4(Vec4& r, const Vec3& v, const float w, const Mat4& t) { - Vector4 v_new(v, w); - MulVector4ByTransposedMatrix4(r, v_new, a); + Vec4 v_new(v, w); + MulVec4ByTransposedMat4(r, v_new, t); } //---------------------------------------------------------------------------------------- -slInline Vector4 MulVector3ByTransposedMatrix4(const Vector3& v, const float w, const Matrix4& t) +slInline Vec4 MulVec3ByTransposedMat4(const Vec3& v, const float w, const Mat4& t) { - Vector4 v_as_v4(v, w); - return MulVector4ByTransposedMatrix4(v_as_v4, t); + Vec4 v_as_v4(v, w); + return MulVec4ByTransposedMat4(v_as_v4, t); } diff --git a/Classes/Foundation/Math/Quaternion.h b/Classes/Foundation/Math/Quaternion.h index 8a303db..d9cce5d 100755 --- a/Classes/Foundation/Math/Quaternion.h +++ b/Classes/Foundation/Math/Quaternion.h @@ -1,14 +1,14 @@ #pragma once #include "Foundation/Common/GlobalInclude.h" -#include "Foundation/Common/MathTypes.h" +#include "Foundation/Math/MathTypes.h" #include "Foundation/Math/Vector.h" //---------------------------------------------------------------------------------------- // Quaternion //---------------------------------------------------------------------------------------- void SetQuaternion(Quaternion& r, const float angle, const float x, const float y, const float z); -void SetQuaternion(Quaternion& r, const float angle, const Vector3& rotation_axis); +void SetQuaternion(Quaternion& r, const float angle, const Vec3& rotation_axis); void ScaleQuaternion(Quaternion& r, const float s, const Quaternion& q); void MulQuaternion(Quaternion& r, const Quaternion& p, const Quaternion& q); void ConjugateOfQuaternion(Quaternion& r, const Quaternion& q); @@ -20,29 +20,29 @@ void InverseQuaterion(Quaternion& r, const Quaternion& q); //---------------------------------------------------------------------------------------- void SetQuaternion(Quaternion& r, const float angle, const float x, const float y, const float z) { - Assert( EpsilonEquals(LengthVector3(rotation_axis), 0.0f, kEpsilon) ); + Assert( EpsilonEquals(x*x + y*y + z*z, 0.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); r.i = x * sin_half_angle; r.j = y * sin_half_angle; r.k = z * sin_half_angle; - r.s = Cosf(half_angle); + r.s = (float)Cosf(half_angle); } //---------------------------------------------------------------------------------------- -void SetQuaternion(Quaternion& r, const float angle, const Vector3& rotation_axis) +void SetQuaternion(Quaternion& r, const float angle, const Vec3& rotation_axis) { - Assert( EpsilonEquals(LengthVector3(rotation_axis), 0.0f, kEpsilon) ); + Assert( EpsilonEquals(rotation_axis.x * rotation_axis.x + rotation_axis.y * rotation_axis.y + rotation_axis.z * rotation_axis.z, 0.0f, kSqrtEpsilon) ); float half_angle = angle * 0.5f; - float sin_half_angle = Sinf(half_angle); + float sin_half_angle = (float)Sinf(half_angle); r.i = rotation_axis.x * sin_half_angle; r.j = rotation_axis.y * sin_half_angle; r.k = rotation_axis.z * sin_half_angle; - r.s = Cosf(half_angle); + r.s = (float)Cosf(half_angle); } //---------------------------------------------------------------------------------------- @@ -75,7 +75,7 @@ void ConjugateOfQuaternion(Quaternion& r, const Quaternion& q) //---------------------------------------------------------------------------------------- float NormOfQuaternion(const Quaternion& q) { - return Sqrtf( q.i * q.i + q.j * q.j + q.k * q.k + q.s * q.s); + return (float)Sqrtf( q.i * q.i + q.j * q.j + q.k * q.k + q.s * q.s); } //---------------------------------------------------------------------------------------- @@ -87,7 +87,7 @@ float NormSquaredOfQuaternion(const Quaternion& q) //---------------------------------------------------------------------------------------- void NormalizeQuaternion(Quaternion& r, Quaternion& q) { - float norm_scale = 1.0f / NormQuaternion( q ); + float norm_scale = 1.0f / NormOfQuaternion( q ); ScaleQuaternion( r, norm_scale, q ); } diff --git a/Classes/Foundation/Math/Vector.h b/Classes/Foundation/Math/Vector.h index 3e5e524..91cc817 100755 --- a/Classes/Foundation/Math/Vector.h +++ b/Classes/Foundation/Math/Vector.h @@ -5,407 +5,407 @@ #include "Foundation/Math/MathOperations.h" //---------------------------------------------------------------------------------------- -// Vector2 +// Vec2 //---------------------------------------------------------------------------------------- -void SetVector2(Vector2& r, const Vector2& v); -void SetVector2(Vector2& r, const float x, const float y); -void SetVector2(Vector2& r, const float xy); -void AbsVector2(Vector2& r, const Vector2& v); -float MinComponentVector2(const Vector2& v); -float MaxComponentVector2(const Vector2& v); -uint32_t MinIndexVector2(const Vector2& v); -uint32_t MaxIndexVector2(const Vector2& v); -float DotVector2(const Vector2& a, const Vector2& b); -float DotVector2(const Vector2& a, const float x, const float y); +void SetVec2(Vec2& r, const Vec2& v); +void SetVec2(Vec2& r, const float x, const float y); +void SetVec2(Vec2& r, const float xy); +void AbsVec2(Vec2& r, const Vec2& v); +float MinComponentVec2(const Vec2& v); +float MaxComponentVec2(const Vec2& v); +uint32_t MinIndexVec2(const Vec2& v); +uint32_t MaxIndexVec2(const Vec2& v); +float DotVec2(const Vec2& a, const Vec2& b); +float DotVec2(const Vec2& a, const float x, const float y); -void PerpendicularVector2(Vector2& r, const Vector2& v); -Vector2 PerpendicularVector2(const Vector2& v); +void PerpendicularVec2(Vec2& r, const Vec2& v); +Vec2 PerpendicularVec2(const Vec2& v); -void AddVector2ByScalar(Vector2& r, const float s, const Vector2& v); -Vector2 AddVector2ByScalar(const float s, const Vector2& v); +void AddVec2ByScalar(Vec2& r, const float s, const Vec2& v); +Vec2 AddVec2ByScalar(const float s, const Vec2& v); -void AddVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 AddVector2(const Vector2& a, const Vector2& b); +void AddVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 AddVec2(const Vec2& a, const Vec2& b); -void AddVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 AddVector2(const Vector2& a, const float x, const float y); +void AddVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 AddVec2(const Vec2& a, const float x, const float y); -void SubVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 SubVector2(const Vector2& a, const Vector2& b); +void SubVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 SubVec2(const Vec2& a, const Vec2& b); -void SubVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 SubVector2(const Vector2& a, const float x, const float y); +void SubVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 SubVec2(const Vec2& a, const float x, const float y); -void ScaleVector2(Vector2& r, const float s, const Vector2& v); -Vector2 ScaleVector2(const float s, const Vector2& v); +void ScaleVec2(Vec2& r, const float s, const Vec2& v); +Vec2 ScaleVec2(const float s, const Vec2& v); -void MulVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 MulVector2(const Vector2& a, const Vector2& b); +void MulVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 MulVec2(const Vec2& a, const Vec2& b); -void MulVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 MulVector2(const Vector2& a, const float x, const float y); +void MulVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 MulVec2(const Vec2& a, const float x, const float y); -void DivVector2(Vector2& r, const Vector2& a, const Vector2& b); -Vector2 DivVector2(const Vector2& a, const Vector2& b); +void DivVec2(Vec2& r, const Vec2& a, const Vec2& b); +Vec2 DivVec2(const Vec2& a, const Vec2& b); -void DivVector2(Vector2& r, const Vector2& a, const float x, const float y); -Vector2 DivVector2(const Vector2& a, const float x, const float y); +void DivVec2(Vec2& r, const Vec2& a, const float x, const float y); +Vec2 DivVec2(const Vec2& a, const float x, const float y); -void ScaleAddVector2(Vector2& r, const float s, const Vector2& v_scale, const Vector2& v_add); -Vector2 ScaleAddVector2(const float s, const Vector2& v_scale, const Vector2& v_add); +void ScaleAddVec2(Vec2& r, const float s, const Vec2& v_scale, const Vec2& v_add); +Vec2 ScaleAddVec2(const float s, const Vec2& v_scale, const Vec2& v_add); -void NormalizeVector2(Vector2& r, const Vector2& a); -Vector2 NormalizeVector2(const Vector2& a); +void NormalizeVec2(Vec2& r, const Vec2& a); +Vec2 NormalizeVec2(const Vec2& a); -float LengthOfVector2(const Vector2& a); -float LengthSquaredOfVector2(const Vector2& a); +float LengthOfVec2(const Vec2& a); +float LengthSquaredOfVec2(const Vec2& a); //---------------------------------------------------------------------------------------- -slInline void SetVector2(Vector2& r, const Vector2& v) +slInline void SetVec2(Vec2& r, const Vec2& v) { r.x = v.x; r.y = v.y; } //---------------------------------------------------------------------------------------- -slInline void SetVector2(Vector2& r, const float x, const float y) +slInline void SetVec2(Vec2& r, const float x, const float y) { r.x = x; r.y = y; } //---------------------------------------------------------------------------------------- -slInline void SetVector2(Vector2& r, const float xy) +slInline void SetVec2(Vec2& r, const float xy) { r.x = xy; r.y = xy; } //---------------------------------------------------------------------------------------- -void AbsVector2(Vector2& r, const Vector2& v) +void AbsVec2(Vec2& r, const Vec2& v) { r.x = Absf(v.x); r.y = Absf(v.y); } //---------------------------------------------------------------------------------------- -float MinComponentVector2(const Vector2& v) +float MinComponentVec2(const Vec2& v) { return v.x <= v.y ? v.x : v.y; } //---------------------------------------------------------------------------------------- -float MaxComponentVector2(const Vector2& v) +float MaxComponentVec2(const Vec2& v) { return v.x >= v.y ? v.x : v.y; } //---------------------------------------------------------------------------------------- -uint32_t MinIndexVector2(const Vector2& v) +uint32_t MinIndexVec2(const Vec2& v) { return v.x <= v.y ? 0 : 1; } //---------------------------------------------------------------------------------------- -uint32_t MaxIndexVector2(const Vector2& v) +uint32_t MaxIndexVec2(const Vec2& v) { return v.x >= v.y ? 0 : 1; } //---------------------------------------------------------------------------------------- -slInline float DotVector2(const Vector2& a, const Vector2& b) +slInline float DotVec2(const Vec2& a, const Vec2& b) { return a.x * b.x + a.y * b.y; } //---------------------------------------------------------------------------------------- -slInline float DotVector2(const Vector2& a, const float x, const float y) +slInline float DotVec2(const Vec2& a, const float x, const float y) { return a.x * x + a.y * y; } //---------------------------------------------------------------------------------------- -slInline void PerpendicularVector2(Vector2& r, const Vector2& v) +slInline void PerpendicularVec2(Vec2& r, const Vec2& v) { r.x = -v.y; r.y = v.x; } //---------------------------------------------------------------------------------------- -slInline Vector2 PerpendicularVector2(const Vector2& v) +slInline Vec2 PerpendicularVec2(const Vec2& v) { - Vector2 r; + Vec2 r; r.x = -v.y; r.y = v.x; return r; } //---------------------------------------------------------------------------------------- -slInline void AddVector2ByScalar(Vector2& r, const float s, Vector2& v) +slInline void AddVec2ByScalar(Vec2& r, const float s, Vec2& v) { r.x = s + v.x; r.y = s + v.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 AddVector2ByScalar(const float s, const Vector2& v) +slInline Vec2 AddVec2ByScalar(const float s, const Vec2& v) { - Vector2 r; + Vec2 r; r.x = s + v.x; r.y = s + v.y; return r; } //---------------------------------------------------------------------------------------- -slInline void AddVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void AddVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x + b.x; r.y = a.y + b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 AddVector2(const Vector2& a, const Vector2& b) +slInline Vec2 AddVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x + b.x; r.y = a.y + b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void AddVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void AddVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x + x; r.y = a.y + y; } //---------------------------------------------------------------------------------------- -slInline Vector2 AddVector2(const Vector2& a, const float x, const float y) +slInline Vec2 AddVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x + x; r.y = a.y + y; return r; } //---------------------------------------------------------------------------------------- -slInline void SubVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void SubVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x - b.x; r.y = a.y - b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 SubVector2(const Vector2& a, const Vector2& b) +slInline Vec2 SubVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x - b.x; r.y = a.y - b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void SubVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void SubVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x - x; r.y = a.y - y; } //---------------------------------------------------------------------------------------- -slInline Vector2 SubVector2(const Vector2& a, const float x, const float y) +slInline Vec2 SubVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x - x; r.y = a.y - y; return r; } //---------------------------------------------------------------------------------------- -slInline void ScaleVector2(Vector2& r, const float s, const Vector2& v) +slInline void ScaleVec2(Vec2& r, const float s, const Vec2& v) { r.x = s * v.x; r.y = s * v.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 ScaleVector2(const float s, const Vector2& v) +slInline Vec2 ScaleVec2(const float s, const Vec2& v) { - Vector2 r; + Vec2 r; r.x = s * v.x; r.y = s * v.y; return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void MulVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x * b.x; r.y = a.y * b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 MulVector2(const Vector2& a, const Vector2& b) +slInline Vec2 MulVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x * b.x; r.y = a.y * b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void MulVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void MulVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x * x; r.y = a.y * y; } //---------------------------------------------------------------------------------------- -slInline Vector2 MulVector2(const Vector2& a, const float x, const float y) +slInline Vec2 MulVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x * x; r.y = a.y * y; return r; } //---------------------------------------------------------------------------------------- -slInline void DivVector2(Vector2& r, const Vector2& a, const Vector2& b) +slInline void DivVec2(Vec2& r, const Vec2& a, const Vec2& b) { r.x = a.x / b.x; r.y = a.y / b.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 DivVector2(const Vector2& a, const Vector2& b) +slInline Vec2 DivVec2(const Vec2& a, const Vec2& b) { - Vector2 r; + Vec2 r; r.x = a.x / b.x; r.y = a.y / b.y; return r; } //---------------------------------------------------------------------------------------- -slInline void DivVector2(Vector2& r, const Vector2& a, const float x, const float y) +slInline void DivVec2(Vec2& r, const Vec2& a, const float x, const float y) { r.x = a.x / x; r.y = a.y / y; } //---------------------------------------------------------------------------------------- -slInline Vector2 DivVector2(const Vector2& a, const float x, const float y) +slInline Vec2 DivVec2(const Vec2& a, const float x, const float y) { - Vector2 r; + Vec2 r; r.x = a.x / x; r.y = a.y / y; return r; } //---------------------------------------------------------------------------------------- -slInline void ScaleAddVector2(Vector2& r, const float s, const Vector2& v_scale, const Vector2& v_add) +slInline void ScaleAddVec2(Vec2& r, const float s, const Vec2& v_scale, const Vec2& v_add) { r.x = v_scale.x * s + v_add.x; r.y = v_scale.y * s + v_add.y; } //---------------------------------------------------------------------------------------- -slInline Vector2 ScaleAddVector2(const float s, const Vector2& v_scale, const Vector2& v_add) +slInline Vec2 ScaleAddVec2(const float s, const Vec2& v_scale, const Vec2& v_add) { - Vector2 r; + Vec2 r; r.x = v_scale.x * s + v_add.x; r.y = v_scale.y * s + v_add.y; return r; } //---------------------------------------------------------------------------------------- -slInline void NormalizeVector2(Vector2& r, const Vector2& a) +slInline void NormalizeVec2(Vec2& r, const Vec2& a) { - float scale = 1.0f / LengthOfVector2(a); - ScaleVector2( r, scale, a ); + float scale = 1.0f / LengthOfVec2(a); + ScaleVec2( r, scale, a ); } //---------------------------------------------------------------------------------------- -slInline Vector2 NormalizeVector2(const Vector2& a) +slInline Vec2 NormalizeVec2(const Vec2& a) { - float scale = 1.0f / LengthOfVector2(a); - return ScaleVector2( scale, a ); + float scale = 1.0f / LengthOfVec2(a); + return ScaleVec2( scale, a ); } //---------------------------------------------------------------------------------------- -slInline float LengthOfVector2(const Vector2& a) +slInline float LengthOfVec2(const Vec2& a) { - return Sqrtf( DotVector2(a, a) ); + return (float)Sqrtf( DotVec2(a, a) ); } //---------------------------------------------------------------------------------------- -slInline float LengthSquaredOfVector2(const Vector2& a) +slInline float LengthSquaredOfVec2(const Vec2& a) { - return DotVector2(a, a); + return DotVec2(a, a); } //---------------------------------------------------------------------------------------- -// Vector3 +// Vec3 //---------------------------------------------------------------------------------------- -void SetVector3(Vector3& r, const Vector3& v); -void SetVector3(Vector3& r, const Vector2& v, const float z); -void SetVector3(Vector3& r, const float xyz); -void SetVector3(Vector3& r, const float x, const float y, const float z); +void SetVec3(Vec3& r, const Vec3& v); +void SetVec3(Vec3& r, const Vec2& v, const float z); +void SetVec3(Vec3& r, const float xyz); +void SetVec3(Vec3& r, const float x, const float y, const float z); -void AbsVector3(Vector3& r, const Vector3& v); -Vector3 AbsVector3(const Vector3& v); +void AbsVec3(Vec3& r, const Vec3& v); +Vec3 AbsVec3(const Vec3& v); -float MinComponentVector3(const Vector3& v); -float MaxComponentVector3(const Vector3& v); -uint32_t MinIndexVector3(const Vector3& v); -uint32_t MaxIndexVector3(const Vector3& v); -float DotVector3(const Vector3& a, const Vector3& b); -float DotVector3(const Vector3& a, const float x, const float y, const float z); +float MinComponentVec3(const Vec3& v); +float MaxComponentVec3(const Vec3& v); +uint32_t MinIndexVec3(const Vec3& v); +uint32_t MaxIndexVec3(const Vec3& v); +float DotVec3(const Vec3& a, const Vec3& b); +float DotVec3(const Vec3& a, const float x, const float y, const float z); -void CrossVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 CrossVector3(const Vector3& a, const Vector3& b); +void CrossVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 CrossVec3(const Vec3& a, const Vec3& b); -void AddVector3ByScalar(Vector3& r, const float s, Vector3& v); -Vector3 AddVector3ByScalar(const float s, Vector3& v); +void AddVec3ByScalar(Vec3& r, const float s, Vec3& v); +Vec3 AddVec3ByScalar(const float s, Vec3& v); -void AddVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 AddVector3(const Vector3& a, const Vector3& b); +void AddVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 AddVec3(const Vec3& a, const Vec3& b); -void AddVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 AddVector3(const Vector3& a, const float x, const float y, const float z); +void AddVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 AddVec3(const Vec3& a, const float x, const float y, const float z); -void SubVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 SubVector3(const Vector3& a, const Vector3& b); +void SubVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 SubVec3(const Vec3& a, const Vec3& b); -void SubVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 SubVector3(const Vector3& a, const float x, const float y, const float z); +void SubVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 SubVec3(const Vec3& a, const float x, const float y, const float z); -void ScaleVector3(Vector3& r, const float s, const Vector3& v); -Vector3 ScaleVector3(const float s, const Vector3& v); +void ScaleVec3(Vec3& r, const float s, const Vec3& v); +Vec3 ScaleVec3(const float s, const Vec3& v); -void MulVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 MulVector3(const Vector3& a, const Vector3& b); +void MulVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 MulVec3(const Vec3& a, const Vec3& b); -void MulVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 MulVector3(const Vector3& a, const float x, const float y, const float z); +void MulVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 MulVec3(const Vec3& a, const float x, const float y, const float z); -void DivVector3(Vector3& r, const Vector3& a, const Vector3& b); -Vector3 DivVector3(const Vector3& a, const Vector3& b); +void DivVec3(Vec3& r, const Vec3& a, const Vec3& b); +Vec3 DivVec3(const Vec3& a, const Vec3& b); -void DivVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z); -Vector3 DivVector3(const Vector3& a, const float x, const float y, const float z); +void DivVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z); +Vec3 DivVec3(const Vec3& a, const float x, const float y, const float z); -void ScaleAddVector3(Vector3& r, const float s, const Vector3& v_scale, const Vector3& v_add); -Vector3 ScaleAddVector3(const float s, const Vector3& v_scale, const Vector3& v_add); +void ScaleAddVec3(Vec3& r, const float s, const Vec3& v_scale, const Vec3& v_add); +Vec3 ScaleAddVec3(const float s, const Vec3& v_scale, const Vec3& v_add); -void NormalizeVector3(Vector3& r, const Vector3& a); -Vector3 NormalizeVector3(const Vector3& a); +void NormalizeVec3(Vec3& r, const Vec3& a); +Vec3 NormalizeVec3(const Vec3& a); -float LengthVector3(const Vector3& a); -float LengthSquaredVector3(const Vector3& a); +float LengthOfVec3(const Vec3& a); +float LengthSquaredVec3(const Vec3& a); //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const Vector3& v) +slInline void SetVec3(Vec3& r, const Vec3& v) { r.x = v.x; r.y = v.y; @@ -413,7 +413,7 @@ slInline void SetVector3(Vector3& r, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const Vector2& v, const float z) +slInline void SetVec3(Vec3& r, const Vec2& v, const float z) { r.x = v.x; r.y = v.y; @@ -421,7 +421,7 @@ slInline void SetVector3(Vector3& r, const Vector2& v, const float z) } //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const float xyz) +slInline void SetVec3(Vec3& r, const float xyz) { r.x = xyz; r.y = xyz; @@ -429,7 +429,7 @@ slInline void SetVector3(Vector3& r, const float xyz) } //---------------------------------------------------------------------------------------- -slInline void SetVector3(Vector3& r, const float x, const float y, const float z) +slInline void SetVec3(Vec3& r, const float x, const float y, const float z) { r.x = x; r.y = y; @@ -437,7 +437,7 @@ slInline void SetVector3(Vector3& r, const float x, const float y, const float z } //---------------------------------------------------------------------------------------- -slInline void AbsVector3(Vector3& r, const Vector3& v) +slInline void AbsVec3(Vec3& r, const Vec3& v) { r.x = Absf(v.x); r.y = Absf(v.y); @@ -445,9 +445,9 @@ slInline void AbsVector3(Vector3& r, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline Vector3 AbsVector3(const Vector3& v) +slInline Vec3 AbsVec3(const Vec3& v) { - Vector3 r; + Vec3 r; r.x = Absf(v.x); r.y = Absf(v.y); r.z = Absf(v.z); @@ -455,21 +455,21 @@ slInline Vector3 AbsVector3(const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline float MinComponentVector3(const Vector3& v) +slInline float MinComponentVec3(const Vec3& v) { float xy = v.x <= v.y ? v.x : v.y; return xy <= v.z ? xy : v.z; } //---------------------------------------------------------------------------------------- -slInline float MaxComponentVector3(const Vector3& v) +slInline float MaxComponentVec3(const Vec3& v) { float xy = v.x >= v.y ? v.x : v.y; return xy >= v.z ? xy : v.z; } //---------------------------------------------------------------------------------------- -slInline uint32_t MinIndexVector3(const Vector3& v) +slInline uint32_t MinIndexVec3(const Vec3& v) { const float* v_array = &v.x; uint32_t xy = v.x <= v.y ? 0 : 1; @@ -477,7 +477,7 @@ slInline uint32_t MinIndexVector3(const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline uint32_t MaxIndexVector3(const Vector3& v) +slInline uint32_t MaxIndexVec3(const Vec3& v) { const float* v_array = &v.x; uint32_t xy = v.x >= v.y ? 0 : 1; @@ -485,19 +485,19 @@ slInline uint32_t MaxIndexVector3(const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline float DotVector3(const Vector3& a, const Vector3& b) +slInline float DotVec3(const Vec3& a, const Vec3& b) { return a.x * b.x + a.y * b.y + a.z * b.z; } //---------------------------------------------------------------------------------------- -slInline float DotVector3(const Vector3& a, const float x, const float y, const float z) +slInline float DotVec3(const Vec3& a, const float x, const float y, const float z) { return a.x * x + a.y * y + a.z * z; } //---------------------------------------------------------------------------------------- -slInline void CrossVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void CrossVec3(Vec3& r, const Vec3& a, const Vec3& b) { float x = a.y * b.z - b.y * a.z; float y = a.z * b.x - b.z * a.x; @@ -508,9 +508,9 @@ slInline void CrossVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 CrossVector3(const Vector3& a, const Vector3& b) +slInline Vec3 CrossVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.y * b.z - b.y * a.z; r.y = a.z * b.x - b.z * a.x; r.z = a.x * b.y - b.x * a.y; @@ -518,7 +518,7 @@ slInline Vector3 CrossVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void AddVector3ByScalar(Vector3& r, const float s, Vector3& v) +slInline void AddVec3ByScalar(Vec3& r, const float s, Vec3& v) { r.x = s + v.x; r.y = s + v.y; @@ -526,9 +526,9 @@ slInline void AddVector3ByScalar(Vector3& r, const float s, Vector3& v) } //---------------------------------------------------------------------------------------- -slInline Vector3 AddVector3ByScalar(const float s, Vector3& v) +slInline Vec3 AddVec3ByScalar(const float s, Vec3& v) { - Vector3 r; + Vec3 r; r.x = s + v.x; r.y = s + v.y; r.z = s + v.z; @@ -536,7 +536,7 @@ slInline Vector3 AddVector3ByScalar(const float s, Vector3& v) } //---------------------------------------------------------------------------------------- -slInline void AddVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void AddVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x + b.x; r.y = a.y + b.y; @@ -544,9 +544,9 @@ slInline void AddVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 AddVector3(const Vector3& a, const Vector3& b) +slInline Vec3 AddVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x + b.x; r.y = a.y + b.y; r.z = a.z + b.z; @@ -554,7 +554,7 @@ slInline Vector3 AddVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void AddVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z) +slInline void AddVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z) { r.x = a.x + x; r.y = a.y + y; @@ -562,9 +562,9 @@ slInline void AddVector3(Vector3& r, const Vector3& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector3 AddVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 AddVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x + x; r.y = a.y + y; r.z = a.z + z; @@ -572,7 +572,7 @@ slInline Vector3 AddVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void SubVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void SubVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x - b.x; r.y = a.y - b.y; @@ -580,9 +580,9 @@ slInline void SubVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 SubVector3(const Vector3& a, const Vector3& b) +slInline Vec3 SubVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x - b.x; r.y = a.y - b.y; r.z = a.z - b.z; @@ -590,9 +590,9 @@ slInline Vector3 SubVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 SubVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 SubVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x - x; r.y = a.y - y; r.z = a.z - z; @@ -600,7 +600,7 @@ slInline Vector3 SubVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void ScaleVector3(Vector3& r, const float s, const Vector3& v) +slInline void ScaleVec3(Vec3& r, const float s, const Vec3& v) { r.x = s * v.x; r.y = s * v.y; @@ -608,9 +608,9 @@ slInline void ScaleVector3(Vector3& r, const float s, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline Vector3 ScaleVector3(const float s, const Vector3& v) +slInline Vec3 ScaleVec3(const float s, const Vec3& v) { - Vector3 r; + Vec3 r; r.x = s * v.x; r.y = s * v.y; r.z = s * v.z; @@ -618,7 +618,7 @@ slInline Vector3 ScaleVector3(const float s, const Vector3& v) } //---------------------------------------------------------------------------------------- -slInline void MulVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void MulVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x * b.x; r.y = a.y * b.y; @@ -626,9 +626,9 @@ slInline void MulVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 MulVector3(const Vector3& a, const Vector3& b) +slInline Vec3 MulVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x * b.x; r.y = a.y * b.y; r.z = a.z * b.z; @@ -636,7 +636,7 @@ slInline Vector3 MulVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void MulVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z) +slInline void MulVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z) { r.x = a.x * x; r.y = a.y * y; @@ -644,9 +644,9 @@ slInline void MulVector3(Vector3& r, const Vector3& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector3 MulVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 MulVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x * x; r.y = a.y * y; r.z = a.z * z; @@ -654,7 +654,7 @@ slInline Vector3 MulVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void DivVector3(Vector3& r, const Vector3& a, const Vector3& b) +slInline void DivVec3(Vec3& r, const Vec3& a, const Vec3& b) { r.x = a.x / b.x; r.y = a.y / b.y; @@ -662,9 +662,9 @@ slInline void DivVector3(Vector3& r, const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline Vector3 DivVector3(const Vector3& a, const Vector3& b) +slInline Vec3 DivVec3(const Vec3& a, const Vec3& b) { - Vector3 r; + Vec3 r; r.x = a.x / b.x; r.y = a.y / b.y; r.z = a.z / b.z; @@ -672,7 +672,7 @@ slInline Vector3 DivVector3(const Vector3& a, const Vector3& b) } //---------------------------------------------------------------------------------------- -slInline void DivVector3(Vector3& r, const Vector3& a, const float x, const float y, const float z) +slInline void DivVec3(Vec3& r, const Vec3& a, const float x, const float y, const float z) { r.x = a.x / x; r.y = a.y / y; @@ -680,9 +680,9 @@ slInline void DivVector3(Vector3& r, const Vector3& a, const float x, const floa } //---------------------------------------------------------------------------------------- -slInline Vector3 DivVector3(const Vector3& a, const float x, const float y, const float z) +slInline Vec3 DivVec3(const Vec3& a, const float x, const float y, const float z) { - Vector3 r; + Vec3 r; r.x = a.x / x; r.y = a.y / y; r.z = a.z / z; @@ -690,7 +690,7 @@ slInline Vector3 DivVector3(const Vector3& a, const float x, const float y, cons } //---------------------------------------------------------------------------------------- -slInline void ScaleAddVector3(Vector3& r, const float s, const Vector3& v_scale, const Vector3& v_add) +slInline void ScaleAddVec3(Vec3& r, const float s, const Vec3& v_scale, const Vec3& v_add) { r.x = s * v_scale.x + v_add.x; r.y = s * v_scale.y + v_add.y; @@ -698,9 +698,9 @@ slInline void ScaleAddVector3(Vector3& r, const float s, const Vector3& v_scale, } //---------------------------------------------------------------------------------------- -slInline Vector3 ScaleAddVector3(const float s, const Vector3& v_scale, const Vector3& v_add) +slInline Vec3 ScaleAddVec3(const float s, const Vec3& v_scale, const Vec3& v_add) { - Vector3 r; + Vec3 r; r.x = s * v_scale.x + v_add.x; r.y = s * v_scale.y + v_add.y; r.z = s * v_scale.z + v_add.z; @@ -708,96 +708,96 @@ slInline Vector3 ScaleAddVector3(const float s, const Vector3& v_scale, const Ve } //---------------------------------------------------------------------------------------- -slInline void NormalizeVector3(Vector3& r, const Vector3& a) +slInline void NormalizeVec3(Vec3& r, const Vec3& a) { - float scale = 1.0f / LengthOfVector3( a ); - ScaleVector3( r, scale, a ); + float scale = 1.0f / LengthOfVec3( a ); + ScaleVec3( r, scale, a ); } //---------------------------------------------------------------------------------------- -slInline Vector3 NormalizeVector3(const Vector3& a) +slInline Vec3 NormalizeVec3(const Vec3& a) { - float scale = 1.0f / LengthOfVector3( a ); - return ScaleVector3( scale, a ); + float scale = 1.0f / LengthOfVec3( a ); + return ScaleVec3( scale, a ); } //---------------------------------------------------------------------------------------- -slInline float LengthOfVector3(const Vector3& a) +slInline float LengthOfVec3(const Vec3& a) { - return Sqrtf( DotVector3(a, a) ); + return (float)Sqrtf( DotVec3(a, a) ); } //---------------------------------------------------------------------------------------- -slInline float LengthSquaredOfVector3(const Vector3& a) +slInline float LengthSquaredOfVec3(const Vec3& a) { - return DotVector3( a, a ); + return DotVec3( a, a ); } //---------------------------------------------------------------------------------------- -// Vector4 +// Vec4 //---------------------------------------------------------------------------------------- -void SetVector4(Vector4& r, const Vector4& v); -void SetVector4(Vector4& r, const Vector2& a, const Vector2& b); -void SetVector4(Vector4& r, const Vector3& v, const float w); -void SetVector4(Vector4& r, const float xyzw); -void SetVector4(Vector4& r, const float x, const float y, const float z, const float w); +void SetVec4(Vec4& r, const Vec4& v); +void SetVec4(Vec4& r, const Vec2& a, const Vec2& b); +void SetVec4(Vec4& r, const Vec3& v, const float w); +void SetVec4(Vec4& r, const float xyzw); +void SetVec4(Vec4& r, const float x, const float y, const float z, const float w); -void AbsVector4(Vector4& r, const Vector4& v); -Vector4 AbsVector4(const Vector4& v); +void AbsVec4(Vec4& r, const Vec4& v); +Vec4 AbsVec4(const Vec4& v); -float MinComponentVector4(const Vector4& v); -float MaxComponentVector4(const Vector4& v); -uint32_t MinIndexVector4(const Vector4& v); -uint32_t MaxIndexVector4(const Vector4& v); -float DotVector4(const Vector4& a, const Vector4& b); -float DotVector4(const Vector4& a, const float x, const float y, const float z, const float w); +float MinComponentVec4(const Vec4& v); +float MaxComponentVec4(const Vec4& v); +uint32_t MinIndexVec4(const Vec4& v); +uint32_t MaxIndexVec4(const Vec4& v); +float DotVec4(const Vec4& a, const Vec4& b); +float DotVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void CrossVector4(Vector4& r, const Vector4& a, const Vector4& b, const Vector4& c); -Vector4 CrossVector4(const Vector4& a, const Vector4& b, const Vector4& c); +void CrossVec4(Vec4& r, const Vec4& a, const Vec4& b, const Vec4& c); +Vec4 CrossVec4(const Vec4& a, const Vec4& b, const Vec4& c); -void AddVector4ByScalar(Vector4& r, const float s, Vector4& v); -Vector4 AddVector4ByScalar(const float s, Vector4& v); +void AddVec4ByScalar(Vec4& r, const float s, Vec4& v); +Vec4 AddVec4ByScalar(const float s, Vec4& v); -void AddVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 AddVector4(const Vector4& a, const Vector4& b); +void AddVec4(Vec4& r, const Vec4& a, const Vec4& b); +Vec4 AddVec4(const Vec4& a, const Vec4& b); -void AddVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w); -Vector4 AddVector4(const Vector4& a, const float x, const float y, const float z, const float w); +void AddVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w); +Vec4 AddVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void SubVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 SubVector4(const Vector4& a, const Vector4& b); +void SubVec4(Vec4& r, const Vec4& a, const Vec4& b); +Vec4 SubVec4(const Vec4& a, const Vec4& b); -void SubVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w); -Vector4 SubVector4(const Vector4& a, const float x, const float y, const float z, const float w); +void SubVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w); +Vec4 SubVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void ScaleVector4(Vector4& r, const float s, const Vector4& v); -Vector4 ScaleVector4(const float s, const Vector4& v); +void ScaleVec4(Vec4& r, const float s, const Vec4& v); +Vec4 ScaleVec4(const float s, const Vec4& v); -void MulVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 MulVector4(const Vector4& a, const Vector4& b); +void MulVec4(Vec4& r, const Vec4& a, const Vec4& b); +Vec4 MulVec4(const Vec4& a, const Vec4& b); -void MulVector4(Vector4& r, const Vector4& a, const float x, const float y, const float z, const float w); -Vector4 MulVector4(const Vector4& a, const float x, const float y, const float z, const float w); +void MulVec4(Vec4& r, const Vec4& a, const float x, const float y, const float z, const float w); +Vec4 MulVec4(const Vec4& a, const float x, const float y, const float z, const float w); -void DivVector4(Vector4& r, const Vector4& a, const Vector4& b); -Vector4 DivVector4(const Vector4& a, const Vector4& b); +void