From e8ed19a255394498a51a496b8ef80c65154f3fcf Mon Sep 17 00:00:00 2001 From: Francesco Bertolaccini Date: Mon, 14 May 2018 08:53:26 +0200 Subject: [PATCH 1/2] Add utility conversion constructors to Mathlib --- src/math/mathlib.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/math/mathlib.h b/src/math/mathlib.h index 7b0c4e94..9082b8c6 100644 --- a/src/math/mathlib.h +++ b/src/math/mathlib.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace Math { @@ -105,6 +106,16 @@ namespace Math this->x = x; this->y = y; } + t_float2(const ZMath::float2& v) + { + this->x = v.x; + this->y = v.y; + } + t_float2(float v) + { + this->x = v; + this->y = v; + } union { struct @@ -139,6 +150,18 @@ namespace Math this->y = y; this->z = z; } + t_float3(const ZMath::float3& v) + { + this->x = v.x; + this->y = v.y; + this->z = v.z; + } + t_float3(float v) + { + this->x = v; + this->y = v; + this->z = v; + } union { struct @@ -175,6 +198,20 @@ namespace Math this->z = z; this->w = w; } + t_float4(const ZMath::float4& v) + { + this->x = v.x; + this->y = v.y; + this->z = v.z; + this->w = v.w; + } + t_float4(float v) + { + this->x = v; + this->y = v; + this->z = v; + this->w = w; + } union { struct From b27b6d0f31a042e5a9cfcb410cac857f7bf99ae9 Mon Sep 17 00:00:00 2001 From: Francesco Bertolaccini Date: Wed, 16 May 2018 20:53:04 +0200 Subject: [PATCH 2/2] Fix warnings about `memcpy` being used improperly --- src/math/mathlib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/math/mathlib.h b/src/math/mathlib.h index 9082b8c6..f4efb44f 100644 --- a/src/math/mathlib.h +++ b/src/math/mathlib.h @@ -326,7 +326,7 @@ namespace Math t_vector() {} t_vector(const void* v) { - memcpy(this, v, sizeof(T)); + memcpy(T::v, v, sizeof(T)); } t_vector(const T& v) @@ -507,7 +507,7 @@ namespace Math // Assignment operators Matrix& operator=(const Matrix& M) { - memcpy(this, &M, sizeof(float) * 16); + memcpy(m, &M, sizeof(mv)); return *this; } Matrix& operator+=(const Matrix& M)