Removed Math::Vector alias and refactored remaining uses of it
parent
d5e8cfd4ba
commit
50fe905455
|
@ -472,25 +472,25 @@ inline Math::Matrix MultiplyMatrices(const Math::Matrix &left, const Math::Matri
|
||||||
|
|
||||||
The result, a 4x1 vector is then converted to 3x1 by dividing
|
The result, a 4x1 vector is then converted to 3x1 by dividing
|
||||||
x,y,z coords by the fourth coord (w). */
|
x,y,z coords by the fourth coord (w). */
|
||||||
inline Math::Vector MatrixVectorMultiply(const Math::Matrix &m, const Math::Vector &v, bool wDivide = false)
|
inline glm::vec3 MatrixVectorMultiply(const Math::Matrix &m, const glm::vec3 &v, bool wDivide = false)
|
||||||
{
|
{
|
||||||
float x = v.x * m.m[0 ] + v.y * m.m[4 ] + v.z * m.m[8 ] + m.m[12];
|
float x = v.x * m.m[0 ] + v.y * m.m[4 ] + v.z * m.m[8 ] + m.m[12];
|
||||||
float y = v.x * m.m[1 ] + v.y * m.m[5 ] + v.z * m.m[9 ] + m.m[13];
|
float y = v.x * m.m[1 ] + v.y * m.m[5 ] + v.z * m.m[9 ] + m.m[13];
|
||||||
float z = v.x * m.m[2 ] + v.y * m.m[6 ] + v.z * m.m[10] + m.m[14];
|
float z = v.x * m.m[2 ] + v.y * m.m[6 ] + v.z * m.m[10] + m.m[14];
|
||||||
|
|
||||||
if (!wDivide)
|
if (!wDivide)
|
||||||
return Math::Vector(x, y, z);
|
return glm::vec3(x, y, z);
|
||||||
|
|
||||||
float w = v.x * m.m[3 ] + v.y * m.m[7 ] + v.z * m.m[11] + m.m[15];
|
float w = v.x * m.m[3 ] + v.y * m.m[7 ] + v.z * m.m[11] + m.m[15];
|
||||||
|
|
||||||
if (IsZero(w))
|
if (IsZero(w))
|
||||||
return Math::Vector(x, y, z);
|
return glm::vec3(x, y, z);
|
||||||
|
|
||||||
x /= w;
|
x /= w;
|
||||||
y /= w;
|
y /= w;
|
||||||
z /= w;
|
z /= w;
|
||||||
|
|
||||||
return Math::Vector(x, y, z);
|
return glm::vec3(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,15 +26,15 @@ namespace Math
|
||||||
|
|
||||||
struct Sphere
|
struct Sphere
|
||||||
{
|
{
|
||||||
Sphere(const Vector& pos = Vector(), float radius = 0.0f)
|
Sphere(const glm::vec3& pos = glm::vec3(), float radius = 0.0f)
|
||||||
: pos(pos), radius(radius) {}
|
: pos(pos), radius(radius) {}
|
||||||
|
|
||||||
Vector pos;
|
glm::vec3 pos;
|
||||||
float radius;
|
float radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Compute distance between given \a point and \a sphere
|
//! Compute distance between given \a point and \a sphere
|
||||||
inline float DistanceToSphere(const Vector& point, const Sphere& sphere)
|
inline float DistanceToSphere(const glm::vec3& point, const Sphere& sphere)
|
||||||
{
|
{
|
||||||
return Math::Distance(point, sphere.pos) - sphere.radius;
|
return Math::Distance(point, sphere.pos) - sphere.radius;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ inline float DistanceBetweenSpheres(const Sphere& sphere1, const Sphere& sphere2
|
||||||
return Math::Distance(sphere1.pos, sphere2.pos) - sphere1.radius - sphere2.radius;
|
return Math::Distance(sphere1.pos, sphere2.pos) - sphere1.radius - sphere2.radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Sphere BoundingSphereForBox(Vector mins, Vector maxs)
|
inline Sphere BoundingSphereForBox(glm::vec3 mins, glm::vec3 maxs)
|
||||||
{
|
{
|
||||||
auto centroid = (maxs + mins) / 2.0f;
|
auto centroid = (maxs + mins) / 2.0f;
|
||||||
auto halfExtent = (maxs - centroid);
|
auto halfExtent = (maxs - centroid);
|
||||||
|
|
|
@ -37,9 +37,6 @@
|
||||||
namespace Math
|
namespace Math
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
using Vector = glm::vec3;
|
|
||||||
|
|
||||||
//! Checks if two vectors are equal within given \a tolerance
|
//! Checks if two vectors are equal within given \a tolerance
|
||||||
inline bool VectorsEqual(const glm::vec3 &a, const glm::vec3 &b, float tolerance = TOLERANCE)
|
inline bool VectorsEqual(const glm::vec3 &a, const glm::vec3 &b, float tolerance = TOLERANCE)
|
||||||
{
|
{
|
||||||
|
@ -49,7 +46,7 @@ inline bool VectorsEqual(const glm::vec3 &a, const glm::vec3 &b, float tolerance
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Convenience function for getting normalized vector
|
//! Convenience function for getting normalized vector
|
||||||
inline Vector Normalize(const glm::vec3 &v)
|
inline glm::vec3 Normalize(const glm::vec3 &v)
|
||||||
{
|
{
|
||||||
return glm::normalize(v);
|
return glm::normalize(v);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +58,7 @@ inline float DotProduct(const glm::vec3 &left, const glm::vec3 &right)
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Convenience function for calculating cross product
|
//! Convenience function for calculating cross product
|
||||||
inline Vector CrossProduct(const glm::vec3 &left, const glm::vec3 &right)
|
inline glm::vec3 CrossProduct(const glm::vec3 &left, const glm::vec3 &right)
|
||||||
{
|
{
|
||||||
return glm::cross(left, right);
|
return glm::cross(left, right);
|
||||||
}
|
}
|
||||||
|
@ -79,12 +76,12 @@ inline float Distance(const glm::vec3 &a, const glm::vec3 &b)
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Clamps the vector \a vec to range between \a min and \a max
|
//! Clamps the vector \a vec to range between \a min and \a max
|
||||||
inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
|
inline glm::vec3 Clamp(const glm::vec3&vec, const glm::vec3&min, const glm::vec3&max)
|
||||||
{
|
{
|
||||||
return glm::clamp(vec, min, max);
|
return glm::clamp(vec, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ToString(const Vector& vector)
|
inline std::string ToString(const glm::vec3& vector)
|
||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s.precision(3);
|
s.precision(3);
|
||||||
|
|
|
@ -46,11 +46,11 @@ protected:
|
||||||
|
|
||||||
void SetUp() override;
|
void SetUp() override;
|
||||||
|
|
||||||
void PrepareLightTesting(int maxLights, Math::Vector eyePos);
|
void PrepareLightTesting(int maxLights, glm::vec3 eyePos);
|
||||||
void CheckLightSorting(EngineObjectType objectType, const std::vector<int>& expectedLights);
|
void CheckLightSorting(EngineObjectType objectType, const std::vector<int>& expectedLights);
|
||||||
void CheckLight(int index, const Light& light);
|
void CheckLight(int index, const Light& light);
|
||||||
void AddLight(int type, LightPriority priority, bool used, bool enabled,
|
void AddLight(int type, LightPriority priority, bool used, bool enabled,
|
||||||
Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType);
|
glm::vec3 pos, EngineObjectType includeType, EngineObjectType excludeType);
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<CLightManager> m_lightManager;
|
std::unique_ptr<CLightManager> m_lightManager;
|
||||||
|
@ -72,7 +72,7 @@ void CLightManagerUT::SetUp()
|
||||||
m_lightManager = MakeUnique<CLightManager>(m_engine);
|
m_lightManager = MakeUnique<CLightManager>(m_engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLightManagerUT::PrepareLightTesting(int maxLights, Math::Vector eyePos)
|
void CLightManagerUT::PrepareLightTesting(int maxLights, glm::vec3 eyePos)
|
||||||
{
|
{
|
||||||
m_maxLightsCount = maxLights;
|
m_maxLightsCount = maxLights;
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ void CLightManagerUT::CheckLight(int index, const Light& light)
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLightManagerUT::AddLight(int type, LightPriority priority, bool used, bool enabled,
|
void CLightManagerUT::AddLight(int type, LightPriority priority, bool used, bool enabled,
|
||||||
Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType)
|
glm::vec3 pos, EngineObjectType includeType, EngineObjectType excludeType)
|
||||||
{
|
{
|
||||||
int rank = m_lightManager->CreateLight(priority);
|
int rank = m_lightManager->CreateLight(priority);
|
||||||
|
|
||||||
|
@ -132,12 +132,12 @@ void CLightManagerUT::AddLight(int type, LightPriority priority, bool used, bool
|
||||||
TEST_F(CLightManagerUT, LightSorting_UnusedOrDisabledAreSkipped)
|
TEST_F(CLightManagerUT, LightSorting_UnusedOrDisabledAreSkipped)
|
||||||
{
|
{
|
||||||
const int lightCount = 10;
|
const int lightCount = 10;
|
||||||
const Math::Vector eyePos(0.0f, 0.0f, 0.0f);
|
const glm::vec3 eyePos(0.0f, 0.0f, 0.0f);
|
||||||
PrepareLightTesting(lightCount, eyePos);
|
PrepareLightTesting(lightCount, eyePos);
|
||||||
|
|
||||||
AddLight(1, LIGHT_PRI_LOW, false, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(1, LIGHT_PRI_LOW, false, true, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(2, LIGHT_PRI_LOW, true, false, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(2, LIGHT_PRI_LOW, true, false, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(3, LIGHT_PRI_LOW, false, false, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(3, LIGHT_PRI_LOW, false, false, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
|
|
||||||
std::vector<int> expectedLights;
|
std::vector<int> expectedLights;
|
||||||
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
||||||
|
@ -146,12 +146,12 @@ TEST_F(CLightManagerUT, LightSorting_UnusedOrDisabledAreSkipped)
|
||||||
TEST_F(CLightManagerUT, LightSorting_IncludeTypesAreIncluded)
|
TEST_F(CLightManagerUT, LightSorting_IncludeTypesAreIncluded)
|
||||||
{
|
{
|
||||||
const int lightCount = 10;
|
const int lightCount = 10;
|
||||||
const Math::Vector eyePos(0.0f, 0.0f, 0.0f);
|
const glm::vec3 eyePos(0.0f, 0.0f, 0.0f);
|
||||||
PrepareLightTesting(lightCount, eyePos);
|
PrepareLightTesting(lightCount, eyePos);
|
||||||
|
|
||||||
AddLight(1, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(1, LIGHT_PRI_LOW, true, true, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_TERRAIN, ENG_OBJTYPE_NULL);
|
AddLight(2, LIGHT_PRI_LOW, true, true, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_TERRAIN, ENG_OBJTYPE_NULL);
|
||||||
AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_QUARTZ, ENG_OBJTYPE_NULL);
|
AddLight(3, LIGHT_PRI_LOW, true, true, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_QUARTZ, ENG_OBJTYPE_NULL);
|
||||||
|
|
||||||
std::vector<int> expectedLights = { 1, 2 };
|
std::vector<int> expectedLights = { 1, 2 };
|
||||||
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
||||||
|
@ -160,12 +160,12 @@ TEST_F(CLightManagerUT, LightSorting_IncludeTypesAreIncluded)
|
||||||
TEST_F(CLightManagerUT, LightSorting_ExcludeTypesAreExcluded)
|
TEST_F(CLightManagerUT, LightSorting_ExcludeTypesAreExcluded)
|
||||||
{
|
{
|
||||||
const int lightCount = 10;
|
const int lightCount = 10;
|
||||||
const Math::Vector eyePos(0.0f, 0.0f, 0.0f);
|
const glm::vec3 eyePos(0.0f, 0.0f, 0.0f);
|
||||||
PrepareLightTesting(lightCount, eyePos);
|
PrepareLightTesting(lightCount, eyePos);
|
||||||
|
|
||||||
AddLight(1, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(1, LIGHT_PRI_LOW, true, true, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_TERRAIN);
|
AddLight(2, LIGHT_PRI_LOW, true, true, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_TERRAIN);
|
||||||
AddLight(3, LIGHT_PRI_LOW, true, true, Math::Vector(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_QUARTZ);
|
AddLight(3, LIGHT_PRI_LOW, true, true, glm::vec3(0.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_QUARTZ);
|
||||||
|
|
||||||
std::vector<int> expectedLights = { 1, 3 };
|
std::vector<int> expectedLights = { 1, 3 };
|
||||||
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
||||||
|
@ -174,15 +174,15 @@ TEST_F(CLightManagerUT, LightSorting_ExcludeTypesAreExcluded)
|
||||||
TEST_F(CLightManagerUT, LightSorting_SortingAccordingToDistance)
|
TEST_F(CLightManagerUT, LightSorting_SortingAccordingToDistance)
|
||||||
{
|
{
|
||||||
const int lightCount = 3;
|
const int lightCount = 3;
|
||||||
const Math::Vector eyePos(0.0f, 0.0f, 0.0f);
|
const glm::vec3 eyePos(0.0f, 0.0f, 0.0f);
|
||||||
PrepareLightTesting(lightCount, eyePos);
|
PrepareLightTesting(lightCount, eyePos);
|
||||||
|
|
||||||
AddLight(1, LIGHT_PRI_HIGH, true, true, Math::Vector(10.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(1, LIGHT_PRI_HIGH, true, true, glm::vec3(10.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(2, LIGHT_PRI_LOW, true, true, Math::Vector(4.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(2, LIGHT_PRI_LOW, true, true, glm::vec3(4.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(3, LIGHT_PRI_HIGH, true, true, Math::Vector(20.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(3, LIGHT_PRI_HIGH, true, true, glm::vec3(20.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(4, LIGHT_PRI_LOW, true, true, Math::Vector(11.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(4, LIGHT_PRI_LOW, true, true, glm::vec3(11.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(5, LIGHT_PRI_LOW, true, true, Math::Vector(100.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(5, LIGHT_PRI_LOW, true, true, glm::vec3(100.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
AddLight(6, LIGHT_PRI_HIGH, true, true, Math::Vector(21.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
AddLight(6, LIGHT_PRI_HIGH, true, true, glm::vec3(21.0f, 0.0f, 0.0f), ENG_OBJTYPE_NULL, ENG_OBJTYPE_NULL);
|
||||||
|
|
||||||
std::vector<int> expectedLights = { 2, 1, 3 };
|
std::vector<int> expectedLights = { 2, 1, 3 };
|
||||||
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
CheckLightSorting(ENG_OBJTYPE_TERRAIN, expectedLights);
|
||||||
|
|
|
@ -58,8 +58,8 @@ TEST(GeometryTest, RotateAngleTest)
|
||||||
|
|
||||||
int TestAngle()
|
int TestAngle()
|
||||||
{
|
{
|
||||||
const Math::Vector u(-0.0786076246943884, 0.2231249091714256, -1.1601361718477805);
|
const glm::vec3 u(-0.0786076246943884, 0.2231249091714256, -1.1601361718477805);
|
||||||
const Math::Vector v(-1.231228742001907, -1.720549809950561, -0.690468438834111);
|
const glm::vec3 v(-1.231228742001907, -1.720549809950561, -0.690468438834111);
|
||||||
|
|
||||||
float mathResult = Math::Angle(u, v);
|
float mathResult = Math::Angle(u, v);
|
||||||
float oldMathResult = Angle(VEC_TO_D3DVEC(u), VEC_TO_D3DVEC(v));
|
float oldMathResult = Angle(VEC_TO_D3DVEC(u), VEC_TO_D3DVEC(v));
|
||||||
|
@ -72,13 +72,13 @@ int TestAngle()
|
||||||
|
|
||||||
int TestRotateView()
|
int TestRotateView()
|
||||||
{
|
{
|
||||||
const Math::Vector center(0.617909142705555, 0.896939729454538, -0.615041943652284);
|
const glm::vec3 center(0.617909142705555, 0.896939729454538, -0.615041943652284);
|
||||||
const float angleH = 44.5;
|
const float angleH = 44.5;
|
||||||
const float angleV = 12.3;
|
const float angleV = 12.3;
|
||||||
const float dist = 34.76;
|
const float dist = 34.76;
|
||||||
|
|
||||||
Math::Vector mathResult = Math::RotateView(center, angleH, angleV, dist);
|
glm::vec3 mathResult = Math::RotateView(center, angleH, angleV, dist);
|
||||||
Math::Vector oldMathResult = D3DVEC_TO_VEC(RotateView(VEC_TO_D3DVEC(center), angleH, angleV, dist));
|
glm::vec3 oldMathResult = D3DVEC_TO_VEC(RotateView(VEC_TO_D3DVEC(center), angleH, angleV, dist));
|
||||||
|
|
||||||
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
||||||
return __LINE__;
|
return __LINE__;
|
||||||
|
@ -88,13 +88,13 @@ int TestRotateView()
|
||||||
|
|
||||||
int TestLookatPoint()
|
int TestLookatPoint()
|
||||||
{
|
{
|
||||||
const Math::Vector eye(-2.451183170579471, 0.241270270546559, -0.490677411454893);
|
const glm::vec3 eye(-2.451183170579471, 0.241270270546559, -0.490677411454893);
|
||||||
const float angleH = 48.4;
|
const float angleH = 48.4;
|
||||||
const float angleV = 32.4;
|
const float angleV = 32.4;
|
||||||
const float length = 74.44;
|
const float length = 74.44;
|
||||||
|
|
||||||
Math::Vector mathResult = Math::LookatPoint(eye, angleH, angleV, length);
|
glm::vec3 mathResult = Math::LookatPoint(eye, angleH, angleV, length);
|
||||||
Math::Vector oldMathResult = D3DVEC_TO_VEC(LookatPoint(VEC_TO_D3DVEC(eye), angleH, angleV, length));
|
glm::vec3 oldMathResult = D3DVEC_TO_VEC(LookatPoint(VEC_TO_D3DVEC(eye), angleH, angleV, length));
|
||||||
|
|
||||||
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
||||||
return __LINE__;
|
return __LINE__;
|
||||||
|
@ -104,12 +104,12 @@ int TestLookatPoint()
|
||||||
|
|
||||||
int TestProjection()
|
int TestProjection()
|
||||||
{
|
{
|
||||||
const Math::Vector a(0.852064846846319, -0.794279497087496, -0.655779805476688);
|
const glm::vec3 a(0.852064846846319, -0.794279497087496, -0.655779805476688);
|
||||||
const Math::Vector b(-0.245838834102304, -0.841115596038861, 0.470457161487799);
|
const glm::vec3 b(-0.245838834102304, -0.841115596038861, 0.470457161487799);
|
||||||
const Math::Vector p(2.289326061164255, -0.505511362271196, 0.660204551169491);
|
const glm::vec3 p(2.289326061164255, -0.505511362271196, 0.660204551169491);
|
||||||
|
|
||||||
Math::Vector mathResult = Math::Projection(a, b, p);
|
glm::vec3 mathResult = Math::Projection(a, b, p);
|
||||||
Math::Vector oldMathResult = D3DVEC_TO_VEC(Projection(VEC_TO_D3DVEC(a), VEC_TO_D3DVEC(b), VEC_TO_D3DVEC(p)));
|
glm::vec3 oldMathResult = D3DVEC_TO_VEC(Projection(VEC_TO_D3DVEC(a), VEC_TO_D3DVEC(b), VEC_TO_D3DVEC(p)));
|
||||||
|
|
||||||
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
||||||
return __LINE__;
|
return __LINE__;
|
||||||
|
@ -119,9 +119,9 @@ int TestProjection()
|
||||||
|
|
||||||
int TestLoadViewMatrix()
|
int TestLoadViewMatrix()
|
||||||
{
|
{
|
||||||
const Math::Vector from(2.5646013154868874, -0.6058794133917031, -0.0441195127419744);
|
const glm::vec3 from(2.5646013154868874, -0.6058794133917031, -0.0441195127419744);
|
||||||
const Math::Vector at(0.728044925765569, -0.206343977871841, 2.543158236935463);
|
const glm::vec3 at(0.728044925765569, -0.206343977871841, 2.543158236935463);
|
||||||
const Math::Vector worldUp(-1.893738133660711, -1.009584441407070, 0.521745988225582);
|
const glm::vec3 worldUp(-1.893738133660711, -1.009584441407070, 0.521745988225582);
|
||||||
|
|
||||||
Math::Matrix mathResult;
|
Math::Matrix mathResult;
|
||||||
Math::LoadViewMatrix(mathResult, from, at, worldUp);
|
Math::LoadViewMatrix(mathResult, from, at, worldUp);
|
||||||
|
@ -167,7 +167,7 @@ int TestLoadProjectionMatrix()
|
||||||
|
|
||||||
int TestLoadTranslationMatrix()
|
int TestLoadTranslationMatrix()
|
||||||
{
|
{
|
||||||
const Math::Vector translation(-0.3631590720995237, 1.6976327614875211, 0.0148815191502145);
|
const glm::vec3 translation(-0.3631590720995237, 1.6976327614875211, 0.0148815191502145);
|
||||||
|
|
||||||
Math::Matrix mathResult;
|
Math::Matrix mathResult;
|
||||||
Math::LoadTranslationMatrix(mathResult, translation);
|
Math::LoadTranslationMatrix(mathResult, translation);
|
||||||
|
@ -187,7 +187,7 @@ int TestLoadTranslationMatrix()
|
||||||
|
|
||||||
int TestLoadScaleMatrix()
|
int TestLoadScaleMatrix()
|
||||||
{
|
{
|
||||||
const Math::Vector scale(0.612236460285503, -0.635566935025364, -0.254321375332065);
|
const glm::vec3 scale(0.612236460285503, -0.635566935025364, -0.254321375332065);
|
||||||
|
|
||||||
Math::Matrix mathResult;
|
Math::Matrix mathResult;
|
||||||
Math::LoadScaleMatrix(mathResult, scale);
|
Math::LoadScaleMatrix(mathResult, scale);
|
||||||
|
@ -268,7 +268,7 @@ int TestLoadRotationZMatrix()
|
||||||
int TestLoadRotationMatrix()
|
int TestLoadRotationMatrix()
|
||||||
{
|
{
|
||||||
const float angle = -0.987747190637790;
|
const float angle = -0.987747190637790;
|
||||||
const Math::Vector dir(-0.113024727688331, -0.781265998072571, 1.838972397076884);
|
const glm::vec3 dir(-0.113024727688331, -0.781265998072571, 1.838972397076884);
|
||||||
|
|
||||||
Math::Matrix mathResult;
|
Math::Matrix mathResult;
|
||||||
Math::LoadRotationMatrix(mathResult, dir, angle);
|
Math::LoadRotationMatrix(mathResult, dir, angle);
|
||||||
|
@ -289,7 +289,7 @@ int TestLoadRotationMatrix()
|
||||||
|
|
||||||
int TestLoadRotationXZYMatrix()
|
int TestLoadRotationXZYMatrix()
|
||||||
{
|
{
|
||||||
const Math::Vector angles(-0.841366567984597, -0.100543315396357, 1.610647811559988);
|
const glm::vec3 angles(-0.841366567984597, -0.100543315396357, 1.610647811559988);
|
||||||
|
|
||||||
Math::Matrix mathResult;
|
Math::Matrix mathResult;
|
||||||
Math::LoadRotationXZYMatrix(mathResult, angles);
|
Math::LoadRotationXZYMatrix(mathResult, angles);
|
||||||
|
@ -309,7 +309,7 @@ int TestLoadRotationXZYMatrix()
|
||||||
|
|
||||||
int TestLoadRotationZXYMatrix()
|
int TestLoadRotationZXYMatrix()
|
||||||
{
|
{
|
||||||
const Math::Vector angles(0.275558495480206, -0.224328265970090, 0.943077216574253);
|
const glm::vec3 angles(0.275558495480206, -0.224328265970090, 0.943077216574253);
|
||||||
|
|
||||||
Math::Matrix mathResult;
|
Math::Matrix mathResult;
|
||||||
Math::LoadRotationZXYMatrix(mathResult, angles);
|
Math::LoadRotationZXYMatrix(mathResult, angles);
|
||||||
|
@ -338,10 +338,10 @@ int TestTransform()
|
||||||
{ 0.0f, 0.0f, 0.0f, 1.0f }
|
{ 0.0f, 0.0f, 0.0f, 1.0f }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Math::Vector vector(-0.314596433318370, -0.622681232583150, -0.371307535743574);
|
glm::vec3 vector(-0.314596433318370, -0.622681232583150, -0.371307535743574);
|
||||||
|
|
||||||
Math::Vector mathResult = Math::Transform(transformMatrix, vector);
|
glm::vec3 mathResult = Math::Transform(transformMatrix, vector);
|
||||||
Math::Vector oldMathResult = Transform(transformMatrix, vector);
|
glm::vec3 oldMathResult = Transform(transformMatrix, vector);
|
||||||
|
|
||||||
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
if (! Math::VectorsEqual(mathResult, oldMathResult, TEST_TOLERANCE))
|
||||||
return __LINE__;
|
return __LINE__;
|
||||||
|
|
|
@ -270,11 +270,11 @@ TEST(MatrixTest, MultiplyVectorTest)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const Math::Vector vec1(-0.824708565156661f, -1.598287748103842f, -0.422498044734181f);
|
const glm::vec3 vec1(-0.824708565156661f, -1.598287748103842f, -0.422498044734181f);
|
||||||
|
|
||||||
const Math::Vector expectedMultiply1(0.608932463260470f, -1.356893266403749f, 3.457156276255142f);
|
const glm::vec3 expectedMultiply1(0.608932463260470f, -1.356893266403749f, 3.457156276255142f);
|
||||||
|
|
||||||
Math::Vector multiply1 = Math::MatrixVectorMultiply(mat1, vec1, false);
|
glm::vec3 multiply1 = Math::MatrixVectorMultiply(mat1, vec1, false);
|
||||||
EXPECT_TRUE(Math::VectorsEqual(multiply1, expectedMultiply1, TEST_TOLERANCE));
|
EXPECT_TRUE(Math::VectorsEqual(multiply1, expectedMultiply1, TEST_TOLERANCE));
|
||||||
|
|
||||||
const Math::Matrix mat2(
|
const Math::Matrix mat2(
|
||||||
|
@ -286,10 +286,10 @@ TEST(MatrixTest, MultiplyVectorTest)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const Math::Vector vec2(0.330987381051962f, 1.494375516393466f, 1.483422335561857f);
|
const glm::vec3 vec2(0.330987381051962f, 1.494375516393466f, 1.483422335561857f);
|
||||||
|
|
||||||
const Math::Vector expectedMultiply2(0.2816820577317669f, 0.0334468811767428f, 0.1996974284970455f);
|
const glm::vec3 expectedMultiply2(0.2816820577317669f, 0.0334468811767428f, 0.1996974284970455f);
|
||||||
|
|
||||||
Math::Vector multiply2 = Math::MatrixVectorMultiply(mat2, vec2, true);
|
glm::vec3 multiply2 = Math::MatrixVectorMultiply(mat2, vec2, true);
|
||||||
EXPECT_TRUE(Math::VectorsEqual(multiply2, expectedMultiply2, TEST_TOLERANCE));
|
EXPECT_TRUE(Math::VectorsEqual(multiply2, expectedMultiply2, TEST_TOLERANCE));
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ const float TEST_TOLERANCE = 1e-6;
|
||||||
|
|
||||||
TEST(VectorTest, LengthTest)
|
TEST(VectorTest, LengthTest)
|
||||||
{
|
{
|
||||||
Math::Vector vec(-1.288447945923275, 0.681452565308134, -0.633761098985957);
|
glm::vec3 vec(-1.288447945923275, 0.681452565308134, -0.633761098985957);
|
||||||
const float expectedLength = 1.58938001708428;
|
const float expectedLength = 1.58938001708428;
|
||||||
|
|
||||||
EXPECT_TRUE(Math::IsEqual(glm::length(vec), expectedLength, TEST_TOLERANCE));
|
EXPECT_TRUE(Math::IsEqual(glm::length(vec), expectedLength, TEST_TOLERANCE));
|
||||||
|
@ -43,8 +43,8 @@ TEST(VectorTest, LengthTest)
|
||||||
|
|
||||||
TEST(VectorTest, NormalizeTest)
|
TEST(VectorTest, NormalizeTest)
|
||||||
{
|
{
|
||||||
Math::Vector vec(1.848877241804398, -0.157262961268577, -1.963031403332377);
|
glm::vec3 vec(1.848877241804398, -0.157262961268577, -1.963031403332377);
|
||||||
const Math::Vector expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797);
|
const glm::vec3 expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797);
|
||||||
|
|
||||||
vec = glm::normalize(vec);
|
vec = glm::normalize(vec);
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ TEST(VectorTest, NormalizeTest)
|
||||||
|
|
||||||
TEST(VectorTest, DotTest)
|
TEST(VectorTest, DotTest)
|
||||||
{
|
{
|
||||||
Math::Vector vecA(0.8202190530968309, 0.0130926060162780, 0.2411914183883510);
|
glm::vec3 vecA(0.8202190530968309, 0.0130926060162780, 0.2411914183883510);
|
||||||
Math::Vector vecB(-0.0524083951404069, 1.5564932716738220, -0.8971342631500536);
|
glm::vec3 vecB(-0.0524083951404069, 1.5564932716738220, -0.8971342631500536);
|
||||||
|
|
||||||
float expectedDot = -0.238988896477326;
|
float expectedDot = -0.238988896477326;
|
||||||
|
|
||||||
|
@ -63,11 +63,11 @@ TEST(VectorTest, DotTest)
|
||||||
|
|
||||||
TEST(VectorTest, CrossTest)
|
TEST(VectorTest, CrossTest)
|
||||||
{
|
{
|
||||||
Math::Vector vecA(1.37380499798567, 1.18054518384682, 1.95166361293121);
|
glm::vec3 vecA(1.37380499798567, 1.18054518384682, 1.95166361293121);
|
||||||
Math::Vector vecB(0.891657855926886, 0.447591335394532, -0.901604070087823);
|
glm::vec3 vecB(0.891657855926886, 0.447591335394532, -0.901604070087823);
|
||||||
|
|
||||||
Math::Vector expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581);
|
glm::vec3 expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581);
|
||||||
Math::Vector expectedReverseCross = -expectedCross;
|
glm::vec3 expectedReverseCross = -expectedCross;
|
||||||
|
|
||||||
EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecA, vecB), expectedCross, TEST_TOLERANCE));
|
EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecA, vecB), expectedCross, TEST_TOLERANCE));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue