|
@@ -1,16 +1,17 @@
|
|
-#include <cmath>
|
|
|
|
-
|
|
|
|
#include "tests/MatrixTests.h"
|
|
#include "tests/MatrixTests.h"
|
|
|
|
+#include "math/Matrix.h"
|
|
#include "tests/Test.h"
|
|
#include "tests/Test.h"
|
|
#include "utils/StringBuffer.h"
|
|
#include "utils/StringBuffer.h"
|
|
-#include "math/Matrix.h"
|
|
|
|
|
|
|
|
const float eps = 0.0001f;
|
|
const float eps = 0.0001f;
|
|
|
|
|
|
template<int N>
|
|
template<int N>
|
|
-static void compareVectors(Test& test, const Vector<N>& wanted, const Vector<N>& actual, const char* text) {
|
|
|
|
|
|
+static void compareVectors(Test& test, const Vector<N>& wanted,
|
|
|
|
+ const Vector<N>& actual, const char* text) {
|
|
for(int i = 0; i < N; i++) {
|
|
for(int i = 0; i < N; i++) {
|
|
- test.checkFloat(wanted[i], actual[i], eps, StringBuffer<50>(text).append(" (").append(i).append(")"));
|
|
|
|
|
|
+ test.checkFloat(
|
|
|
|
+ wanted[i], actual[i], eps,
|
|
|
|
+ StringBuffer<50>(text).append(" (").append(i).append(")"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -20,7 +21,8 @@ static void testInit(Test& test) {
|
|
for(int i = 0; i < 16; i++) {
|
|
for(int i = 0; i < 16; i++) {
|
|
int x = i % 4;
|
|
int x = i % 4;
|
|
int y = i / 4;
|
|
int y = i / 4;
|
|
- test.checkEqual(static_cast<float> (x == y), data[i], StringBuffer<50>("init ").append(i));
|
|
|
|
|
|
+ test.checkEqual(static_cast<float>(x == y), data[i],
|
|
|
|
+ StringBuffer<50>("init ").append(i));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -44,44 +46,51 @@ static void testTranspose(Test& test) {
|
|
}
|
|
}
|
|
const float* mp2 = m2.getValues();
|
|
const float* mp2 = m2.getValues();
|
|
for(int i = 0; i < 16; i++) {
|
|
for(int i = 0; i < 16; i++) {
|
|
- test.checkEqual(mp[i], mp2[i], StringBuffer<50>("transpose ").append(i));
|
|
|
|
|
|
+ test.checkEqual(mp[i], mp2[i],
|
|
|
|
+ StringBuffer<50>("transpose ").append(i));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
static void testScale(Test& test) {
|
|
static void testScale(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.scale(Vector3(2.0f, 3.0f, 4.0f));
|
|
m.scale(Vector3(2.0f, 3.0f, 4.0f));
|
|
- compareVectors(test, Vector3(-8.0f, 18.0f, 28.0f), m * Vector3(-4.0f, 6.0f, 7.0f), "scale");
|
|
|
|
|
|
+ compareVectors(test, Vector3(-8.0f, 18.0f, 28.0f),
|
|
|
|
+ m * Vector3(-4.0f, 6.0f, 7.0f), "scale");
|
|
}
|
|
}
|
|
|
|
|
|
static void testUniformScale(Test& test) {
|
|
static void testUniformScale(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.scale(2.0f);
|
|
m.scale(2.0f);
|
|
- compareVectors(test, Vector3(-8.0f, 12.0f, 14.0f), m * Vector3(-4.0f, 6.0f, 7.0f), "uniform scale");
|
|
|
|
|
|
+ compareVectors(test, Vector3(-8.0f, 12.0f, 14.0f),
|
|
|
|
+ m * Vector3(-4.0f, 6.0f, 7.0f), "uniform scale");
|
|
}
|
|
}
|
|
|
|
|
|
static void testTranslateX(Test& test) {
|
|
static void testTranslateX(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.translateX(5.0f);
|
|
m.translateX(5.0f);
|
|
- compareVectors(test, Vector3(1.0f, 6.0f, 7.0f), m * Vector3(-4.0f, 6.0f, 7.0f), "translate x");
|
|
|
|
|
|
+ compareVectors(test, Vector3(1.0f, 6.0f, 7.0f),
|
|
|
|
+ m * Vector3(-4.0f, 6.0f, 7.0f), "translate x");
|
|
}
|
|
}
|
|
|
|
|
|
static void testTranslateY(Test& test) {
|
|
static void testTranslateY(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.translateY(6.0f);
|
|
m.translateY(6.0f);
|
|
- compareVectors(test, Vector3(-4.0f, 12.0f, 7.0f), m * Vector3(-4.0f, 6.0f, 7.0f), "translate y");
|
|
|
|
|
|
+ compareVectors(test, Vector3(-4.0f, 12.0f, 7.0f),
|
|
|
|
+ m * Vector3(-4.0f, 6.0f, 7.0f), "translate y");
|
|
}
|
|
}
|
|
|
|
|
|
static void testTranslateZ(Test& test) {
|
|
static void testTranslateZ(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.translateZ(7.0f);
|
|
m.translateZ(7.0f);
|
|
- compareVectors(test, Vector3(-4.0f, 6.0f, 14.0f), m * Vector3(-4.0f, 6.0f, 7.0f), "translate z");
|
|
|
|
|
|
+ compareVectors(test, Vector3(-4.0f, 6.0f, 14.0f),
|
|
|
|
+ m * Vector3(-4.0f, 6.0f, 7.0f), "translate z");
|
|
}
|
|
}
|
|
|
|
|
|
static void testTranslate(Test& test) {
|
|
static void testTranslate(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.translate(Vector3(1.0f, 2.0f, 3.0f));
|
|
m.translate(Vector3(1.0f, 2.0f, 3.0f));
|
|
- compareVectors(test, Vector3(-3.0f, 8.0f, 10.0f), m * Vector3(-4.0f, 6.0f, 7.0f), "translate");
|
|
|
|
|
|
+ compareVectors(test, Vector3(-3.0f, 8.0f, 10.0f),
|
|
|
|
+ m * Vector3(-4.0f, 6.0f, 7.0f), "translate");
|
|
}
|
|
}
|
|
|
|
|
|
static void testCombination(Test& test) {
|
|
static void testCombination(Test& test) {
|
|
@@ -93,7 +102,8 @@ static void testCombination(Test& test) {
|
|
m.translate(Vector3(-4.0f, 2.0f, 3.0f));
|
|
m.translate(Vector3(-4.0f, 2.0f, 3.0f));
|
|
m.scale(Vector3(2.0f, 3.0f, 4.0f));
|
|
m.scale(Vector3(2.0f, 3.0f, 4.0f));
|
|
m.scale(0.5f);
|
|
m.scale(0.5f);
|
|
- compareVectors(test, Vector3(-1.0f, 9.0f, 16.0f), m * Vector3(1.0f, 1.0f, 1.0f), "combination");
|
|
|
|
|
|
+ compareVectors(test, Vector3(-1.0f, 9.0f, 16.0f),
|
|
|
|
+ m * Vector3(1.0f, 1.0f, 1.0f), "combination");
|
|
}
|
|
}
|
|
|
|
|
|
static void testMatrixCombination(Test& test) {
|
|
static void testMatrixCombination(Test& test) {
|
|
@@ -109,31 +119,41 @@ static void testMatrixCombination(Test& test) {
|
|
c.translate(Vector3(-1.0f, -2.0f, -3.0f));
|
|
c.translate(Vector3(-1.0f, -2.0f, -3.0f));
|
|
c *= b * a;
|
|
c *= b * a;
|
|
|
|
|
|
- compareVectors(test, Vector3(9.0f, 11.0f, 13.0f), c * Vector3(1.0f, 1.0f, 1.0f), "combination");
|
|
|
|
|
|
+ compareVectors(test, Vector3(9.0f, 11.0f, 13.0f),
|
|
|
|
+ c * Vector3(1.0f, 1.0f, 1.0f), "combination");
|
|
}
|
|
}
|
|
|
|
|
|
static void testRotateX(Test& test) {
|
|
static void testRotateX(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.rotateX(90);
|
|
m.rotateX(90);
|
|
- compareVectors(test, Vector3(1.0f, 0.0f, 0.0f), m * Vector3(1.0f, 0.0f, 0.0f), "rotate x 1");
|
|
|
|
- compareVectors(test, Vector3(0.0f, 0.0f, 1.0f), m * Vector3(0.0f, 1.0f, 0.0f), "rotate x 2");
|
|
|
|
- compareVectors(test, Vector3(0.0f, -1.0f, 0.0f), m * Vector3(0.0f, 0.0f, 1.0f), "rotate x 3");
|
|
|
|
|
|
+ compareVectors(test, Vector3(1.0f, 0.0f, 0.0f),
|
|
|
|
+ m * Vector3(1.0f, 0.0f, 0.0f), "rotate x 1");
|
|
|
|
+ compareVectors(test, Vector3(0.0f, 0.0f, 1.0f),
|
|
|
|
+ m * Vector3(0.0f, 1.0f, 0.0f), "rotate x 2");
|
|
|
|
+ compareVectors(test, Vector3(0.0f, -1.0f, 0.0f),
|
|
|
|
+ m * Vector3(0.0f, 0.0f, 1.0f), "rotate x 3");
|
|
}
|
|
}
|
|
|
|
|
|
static void testRotateY(Test& test) {
|
|
static void testRotateY(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.rotateY(90);
|
|
m.rotateY(90);
|
|
- compareVectors(test, Vector3(0.0f, 0.0f, -1.0f), m * Vector3(1.0f, 0.0f, 0.0f), "rotate y 1");
|
|
|
|
- compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), m * Vector3(0.0f, 1.0f, 0.0f), "rotate y 2");
|
|
|
|
- compareVectors(test, Vector3(1.0f, 0.0f, 0.0f), m * Vector3(0.0f, 0.0f, 1.0f), "rotate y 3");
|
|
|
|
|
|
+ compareVectors(test, Vector3(0.0f, 0.0f, -1.0f),
|
|
|
|
+ m * Vector3(1.0f, 0.0f, 0.0f), "rotate y 1");
|
|
|
|
+ compareVectors(test, Vector3(0.0f, 1.0f, 0.0f),
|
|
|
|
+ m * Vector3(0.0f, 1.0f, 0.0f), "rotate y 2");
|
|
|
|
+ compareVectors(test, Vector3(1.0f, 0.0f, 0.0f),
|
|
|
|
+ m * Vector3(0.0f, 0.0f, 1.0f), "rotate y 3");
|
|
}
|
|
}
|
|
|
|
|
|
static void testRotateZ(Test& test) {
|
|
static void testRotateZ(Test& test) {
|
|
Matrix m;
|
|
Matrix m;
|
|
m.rotateZ(90);
|
|
m.rotateZ(90);
|
|
- compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), m * Vector3(1.0f, 0.0f, 0.0f), "rotate z 1");
|
|
|
|
- compareVectors(test, Vector3(-1.0f, 0.0f, 0.0f), m * Vector3(0.0f, 1.0f, 0.0f), "rotate z 2");
|
|
|
|
- compareVectors(test, Vector3(0.0f, 0.0f, 1.0f), m * Vector3(0.0f, 0.0f, 1.0f), "rotate z 3");
|
|
|
|
|
|
+ compareVectors(test, Vector3(0.0f, 1.0f, 0.0f),
|
|
|
|
+ m * Vector3(1.0f, 0.0f, 0.0f), "rotate z 1");
|
|
|
|
+ compareVectors(test, Vector3(-1.0f, 0.0f, 0.0f),
|
|
|
|
+ m * Vector3(0.0f, 1.0f, 0.0f), "rotate z 2");
|
|
|
|
+ compareVectors(test, Vector3(0.0f, 0.0f, 1.0f),
|
|
|
|
+ m * Vector3(0.0f, 0.0f, 1.0f), "rotate z 3");
|
|
}
|
|
}
|
|
|
|
|
|
static void testToString(Test& test) {
|
|
static void testToString(Test& test) {
|
|
@@ -144,8 +164,11 @@ static void testToString(Test& test) {
|
|
m.set(2, Vector4(9.0f, 10.0f, 11.0f, 12.0f));
|
|
m.set(2, Vector4(9.0f, 10.0f, 11.0f, 12.0f));
|
|
m.set(3, Vector4(13.0f, 14.0f, 15.0f, 16.0f));
|
|
m.set(3, Vector4(13.0f, 14.0f, 15.0f, 16.0f));
|
|
s.append(m);
|
|
s.append(m);
|
|
- test.checkEqual(StringBuffer<200>("[[1.00, 2.00, 3.00, 4.00], [5.00, 6.00, 7.00, 8.00], "
|
|
|
|
- "[9.00, 10.00, 11.00, 12.00], [13.00, 14.00, 15.00, 16.00]]"), s, "to string");
|
|
|
|
|
|
+ test.checkEqual(
|
|
|
|
+ StringBuffer<200>(
|
|
|
|
+ "[[1.00, 2.00, 3.00, 4.00], [5.00, 6.00, 7.00, 8.00], "
|
|
|
|
+ "[9.00, 10.00, 11.00, 12.00], [13.00, 14.00, 15.00, 16.00]]"),
|
|
|
|
+ s, "to string");
|
|
}
|
|
}
|
|
|
|
|
|
static void testQuaternionMatrix(Test& test) {
|
|
static void testQuaternionMatrix(Test& test) {
|
|
@@ -164,7 +187,8 @@ static void testQuaternionMatrix(Test& test) {
|
|
check.translate(Vector3(1.0f, 2.0f, 3.0f));
|
|
check.translate(Vector3(1.0f, 2.0f, 3.0f));
|
|
|
|
|
|
for(int i = 0; i < 16; i++) {
|
|
for(int i = 0; i < 16; i++) {
|
|
- test.checkFloat(check.getValues()[i], m.getValues()[i], eps, "mul matrix");
|
|
|
|
|
|
+ test.checkFloat(check.getValues()[i], m.getValues()[i], eps,
|
|
|
|
+ "mul matrix");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|