123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include "tests/ViewTests.h"
- #include "math/View.h"
- #include "tests/Test.h"
- #include "utils/StringBuffer.h"
- const float eps = 0.0001f;
- template<int N, typename T>
- static void compareVectors(Test& test, const Vector<N, T>& wanted,
- const Vector<N, T>& actual, const char* text) {
- for(int i = 0; i < N; i++) {
- test.checkFloat(
- wanted[i], actual[i], eps,
- StringBuffer<100>(text).append(" (").append(i).append(")"));
- }
- }
- static void testFromAngles(Test& test) {
- View v;
- v.updateDirections(0.0f, 0.0f);
- compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), v.getUp(), "up");
- compareVectors(test, Vector3(0.0f, -1.0f, 0.0f), v.getDown(), "down");
- compareVectors(test, Vector3(0.0f, 0.0f, -1.0f), v.getLeft(), "left");
- compareVectors(test, Vector3(0.0f, 0.0f, 1.0f), v.getRight(), "right");
- compareVectors(test, Vector3(1.0f, 0.0f, 0.0f), v.getFront(), "front");
- compareVectors(test, Vector3(-1.0f, 0.0f, 0.0f), v.getBack(), "back");
- }
- static void testFromQuaternion(Test& test) {
- View v;
- v.updateDirections(Quaternion());
- compareVectors(test, Vector3(0.0f, 1.0f, 0.0f), v.getUp(), "up");
- compareVectors(test, Vector3(0.0f, -1.0f, 0.0f), v.getDown(), "down");
- compareVectors(test, Vector3(0.0f, 0.0f, -1.0f), v.getLeft(), "left");
- compareVectors(test, Vector3(0.0f, 0.0f, 1.0f), v.getRight(), "right");
- compareVectors(test, Vector3(1.0f, 0.0f, 0.0f), v.getFront(), "front");
- compareVectors(test, Vector3(-1.0f, 0.0f, 0.0f), v.getBack(), "back");
- }
- void ViewTests::test() {
- Test test("View");
- testFromAngles(test);
- testFromQuaternion(test);
- test.finalize();
- }
|