_matrix experiments
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Vector2.h"
|
||||
#include "Vector3.h"
|
||||
#include "Vector4.h"
|
||||
#include "Engine/Platform/Platform.h"
|
||||
|
||||
/// <summary>
|
||||
@@ -538,6 +539,47 @@ public:
|
||||
/// <param name="result">The result.</param>
|
||||
static void Transform2DPoint(const Float2& point, const Matrix3x3& transform, Float2& result)
|
||||
{
|
||||
//Float4 pointVector = Float4(0.0f, 0.0f, point.Y, point.X);
|
||||
/*
|
||||
// Load the matrix into SIMD registers
|
||||
const Float4 row1 = Float4((Float3)transform.Values[0], 0.0f);
|
||||
const Float4 row2 = Float4((Float3)transform.Values[1], 0.0f);
|
||||
const Float4 row3 = Float4((Float3)transform.Values[2], 0.0f);
|
||||
|
||||
const Float4 res(
|
||||
point.X * row1.Raw[0] + point.Y * row2.Raw[0] + row3.Raw[0],
|
||||
point.X * row1.Raw[1] + point.Y * row2.Raw[1] + row3.Raw[1], 0.0f, 0.0f
|
||||
);
|
||||
result = Float2(res.X, res.Y);
|
||||
|
||||
*/
|
||||
/*
|
||||
// Load the point into SIMD registers
|
||||
__m128 pointVector = _mm_set_ps(0.0f, 0.0f, point.Y, point.X);
|
||||
|
||||
// Load the matrix into SIMD registers
|
||||
__m128 row1 = _mm_loadu_ps(transform.Values[0]);
|
||||
__m128 row2 = _mm_loadu_ps(transform.Values[1]);
|
||||
__m128 row3 = _mm_loadu_ps(transform.Values[2]);
|
||||
|
||||
// Perform the matrix-vector multiplication
|
||||
__m128 result2 = _mm_add_ps(
|
||||
_mm_add_ps(_mm_mul_ps(row1, pointVector), _mm_mul_ps(row2, pointVector)),
|
||||
row3
|
||||
);
|
||||
|
||||
// Store the result back into a Point2D structure
|
||||
_mm_storeu_ps(&result.X, result2);
|
||||
|
||||
*/
|
||||
|
||||
/*auto result3 = Float2(
|
||||
point.X * transform.M11 + point.Y * transform.M21 + transform.M31,
|
||||
point.X * transform.M12 + point.Y * transform.M22 + transform.M32);
|
||||
|
||||
ASSERT(result == result3);*/
|
||||
|
||||
|
||||
result = Float2(
|
||||
point.X * transform.M11 + point.Y * transform.M21 + transform.M31,
|
||||
point.X * transform.M12 + point.Y * transform.M22 + transform.M32);
|
||||
@@ -552,6 +594,39 @@ public:
|
||||
/// <param name="result">The result.</param>
|
||||
static void Transform2DVector(const Float2& vector, const Matrix3x3& transform, Float2& result)
|
||||
{
|
||||
//Float4 pointVector = Float4(0.0f, 0.0f, vector.Y, vector.X);
|
||||
|
||||
// Load the matrix into SIMD registers
|
||||
/*const Float4 row1 = Float4((Float3)transform.Values[0], 0.0f);
|
||||
const Float4 row2 = Float4((Float3)transform.Values[1], 0.0f);
|
||||
const Float4 row3 = Float4((Float3)transform.Values[2], 0.0f);
|
||||
|
||||
const Float4 res(
|
||||
vector.X * row1.Raw[0] + vector.Y * row2.Raw[0],
|
||||
vector.X * row1.Raw[1] + vector.Y * row2.Raw[1], 0.0f, 0.0f
|
||||
);
|
||||
result = Float2(res.X, res.Y);*/
|
||||
/*
|
||||
// Load the point into SIMD registers
|
||||
__m128 pointVector = _mm_set_ps(0.0f, 0.0f, vector.Y, vector.X);
|
||||
|
||||
// Load the matrix into SIMD registers
|
||||
__m128 row1 = _mm_loadu_ps(transform.Values[0]);
|
||||
__m128 row2 = _mm_loadu_ps(transform.Values[1]);
|
||||
|
||||
// Perform the matrix-vector multiplication
|
||||
__m128 result2 = _mm_add_ps(_mm_mul_ps(row1, pointVector), _mm_mul_ps(row2, pointVector));
|
||||
|
||||
// Store the result back into a Point2D structure
|
||||
_mm_storeu_ps(&result.X, result2);
|
||||
*/
|
||||
/*auto result3 = Float2(
|
||||
vector.X * transform.M11 + vector.Y * transform.M21,
|
||||
vector.X * transform.M12 + vector.Y * transform.M22);
|
||||
|
||||
ASSERT(result == result3);*/
|
||||
|
||||
|
||||
result = Float2(
|
||||
vector.X * transform.M11 + vector.Y * transform.M21,
|
||||
vector.X * transform.M12 + vector.Y * transform.M22);
|
||||
|
||||
Reference in New Issue
Block a user