diff --git a/tests/physics/CMakeLists.txt b/tests/physics/CMakeLists.txt new file mode 100644 index 0000000000..482e6e0ec3 --- /dev/null +++ b/tests/physics/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 2.8) + +set(TARGET_NAME physics-tests) + +set(ROOT_DIR ../..) +set(MACRO_DIR ${ROOT_DIR}/cmake/macros) + +# setup for find modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules/") + +#find_package(Qt5Network REQUIRED) +#find_package(Qt5Script REQUIRED) +#find_package(Qt5Widgets REQUIRED) + +include(${MACRO_DIR}/SetupHifiProject.cmake) +setup_hifi_project(${TARGET_NAME} TRUE) + +include(${MACRO_DIR}/AutoMTC.cmake) +auto_mtc(${TARGET_NAME} ${ROOT_DIR}) + +#qt5_use_modules(${TARGET_NAME} Network Script Widgets) + +#include glm +include(${MACRO_DIR}/IncludeGLM.cmake) +include_glm(${TARGET_NAME} ${ROOT_DIR}) + +# link in the shared libraries +include(${MACRO_DIR}/LinkHifiLibrary.cmake) +link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) + +IF (WIN32) + #target_link_libraries(${TARGET_NAME} Winmm Ws2_32) +ENDIF(WIN32) + diff --git a/tests/physics/src/CollisionInfoTests.cpp b/tests/physics/src/CollisionInfoTests.cpp new file mode 100644 index 0000000000..0355e2d27b --- /dev/null +++ b/tests/physics/src/CollisionInfoTests.cpp @@ -0,0 +1,102 @@ +// +// CollisionInfoTests.cpp +// physics-tests +// +// Created by Andrew Meadows on 2014.02.21 +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#include + +#include +#include + +#include +#include + +#include "CollisionInfoTests.h" +#include "PhysicsTestUtil.h" + + +void CollisionInfoTests::rotateThenTranslate() { + CollisionInfo collision; + collision._penetration = xAxis; + collision._contactPoint = yAxis; + collision._addedVelocity = xAxis + yAxis + zAxis; + + glm::quat rotation = glm::angleAxis(rightAngle, zAxis); + float distance = 3.f; + glm::vec3 translation = distance * yAxis; + + collision.rotateThenTranslate(rotation, translation); + + float error = glm::distance(collision._penetration, yAxis); + if (error > EPSILON) { + std::cout << __FILE__ << ":" << __LINE__ + << " ERROR: collision._penetration = " << collision._penetration + << " but we expected " << yAxis + << std::endl; + } + + glm::vec3 expectedContactPoint = -xAxis + translation; + error = glm::distance(collision._contactPoint, expectedContactPoint); + if (error > EPSILON) { + std::cout << __FILE__ << ":" << __LINE__ + << " ERROR: collision._contactPoint = " << collision._contactPoint + << " but we expected " << expectedContactPoint + << std::endl; + } + + glm::vec3 expectedAddedVelocity = yAxis - xAxis + zAxis; + error = glm::distance(collision._addedVelocity, expectedAddedVelocity); + if (error > EPSILON) { + std::cout << __FILE__ << ":" << __LINE__ + << " ERROR: collision._addedVelocity = " << collision._contactPoint + << " but we expected " << expectedAddedVelocity + << std::endl; + } +} + +void CollisionInfoTests::translateThenRotate() { + CollisionInfo collision; + collision._penetration = xAxis; + collision._contactPoint = yAxis; + collision._addedVelocity = xAxis + yAxis + zAxis; + + glm::quat rotation = glm::angleAxis( -rightAngle, zAxis); + float distance = 3.f; + glm::vec3 translation = distance * yAxis; + + collision.translateThenRotate(translation, rotation); + + float error = glm::distance(collision._penetration, -yAxis); + if (error > EPSILON) { + std::cout << __FILE__ << ":" << __LINE__ + << " ERROR: collision._penetration = " << collision._penetration + << " but we expected " << -yAxis + << std::endl; + } + + glm::vec3 expectedContactPoint = (1.f + distance) * xAxis; + error = glm::distance(collision._contactPoint, expectedContactPoint); + if (error > EPSILON) { + std::cout << __FILE__ << ":" << __LINE__ + << " ERROR: collision._contactPoint = " << collision._contactPoint + << " but we expected " << expectedContactPoint + << std::endl; + } + + glm::vec3 expectedAddedVelocity = - yAxis + xAxis + zAxis; + error = glm::distance(collision._addedVelocity, expectedAddedVelocity); + if (error > EPSILON) { + std::cout << __FILE__ << ":" << __LINE__ + << " ERROR: collision._addedVelocity = " << collision._contactPoint + << " but we expected " << expectedAddedVelocity + << std::endl; + } +} + +void CollisionInfoTests::runAllTests() { + CollisionInfoTests::rotateThenTranslate(); + CollisionInfoTests::translateThenRotate(); +} diff --git a/tests/physics/src/CollisionInfoTests.h b/tests/physics/src/CollisionInfoTests.h new file mode 100644 index 0000000000..cc0ef337a2 --- /dev/null +++ b/tests/physics/src/CollisionInfoTests.h @@ -0,0 +1,21 @@ +// +// CollisionInfoTests.h +// physics-tests +// +// Created by Andrew Meadows on 2014.02.21 +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __tests__CollisionInfoTests__ +#define __tests__CollisionInfoTests__ + +namespace CollisionInfoTests { + + void rotateThenTranslate(); + void translateThenRotate(); + + void runAllTests(); +} + +#endif // __tests__CollisionInfoTests__ + diff --git a/tests/physics/src/PhysicsTestUtil.cpp b/tests/physics/src/PhysicsTestUtil.cpp new file mode 100644 index 0000000000..f14739c07f --- /dev/null +++ b/tests/physics/src/PhysicsTestUtil.cpp @@ -0,0 +1,21 @@ +// +// PhysicsTestUtil.cpp +// physics-tests +// +// Created by Andrew Meadows on 2014.02.21 +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#include "PhysicsTestUtil.h" + +std::ostream& operator<<(std::ostream& s, const glm::vec3& v) { + s << "<" << v.x << "," << v.y << "," << v.z << ">"; + return s; +} + +std::ostream& operator<<(std::ostream& s, const CollisionInfo& c) { + s << "[penetration=" << c._penetration + << ", contactPoint=" << c._contactPoint + << ", addedVelocity=" << c._addedVelocity; + return s; +} diff --git a/tests/physics/src/PhysicsTestUtil.h b/tests/physics/src/PhysicsTestUtil.h new file mode 100644 index 0000000000..f63e7e5910 --- /dev/null +++ b/tests/physics/src/PhysicsTestUtil.h @@ -0,0 +1,26 @@ +// +// PhysicsTestUtil.h +// physics-tests +// +// Created by Andrew Meadows on 2014.02.21 +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __tests__PhysicsTestUtil__ +#define __tests__PhysicsTestUtil__ + +#include +#include + +#include + +const glm::vec3 xAxis(1.f, 0.f, 0.f); +const glm::vec3 yAxis(0.f, 1.f, 0.f); +const glm::vec3 zAxis(0.f, 0.f, 1.f); + +const float rightAngle = 90.f; // degrees + +std::ostream& operator<<(std::ostream& s, const glm::vec3& v); +std::ostream& operator<<(std::ostream& s, const CollisionInfo& c); + +#endif // __tests__PhysicsTestUtil__ diff --git a/tests/physics/src/ShapeColliderTests.cpp b/tests/physics/src/ShapeColliderTests.cpp new file mode 100644 index 0000000000..c103179b07 --- /dev/null +++ b/tests/physics/src/ShapeColliderTests.cpp @@ -0,0 +1,33 @@ +// +// ShapeColliderTests.cpp +// physics-tests +// +// Created by Andrew Meadows on 2014.02.21 +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +//#include +#include + +#include +#include + +#include +#include + +#include "PhysicsTestUtil.h" +#include "ShapeColliderTests.h" + + +/* +void ShapeColliderTests::test1() { +} + +void ShapeColliderTests::test2() { +} +*/ + +void ShapeColliderTests::runAllTests() { +// ShapeColliderTests::test1(); +// ShapeColliderTests::test2(); +} diff --git a/tests/physics/src/ShapeColliderTests.h b/tests/physics/src/ShapeColliderTests.h new file mode 100644 index 0000000000..a51fb83854 --- /dev/null +++ b/tests/physics/src/ShapeColliderTests.h @@ -0,0 +1,20 @@ +// +// ShapeColliderTests.h +// physics-tests +// +// Created by Andrew Meadows on 2014.02.21 +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __tests__ShapeColliderTests__ +#define __tests__ShapeColliderTests__ + +namespace ShapeColliderTests { + + //void rotateThenTranslate(); + //void translateThenRotate(); + + void runAllTests(); +} + +#endif // __tests__ShapeColliderTests__ diff --git a/tests/physics/src/main.cpp b/tests/physics/src/main.cpp new file mode 100644 index 0000000000..3ae5a0a6fe --- /dev/null +++ b/tests/physics/src/main.cpp @@ -0,0 +1,15 @@ +// +// main.cpp +// physics-tests +// + +//#include + +#include "ShapeColliderTests.h" +#include "CollisionInfoTests.h" + +int main(int argc, char** argv) { + CollisionInfoTests::runAllTests(); + ShapeColliderTests::runAllTests(); + return 0; +}