#include "tests/ViewTests.h" #include "math/View.h" #include "tests/Test.h" #include "utils/StringBuffer.h" const float eps = 0.0001f; template static void compareVectors(Test& test, const Vector& wanted, const Vector& 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(); }