Merge develop into dod and fix conflicts

This commit is contained in:
Daniel Chappuis 2018-09-09 22:08:55 +02:00
commit 23e16cf156
37 changed files with 3160 additions and 3094 deletions

View File

@ -86,31 +86,33 @@ matrix:
env: env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="False" VALGRIND="True" - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="False" VALGRIND="True"
# This is commented until Travis fixes this issue with GCC install in OSX: https://github.com/travis-ci/travis-ci/issues/8826
# ----- OS X / GCC ----- # ----- OS X / GCC -----
- os: osx #- os: osx
osx_image: xcode8 #- osx_image: xcode9.3
env: #- env:
- MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="False" # - MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="False"
- os: osx #- os: osx
osx_image: xcode8 # osx_image: xcode9.3
env: # env:
- MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Release" DOUBLE_PRECISION="False" # - MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Release" DOUBLE_PRECISION="False"
- os: osx #- os: osx
osx_image: xcode8 # osx_image: xcode9.3
env: # env:
- MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="True" # - MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="True"
- os: osx #- os: osx
osx_image: xcode8 # osx_image: xcode9.3
env: # env:
- MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Release" DOUBLE_PRECISION="True" # - MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Release" DOUBLE_PRECISION="True"
- os: osx #- os: osx
osx_image: xcode8 # osx_image: xcode9.3
env: # env:
- MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="True" LOGGER="True" PROFILER="True" # - MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Debug" DOUBLE_PRECISION="True" LOGGER="True" PROFILER="True"
- os: osx #- os: osx
osx_image: xcode8 # osx_image: xcode9.3
env: # env:
- MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Release" DOUBLE_PRECISION="True" LOGGER="True" PROFILER="True" # - MATRIX_EVAL="brew update && brew install gcc && CC=gcc-7 && CXX=g++-7" BUILD_TYPE="Release" DOUBLE_PRECISION="True" LOGGER="True" PROFILER="True"
# ----- Linux / Clang ----- # ----- Linux / Clang -----
- os: linux - os: linux

View File

@ -1,5 +1,22 @@
# Changelog # Changelog
## Release Candidate
### Fixed
- Bug [#45](https://github.com/DanielChappuis/reactphysics3d/issues/45) has been fixed.
- Bug [#50](https://github.com/DanielChappuis/reactphysics3d/issues/50) has been fixed.
- Bug [#52](https://github.com/DanielChappuis/reactphysics3d/issues/52) has been fixed.
- Bug [#53](https://github.com/DanielChappuis/reactphysics3d/issues/53) has been fixed.
- Bug [#54](https://github.com/DanielChappuis/reactphysics3d/issues/54) has been fixed.
- Bug [#55](https://github.com/DanielChappuis/reactphysics3d/issues/55) has been fixed.
- Bug [#51](https://github.com/DanielChappuis/reactphysics3d/issues/51) has been fixed.
- Bug [#60](https://github.com/DanielChappuis/reactphysics3d/issues/60) has been fixed.
- Bug [#57](https://github.com/DanielChappuis/reactphysics3d/issues/57) has been fixed.
- Bug [#37](https://github.com/DanielChappuis/reactphysics3d/issues/37) has been fixed.
- Bug [#62](https://github.com/DanielChappuis/reactphysics3d/issues/62) has been fixed.
- Bug [#63](https://github.com/DanielChappuis/reactphysics3d/issues/63) has been fixed.
## Version 0.7.0 (May 1, 2018) ## Version 0.7.0 (May 1, 2018)
### Added ### Added

View File

@ -232,7 +232,7 @@ SET (REACTPHYSICS3D_SOURCES
) )
# Create the library # Create the library
ADD_LIBRARY(reactphysics3d STATIC ${REACTPHYSICS3D_HEADERS} ${REACTPHYSICS3D_SOURCES}) ADD_LIBRARY(reactphysics3d ${REACTPHYSICS3D_HEADERS} ${REACTPHYSICS3D_SOURCES})
# Headers # Headers
TARGET_INCLUDE_DIRECTORIES(reactphysics3d PUBLIC TARGET_INCLUDE_DIRECTORIES(reactphysics3d PUBLIC
@ -250,10 +250,18 @@ IF(RP3D_COMPILE_TESTS)
add_subdirectory(test/) add_subdirectory(test/)
ENDIF() ENDIF()
SET_TARGET_PROPERTIES(reactphysics3d PROPERTIES PUBLIC_HEADER "${REACTPHYSICS3D_HEADERS}")
# Version number and soname for the library
SET_TARGET_PROPERTIES(reactphysics3d PROPERTIES
VERSION "0.7.0"
SOVERSION "0.7"
)
# Install target # Install target
INSTALL(TARGETS reactphysics3d INSTALL(TARGETS reactphysics3d
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/reactphysics3d
) )

View File

@ -112,7 +112,7 @@ class CollisionDetection {
void computeNarrowPhase(); void computeNarrowPhase();
/// Add a contact manifold to the linked list of contact manifolds of the two bodies /// Add a contact manifold to the linked list of contact manifolds of the two bodies
/// involed in the corresponding contact. /// involved in the corresponding contact.
void addContactManifoldToBody(OverlappingPair* pair); void addContactManifoldToBody(OverlappingPair* pair);
/// Fill-in the collision detection matrix /// Fill-in the collision detection matrix

View File

@ -36,20 +36,10 @@ using namespace reactphysics3d;
// Constructor // Constructor
BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection) BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection)
:mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP), :mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP),
mNbMovedShapes(0), mNbAllocatedMovedShapes(8), mMovedShapes(collisionDetection.getMemoryManager().getPoolAllocator()),
mNbNonUsedMovedShapes(0), mNbPotentialPairs(0), mNbAllocatedPotentialPairs(8), mPotentialPairs(collisionDetection.getMemoryManager().getPoolAllocator()),
mCollisionDetection(collisionDetection) { mCollisionDetection(collisionDetection) {
PoolAllocator& poolAllocator = collisionDetection.getMemoryManager().getPoolAllocator();
// Allocate memory for the array of non-static proxy shapes IDs
mMovedShapes = static_cast<int*>(poolAllocator.allocate(mNbAllocatedMovedShapes * sizeof(int)));
assert(mMovedShapes != nullptr);
// Allocate memory for the array of potential overlapping pairs
mPotentialPairs = static_cast<BroadPhasePair*>(poolAllocator.allocate(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair)));
assert(mPotentialPairs != nullptr);
#ifdef IS_PROFILING_ACTIVE #ifdef IS_PROFILING_ACTIVE
mProfiler = nullptr; mProfiler = nullptr;
@ -58,46 +48,6 @@ BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection)
} }
// Destructor
BroadPhaseAlgorithm::~BroadPhaseAlgorithm() {
// Get the memory pool allocatory
PoolAllocator& poolAllocator = mCollisionDetection.getMemoryManager().getPoolAllocator();
// Release the memory for the array of non-static proxy shapes IDs
poolAllocator.release(mMovedShapes, mNbAllocatedMovedShapes * sizeof (int));
// Release the memory for the array of potential overlapping pairs
poolAllocator.release(mPotentialPairs, mNbAllocatedPotentialPairs * sizeof(BroadPhasePair));
}
// Add a collision shape in the array of shapes that have moved in the last simulation step
// and that need to be tested again for broad-phase overlapping.
void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) {
// Allocate more elements in the array of shapes that have moved if necessary
if (mNbAllocatedMovedShapes == mNbMovedShapes) {
// Get the memory pool allocatory
PoolAllocator& poolAllocator = mCollisionDetection.getMemoryManager().getPoolAllocator();
uint oldNbAllocatedMovedShapes = mNbAllocatedMovedShapes;
mNbAllocatedMovedShapes *= 2;
int* oldArray = mMovedShapes;
mMovedShapes = static_cast<int*>(poolAllocator.allocate(mNbAllocatedMovedShapes * sizeof(int)));
assert(mMovedShapes != nullptr);
std::memcpy(mMovedShapes, oldArray, mNbMovedShapes * sizeof(int));
poolAllocator.release(oldArray, oldNbAllocatedMovedShapes * sizeof(int));
}
// Store the broad-phase ID into the array of shapes that have moved
assert(mNbMovedShapes < mNbAllocatedMovedShapes);
assert(mMovedShapes != nullptr);
mMovedShapes[mNbMovedShapes] = broadPhaseID;
mNbMovedShapes++;
}
// Return true if the two broad-phase collision shapes are overlapping // Return true if the two broad-phase collision shapes are overlapping
bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1, bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1,
const ProxyShape* shape2) const { const ProxyShape* shape2) const {
@ -123,47 +73,6 @@ void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTest,
mDynamicAABBTree.raycast(ray, broadPhaseRaycastCallback); mDynamicAABBTree.raycast(ray, broadPhaseRaycastCallback);
} }
// Remove a collision shape from the array of shapes that have moved in the last simulation step
// and that need to be tested again for broad-phase overlapping.
void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) {
assert(mNbNonUsedMovedShapes <= mNbMovedShapes);
// If less than the quarter of allocated elements of the non-static shapes IDs array
// are used, we release some allocated memory
if ((mNbMovedShapes - mNbNonUsedMovedShapes) < mNbAllocatedMovedShapes / 4 &&
mNbAllocatedMovedShapes > 8) {
// Get the memory pool allocatory
PoolAllocator& poolAllocator = mCollisionDetection.getMemoryManager().getPoolAllocator();
uint oldNbAllocatedMovedShapes = mNbAllocatedMovedShapes;
mNbAllocatedMovedShapes /= 2;
int* oldArray = mMovedShapes;
mMovedShapes = static_cast<int*>(poolAllocator.allocate(mNbAllocatedMovedShapes * sizeof(int)));
assert(mMovedShapes != nullptr);
uint nbElements = 0;
for (uint i=0; i<mNbMovedShapes; i++) {
if (oldArray[i] != -1) {
mMovedShapes[nbElements] = oldArray[i];
nbElements++;
}
}
mNbMovedShapes = nbElements;
mNbNonUsedMovedShapes = 0;
poolAllocator.release(oldArray, oldNbAllocatedMovedShapes * sizeof(int));
}
// Remove the broad-phase ID from the array
for (uint i=0; i<mNbMovedShapes; i++) {
if (mMovedShapes[i] == broadPhaseID) {
mMovedShapes[i] = -1;
mNbNonUsedMovedShapes++;
break;
}
}
}
// Add a proxy collision shape into the broad-phase collision detection // Add a proxy collision shape into the broad-phase collision detection
void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) { void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) {
@ -233,14 +142,14 @@ void BroadPhaseAlgorithm::computeOverlappingPairs(MemoryManager& memoryManager)
// TODO : Try to see if we can allocate potential pairs in single frame allocator // TODO : Try to see if we can allocate potential pairs in single frame allocator
// Reset the potential overlapping pairs // Reset the potential overlapping pairs
mNbPotentialPairs = 0; mPotentialPairs.clear();
LinkedList<int> overlappingNodes(memoryManager.getPoolAllocator()); LinkedList<int> overlappingNodes(memoryManager.getPoolAllocator());
// For all collision shapes that have moved (or have been created) during the // For all collision shapes that have moved (or have been created) during the
// last simulation step // last simulation step
for (uint i=0; i<mNbMovedShapes; i++) { for (auto it = mMovedShapes.begin(); it != mMovedShapes.end(); ++it) {
int shapeID = mMovedShapes[i]; int shapeID = *it;
if (shapeID == -1) continue; if (shapeID == -1) continue;
@ -263,25 +172,25 @@ void BroadPhaseAlgorithm::computeOverlappingPairs(MemoryManager& memoryManager)
// Reset the array of collision shapes that have move (or have been created) during the // Reset the array of collision shapes that have move (or have been created) during the
// last simulation step // last simulation step
mNbMovedShapes = 0; mMovedShapes.clear();
// Sort the array of potential overlapping pairs in order to remove duplicate pairs // Sort the array of potential overlapping pairs in order to remove duplicate pairs
std::sort(mPotentialPairs, mPotentialPairs + mNbPotentialPairs, BroadPhasePair::smallerThan); std::sort(mPotentialPairs.begin(), mPotentialPairs.end(), BroadPhasePair::smallerThan);
// Check all the potential overlapping pairs avoiding duplicates to report unique // Check all the potential overlapping pairs avoiding duplicates to report unique
// overlapping pairs // overlapping pairs
uint i=0; auto it = mPotentialPairs.begin();
while (i < mNbPotentialPairs) { while (it != mPotentialPairs.end()) {
// Get a potential overlapping pair // Get a potential overlapping pair
BroadPhasePair* pair = mPotentialPairs + i; BroadPhasePair& pair = *it;
i++; ++it;
assert(pair->collisionShape1ID != pair->collisionShape2ID); assert(pair.collisionShape1ID != pair.collisionShape2ID);
// Get the two collision shapes of the pair // Get the two collision shapes of the pair
ProxyShape* shape1 = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(pair->collisionShape1ID)); ProxyShape* shape1 = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(pair.collisionShape1ID));
ProxyShape* shape2 = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(pair->collisionShape2ID)); ProxyShape* shape2 = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(pair.collisionShape2ID));
// If the two proxy collision shapes are from the same body, skip it // If the two proxy collision shapes are from the same body, skip it
if (shape1->getBody()->getId() != shape2->getBody()->getId()) { if (shape1->getBody()->getId() != shape2->getBody()->getId()) {
@ -291,35 +200,19 @@ void BroadPhaseAlgorithm::computeOverlappingPairs(MemoryManager& memoryManager)
} }
// Skip the duplicate overlapping pairs // Skip the duplicate overlapping pairs
while (i < mNbPotentialPairs) { while (it != mPotentialPairs.end()) {
// Get the next pair // Get the next pair
BroadPhasePair* nextPair = mPotentialPairs + i; BroadPhasePair& nextPair = *it;
// If the next pair is different from the previous one, we stop skipping pairs // If the next pair is different from the previous one, we stop skipping pairs
if (nextPair->collisionShape1ID != pair->collisionShape1ID || if (nextPair.collisionShape1ID != pair.collisionShape1ID ||
nextPair->collisionShape2ID != pair->collisionShape2ID) { nextPair.collisionShape2ID != pair.collisionShape2ID) {
break; break;
} }
i++; ++it;
} }
} }
// If the number of potential overlapping pairs is less than the quarter of allocated
// number of overlapping pairs
if (mNbPotentialPairs < mNbAllocatedPotentialPairs / 4 && mNbPotentialPairs > 8) {
PoolAllocator& poolAllocator = mCollisionDetection.getMemoryManager().getPoolAllocator();
// Reduce the number of allocated potential overlapping pairs
BroadPhasePair* oldPairs = mPotentialPairs;
uint oldNbAllocatedPotentialPairs = mNbAllocatedPotentialPairs;
mNbAllocatedPotentialPairs /= 2;
mPotentialPairs = static_cast<BroadPhasePair*>(poolAllocator.allocate(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair)));
assert(mPotentialPairs);
memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPhasePair));
poolAllocator.release(oldPairs, oldNbAllocatedPotentialPairs * sizeof(BroadPhasePair));
}
} }
// Notify the broad-phase about a potential overlapping pair in the dynamic AABB tree // Notify the broad-phase about a potential overlapping pair in the dynamic AABB tree
@ -332,25 +225,9 @@ void BroadPhaseAlgorithm::addOverlappingNodes(int referenceNodeId, const LinkedL
// If both the nodes are the same, we do not create store the overlapping pair // If both the nodes are the same, we do not create store the overlapping pair
if (referenceNodeId != elem->data) { if (referenceNodeId != elem->data) {
// If we need to allocate more memory for the array of potential overlapping pairs
if (mNbPotentialPairs == mNbAllocatedPotentialPairs) {
PoolAllocator& poolAllocator = mCollisionDetection.getMemoryManager().getPoolAllocator();
// Allocate more memory for the array of potential pairs
BroadPhasePair* oldPairs = mPotentialPairs;
uint oldNbAllocatedPotentialPairs = mNbAllocatedPotentialPairs;
mNbAllocatedPotentialPairs *= 2;
mPotentialPairs = static_cast<BroadPhasePair*>(poolAllocator.allocate(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair)));
assert(mPotentialPairs);
memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPhasePair));
poolAllocator.release(oldPairs, oldNbAllocatedPotentialPairs * sizeof(BroadPhasePair));
}
// Add the new potential pair into the array of potential overlapping pairs // Add the new potential pair into the array of potential overlapping pairs
mPotentialPairs[mNbPotentialPairs].collisionShape1ID = std::min(referenceNodeId, elem->data); mPotentialPairs.add(BroadPhasePair(std::min(referenceNodeId, elem->data),
mPotentialPairs[mNbPotentialPairs].collisionShape2ID = std::max(referenceNodeId, elem->data); std::max(referenceNodeId, elem->data)));
mNbPotentialPairs++;
} }
elem = elem->next; elem = elem->next;

View File

@ -29,6 +29,7 @@
// Libraries // Libraries
#include "DynamicAABBTree.h" #include "DynamicAABBTree.h"
#include "containers/LinkedList.h" #include "containers/LinkedList.h"
#include "containers/Set.h"
/// Namespace ReactPhysics3D /// Namespace ReactPhysics3D
namespace reactphysics3d { namespace reactphysics3d {
@ -58,8 +59,14 @@ struct BroadPhasePair {
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Constructor
BroadPhasePair(int shapeId1, int shapeId2) {
collisionShape1ID = shapeId1;
collisionShape2ID = shapeId2;
}
/// Method used to compare two pairs for sorting algorithm /// Method used to compare two pairs for sorting algorithm
static bool smallerThan(const BroadPhasePair& pair1, const BroadPhasePair& pair2); static bool smallerThan(const BroadPhasePair &pair1, const BroadPhasePair &pair2);
}; };
// class AABBOverlapCallback // class AABBOverlapCallback
@ -133,31 +140,13 @@ class BroadPhaseAlgorithm {
/// Dynamic AABB tree /// Dynamic AABB tree
DynamicAABBTree mDynamicAABBTree; DynamicAABBTree mDynamicAABBTree;
/// Array with the broad-phase IDs of all collision shapes that have moved (or have been /// Set with the broad-phase IDs of all collision shapes that have moved (or have been
/// created) during the last simulation step. Those are the shapes that need to be tested /// created) during the last simulation step. Those are the shapes that need to be tested
/// for overlapping in the next simulation step. /// for overlapping in the next simulation step.
int* mMovedShapes; Set<int> mMovedShapes;
/// Number of collision shapes in the array of shapes that have moved during the last
/// simulation step.
uint mNbMovedShapes;
/// Number of allocated elements for the array of shapes that have moved during the last
/// simulation step.
uint mNbAllocatedMovedShapes;
/// Number of non-used elements in the array of shapes that have moved during the last
/// simulation step.
uint mNbNonUsedMovedShapes;
/// Temporary array of potential overlapping pairs (with potential duplicates) /// Temporary array of potential overlapping pairs (with potential duplicates)
BroadPhasePair* mPotentialPairs; List<BroadPhasePair> mPotentialPairs;
/// Number of potential overlapping pairs
uint mNbPotentialPairs;
/// Number of allocated elements for the array of potential overlapping pairs
uint mNbAllocatedPotentialPairs;
/// Reference to the collision detection object /// Reference to the collision detection object
CollisionDetection& mCollisionDetection; CollisionDetection& mCollisionDetection;
@ -177,7 +166,7 @@ class BroadPhaseAlgorithm {
BroadPhaseAlgorithm(CollisionDetection& collisionDetection); BroadPhaseAlgorithm(CollisionDetection& collisionDetection);
/// Destructor /// Destructor
~BroadPhaseAlgorithm(); ~BroadPhaseAlgorithm() = default;
/// Deleted copy-constructor /// Deleted copy-constructor
BroadPhaseAlgorithm(const BroadPhaseAlgorithm& algorithm) = delete; BroadPhaseAlgorithm(const BroadPhaseAlgorithm& algorithm) = delete;
@ -234,7 +223,8 @@ class BroadPhaseAlgorithm {
}; };
// Method used to compare two pairs for sorting algorithm // Method used to compare two pairs for sorting algorithm
inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1, const BroadPhasePair& pair2) { inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1,
const BroadPhasePair& pair2) {
if (pair1.collisionShape1ID < pair2.collisionShape1ID) return true; if (pair1.collisionShape1ID < pair2.collisionShape1ID) return true;
if (pair1.collisionShape1ID == pair2.collisionShape1ID) { if (pair1.collisionShape1ID == pair2.collisionShape1ID) {
@ -248,6 +238,22 @@ inline const AABB& BroadPhaseAlgorithm::getFatAABB(int broadPhaseId) const {
return mDynamicAABBTree.getFatAABB(broadPhaseId); return mDynamicAABBTree.getFatAABB(broadPhaseId);
} }
// Add a collision shape in the array of shapes that have moved in the last simulation step
// and that need to be tested again for broad-phase overlapping.
inline void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) {
// Store the broad-phase ID into the array of shapes that have moved
mMovedShapes.add(broadPhaseID);
}
// Remove a collision shape from the array of shapes that have moved in the last simulation step
// and that need to be tested again for broad-phase overlapping.
inline void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) {
// Remove the broad-phase ID from the set
mMovedShapes.remove(broadPhaseID);
}
// Return the proxy shape corresponding to the broad-phase node id in parameter // Return the proxy shape corresponding to the broad-phase node id in parameter
inline ProxyShape* BroadPhaseAlgorithm::getProxyShapeForBroadPhaseId(int broadPhaseId) const { inline ProxyShape* BroadPhaseAlgorithm::getProxyShapeForBroadPhaseId(int broadPhaseId) const {
return static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(broadPhaseId)); return static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(broadPhaseId));

View File

@ -479,10 +479,7 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
Vector3 separatingEdge1A, separatingEdge1B; Vector3 separatingEdge1A, separatingEdge1B;
Vector3 separatingEdge2A, separatingEdge2B; Vector3 separatingEdge2A, separatingEdge2B;
Vector3 minEdgeVsEdgeSeparatingAxisPolyhedron2Space; Vector3 minEdgeVsEdgeSeparatingAxisPolyhedron2Space;
bool isShape1Triangle = polyhedron1->getName() == CollisionShapeName::TRIANGLE;
// True if the shapes were overlapping in the previous frame and are
// still overlapping on the same axis in this frame
bool isTemporalCoherenceValid = false;
LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfo->getLastFrameCollisionInfo(); LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfo->getLastFrameCollisionInfo();
@ -499,18 +496,16 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
decimal penetrationDepth = testSingleFaceDirectionPolyhedronVsPolyhedron(polyhedron1, polyhedron2, polyhedron1ToPolyhedron2, decimal penetrationDepth = testSingleFaceDirectionPolyhedronVsPolyhedron(polyhedron1, polyhedron2, polyhedron1ToPolyhedron2,
lastFrameCollisionInfo->satMinAxisFaceIndex); lastFrameCollisionInfo->satMinAxisFaceIndex);
// If the previous axis is a separating axis
if (penetrationDepth <= decimal(0.0)) {
// Return no collision // If the previous axis was a separating axis and is still a separating axis in this frame
if (!lastFrameCollisionInfo->wasColliding && penetrationDepth <= decimal(0.0)) {
// Return no collision without running the whole SAT algorithm
return false; return false;
} }
// The two shapes are overlapping as in the previous frame and on the same axis, therefore // The two shapes were overlapping in the previous frame and still seem to overlap in this one
// we will skip the entire SAT algorithm because the minimum separating axis did not change if (lastFrameCollisionInfo->wasColliding && penetrationDepth > decimal(0.0)) {
isTemporalCoherenceValid = lastFrameCollisionInfo->wasColliding;
if (isTemporalCoherenceValid) {
minPenetrationDepth = penetrationDepth; minPenetrationDepth = penetrationDepth;
minFaceIndex = lastFrameCollisionInfo->satMinAxisFaceIndex; minFaceIndex = lastFrameCollisionInfo->satMinAxisFaceIndex;
@ -518,7 +513,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
isMinPenetrationFaceNormalPolyhedron1 = true; isMinPenetrationFaceNormalPolyhedron1 = true;
// Compute the contact points between two faces of two convex polyhedra. // Compute the contact points between two faces of two convex polyhedra.
// If contact points have been found, we report them without running the whole SAT algorithm
if(computePolyhedronVsPolyhedronFaceContactPoints(isMinPenetrationFaceNormalPolyhedron1, polyhedron1, polyhedron2, if(computePolyhedronVsPolyhedronFaceContactPoints(isMinPenetrationFaceNormalPolyhedron1, polyhedron1, polyhedron2,
polyhedron1ToPolyhedron2, polyhedron2ToPolyhedron1, minFaceIndex, polyhedron1ToPolyhedron2, polyhedron2ToPolyhedron1, minFaceIndex,
narrowPhaseInfo, minPenetrationDepth)) { narrowPhaseInfo, minPenetrationDepth)) {
@ -527,13 +521,12 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = !isMinPenetrationFaceNormalPolyhedron1; lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = !isMinPenetrationFaceNormalPolyhedron1;
lastFrameCollisionInfo->satMinAxisFaceIndex = minFaceIndex; lastFrameCollisionInfo->satMinAxisFaceIndex = minFaceIndex;
// The shapes are still overlapping in the previous axis (the contact manifold is not empty).
// Therefore, we can return without running the whole SAT algorithm
return true; return true;
} }
else { // Contact points have not been found (the set of clipped points was empty)
// Therefore, we need to run the whole SAT algorithm again // The contact manifold is empty. Therefore, we have to run the whole SAT algorithm again
isTemporalCoherenceValid = false;
}
} }
} }
else if (lastFrameCollisionInfo->satIsAxisFacePolyhedron2) { // If the previous separating axis (or axis with minimum penetration depth) else if (lastFrameCollisionInfo->satIsAxisFacePolyhedron2) { // If the previous separating axis (or axis with minimum penetration depth)
@ -542,18 +535,15 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
decimal penetrationDepth = testSingleFaceDirectionPolyhedronVsPolyhedron(polyhedron2, polyhedron1, polyhedron2ToPolyhedron1, decimal penetrationDepth = testSingleFaceDirectionPolyhedronVsPolyhedron(polyhedron2, polyhedron1, polyhedron2ToPolyhedron1,
lastFrameCollisionInfo->satMinAxisFaceIndex); lastFrameCollisionInfo->satMinAxisFaceIndex);
// If the previous axis is a separating axis // If the previous axis was a separating axis and is still a separating axis in this frame
if (penetrationDepth <= decimal(0.0)) { if (!lastFrameCollisionInfo->wasColliding && penetrationDepth <= decimal(0.0)) {
// Return no collision // Return no collision without running the whole SAT algorithm
return false; return false;
} }
// The two shapes are overlapping as in the previous frame and on the same axis, therefore // The two shapes were overlapping in the previous frame and still seem to overlap in this one
// we will skip the entire SAT algorithm because the minimum separating axis did not change if (lastFrameCollisionInfo->wasColliding && penetrationDepth > decimal(0.0)) {
isTemporalCoherenceValid = lastFrameCollisionInfo->wasColliding;
if (isTemporalCoherenceValid) {
minPenetrationDepth = penetrationDepth; minPenetrationDepth = penetrationDepth;
minFaceIndex = lastFrameCollisionInfo->satMinAxisFaceIndex; minFaceIndex = lastFrameCollisionInfo->satMinAxisFaceIndex;
@ -561,7 +551,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
isMinPenetrationFaceNormalPolyhedron1 = false; isMinPenetrationFaceNormalPolyhedron1 = false;
// Compute the contact points between two faces of two convex polyhedra. // Compute the contact points between two faces of two convex polyhedra.
// If contact points have been found, we report them without running the whole SAT algorithm
if(computePolyhedronVsPolyhedronFaceContactPoints(isMinPenetrationFaceNormalPolyhedron1, polyhedron1, polyhedron2, if(computePolyhedronVsPolyhedronFaceContactPoints(isMinPenetrationFaceNormalPolyhedron1, polyhedron1, polyhedron2,
polyhedron1ToPolyhedron2, polyhedron2ToPolyhedron1, minFaceIndex, polyhedron1ToPolyhedron2, polyhedron2ToPolyhedron1, minFaceIndex,
narrowPhaseInfo, minPenetrationDepth)) { narrowPhaseInfo, minPenetrationDepth)) {
@ -570,13 +559,12 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = !isMinPenetrationFaceNormalPolyhedron1; lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = !isMinPenetrationFaceNormalPolyhedron1;
lastFrameCollisionInfo->satMinAxisFaceIndex = minFaceIndex; lastFrameCollisionInfo->satMinAxisFaceIndex = minFaceIndex;
// The shapes are still overlapping in the previous axis (the contact manifold is not empty).
// Therefore, we can return without running the whole SAT algorithm
return true; return true;
} }
else { // Contact points have not been found (the set of clipped points was empty)
// Therefore, we need to run the whole SAT algorithm again // The contact manifold is empty. Therefore, we have to run the whole SAT algorithm again
isTemporalCoherenceValid = false;
}
} }
} }
else { // If the previous separating axis (or axis with minimum penetration depth) was the cross product of two edges else { // If the previous separating axis (or axis with minimum penetration depth) was the cross product of two edges
@ -584,8 +572,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
const HalfEdgeStructure::Edge& edge1 = polyhedron1->getHalfEdge(lastFrameCollisionInfo->satMinEdge1Index); const HalfEdgeStructure::Edge& edge1 = polyhedron1->getHalfEdge(lastFrameCollisionInfo->satMinEdge1Index);
const HalfEdgeStructure::Edge& edge2 = polyhedron2->getHalfEdge(lastFrameCollisionInfo->satMinEdge2Index); const HalfEdgeStructure::Edge& edge2 = polyhedron2->getHalfEdge(lastFrameCollisionInfo->satMinEdge2Index);
Vector3 separatingAxisPolyhedron2Space;
const Vector3 edge1A = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(edge1.vertexIndex); const Vector3 edge1A = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(edge1.vertexIndex);
const Vector3 edge1B = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(polyhedron1->getHalfEdge(edge1.nextEdgeIndex).vertexIndex); const Vector3 edge1B = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(polyhedron1->getHalfEdge(edge1.nextEdgeIndex).vertexIndex);
const Vector3 edge1Direction = edge1B - edge1A; const Vector3 edge1Direction = edge1B - edge1A;
@ -593,138 +579,174 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
const Vector3 edge2B = polyhedron2->getVertexPosition(polyhedron2->getHalfEdge(edge2.nextEdgeIndex).vertexIndex); const Vector3 edge2B = polyhedron2->getVertexPosition(polyhedron2->getHalfEdge(edge2.nextEdgeIndex).vertexIndex);
const Vector3 edge2Direction = edge2B - edge2A; const Vector3 edge2Direction = edge2B - edge2A;
// Compute the penetration depth // If the two edges build a minkowski face (and the cross product is
decimal penetrationDepth = computeDistanceBetweenEdges(edge1A, edge2A, polyhedron2->getCentroid(), // therefore a candidate for separating axis
edge1Direction, edge2Direction, separatingAxisPolyhedron2Space); if (testEdgesBuildMinkowskiFace(polyhedron1, edge1, polyhedron2, edge2, polyhedron1ToPolyhedron2)) {
// If the previous axis is a separating axis Vector3 separatingAxisPolyhedron2Space;
if (penetrationDepth <= decimal(0.0)) {
// Return no collision // Compute the penetration depth along the previous axis
return false; const Vector3 polyhedron1Centroid = polyhedron1ToPolyhedron2 * polyhedron1->getCentroid();
} decimal penetrationDepth = computeDistanceBetweenEdges(edge1A, edge2A, polyhedron1Centroid, polyhedron2->getCentroid(),
edge1Direction, edge2Direction, isShape1Triangle, separatingAxisPolyhedron2Space);
// The two shapes are overlapping as in the previous frame and on the same axis, therefore // If the shapes were not overlapping in the previous frame and are still not
// we will skip the entire SAT algorithm because the minimum separating axis did not change // overlapping in the current one
isTemporalCoherenceValid = lastFrameCollisionInfo->wasColliding; if (!lastFrameCollisionInfo->wasColliding && penetrationDepth <= decimal(0.0)) {
// Temporal coherence is valid only if the two edges build a minkowski // We have found a separating axis without running the whole SAT algorithm
// face (and the cross product is therefore a candidate for separating axis return false;
if (isTemporalCoherenceValid && !testEdgesBuildMinkowskiFace(polyhedron1, edge1, polyhedron2, edge2, polyhedron1ToPolyhedron2)) { }
isTemporalCoherenceValid = false;
}
if (isTemporalCoherenceValid) { // If the shapes were overlapping on the previous axis and still seem to overlap in this frame
if (lastFrameCollisionInfo->wasColliding && penetrationDepth > decimal(0.0)) {
minPenetrationDepth = penetrationDepth; // Compute the closest points between the two edges (in the local-space of poylhedron 2)
isMinPenetrationFaceNormal = false; Vector3 closestPointPolyhedron1Edge, closestPointPolyhedron2Edge;
isMinPenetrationFaceNormalPolyhedron1 = false; computeClosestPointBetweenTwoSegments(edge1A, edge1B, edge2A, edge2B,
minSeparatingEdge1Index = lastFrameCollisionInfo->satMinEdge1Index; closestPointPolyhedron1Edge, closestPointPolyhedron2Edge);
minSeparatingEdge2Index = lastFrameCollisionInfo->satMinEdge2Index;
separatingEdge1A = edge1A; // Here we try to project the closest point on edge1 onto the segment of edge 2 to see if
separatingEdge1B = edge1B; // the projected point falls onto the segment. We also try to project the closest point
separatingEdge2A = edge2A; // on edge 2 to see if it falls onto the segment of edge 1. If one of the point does not
separatingEdge2B = edge2B; // fall onto the opposite segment, it means the edges are not colliding (the contact manifold
minEdgeVsEdgeSeparatingAxisPolyhedron2Space = separatingAxisPolyhedron2Space; // is empty). Therefore, we need to run the whole SAT algorithm again.
const Vector3 vec1 = closestPointPolyhedron1Edge - edge2A;
const Vector3 vec2 = closestPointPolyhedron2Edge - edge1A;
const decimal edge1LengthSquare = edge1Direction.lengthSquare();
const decimal edge2LengthSquare = edge2Direction.lengthSquare();
decimal t1 = vec1.dot(edge2Direction) / edge2LengthSquare;
decimal t2 = vec2.dot(edge1Direction) / edge1LengthSquare;
if (t1 >= decimal(0.0) && t1 <= decimal(1) && t2 >= decimal(0.0) && t2 <= decimal(1.0)) {
// Compute the contact point on polyhedron 1 edge in the local-space of polyhedron 1
Vector3 closestPointPolyhedron1EdgeLocalSpace = polyhedron2ToPolyhedron1 * closestPointPolyhedron1Edge;
// Compute the world normal
// We use the direction from the centroid to the edge of the shape that is not a triangle
// to avoid possible degeneracies when axis direction is orthogonal to triangle normal
Vector3 normal;
if (isShape1Triangle) {
normal = polyhedron2->getCentroid() - closestPointPolyhedron2Edge;
}
else {
normal = polyhedron1ToPolyhedron2.getOrientation() * ((polyhedron2ToPolyhedron1 * closestPointPolyhedron1Edge) - polyhedron1->getCentroid());
}
//Vector3 normalWorld = narrowPhaseInfo->shape2ToWorldTransform.getOrientation() * minEdgeVsEdgeSeparatingAxisPolyhedron2Space;
Vector3 normalWorld = narrowPhaseInfo->shape2ToWorldTransform.getOrientation() * normal.getUnit();
// Compute smooth triangle mesh contact if one of the two collision shapes is a triangle
TriangleShape::computeSmoothTriangleMeshContact(narrowPhaseInfo->collisionShape1, narrowPhaseInfo->collisionShape2,
closestPointPolyhedron1EdgeLocalSpace, closestPointPolyhedron2Edge,
narrowPhaseInfo->shape1ToWorldTransform, narrowPhaseInfo->shape2ToWorldTransform,
penetrationDepth, normalWorld);
// Create the contact point
narrowPhaseInfo->addContactPoint(normalWorld, penetrationDepth,
closestPointPolyhedron1EdgeLocalSpace, closestPointPolyhedron2Edge);
// The shapes are overlapping on the previous axis (the contact manifold is not empty). Therefore
// we return without running the whole SAT algorithm
return true;
}
// The contact manifold is empty. Therefore, we have to run the whole SAT algorithm again
}
} }
} }
} }
// We the shapes are still overlapping in the same axis as in // Test all the face normals of the polyhedron 1 for separating axis
// the previous frame, we skip the whole SAT algorithm uint faceIndex;
if (!isTemporalCoherenceValid) { decimal penetrationDepth = testFacesDirectionPolyhedronVsPolyhedron(polyhedron1, polyhedron2, polyhedron1ToPolyhedron2, faceIndex);
if (penetrationDepth <= decimal(0.0)) {
// Test all the face normals of the polyhedron 1 for separating axis lastFrameCollisionInfo->satIsAxisFacePolyhedron1 = true;
uint faceIndex; lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = false;
decimal penetrationDepth = testFacesDirectionPolyhedronVsPolyhedron(polyhedron1, polyhedron2, polyhedron1ToPolyhedron2, faceIndex); lastFrameCollisionInfo->satMinAxisFaceIndex = faceIndex;
if (penetrationDepth <= decimal(0.0)) {
lastFrameCollisionInfo->satIsAxisFacePolyhedron1 = true; // We have found a separating axis
lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = false; return false;
lastFrameCollisionInfo->satMinAxisFaceIndex = faceIndex; }
if (penetrationDepth < minPenetrationDepth - SAME_SEPARATING_AXIS_BIAS) {
isMinPenetrationFaceNormal = true;
minPenetrationDepth = penetrationDepth;
minFaceIndex = faceIndex;
isMinPenetrationFaceNormalPolyhedron1 = true;
}
// We have found a separating axis // Test all the face normals of the polyhedron 2 for separating axis
return false; penetrationDepth = testFacesDirectionPolyhedronVsPolyhedron(polyhedron2, polyhedron1, polyhedron2ToPolyhedron1, faceIndex);
} if (penetrationDepth <= decimal(0.0)) {
if (penetrationDepth < minPenetrationDepth - SAME_SEPARATING_AXIS_BIAS) {
isMinPenetrationFaceNormal = true;
minPenetrationDepth = penetrationDepth;
minFaceIndex = faceIndex;
isMinPenetrationFaceNormalPolyhedron1 = true;
}
// Test all the face normals of the polyhedron 2 for separating axis lastFrameCollisionInfo->satIsAxisFacePolyhedron1 = false;
penetrationDepth = testFacesDirectionPolyhedronVsPolyhedron(polyhedron2, polyhedron1, polyhedron2ToPolyhedron1, faceIndex); lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = true;
if (penetrationDepth <= decimal(0.0)) { lastFrameCollisionInfo->satMinAxisFaceIndex = faceIndex;
lastFrameCollisionInfo->satIsAxisFacePolyhedron1 = false; // We have found a separating axis
lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = true; return false;
lastFrameCollisionInfo->satMinAxisFaceIndex = faceIndex; }
if (penetrationDepth < minPenetrationDepth - SAME_SEPARATING_AXIS_BIAS) {
isMinPenetrationFaceNormal = true;
minPenetrationDepth = penetrationDepth;
minFaceIndex = faceIndex;
isMinPenetrationFaceNormalPolyhedron1 = false;
}
// We have found a separating axis // Test the cross products of edges of polyhedron 1 with edges of polyhedron 2 for separating axis
return false; for (uint i=0; i < polyhedron1->getNbHalfEdges(); i += 2) {
}
if (penetrationDepth < minPenetrationDepth - SAME_SEPARATING_AXIS_BIAS) {
isMinPenetrationFaceNormal = true;
minPenetrationDepth = penetrationDepth;
minFaceIndex = faceIndex;
isMinPenetrationFaceNormalPolyhedron1 = false;
}
// Test the cross products of edges of polyhedron 1 with edges of polyhedron 2 for separating axis // Get an edge of polyhedron 1
for (uint i=0; i < polyhedron1->getNbHalfEdges(); i += 2) { const HalfEdgeStructure::Edge& edge1 = polyhedron1->getHalfEdge(i);
// Get an edge of polyhedron 1 const Vector3 edge1A = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(edge1.vertexIndex);
const HalfEdgeStructure::Edge& edge1 = polyhedron1->getHalfEdge(i); const Vector3 edge1B = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(polyhedron1->getHalfEdge(edge1.nextEdgeIndex).vertexIndex);
const Vector3 edge1Direction = edge1B - edge1A;
const Vector3 edge1A = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(edge1.vertexIndex); for (uint j=0; j < polyhedron2->getNbHalfEdges(); j += 2) {
const Vector3 edge1B = polyhedron1ToPolyhedron2 * polyhedron1->getVertexPosition(polyhedron1->getHalfEdge(edge1.nextEdgeIndex).vertexIndex);
const Vector3 edge1Direction = edge1B - edge1A;
for (uint j=0; j < polyhedron2->getNbHalfEdges(); j += 2) { // Get an edge of polyhedron 2
const HalfEdgeStructure::Edge& edge2 = polyhedron2->getHalfEdge(j);
// Get an edge of polyhedron 2 const Vector3 edge2A = polyhedron2->getVertexPosition(edge2.vertexIndex);
const HalfEdgeStructure::Edge& edge2 = polyhedron2->getHalfEdge(j); const Vector3 edge2B = polyhedron2->getVertexPosition(polyhedron2->getHalfEdge(edge2.nextEdgeIndex).vertexIndex);
const Vector3 edge2Direction = edge2B - edge2A;
const Vector3 edge2A = polyhedron2->getVertexPosition(edge2.vertexIndex); // If the two edges build a minkowski face (and the cross product is
const Vector3 edge2B = polyhedron2->getVertexPosition(polyhedron2->getHalfEdge(edge2.nextEdgeIndex).vertexIndex); // therefore a candidate for separating axis
const Vector3 edge2Direction = edge2B - edge2A; if (testEdgesBuildMinkowskiFace(polyhedron1, edge1, polyhedron2, edge2, polyhedron1ToPolyhedron2)) {
// If the two edges build a minkowski face (and the cross product is Vector3 separatingAxisPolyhedron2Space;
// therefore a candidate for separating axis
if (testEdgesBuildMinkowskiFace(polyhedron1, edge1, polyhedron2, edge2, polyhedron1ToPolyhedron2)) {
Vector3 separatingAxisPolyhedron2Space; // Compute the penetration depth
const Vector3 polyhedron1Centroid = polyhedron1ToPolyhedron2 * polyhedron1->getCentroid();
decimal penetrationDepth = computeDistanceBetweenEdges(edge1A, edge2A, polyhedron1Centroid, polyhedron2->getCentroid(),
edge1Direction, edge2Direction, isShape1Triangle, separatingAxisPolyhedron2Space);
// Compute the penetration depth if (penetrationDepth <= decimal(0.0)) {
decimal penetrationDepth = computeDistanceBetweenEdges(edge1A, edge2A, polyhedron2->getCentroid(),
edge1Direction, edge2Direction, separatingAxisPolyhedron2Space);
if (penetrationDepth <= decimal(0.0)) { lastFrameCollisionInfo->satIsAxisFacePolyhedron1 = false;
lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = false;
lastFrameCollisionInfo->satMinEdge1Index = i;
lastFrameCollisionInfo->satMinEdge2Index = j;
lastFrameCollisionInfo->satIsAxisFacePolyhedron1 = false; // We have found a separating axis
lastFrameCollisionInfo->satIsAxisFacePolyhedron2 = false; return false;
lastFrameCollisionInfo->satMinEdge1Index = i; }
lastFrameCollisionInfo->satMinEdge2Index = j;
// We have found a separating axis if (penetrationDepth < minPenetrationDepth - SAME_SEPARATING_AXIS_BIAS) {
return false;
}
if (penetrationDepth < minPenetrationDepth - SAME_SEPARATING_AXIS_BIAS) {
minPenetrationDepth = penetrationDepth;
isMinPenetrationFaceNormalPolyhedron1 = false;
isMinPenetrationFaceNormal = false;
minSeparatingEdge1Index = i;
minSeparatingEdge2Index = j;
separatingEdge1A = edge1A;
separatingEdge1B = edge1B;
separatingEdge2A = edge2A;
separatingEdge2B = edge2B;
minEdgeVsEdgeSeparatingAxisPolyhedron2Space = separatingAxisPolyhedron2Space;
}
minPenetrationDepth = penetrationDepth;
isMinPenetrationFaceNormalPolyhedron1 = false;
isMinPenetrationFaceNormal = false;
minSeparatingEdge1Index = i;
minSeparatingEdge2Index = j;
separatingEdge1A = edge1A;
separatingEdge1B = edge1B;
separatingEdge2A = edge2A;
separatingEdge2B = edge2B;
minEdgeVsEdgeSeparatingAxisPolyhedron2Space = separatingAxisPolyhedron2Space;
} }
} }
} }
@ -776,7 +798,17 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn
Vector3 closestPointPolyhedron1EdgeLocalSpace = polyhedron2ToPolyhedron1 * closestPointPolyhedron1Edge; Vector3 closestPointPolyhedron1EdgeLocalSpace = polyhedron2ToPolyhedron1 * closestPointPolyhedron1Edge;
// Compute the world normal // Compute the world normal
Vector3 normalWorld = narrowPhaseInfo->shape2ToWorldTransform.getOrientation() * minEdgeVsEdgeSeparatingAxisPolyhedron2Space; // We use the direction from the centroid to the edge of the shape that is not a triangle
// to avoid possible degeneracies when axis direction is orthogonal to triangle normal
Vector3 normal;
if (isShape1Triangle) {
normal = polyhedron2->getCentroid() - closestPointPolyhedron2Edge;
}
else {
normal = polyhedron1ToPolyhedron2.getOrientation() * ((polyhedron2ToPolyhedron1 * closestPointPolyhedron1Edge) - polyhedron1->getCentroid());
}
//Vector3 normalWorld = narrowPhaseInfo->shape2ToWorldTransform.getOrientation() * minEdgeVsEdgeSeparatingAxisPolyhedron2Space;
Vector3 normalWorld = narrowPhaseInfo->shape2ToWorldTransform.getOrientation() * normal.getUnit();
// Compute smooth triangle mesh contact if one of the two collision shapes is a triangle // Compute smooth triangle mesh contact if one of the two collision shapes is a triangle
TriangleShape::computeSmoothTriangleMeshContact(narrowPhaseInfo->collisionShape1, narrowPhaseInfo->collisionShape2, TriangleShape::computeSmoothTriangleMeshContact(narrowPhaseInfo->collisionShape1, narrowPhaseInfo->collisionShape2,
@ -916,9 +948,10 @@ bool SATAlgorithm::computePolyhedronVsPolyhedronFaceContactPoints(bool isMinPene
// Compute and return the distance between the two edges in the direction of the candidate separating axis // Compute and return the distance between the two edges in the direction of the candidate separating axis
decimal SATAlgorithm::computeDistanceBetweenEdges(const Vector3& edge1A, const Vector3& edge2A, const Vector3& polyhedron2Centroid, decimal SATAlgorithm::computeDistanceBetweenEdges(const Vector3& edge1A, const Vector3& edge2A,
const Vector3& polyhedron1Centroid, const Vector3& polyhedron2Centroid,
const Vector3& edge1Direction, const Vector3& edge2Direction, const Vector3& edge1Direction, const Vector3& edge2Direction,
Vector3& outSeparatingAxisPolyhedron2Space) const { bool isShape1Triangle, Vector3& outSeparatingAxisPolyhedron2Space) const {
RP3D_PROFILE("SATAlgorithm::computeDistanceBetweenEdges", mProfiler); RP3D_PROFILE("SATAlgorithm::computeDistanceBetweenEdges", mProfiler);
@ -933,7 +966,24 @@ decimal SATAlgorithm::computeDistanceBetweenEdges(const Vector3& edge1A, const V
Vector3 axis = edge1Direction.cross(edge2Direction).getUnit(); Vector3 axis = edge1Direction.cross(edge2Direction).getUnit();
// Make sure the axis direction is going from first to second polyhedron // Make sure the axis direction is going from first to second polyhedron
if (axis.dot(edge2A - polyhedron2Centroid) > decimal(0.0)) { decimal dotProd;
if (isShape1Triangle) {
// The shape 1 is a triangle. It is safer to use a vector from
// centroid to edge of the shape 2 because for a triangle, we
// can have a vector that is orthogonal to the axis
dotProd = axis.dot(edge2A - polyhedron2Centroid);
}
else {
// The shape 2 might be a triangle. It is safer to use a vector from
// centroid to edge of the shape 2 because for a triangle, we
// can have a vector that is orthogonal to the axis
dotProd = axis.dot(polyhedron1Centroid - edge1A);
}
if (dotProd > decimal(0.0)) {
axis = -axis; axis = -axis;
} }
@ -943,6 +993,7 @@ decimal SATAlgorithm::computeDistanceBetweenEdges(const Vector3& edge1A, const V
return -axis.dot(edge2A - edge1A); return -axis.dot(edge2A - edge1A);
} }
// Return the penetration depth between two polyhedra along a face normal axis of the first polyhedron // Return the penetration depth between two polyhedra along a face normal axis of the first polyhedron
decimal SATAlgorithm::testSingleFaceDirectionPolyhedronVsPolyhedron(const ConvexPolyhedronShape* polyhedron1, decimal SATAlgorithm::testSingleFaceDirectionPolyhedronVsPolyhedron(const ConvexPolyhedronShape* polyhedron1,
const ConvexPolyhedronShape* polyhedron2, const ConvexPolyhedronShape* polyhedron2,

View File

@ -83,9 +83,10 @@ class SATAlgorithm {
const Vector3& bCrossA, const Vector3& dCrossC) const; const Vector3& bCrossA, const Vector3& dCrossC) const;
/// Compute and return the distance between the two edges in the direction of the candidate separating axis /// Compute and return the distance between the two edges in the direction of the candidate separating axis
decimal computeDistanceBetweenEdges(const Vector3& edge1A, const Vector3& edge2A, const Vector3& polyhedron2Centroid, decimal computeDistanceBetweenEdges(const Vector3& edge1A, const Vector3& edge2A,
const Vector3& polyhedron1Centroid, const Vector3& polyhedron2Centroid,
const Vector3& edge1Direction, const Vector3& edge2Direction, const Vector3& edge1Direction, const Vector3& edge2Direction,
Vector3& outSeparatingAxis) const; bool isShape1Triangle, Vector3& outSeparatingAxis) const;
/// Return the penetration depth between two polyhedra along a face normal axis of the first polyhedron /// Return the penetration depth between two polyhedra along a face normal axis of the first polyhedron
decimal testSingleFaceDirectionPolyhedronVsPolyhedron(const ConvexPolyhedronShape* polyhedron1, decimal testSingleFaceDirectionPolyhedronVsPolyhedron(const ConvexPolyhedronShape* polyhedron1,

View File

@ -64,9 +64,15 @@ void ConcaveMeshShape::initBVHTree() {
triangleVertexArray->getTriangleVertices(triangleIndex, trianglePoints); triangleVertexArray->getTriangleVertices(triangleIndex, trianglePoints);
// Apply the scaling factor to the vertices // Apply the scaling factor to the vertices
trianglePoints[0] *= mScaling.x; trianglePoints[0].x *= mScaling.x;
trianglePoints[1] *= mScaling.y; trianglePoints[0].y *= mScaling.y;
trianglePoints[2] *= mScaling.z; trianglePoints[0].z *= mScaling.z;
trianglePoints[1].x *= mScaling.x;
trianglePoints[1].y *= mScaling.y;
trianglePoints[1].z *= mScaling.z;
trianglePoints[2].x *= mScaling.x;
trianglePoints[2].y *= mScaling.y;
trianglePoints[2].z *= mScaling.z;
// Create the AABB for the triangle // Create the AABB for the triangle
AABB aabb = AABB::createAABBForTriangle(trianglePoints); AABB aabb = AABB::createAABBForTriangle(trianglePoints);
@ -88,9 +94,15 @@ void ConcaveMeshShape::getTriangleVertices(uint subPart, uint triangleIndex,
triangleVertexArray->getTriangleVertices(triangleIndex, outTriangleVertices); triangleVertexArray->getTriangleVertices(triangleIndex, outTriangleVertices);
// Apply the scaling factor to the vertices // Apply the scaling factor to the vertices
outTriangleVertices[0] *= mScaling.x; outTriangleVertices[0].x *= mScaling.x;
outTriangleVertices[1] *= mScaling.y; outTriangleVertices[0].y *= mScaling.y;
outTriangleVertices[2] *= mScaling.z; outTriangleVertices[0].z *= mScaling.z;
outTriangleVertices[1].x *= mScaling.x;
outTriangleVertices[1].y *= mScaling.y;
outTriangleVertices[1].z *= mScaling.z;
outTriangleVertices[2].x *= mScaling.x;
outTriangleVertices[2].y *= mScaling.y;
outTriangleVertices[2].z *= mScaling.z;
} }
// Return the three vertex normals (in the array outVerticesNormals) of a triangle // Return the three vertex normals (in the array outVerticesNormals) of a triangle

View File

@ -62,13 +62,17 @@ TriangleShape::TriangleShape(const Vector3* vertices, const Vector3* verticesNor
mVerticesNormals[2] = verticesNormals[2]; mVerticesNormals[2] = verticesNormals[2];
// Faces // Faces
for (uint i=0; i<2; i++) { mFaces[0].faceVertices.reserve(3);
mFaces[i].faceVertices.reserve(3); mFaces[0].faceVertices.add(0);
mFaces[i].faceVertices.add(0); mFaces[0].faceVertices.add(1);
mFaces[i].faceVertices.add(1); mFaces[0].faceVertices.add(2);
mFaces[i].faceVertices.add(2); mFaces[0].edgeIndex = 0;
mFaces[i].edgeIndex = i;
} mFaces[1].faceVertices.reserve(3);
mFaces[1].faceVertices.add(0);
mFaces[1].faceVertices.add(2);
mFaces[1].faceVertices.add(1);
mFaces[1].edgeIndex = 1;
// Edges // Edges
for (uint i=0; i<6; i++) { for (uint i=0; i<6; i++) {

View File

@ -79,8 +79,10 @@ class List {
using value_type = T; using value_type = T;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
using pointer = T*; using pointer = T*;
using const_pointer = T const*;
using reference = T&; using reference = T&;
using iterator_category = std::bidirectional_iterator_tag; using const_reference = const T&;
using iterator_category = std::random_access_iterator_tag;
/// Constructor /// Constructor
Iterator() = default; Iterator() = default;
@ -98,13 +100,19 @@ class List {
} }
/// Deferencable /// Deferencable
reference operator*() const { reference operator*() {
assert(mCurrentIndex >= 0 && mCurrentIndex < mSize);
return mBuffer[mCurrentIndex];
}
/// Const Deferencable
const_reference operator*() const {
assert(mCurrentIndex >= 0 && mCurrentIndex < mSize); assert(mCurrentIndex >= 0 && mCurrentIndex < mSize);
return mBuffer[mCurrentIndex]; return mBuffer[mCurrentIndex];
} }
/// Deferencable /// Deferencable
pointer operator->() const { const_pointer operator->() const {
assert(mCurrentIndex >= 0 && mCurrentIndex < mSize); assert(mCurrentIndex >= 0 && mCurrentIndex < mSize);
return &(mBuffer[mCurrentIndex]); return &(mBuffer[mCurrentIndex]);
} }
@ -138,6 +146,53 @@ class List {
mCurrentIndex--; mCurrentIndex--;
return tmp; return tmp;
} }
/// Plus operator
Iterator operator+(const difference_type& n) {
return Iterator(mBuffer, mCurrentIndex + n, mSize);
}
/// Plus operator
Iterator& operator+=(const difference_type& n) {
mCurrentIndex += n;
return *this;
}
/// Minus operator
Iterator operator-(const difference_type& n) {
return Iterator(mBuffer, mCurrentIndex - n, mSize);
}
/// Minus operator
Iterator& operator-=(const difference_type& n) {
mCurrentIndex -= n;
return *this;
}
/// Difference operator
difference_type operator-(const Iterator& iterator) const {
return mCurrentIndex - iterator.mCurrentIndex;
}
/// Comparison operator
bool operator<(const Iterator& other) const {
return mCurrentIndex < other.mCurrentIndex;
}
/// Comparison operator
bool operator>(const Iterator& other) const {
return mCurrentIndex > other.mCurrentIndex;
}
/// Comparison operator
bool operator<=(const Iterator& other) const {
return mCurrentIndex <= other.mCurrentIndex;
}
/// Comparison operator
bool operator>=(const Iterator& other) const {
return mCurrentIndex >= other.mCurrentIndex;
}
/// Equality operator (it == end()) /// Equality operator (it == end())
bool operator==(const Iterator& iterator) const { bool operator==(const Iterator& iterator) const {

View File

@ -186,6 +186,9 @@ void CollisionWorld::destroyCollisionBody(CollisionBody* collisionBody) {
// Add the body ID to the list of free IDs // Add the body ID to the list of free IDs
mFreeBodiesIds.add(collisionBody->getId()); mFreeBodiesIds.add(collisionBody->getId());
// Reset the contact manifold list of the body
collisionBody->resetContactManifoldsList();
// Call the destructor of the collision body // Call the destructor of the collision body
collisionBody->~CollisionBody(); collisionBody->~CollisionBody();
@ -244,13 +247,13 @@ bool CollisionWorld::testAABBOverlap(const CollisionBody* body1,
return body1AABB.testCollision(body2AABB); return body1AABB.testCollision(body2AABB);
} }
// Report all the bodies that overlap with the aabb in parameter // Report all the bodies which have an AABB that overlaps with the AABB in parameter
/** /**
* @param aabb AABB used to test for overlap * @param aabb AABB used to test for overlap
* @param overlapCallback Pointer to the callback class to report overlap * @param overlapCallback Pointer to the callback class to report overlap
* @param categoryMaskBits bits mask used to filter the bodies to test overlap with * @param categoryMaskBits bits mask used to filter the bodies to test overlap with
*/ */
inline void CollisionWorld::testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits) { void CollisionWorld::testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits) {
mCollisionDetection.testAABBOverlap(aabb, overlapCallback, categoryMaskBits); mCollisionDetection.testAABBOverlap(aabb, overlapCallback, categoryMaskBits);
} }

View File

@ -147,7 +147,7 @@ class CollisionWorld {
bool testAABBOverlap(const CollisionBody* body1, bool testAABBOverlap(const CollisionBody* body1,
const CollisionBody* body2) const; const CollisionBody* body2) const;
/// Report all the bodies that overlap with the AABB in parameter /// Report all the bodies which have an AABB that overlaps with the AABB in parameter
void testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF); void testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF);
/// Return true if two bodies overlap /// Return true if two bodies overlap

View File

@ -359,11 +359,8 @@ void DynamicsWorld::solveContactsAndConstraints() {
// For each island of the world // For each island of the world
for (uint islandIndex = 0; islandIndex < mNbIslands; islandIndex++) { for (uint islandIndex = 0; islandIndex < mNbIslands; islandIndex++) {
// Check if there are contacts and constraints to solve // If there are constraints to solve
bool isConstraintsToSolve = mIslands[islandIndex]->getNbJoints() > 0; if (mIslands[islandIndex]->getNbJoints() > 0) {
// If there are constraints
if (isConstraintsToSolve) {
// Initialize the constraint solver // Initialize the constraint solver
mConstraintSolver.initializeForIsland(mTimeStep, mIslands[islandIndex]); mConstraintSolver.initializeForIsland(mTimeStep, mIslands[islandIndex]);
@ -374,9 +371,10 @@ void DynamicsWorld::solveContactsAndConstraints() {
for (uint i=0; i<mNbVelocitySolverIterations; i++) { for (uint i=0; i<mNbVelocitySolverIterations; i++) {
for (uint islandIndex = 0; islandIndex < mNbIslands; islandIndex++) { for (uint islandIndex = 0; islandIndex < mNbIslands; islandIndex++) {
// Solve the constraints // Solve the constraints
bool isConstraintsToSolve = mIslands[islandIndex]->getNbJoints() > 0; if (mIslands[islandIndex]->getNbJoints() > 0) {
if (isConstraintsToSolve) {
mConstraintSolver.solveVelocityConstraints(mIslands[islandIndex]); mConstraintSolver.solveVelocityConstraints(mIslands[islandIndex]);
} }
} }
@ -400,11 +398,14 @@ void DynamicsWorld::solvePositionCorrection() {
// ---------- Solve the position error correction for the constraints ---------- // // ---------- Solve the position error correction for the constraints ---------- //
// For each iteration of the position (error correction) solver if (mIslands[islandIndex]->getNbJoints() > 0) {
for (uint i=0; i<mNbPositionSolverIterations; i++) {
// Solve the position constraints // For each iteration of the position (error correction) solver
mConstraintSolver.solvePositionConstraints(mIslands[islandIndex]); for (uint i=0; i<mNbPositionSolverIterations; i++) {
// Solve the position constraints
mConstraintSolver.solvePositionConstraints(mIslands[islandIndex]);
}
} }
} }
} }
@ -724,7 +725,7 @@ void DynamicsWorld::computeIslands() {
RigidBody* bodyToVisit = stackBodiesToVisit[stackIndex]; RigidBody* bodyToVisit = stackBodiesToVisit[stackIndex];
assert(bodyToVisit->isActive()); assert(bodyToVisit->isActive());
// Awake the body if it is slepping // Awake the body if it is sleeping
bodyToVisit->setIsSleeping(false); bodyToVisit->setIsSleeping(false);
// Add the body into the island // Add the body into the island
@ -746,22 +747,27 @@ void DynamicsWorld::computeIslands() {
// Check if the current contact manifold has already been added into an island // Check if the current contact manifold has already been added into an island
if (contactManifold->isAlreadyInIsland()) continue; if (contactManifold->isAlreadyInIsland()) continue;
// Add the contact manifold into the island
mIslands[mNbIslands]->addContactManifold(contactManifold);
contactManifold->mIsAlreadyInIsland = true;
// Get the other body of the contact manifold // Get the other body of the contact manifold
RigidBody* body1 = static_cast<RigidBody*>(contactManifold->getBody1()); RigidBody* body1 = dynamic_cast<RigidBody*>(contactManifold->getBody1());
RigidBody* body2 = static_cast<RigidBody*>(contactManifold->getBody2()); RigidBody* body2 = dynamic_cast<RigidBody*>(contactManifold->getBody2());
RigidBody* otherBody = (body1->getId() == bodyToVisit->getId()) ? body2 : body1;
// Check if the other body has already been added to the island // If the colliding body is a RigidBody (and not a CollisionBody instead)
if (otherBody->mIsAlreadyInIsland) continue; if (body1 != nullptr && body2 != nullptr) {
// Insert the other body into the stack of bodies to visit // Add the contact manifold into the island
stackBodiesToVisit[stackIndex] = otherBody; mIslands[mNbIslands]->addContactManifold(contactManifold);
stackIndex++; contactManifold->mIsAlreadyInIsland = true;
otherBody->mIsAlreadyInIsland = true;
RigidBody* otherBody = (body1->getId() == bodyToVisit->getId()) ? body2 : body1;
// Check if the other body has already been added to the island
if (otherBody->mIsAlreadyInIsland) continue;
// Insert the other body into the stack of bodies to visit
stackBodiesToVisit[stackIndex] = otherBody;
stackIndex++;
otherBody->mIsAlreadyInIsland = true;
}
} }
// For each joint in which the current body is involved // For each joint in which the current body is involved

View File

@ -42,7 +42,7 @@ long double Timer::getCurrentSystemTime() {
LARGE_INTEGER ticks; LARGE_INTEGER ticks;
QueryPerformanceFrequency(&ticksPerSecond); QueryPerformanceFrequency(&ticksPerSecond);
QueryPerformanceCounter(&ticks); QueryPerformanceCounter(&ticks);
return (long double(ticks.QuadPart) / long double(ticksPerSecond.QuadPart)); return ((long double)(ticks.QuadPart) / (long double)(ticksPerSecond.QuadPart));
#else #else
// Initialize the lastUpdateTime with the current time in seconds // Initialize the lastUpdateTime with the current time in seconds
timeval timeValue; timeval timeValue;

View File

@ -188,7 +188,7 @@ inline void Vector2::setAllValues(decimal newX, decimal newY) {
// Return the length of the vector // Return the length of the vector
inline decimal Vector2::length() const { inline decimal Vector2::length() const {
return sqrt(x*x + y*y); return std::sqrt(x*x + y*y);
} }
// Return the square of the length of the vector // Return the square of the length of the vector

View File

@ -26,6 +26,8 @@
#ifndef REACTPHYSICS3D_LOGGER_H #ifndef REACTPHYSICS3D_LOGGER_H
#define REACTPHYSICS3D_LOGGER_H #define REACTPHYSICS3D_LOGGER_H
// If logging is enabled
#ifdef IS_LOGGING_ACTIVE
// Libraries // Libraries
#include "containers/List.h" #include "containers/List.h"
@ -124,7 +126,7 @@ class Logger {
} }
/// Destructor /// Destructor
virtual ~TextFormatter() { virtual ~TextFormatter() override {
} }
@ -277,7 +279,7 @@ class Logger {
} }
/// Destructor /// Destructor
virtual ~HtmlFormatter() { virtual ~HtmlFormatter() override {
} }
@ -461,18 +463,6 @@ class Logger {
} }
#ifdef IS_LOGGING_ACTIVE
// Use this macro to log something
#define RP3D_LOG(logger, level, category, message) logger->log(level, category, message)
#else // If logger is not active
// Empty macro in case logs are not enabled
#define RP3D_LOG(logger, level, category, message)
#endif
// Hash function for struct VerticesPair // Hash function for struct VerticesPair
namespace std { namespace std {
@ -485,4 +475,15 @@ namespace std {
}; };
} }
// Use this macro to log something
#define RP3D_LOG(logger, level, category, message) logger->log(level, category, message)
// If the logging is not enabled
#else
// Empty macro in case logs are not enabled
#define RP3D_LOG(logger, level, category, message)
#endif
#endif #endif

View File

@ -23,6 +23,7 @@
* * * *
********************************************************************************/ ********************************************************************************/
// If profiling is enabled
#ifdef IS_PROFILING_ACTIVE #ifdef IS_PROFILING_ACTIVE
// Libraries // Libraries

View File

@ -26,6 +26,9 @@
#ifndef REACTPHYSICS3D_PROFILER_H #ifndef REACTPHYSICS3D_PROFILER_H
#define REACTPHYSICS3D_PROFILER_H #define REACTPHYSICS3D_PROFILER_H
// If profiling is enabled
#ifdef IS_PROFILING_ACTIVE
// Libraries // Libraries
#include "configuration.h" #include "configuration.h"
#include "engine/Timer.h" #include "engine/Timer.h"
@ -379,18 +382,10 @@ class ProfileSample {
} }
}; };
#ifdef IS_PROFILING_ACTIVE
// Use this macro to start profile a block of code // Use this macro to start profile a block of code
#define RP3D_PROFILE(name, profiler) ProfileSample profileSample(name, profiler) #define RP3D_PROFILE(name, profiler) ProfileSample profileSample(name, profiler)
#else // If profile is not active
// Empty macro in case profiling is not active
#define RP3D_PROFILE(name, profiler)
#endif
// Return true if we are at the root of the profiler tree // Return true if we are at the root of the profiler tree
inline bool ProfileNodeIterator::isRoot() { inline bool ProfileNodeIterator::isRoot() {
return (mCurrentParentNode->getParentNode() == nullptr); return (mCurrentParentNode->getParentNode() == nullptr);
@ -504,5 +499,12 @@ inline void Profiler::destroy() {
} }
// If profiling is disabled
#else
// Empty macro in case profiling is not active
#define RP3D_PROFILE(name, profiler)
#endif
#endif #endif

View File

@ -35,8 +35,8 @@
namespace reactphysics3d { namespace reactphysics3d {
// Macros // Macros
#define test(condition) applyTest(condition, #condition, __FILE__, __LINE__); #define rp3d_test(condition) applyTest(condition, #condition, __FILE__, __LINE__);
#define fail(text) applyFail(text, __FILE__, __LINE__); #define rp3d_fail(text) applyFail(text, __FILE__, __LINE__);
// Class Test // Class Test
/** /**

View File

@ -93,60 +93,60 @@ class TestAABB : public Test {
}; };
AABB aabb3 = AABB::createAABBForTriangle(trianglePoints); AABB aabb3 = AABB::createAABBForTriangle(trianglePoints);
test(aabb1.getMin().x == 0); rp3d_test(aabb1.getMin().x == 0);
test(aabb1.getMin().y == 0); rp3d_test(aabb1.getMin().y == 0);
test(aabb1.getMin().z == 0); rp3d_test(aabb1.getMin().z == 0);
test(aabb1.getMax().x == 0); rp3d_test(aabb1.getMax().x == 0);
test(aabb1.getMax().y == 0); rp3d_test(aabb1.getMax().y == 0);
test(aabb1.getMax().z == 0); rp3d_test(aabb1.getMax().z == 0);
test(aabb2.getMin().x == -3); rp3d_test(aabb2.getMin().x == -3);
test(aabb2.getMin().y == -5); rp3d_test(aabb2.getMin().y == -5);
test(aabb2.getMin().z == -8); rp3d_test(aabb2.getMin().z == -8);
test(aabb2.getMax().x == 65); rp3d_test(aabb2.getMax().x == 65);
test(aabb2.getMax().y == -1); rp3d_test(aabb2.getMax().y == -1);
test(aabb2.getMax().z == 56); rp3d_test(aabb2.getMax().z == 56);
test(aabb3.getMin().x == -12); rp3d_test(aabb3.getMin().x == -12);
test(aabb3.getMin().y == -34); rp3d_test(aabb3.getMin().y == -34);
test(aabb3.getMin().z == -73); rp3d_test(aabb3.getMin().z == -73);
test(aabb3.getMax().x == 45); rp3d_test(aabb3.getMax().x == 45);
test(aabb3.getMax().y == 98); rp3d_test(aabb3.getMax().y == 98);
test(aabb3.getMax().z == 76); rp3d_test(aabb3.getMax().z == 76);
// -------- Test inflate() -------- // // -------- Test inflate() -------- //
AABB aabbInflate(Vector3(-3, 4, 8), Vector3(-1, 6, 32)); AABB aabbInflate(Vector3(-3, 4, 8), Vector3(-1, 6, 32));
aabbInflate.inflate(1, 2, 3); aabbInflate.inflate(1, 2, 3);
test(approxEqual(aabbInflate.getMin().x, -4, 0.00001)); rp3d_test(approxEqual(aabbInflate.getMin().x, -4, 0.00001));
test(approxEqual(aabbInflate.getMin().y, 2, 0.00001)); rp3d_test(approxEqual(aabbInflate.getMin().y, 2, 0.00001));
test(approxEqual(aabbInflate.getMin().z, 5, 0.00001)); rp3d_test(approxEqual(aabbInflate.getMin().z, 5, 0.00001));
test(approxEqual(aabbInflate.getMax().x, 0, 0.00001)); rp3d_test(approxEqual(aabbInflate.getMax().x, 0, 0.00001));
test(approxEqual(aabbInflate.getMax().y, 8, 0.00001)); rp3d_test(approxEqual(aabbInflate.getMax().y, 8, 0.00001));
test(approxEqual(aabbInflate.getMax().z, 35, 0.00001)); rp3d_test(approxEqual(aabbInflate.getMax().z, 35, 0.00001));
// -------- Test getExtent() --------- // // -------- Test getExtent() --------- //
test(approxEqual(mAABB1.getExtent().x, 20)); rp3d_test(approxEqual(mAABB1.getExtent().x, 20));
test(approxEqual(mAABB1.getExtent().y, 20)); rp3d_test(approxEqual(mAABB1.getExtent().y, 20));
test(approxEqual(mAABB1.getExtent().z, 20)); rp3d_test(approxEqual(mAABB1.getExtent().z, 20));
test(approxEqual(mAABB2.getExtent().x, 3)); rp3d_test(approxEqual(mAABB2.getExtent().x, 3));
test(approxEqual(mAABB2.getExtent().y, 16)); rp3d_test(approxEqual(mAABB2.getExtent().y, 16));
test(approxEqual(mAABB2.getExtent().z, 60)); rp3d_test(approxEqual(mAABB2.getExtent().z, 60));
test(approxEqual(mAABB3.getExtent().x, 50)); rp3d_test(approxEqual(mAABB3.getExtent().x, 50));
test(approxEqual(mAABB3.getExtent().y, 50)); rp3d_test(approxEqual(mAABB3.getExtent().y, 50));
test(approxEqual(mAABB3.getExtent().z, 50)); rp3d_test(approxEqual(mAABB3.getExtent().z, 50));
// -------- Test getCenter() -------- // // -------- Test getCenter() -------- //
test(mAABB1.getCenter().x == 0); rp3d_test(mAABB1.getCenter().x == 0);
test(mAABB1.getCenter().y == 0); rp3d_test(mAABB1.getCenter().y == 0);
test(mAABB1.getCenter().z == 0); rp3d_test(mAABB1.getCenter().z == 0);
test(approxEqual(mAABB2.getCenter().x, -3.5)); rp3d_test(approxEqual(mAABB2.getCenter().x, -3.5));
test(approxEqual(mAABB2.getCenter().y, 12)); rp3d_test(approxEqual(mAABB2.getCenter().y, 12));
test(approxEqual(mAABB2.getCenter().z, 0)); rp3d_test(approxEqual(mAABB2.getCenter().z, 0));
// -------- Test setMin(), setMax(), getMin(), getMax() -------- // // -------- Test setMin(), setMax(), getMin(), getMax() -------- //
@ -154,29 +154,29 @@ class TestAABB : public Test {
aabb5.setMin(Vector3(-12, 34, 6)); aabb5.setMin(Vector3(-12, 34, 6));
aabb5.setMax(Vector3(-3, 56, 20)); aabb5.setMax(Vector3(-3, 56, 20));
test(aabb5.getMin().x == -12); rp3d_test(aabb5.getMin().x == -12);
test(aabb5.getMin().y == 34); rp3d_test(aabb5.getMin().y == 34);
test(aabb5.getMin().z == 6); rp3d_test(aabb5.getMin().z == 6);
test(aabb5.getMax().x == -3); rp3d_test(aabb5.getMax().x == -3);
test(aabb5.getMax().y == 56); rp3d_test(aabb5.getMax().y == 56);
test(aabb5.getMax().z == 20); rp3d_test(aabb5.getMax().z == 20);
// -------- Test assignment operator -------- // // -------- Test assignment operator -------- //
AABB aabb6; AABB aabb6;
aabb6 = aabb2; aabb6 = aabb2;
test(aabb6.getMin().x == -3); rp3d_test(aabb6.getMin().x == -3);
test(aabb6.getMin().y == -5); rp3d_test(aabb6.getMin().y == -5);
test(aabb6.getMin().z == -8); rp3d_test(aabb6.getMin().z == -8);
test(aabb6.getMax().x == 65); rp3d_test(aabb6.getMax().x == 65);
test(aabb6.getMax().y == -1); rp3d_test(aabb6.getMax().y == -1);
test(aabb6.getMax().z == 56); rp3d_test(aabb6.getMax().z == 56);
// -------- Test getVolume() -------- // // -------- Test getVolume() -------- //
test(approxEqual(mAABB1.getVolume(), 8000)); rp3d_test(approxEqual(mAABB1.getVolume(), 8000));
test(approxEqual(mAABB2.getVolume(), 2880)); rp3d_test(approxEqual(mAABB2.getVolume(), 2880));
} }
void testMergeMethods() { void testMergeMethods() {
@ -189,70 +189,70 @@ class TestAABB : public Test {
AABB aabb3; AABB aabb3;
aabb3.mergeTwoAABBs(aabb1, mAABB1); aabb3.mergeTwoAABBs(aabb1, mAABB1);
test(aabb3.getMin().x == -45); rp3d_test(aabb3.getMin().x == -45);
test(aabb3.getMin().y == -10); rp3d_test(aabb3.getMin().y == -10);
test(aabb3.getMin().z == -10); rp3d_test(aabb3.getMin().z == -10);
test(aabb3.getMax().x == 23); rp3d_test(aabb3.getMax().x == 23);
test(aabb3.getMax().y == 10); rp3d_test(aabb3.getMax().y == 10);
test(aabb3.getMax().z == 10); rp3d_test(aabb3.getMax().z == 10);
AABB aabb4; AABB aabb4;
aabb4.mergeTwoAABBs(aabb1, aabb2); aabb4.mergeTwoAABBs(aabb1, aabb2);
test(aabb4.getMin().x == -45); rp3d_test(aabb4.getMin().x == -45);
test(aabb4.getMin().y == 6); rp3d_test(aabb4.getMin().y == 6);
test(aabb4.getMin().z == -2); rp3d_test(aabb4.getMin().z == -2);
test(aabb4.getMax().x == 23); rp3d_test(aabb4.getMax().x == 23);
test(aabb4.getMax().y == 9); rp3d_test(aabb4.getMax().y == 9);
test(aabb4.getMax().z == 45); rp3d_test(aabb4.getMax().z == 45);
// -------- Test mergeWithAABB() -------- // // -------- Test mergeWithAABB() -------- //
aabb1.mergeWithAABB(mAABB1); aabb1.mergeWithAABB(mAABB1);
test(aabb1.getMin().x == -45); rp3d_test(aabb1.getMin().x == -45);
test(aabb1.getMin().y == -10); rp3d_test(aabb1.getMin().y == -10);
test(aabb1.getMin().z == -10); rp3d_test(aabb1.getMin().z == -10);
test(aabb1.getMax().x == 23); rp3d_test(aabb1.getMax().x == 23);
test(aabb1.getMax().y == 10); rp3d_test(aabb1.getMax().y == 10);
test(aabb1.getMax().z == 10); rp3d_test(aabb1.getMax().z == 10);
aabb2.mergeWithAABB(mAABB1); aabb2.mergeWithAABB(mAABB1);
test(aabb2.getMin().x == -15); rp3d_test(aabb2.getMin().x == -15);
test(aabb2.getMin().y == -10); rp3d_test(aabb2.getMin().y == -10);
test(aabb2.getMin().z == -10); rp3d_test(aabb2.getMin().z == -10);
test(aabb2.getMax().x == 10); rp3d_test(aabb2.getMax().x == 10);
test(aabb2.getMax().y == 10); rp3d_test(aabb2.getMax().y == 10);
test(aabb2.getMax().z == 45); rp3d_test(aabb2.getMax().z == 45);
} }
void testIntersection() { void testIntersection() {
// -------- Test contains(AABB) -------- // // -------- Test contains(AABB) -------- //
test(!mAABB1.contains(mAABB2)); rp3d_test(!mAABB1.contains(mAABB2));
test(mAABB3.contains(mAABB1)); rp3d_test(mAABB3.contains(mAABB1));
test(!mAABB1.contains(mAABB3)); rp3d_test(!mAABB1.contains(mAABB3));
test(!mAABB1.contains(mAABB4)); rp3d_test(!mAABB1.contains(mAABB4));
test(!mAABB4.contains(mAABB1)); rp3d_test(!mAABB4.contains(mAABB1));
// -------- Test contains(Vector3) -------- // // -------- Test contains(Vector3) -------- //
test(mAABB1.contains(Vector3(0, 0, 0))); rp3d_test(mAABB1.contains(Vector3(0, 0, 0)));
test(mAABB1.contains(Vector3(-5, 6, 9))); rp3d_test(mAABB1.contains(Vector3(-5, 6, 9)));
test(mAABB1.contains(Vector3(-9, -4, -9))); rp3d_test(mAABB1.contains(Vector3(-9, -4, -9)));
test(mAABB1.contains(Vector3(9, 4, 7))); rp3d_test(mAABB1.contains(Vector3(9, 4, 7)));
test(!mAABB1.contains(Vector3(-11, -4, -9))); rp3d_test(!mAABB1.contains(Vector3(-11, -4, -9)));
test(!mAABB1.contains(Vector3(1, 12, -9))); rp3d_test(!mAABB1.contains(Vector3(1, 12, -9)));
test(!mAABB1.contains(Vector3(1, 8, -13))); rp3d_test(!mAABB1.contains(Vector3(1, 8, -13)));
test(!mAABB1.contains(Vector3(-14, 82, -13))); rp3d_test(!mAABB1.contains(Vector3(-14, 82, -13)));
// -------- Test testCollision() -------- // // -------- Test testCollision() -------- //
test(mAABB1.testCollision(mAABB2)); rp3d_test(mAABB1.testCollision(mAABB2));
test(mAABB2.testCollision(mAABB1)); rp3d_test(mAABB2.testCollision(mAABB1));
test(mAABB1.testCollision(mAABB3)); rp3d_test(mAABB1.testCollision(mAABB3));
test(mAABB3.testCollision(mAABB1)); rp3d_test(mAABB3.testCollision(mAABB1));
test(!mAABB1.testCollision(mAABB4)); rp3d_test(!mAABB1.testCollision(mAABB4));
test(!mAABB4.testCollision(mAABB1)); rp3d_test(!mAABB4.testCollision(mAABB1));
// -------- Test testCollisionTriangleAABB() -------- // // -------- Test testCollisionTriangleAABB() -------- //
@ -260,8 +260,8 @@ class TestAABB : public Test {
Vector3 trianglePoints[] = { Vector3 trianglePoints[] = {
Vector3(-2, 4, 6), Vector3(20, -34, -73), Vector3(-12, 98, 76) Vector3(-2, 4, 6), Vector3(20, -34, -73), Vector3(-12, 98, 76)
}; };
test(mAABB1.testCollisionTriangleAABB(trianglePoints)); rp3d_test(mAABB1.testCollisionTriangleAABB(trianglePoints));
test(!aabb.testCollisionTriangleAABB(trianglePoints)); rp3d_test(!aabb.testCollisionTriangleAABB(trianglePoints));
// -------- Test testRayIntersect() -------- // // -------- Test testRayIntersect() -------- //
@ -274,14 +274,14 @@ class TestAABB : public Test {
Ray ray7(Vector3(-4, 6, -100), Vector3(-4, 6, -11), 0.6); Ray ray7(Vector3(-4, 6, -100), Vector3(-4, 6, -11), 0.6);
Ray ray8(Vector3(-403, -432, -100), Vector3(134, 643, 23)); Ray ray8(Vector3(-403, -432, -100), Vector3(134, 643, 23));
test(mAABB1.testRayIntersect(ray1)); rp3d_test(mAABB1.testRayIntersect(ray1));
test(!mAABB1.testRayIntersect(ray2)); rp3d_test(!mAABB1.testRayIntersect(ray2));
test(mAABB1.testRayIntersect(ray3)); rp3d_test(mAABB1.testRayIntersect(ray3));
test(mAABB1.testRayIntersect(ray4)); rp3d_test(mAABB1.testRayIntersect(ray4));
test(mAABB1.testRayIntersect(ray5)); rp3d_test(mAABB1.testRayIntersect(ray5));
test(mAABB1.testRayIntersect(ray6)); rp3d_test(mAABB1.testRayIntersect(ray6));
test(!mAABB1.testRayIntersect(ray7)); rp3d_test(!mAABB1.testRayIntersect(ray7));
test(!mAABB1.testRayIntersect(ray8)); rp3d_test(!mAABB1.testRayIntersect(ray8));
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@ -147,18 +147,18 @@ class TestDynamicAABBTree : public Test {
// Test root AABB // Test root AABB
AABB rootAABB = tree.getRootAABB(); AABB rootAABB = tree.getRootAABB();
test(rootAABB.getMin().x == -6); rp3d_test(rootAABB.getMin().x == -6);
test(rootAABB.getMin().y == -4); rp3d_test(rootAABB.getMin().y == -4);
test(rootAABB.getMin().z == -3); rp3d_test(rootAABB.getMin().z == -3);
test(rootAABB.getMax().x == 10); rp3d_test(rootAABB.getMax().x == 10);
test(rootAABB.getMax().y == 8); rp3d_test(rootAABB.getMax().y == 8);
test(rootAABB.getMax().z == 3); rp3d_test(rootAABB.getMax().z == 3);
// Test data stored at the nodes of the tree // Test data stored at the nodes of the tree
test(*(int*)(tree.getNodeDataPointer(object1Id)) == object1Data); rp3d_test(*(int*)(tree.getNodeDataPointer(object1Id)) == object1Data);
test(*(int*)(tree.getNodeDataPointer(object2Id)) == object2Data); rp3d_test(*(int*)(tree.getNodeDataPointer(object2Id)) == object2Data);
test(*(int*)(tree.getNodeDataPointer(object3Id)) == object3Data); rp3d_test(*(int*)(tree.getNodeDataPointer(object3Id)) == object3Data);
test(*(int*)(tree.getNodeDataPointer(object4Id)) == object4Data); rp3d_test(*(int*)(tree.getNodeDataPointer(object4Id)) == object4Data);
#ifdef IS_PROFILING_ACTIVE #ifdef IS_PROFILING_ACTIVE
delete profiler; delete profiler;
@ -204,42 +204,42 @@ class TestDynamicAABBTree : public Test {
// AABB overlapping nothing // AABB overlapping nothing
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id)); rp3d_test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping everything // AABB overlapping everything
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id)); rp3d_test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id)); rp3d_test(mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id)); rp3d_test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 1 and 3 // AABB overlapping object 1 and 3
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id)); rp3d_test(mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 3 and 4 // AABB overlapping object 3 and 4
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id)); rp3d_test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 2 // AABB overlapping object 2
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id)); rp3d_test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id)); rp3d_test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- // // ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- //
@ -251,42 +251,42 @@ class TestDynamicAABBTree : public Test {
// AABB overlapping nothing // AABB overlapping nothing
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id)); rp3d_test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping everything // AABB overlapping everything
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id)); rp3d_test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id)); rp3d_test(mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id)); rp3d_test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 1 and 3 // AABB overlapping object 1 and 3
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id)); rp3d_test(mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 3 and 4 // AABB overlapping object 3 and 4
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id)); rp3d_test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 2 // AABB overlapping object 2
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id)); rp3d_test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id)); rp3d_test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- // // ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- //
@ -298,42 +298,42 @@ class TestDynamicAABBTree : public Test {
// AABB overlapping nothing // AABB overlapping nothing
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id)); rp3d_test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping everything // AABB overlapping everything
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id)); rp3d_test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id)); rp3d_test(mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id)); rp3d_test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 1 and 3 // AABB overlapping object 1 and 3
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id)); rp3d_test(mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 3 and 4 // AABB overlapping object 3 and 4
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id)); rp3d_test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 2 // AABB overlapping object 2
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id)); rp3d_test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id)); rp3d_test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// ---- Move objects 2 and 3 ----- // // ---- Move objects 2 and 3 ----- //
@ -346,18 +346,18 @@ class TestDynamicAABBTree : public Test {
// AABB overlapping object 3 // AABB overlapping object 3
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(6, -10, -2), Vector3(8, 5, 3)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(6, -10, -2), Vector3(8, 5, 3)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id)); rp3d_test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id)); rp3d_test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id)); rp3d_test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping objects 1, 2 // AABB overlapping objects 1, 2
mOverlapCallback.reset(); mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-8, 5, -3), Vector3(-2, 11, 3)), mOverlapCallback); tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-8, 5, -3), Vector3(-2, 11, 3)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id)); rp3d_test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id)); rp3d_test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id)); rp3d_test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id)); rp3d_test(!mOverlapCallback.isOverlapping(object4Id));
#ifdef IS_PROFILING_ACTIVE #ifdef IS_PROFILING_ACTIVE
delete profiler; delete profiler;
@ -404,37 +404,37 @@ class TestDynamicAABBTree : public Test {
mRaycastCallback.reset(); mRaycastCallback.reset();
Ray ray1(Vector3(4.5, -10, -5), Vector3(4.5, 10, -5)); Ray ray1(Vector3(4.5, -10, -5), Vector3(4.5, 10, -5));
tree.raycast(ray1, mRaycastCallback); tree.raycast(ray1, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id)); rp3d_test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 // Ray that hits object 1
mRaycastCallback.reset(); mRaycastCallback.reset();
Ray ray2(Vector3(-1, -20, -2), Vector3(-1, 20, -2)); Ray ray2(Vector3(-1, -20, -2), Vector3(-1, 20, -2));
tree.raycast(ray2, mRaycastCallback); tree.raycast(ray2, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id)); rp3d_test(mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 and 2 // Ray that hits object 1 and 2
mRaycastCallback.reset(); mRaycastCallback.reset();
Ray ray3(Vector3(-7, 6, -2), Vector3(8, 6, -2)); Ray ray3(Vector3(-7, 6, -2), Vector3(8, 6, -2));
tree.raycast(ray3, mRaycastCallback); tree.raycast(ray3, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id)); rp3d_test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id)); rp3d_test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3 // Ray that hits object 3
mRaycastCallback.reset(); mRaycastCallback.reset();
Ray ray4(Vector3(-7, 2, 0), Vector3(-1, 2, 0)); Ray ray4(Vector3(-7, 2, 0), Vector3(-1, 2, 0));
tree.raycast(ray4, mRaycastCallback); tree.raycast(ray4, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id)); rp3d_test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id)); rp3d_test(mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- // // ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- //
@ -446,34 +446,34 @@ class TestDynamicAABBTree : public Test {
// Ray with no hits // Ray with no hits
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray1, mRaycastCallback); tree.raycast(ray1, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id)); rp3d_test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 // Ray that hits object 1
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray2, mRaycastCallback); tree.raycast(ray2, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id)); rp3d_test(mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 and 2 // Ray that hits object 1 and 2
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray3, mRaycastCallback); tree.raycast(ray3, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id)); rp3d_test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id)); rp3d_test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3 // Ray that hits object 3
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray4, mRaycastCallback); tree.raycast(ray4, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id)); rp3d_test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id)); rp3d_test(mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- // // ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- //
@ -485,34 +485,34 @@ class TestDynamicAABBTree : public Test {
// Ray with no hits // Ray with no hits
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray1, mRaycastCallback); tree.raycast(ray1, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id)); rp3d_test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 // Ray that hits object 1
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray2, mRaycastCallback); tree.raycast(ray2, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id)); rp3d_test(mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 and 2 // Ray that hits object 1 and 2
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray3, mRaycastCallback); tree.raycast(ray3, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id)); rp3d_test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id)); rp3d_test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3 // Ray that hits object 3
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray4, mRaycastCallback); tree.raycast(ray4, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id)); rp3d_test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id)); rp3d_test(mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// ---- Move objects 2 and 3 ----- // // ---- Move objects 2 and 3 ----- //
@ -526,19 +526,19 @@ class TestDynamicAABBTree : public Test {
Ray ray5(Vector3(-4, -5, 0), Vector3(-4, 12, 0)); Ray ray5(Vector3(-4, -5, 0), Vector3(-4, 12, 0));
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray5, mRaycastCallback); tree.raycast(ray5, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id)); rp3d_test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id)); rp3d_test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id)); rp3d_test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id)); rp3d_test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3 and 4 // Ray that hits object 3 and 4
Ray ray6(Vector3(11, -3, 1), Vector3(-2, -3, 1)); Ray ray6(Vector3(11, -3, 1), Vector3(-2, -3, 1));
mRaycastCallback.reset(); mRaycastCallback.reset();
tree.raycast(ray6, mRaycastCallback); tree.raycast(ray6, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id)); rp3d_test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id)); rp3d_test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id)); rp3d_test(mRaycastCallback.isHit(object3Id));
test(mRaycastCallback.isHit(object4Id)); rp3d_test(mRaycastCallback.isHit(object4Id));
#ifdef IS_PROFILING_ACTIVE #ifdef IS_PROFILING_ACTIVE
delete profiler; delete profiler;

View File

@ -4,6 +4,7 @@
// Libraries // Libraries
#include "reactphysics3d.h" #include "reactphysics3d.h"
#include "Test.h" #include "Test.h"
#include <vector>
/// Reactphysics3D namespace /// Reactphysics3D namespace
namespace reactphysics3d { namespace reactphysics3d {
@ -94,54 +95,54 @@ class TestHalfEdgeStructure : public Test {
// --- Test that the half-edge structure of the cube is valid --- // // --- Test that the half-edge structure of the cube is valid --- //
test(cubeStructure.getNbFaces() == 6); rp3d_test(cubeStructure.getNbFaces() == 6);
test(cubeStructure.getNbVertices() == 8); rp3d_test(cubeStructure.getNbVertices() == 8);
test(cubeStructure.getNbHalfEdges() == 24); rp3d_test(cubeStructure.getNbHalfEdges() == 24);
// Test vertices // Test vertices
test(vertices[cubeStructure.getVertex(0).vertexPointIndex].x == -0.5); rp3d_test(vertices[cubeStructure.getVertex(0).vertexPointIndex].x == -0.5);
test(vertices[cubeStructure.getVertex(0).vertexPointIndex].y == -0.5); rp3d_test(vertices[cubeStructure.getVertex(0).vertexPointIndex].y == -0.5);
test(vertices[cubeStructure.getVertex(0).vertexPointIndex].z == 0.5); rp3d_test(vertices[cubeStructure.getVertex(0).vertexPointIndex].z == 0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(0).edgeIndex).vertexIndex == 0); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(0).edgeIndex).vertexIndex == 0);
test(vertices[cubeStructure.getVertex(1).vertexPointIndex].x == 0.5); rp3d_test(vertices[cubeStructure.getVertex(1).vertexPointIndex].x == 0.5);
test(vertices[cubeStructure.getVertex(1).vertexPointIndex].y == -0.5); rp3d_test(vertices[cubeStructure.getVertex(1).vertexPointIndex].y == -0.5);
test(vertices[cubeStructure.getVertex(1).vertexPointIndex].z == 0.5); rp3d_test(vertices[cubeStructure.getVertex(1).vertexPointIndex].z == 0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(1).edgeIndex).vertexIndex == 1); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(1).edgeIndex).vertexIndex == 1);
test(vertices[cubeStructure.getVertex(2).vertexPointIndex].x == 0.5); rp3d_test(vertices[cubeStructure.getVertex(2).vertexPointIndex].x == 0.5);
test(vertices[cubeStructure.getVertex(2).vertexPointIndex].y == 0.5); rp3d_test(vertices[cubeStructure.getVertex(2).vertexPointIndex].y == 0.5);
test(vertices[cubeStructure.getVertex(2).vertexPointIndex].z == 0.5); rp3d_test(vertices[cubeStructure.getVertex(2).vertexPointIndex].z == 0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(2).edgeIndex).vertexIndex == 2); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(2).edgeIndex).vertexIndex == 2);
test(vertices[cubeStructure.getVertex(3).vertexPointIndex].x == -0.5); rp3d_test(vertices[cubeStructure.getVertex(3).vertexPointIndex].x == -0.5);
test(vertices[cubeStructure.getVertex(3).vertexPointIndex].y == 0.5); rp3d_test(vertices[cubeStructure.getVertex(3).vertexPointIndex].y == 0.5);
test(vertices[cubeStructure.getVertex(3).vertexPointIndex].z == 0.5); rp3d_test(vertices[cubeStructure.getVertex(3).vertexPointIndex].z == 0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(3).edgeIndex).vertexIndex == 3); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(3).edgeIndex).vertexIndex == 3);
test(vertices[cubeStructure.getVertex(4).vertexPointIndex].x == -0.5); rp3d_test(vertices[cubeStructure.getVertex(4).vertexPointIndex].x == -0.5);
test(vertices[cubeStructure.getVertex(4).vertexPointIndex].y == -0.5); rp3d_test(vertices[cubeStructure.getVertex(4).vertexPointIndex].y == -0.5);
test(vertices[cubeStructure.getVertex(4).vertexPointIndex].z == -0.5); rp3d_test(vertices[cubeStructure.getVertex(4).vertexPointIndex].z == -0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(4).edgeIndex).vertexIndex == 4); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(4).edgeIndex).vertexIndex == 4);
test(vertices[cubeStructure.getVertex(5).vertexPointIndex].x == 0.5); rp3d_test(vertices[cubeStructure.getVertex(5).vertexPointIndex].x == 0.5);
test(vertices[cubeStructure.getVertex(5).vertexPointIndex].y == -0.5); rp3d_test(vertices[cubeStructure.getVertex(5).vertexPointIndex].y == -0.5);
test(vertices[cubeStructure.getVertex(5).vertexPointIndex].z == -0.5); rp3d_test(vertices[cubeStructure.getVertex(5).vertexPointIndex].z == -0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(5).edgeIndex).vertexIndex == 5); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(5).edgeIndex).vertexIndex == 5);
test(vertices[cubeStructure.getVertex(6).vertexPointIndex].x == 0.5); rp3d_test(vertices[cubeStructure.getVertex(6).vertexPointIndex].x == 0.5);
test(vertices[cubeStructure.getVertex(6).vertexPointIndex].y == 0.5); rp3d_test(vertices[cubeStructure.getVertex(6).vertexPointIndex].y == 0.5);
test(vertices[cubeStructure.getVertex(6).vertexPointIndex].z == -0.5); rp3d_test(vertices[cubeStructure.getVertex(6).vertexPointIndex].z == -0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(6).edgeIndex).vertexIndex == 6); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(6).edgeIndex).vertexIndex == 6);
test(vertices[cubeStructure.getVertex(7).vertexPointIndex].x == -0.5); rp3d_test(vertices[cubeStructure.getVertex(7).vertexPointIndex].x == -0.5);
test(vertices[cubeStructure.getVertex(7).vertexPointIndex].y == 0.5); rp3d_test(vertices[cubeStructure.getVertex(7).vertexPointIndex].y == 0.5);
test(vertices[cubeStructure.getVertex(7).vertexPointIndex].z == -0.5); rp3d_test(vertices[cubeStructure.getVertex(7).vertexPointIndex].z == -0.5);
test(cubeStructure.getHalfEdge(cubeStructure.getVertex(7).edgeIndex).vertexIndex == 7); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getVertex(7).edgeIndex).vertexIndex == 7);
// Test faces // Test faces
for (uint f=0; f<6; f++) { for (uint f=0; f<6; f++) {
test(cubeStructure.getHalfEdge(cubeStructure.getFace(f).edgeIndex).faceIndex == f); rp3d_test(cubeStructure.getHalfEdge(cubeStructure.getFace(f).edgeIndex).faceIndex == f);
} }
// Test edges // Test edges
@ -156,14 +157,14 @@ class TestHalfEdgeStructure : public Test {
rp3d::HalfEdgeStructure::Edge edge = cubeStructure.getHalfEdge(edgeIndex); rp3d::HalfEdgeStructure::Edge edge = cubeStructure.getHalfEdge(edgeIndex);
test(cubeStructure.getHalfEdge(edge.twinEdgeIndex).twinEdgeIndex == edgeIndex); rp3d_test(cubeStructure.getHalfEdge(edge.twinEdgeIndex).twinEdgeIndex == edgeIndex);
test(edge.faceIndex == f); rp3d_test(edge.faceIndex == f);
// Go to the next edge // Go to the next edge
edgeIndex = edge.nextEdgeIndex; edgeIndex = edge.nextEdgeIndex;
} }
test(firstEdgeIndex == edgeIndex); rp3d_test(firstEdgeIndex == edgeIndex);
} }
} }
@ -205,34 +206,34 @@ class TestHalfEdgeStructure : public Test {
// --- Test that the half-edge structure of the tetrahedron is valid --- // // --- Test that the half-edge structure of the tetrahedron is valid --- //
test(tetrahedron.getNbFaces() == 4); rp3d_test(tetrahedron.getNbFaces() == 4);
test(tetrahedron.getNbVertices() == 4); rp3d_test(tetrahedron.getNbVertices() == 4);
test(tetrahedron.getNbHalfEdges() == 12); rp3d_test(tetrahedron.getNbHalfEdges() == 12);
// Test vertices // Test vertices
test(vertices[tetrahedron.getVertex(0).vertexPointIndex].x == 1); rp3d_test(vertices[tetrahedron.getVertex(0).vertexPointIndex].x == 1);
test(vertices[tetrahedron.getVertex(0).vertexPointIndex].y == -1); rp3d_test(vertices[tetrahedron.getVertex(0).vertexPointIndex].y == -1);
test(vertices[tetrahedron.getVertex(0).vertexPointIndex].z == -1); rp3d_test(vertices[tetrahedron.getVertex(0).vertexPointIndex].z == -1);
test(tetrahedron.getHalfEdge(tetrahedron.getVertex(0).edgeIndex).vertexIndex == 0); rp3d_test(tetrahedron.getHalfEdge(tetrahedron.getVertex(0).edgeIndex).vertexIndex == 0);
test(vertices[tetrahedron.getVertex(1).vertexPointIndex].x == -1); rp3d_test(vertices[tetrahedron.getVertex(1).vertexPointIndex].x == -1);
test(vertices[tetrahedron.getVertex(1).vertexPointIndex].y == -1); rp3d_test(vertices[tetrahedron.getVertex(1).vertexPointIndex].y == -1);
test(vertices[tetrahedron.getVertex(1).vertexPointIndex].z == -1); rp3d_test(vertices[tetrahedron.getVertex(1).vertexPointIndex].z == -1);
test(tetrahedron.getHalfEdge(tetrahedron.getVertex(1).edgeIndex).vertexIndex == 1); rp3d_test(tetrahedron.getHalfEdge(tetrahedron.getVertex(1).edgeIndex).vertexIndex == 1);
test(vertices[tetrahedron.getVertex(2).vertexPointIndex].x == 0); rp3d_test(vertices[tetrahedron.getVertex(2).vertexPointIndex].x == 0);
test(vertices[tetrahedron.getVertex(2).vertexPointIndex].y == -1); rp3d_test(vertices[tetrahedron.getVertex(2).vertexPointIndex].y == -1);
test(vertices[tetrahedron.getVertex(2).vertexPointIndex].z == 1); rp3d_test(vertices[tetrahedron.getVertex(2).vertexPointIndex].z == 1);
test(tetrahedron.getHalfEdge(tetrahedron.getVertex(2).edgeIndex).vertexIndex == 2); rp3d_test(tetrahedron.getHalfEdge(tetrahedron.getVertex(2).edgeIndex).vertexIndex == 2);
test(vertices[tetrahedron.getVertex(3).vertexPointIndex].x == 0); rp3d_test(vertices[tetrahedron.getVertex(3).vertexPointIndex].x == 0);
test(vertices[tetrahedron.getVertex(3).vertexPointIndex].y == 1); rp3d_test(vertices[tetrahedron.getVertex(3).vertexPointIndex].y == 1);
test(vertices[tetrahedron.getVertex(3).vertexPointIndex].z == 0); rp3d_test(vertices[tetrahedron.getVertex(3).vertexPointIndex].z == 0);
test(tetrahedron.getHalfEdge(tetrahedron.getVertex(3).edgeIndex).vertexIndex == 3); rp3d_test(tetrahedron.getHalfEdge(tetrahedron.getVertex(3).edgeIndex).vertexIndex == 3);
// Test faces // Test faces
for (uint f=0; f<4; f++) { for (uint f=0; f<4; f++) {
test(tetrahedron.getHalfEdge(tetrahedron.getFace(f).edgeIndex).faceIndex == f); rp3d_test(tetrahedron.getHalfEdge(tetrahedron.getFace(f).edgeIndex).faceIndex == f);
} }
// Test edges // Test edges
@ -246,14 +247,14 @@ class TestHalfEdgeStructure : public Test {
rp3d::HalfEdgeStructure::Edge edge = tetrahedron.getHalfEdge(edgeIndex); rp3d::HalfEdgeStructure::Edge edge = tetrahedron.getHalfEdge(edgeIndex);
test(tetrahedron.getHalfEdge(edge.twinEdgeIndex).twinEdgeIndex == edgeIndex); rp3d_test(tetrahedron.getHalfEdge(edge.twinEdgeIndex).twinEdgeIndex == edgeIndex);
test(edge.faceIndex == f); rp3d_test(edge.faceIndex == f);
// Go to the next edge // Go to the next edge
edgeIndex = edge.nextEdgeIndex; edgeIndex = edge.nextEdgeIndex;
} }
test(firstEdgeIndex == edgeIndex); rp3d_test(firstEdgeIndex == edgeIndex);
} }
} }
}; };

View File

@ -196,56 +196,56 @@ class TestPointInside : public Test {
void testBox() { void testBox() {
// Tests with CollisionBody // Tests with CollisionBody
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); rp3d_test(mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); rp3d_test(!mBoxBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
// Tests with ProxyBoxShape // Tests with ProxyBoxShape
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); rp3d_test(mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); rp3d_test(!mBoxProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
} }
/// Test the ProxySphereShape::testPointInside() and /// Test the ProxySphereShape::testPointInside() and
@ -253,48 +253,48 @@ class TestPointInside : public Test {
void testSphere() { void testSphere() {
// Tests with CollisionBody // Tests with CollisionBody
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5)));
test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5))); rp3d_test(mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5)));
test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5))); rp3d_test(!mSphereBody->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5)));
// Tests with ProxySphereShape // Tests with ProxySphereShape
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -1.5)));
test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5))); rp3d_test(mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 1.5)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, -2, -2)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2, 2, -1.5)));
test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5))); rp3d_test(!mSphereProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.5, -2, 2.5)));
} }
/// Test the ProxyCapsuleShape::testPointInside() and /// Test the ProxyCapsuleShape::testPointInside() and
@ -302,98 +302,98 @@ class TestPointInside : public Test {
void testCapsule() { void testCapsule() {
// Tests with CollisionBody // Tests with CollisionBody
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4)));
test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5))); rp3d_test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -13.1, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -13.1, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 13.1, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 13.1, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 3.1))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 3.1)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -3.1))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -3.1)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 5, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 5, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 5, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 5, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, 2.6))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, 2.6)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, -2.7))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, -2.7)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 3.1))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 3.1)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -3.1))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -3.1)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, -5, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, -5, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -5, 0))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -5, 0)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, 2.6))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, 2.6)));
test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, -2.7))); rp3d_test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, -2.7)));
// Tests with ProxyCapsuleShape // Tests with ProxyCapsuleShape
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -6.9, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 6.9, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 1.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -1.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, 0.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 0, -0.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 1.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -1.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 5, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 5, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, 0.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, 5, -0.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 1.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -1.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, -5, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4)));
test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5))); rp3d_test(mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -13.1, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -13.1, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 13.1, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 13.1, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.1)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 3.1))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, 3.1)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -3.1))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 5, -3.1)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 5, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 5, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 5, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 5, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, 2.6))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, 2.6)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, -2.7))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, 5, -2.7)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 3.1))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, 3.1)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -3.1))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -5, -3.1)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, -5, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, -5, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -5, 0))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, -5, 0)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, 2.6))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, 2.6)));
test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, -2.7))); rp3d_test(!mCapsuleProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.5, -5, -2.7)));
} }
/// Test the ProxyConvexMeshShape::testPointInside() and /// Test the ProxyConvexMeshShape::testPointInside() and
@ -401,101 +401,101 @@ class TestPointInside : public Test {
void testConvexMesh() { void testConvexMesh() {
// Tests with CollisionBody // Tests with CollisionBody
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); rp3d_test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); rp3d_test(!mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
// Tests with ProxyConvexMeshShape // Tests with ProxyConvexMeshShape
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 0, 0)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -2.9, 0)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 2.9, 0)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -3.9)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.9)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -2.9, -3.9)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1.9, 2.9, 3.9)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, -2, -1.5)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, -2.5)));
test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5))); rp3d_test(mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 3.5)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, 0, 0)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 0, 0)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, -3.1, 0)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.1, 0)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -4.1)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 4.1)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-2.1, -3.1, -4.1)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(2.1, 3.1, 4.1)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-10, -2, -1.5)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 4, -2.5)));
test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5))); rp3d_test(!mConvexMeshProxyShape->testPointInside(mLocalShapeToWorld * Vector3(1, -2, 4.5)));
} }
/// Test the CollisionBody::testPointInside() method /// Test the CollisionBody::testPointInside() method
void testCompound() { void testCompound() {
// Points on the capsule // Points on the capsule
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, 0, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 0, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 2.9)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, -2.9)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, 1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, 1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, -1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 0, -1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, -1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, -1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, 1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 0, 1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, 3.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, 3.9, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 3.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, 3.9, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 2.9)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, -2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, -2.9)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, 1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, 1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, -1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, 3.9, -1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, -1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, -1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, 1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, 3.9, 1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, -3.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(2.9, -3.9, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, -3.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-2.9, -3.9, 0)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, 2.9)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, -2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(0, -3.9, -2.9)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, 1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, 1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, -1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(1.7, -3.9, -1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, -1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, -1.7)));
test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, 1.7))); rp3d_test(mCompoundBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, 1.7)));
// Points on the sphere // Points on the sphere
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 0, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 0, 0)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(2.9, 0, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(2.9, 0, 0)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(-2.9, 0, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(-2.9, 0, 0)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 2.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 2.9, 0)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, -2.9, 0))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, -2.9, 0)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 0, 2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 0, 2.9)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 0, 2.9))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(0, 0, 2.9)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(-1, -2, -1.5))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(-1, -2, -1.5)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(-1, 2, -1.5))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(-1, 2, -1.5)));
test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(1, -2, 1.5))); rp3d_test(mCompoundBody->testPointInside(mLocalShape2ToWorld * Vector3(1, -2, 1.5)));
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@ -139,47 +139,47 @@ class TestTriangleVertexArray : public Test {
// ----- First triangle vertex array ----- // // ----- First triangle vertex array ----- //
test(mTriangleVertexArray1->getVertexDataType() == TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE); rp3d_test(mTriangleVertexArray1->getVertexDataType() == TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE);
test(mTriangleVertexArray1->getIndexDataType() == TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); rp3d_test(mTriangleVertexArray1->getIndexDataType() == TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
test(mTriangleVertexArray1->getVertexNormalDataType() == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE); rp3d_test(mTriangleVertexArray1->getVertexNormalDataType() == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE);
test(mTriangleVertexArray1->getNbTriangles() == 2); rp3d_test(mTriangleVertexArray1->getNbTriangles() == 2);
test(mTriangleVertexArray1->getNbVertices() == 4); rp3d_test(mTriangleVertexArray1->getNbVertices() == 4);
test(mTriangleVertexArray1->getIndicesStart() == static_cast<const void*>(mIndices1)); rp3d_test(mTriangleVertexArray1->getIndicesStart() == static_cast<const void*>(mIndices1));
test(mTriangleVertexArray1->getVerticesStart() == static_cast<const void*>(mVertices1)); rp3d_test(mTriangleVertexArray1->getVerticesStart() == static_cast<const void*>(mVertices1));
test(mTriangleVertexArray1->getIndicesStride() == (3 * sizeof(uint))); rp3d_test(mTriangleVertexArray1->getIndicesStride() == (3 * sizeof(uint)));
test(mTriangleVertexArray1->getVerticesStride() == (3 * sizeof(float))); rp3d_test(mTriangleVertexArray1->getVerticesStride() == (3 * sizeof(float)));
// Get triangle indices // Get triangle indices
uint triangle0Indices[3]; uint triangle0Indices[3];
mTriangleVertexArray1->getTriangleVerticesIndices(0, triangle0Indices); mTriangleVertexArray1->getTriangleVerticesIndices(0, triangle0Indices);
test(triangle0Indices[0] == mIndices1[0]); rp3d_test(triangle0Indices[0] == mIndices1[0]);
test(triangle0Indices[1] == mIndices1[1]); rp3d_test(triangle0Indices[1] == mIndices1[1]);
test(triangle0Indices[2] == mIndices1[2]); rp3d_test(triangle0Indices[2] == mIndices1[2]);
uint triangle1Indices[3]; uint triangle1Indices[3];
mTriangleVertexArray1->getTriangleVerticesIndices(1, triangle1Indices); mTriangleVertexArray1->getTriangleVerticesIndices(1, triangle1Indices);
test(triangle1Indices[0] == mIndices1[3]); rp3d_test(triangle1Indices[0] == mIndices1[3]);
test(triangle1Indices[1] == mIndices1[4]); rp3d_test(triangle1Indices[1] == mIndices1[4]);
test(triangle1Indices[2] == mIndices1[5]); rp3d_test(triangle1Indices[2] == mIndices1[5]);
// Get triangle vertices // Get triangle vertices
Vector3 triangle0Vertices[3]; Vector3 triangle0Vertices[3];
mTriangleVertexArray1->getTriangleVertices(0, triangle0Vertices); mTriangleVertexArray1->getTriangleVertices(0, triangle0Vertices);
test(approxEqual(triangle0Vertices[0], mVertex0, decimal(0.0000001))); rp3d_test(approxEqual(triangle0Vertices[0], mVertex0, decimal(0.0000001)));
test(approxEqual(triangle0Vertices[1], mVertex1, decimal(0.0000001))); rp3d_test(approxEqual(triangle0Vertices[1], mVertex1, decimal(0.0000001)));
test(approxEqual(triangle0Vertices[2], mVertex2, decimal(0.0000001))); rp3d_test(approxEqual(triangle0Vertices[2], mVertex2, decimal(0.0000001)));
Vector3 triangle1Vertices[3]; Vector3 triangle1Vertices[3];
mTriangleVertexArray1->getTriangleVertices(1, triangle1Vertices); mTriangleVertexArray1->getTriangleVertices(1, triangle1Vertices);
test(approxEqual(triangle1Vertices[0], mVertex0, decimal(0.0000001))); rp3d_test(approxEqual(triangle1Vertices[0], mVertex0, decimal(0.0000001)));
test(approxEqual(triangle1Vertices[1], mVertex3, decimal(0.0000001))); rp3d_test(approxEqual(triangle1Vertices[1], mVertex3, decimal(0.0000001)));
test(approxEqual(triangle1Vertices[2], mVertex1, decimal(0.0000001))); rp3d_test(approxEqual(triangle1Vertices[2], mVertex1, decimal(0.0000001)));
// Get triangle normals // Get triangle normals
@ -193,64 +193,64 @@ class TestTriangleVertexArray : public Test {
const Vector3 normal2Test(0, 1, 0); const Vector3 normal2Test(0, 1, 0);
const Vector3 normal3Test(1, 0, 0); const Vector3 normal3Test(1, 0, 0);
test(approxEqual(triangle0Normals[0], normal0Test, decimal(0.0001))); rp3d_test(approxEqual(triangle0Normals[0], normal0Test, decimal(0.0001)));
test(approxEqual(triangle0Normals[2], normal2Test, decimal(0.0001))); rp3d_test(approxEqual(triangle0Normals[2], normal2Test, decimal(0.0001)));
test(approxEqual(triangle1Normals[1], normal3Test, decimal(0.0001))); rp3d_test(approxEqual(triangle1Normals[1], normal3Test, decimal(0.0001)));
// ----- Second triangle vertex array ----- // // ----- Second triangle vertex array ----- //
test(mTriangleVertexArray2->getVertexDataType() == TriangleVertexArray::VertexDataType::VERTEX_DOUBLE_TYPE); rp3d_test(mTriangleVertexArray2->getVertexDataType() == TriangleVertexArray::VertexDataType::VERTEX_DOUBLE_TYPE);
test(mTriangleVertexArray2->getIndexDataType() == TriangleVertexArray::IndexDataType::INDEX_SHORT_TYPE); rp3d_test(mTriangleVertexArray2->getIndexDataType() == TriangleVertexArray::IndexDataType::INDEX_SHORT_TYPE);
test(mTriangleVertexArray2->getVertexNormalDataType() == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE); rp3d_test(mTriangleVertexArray2->getVertexNormalDataType() == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE);
test(mTriangleVertexArray2->getNbTriangles() == 2); rp3d_test(mTriangleVertexArray2->getNbTriangles() == 2);
test(mTriangleVertexArray2->getNbVertices() == 4); rp3d_test(mTriangleVertexArray2->getNbVertices() == 4);
test(mTriangleVertexArray2->getIndicesStart() == static_cast<const void*>(mIndices2)); rp3d_test(mTriangleVertexArray2->getIndicesStart() == static_cast<const void*>(mIndices2));
test(mTriangleVertexArray2->getVerticesStart() == static_cast<const void*>(mVertices2)); rp3d_test(mTriangleVertexArray2->getVerticesStart() == static_cast<const void*>(mVertices2));
test(mTriangleVertexArray2->getVerticesNormalsStart() == static_cast<const void*>(mNormals2)); rp3d_test(mTriangleVertexArray2->getVerticesNormalsStart() == static_cast<const void*>(mNormals2));
test(mTriangleVertexArray2->getIndicesStride() == (3 * sizeof(short))); rp3d_test(mTriangleVertexArray2->getIndicesStride() == (3 * sizeof(short)));
test(mTriangleVertexArray2->getVerticesStride() == (3 * sizeof(double))); rp3d_test(mTriangleVertexArray2->getVerticesStride() == (3 * sizeof(double)));
test(mTriangleVertexArray2->getVerticesNormalsStride() == (3 * sizeof(float))); rp3d_test(mTriangleVertexArray2->getVerticesNormalsStride() == (3 * sizeof(float)));
// Get triangle indices // Get triangle indices
mTriangleVertexArray2->getTriangleVerticesIndices(0, triangle0Indices); mTriangleVertexArray2->getTriangleVerticesIndices(0, triangle0Indices);
test(triangle0Indices[0] == static_cast<uint>(mIndices2[0])); rp3d_test(triangle0Indices[0] == static_cast<uint>(mIndices2[0]));
test(triangle0Indices[1] == static_cast<uint>(mIndices2[1])); rp3d_test(triangle0Indices[1] == static_cast<uint>(mIndices2[1]));
test(triangle0Indices[2] == static_cast<uint>(mIndices2[2])); rp3d_test(triangle0Indices[2] == static_cast<uint>(mIndices2[2]));
mTriangleVertexArray2->getTriangleVerticesIndices(1, triangle1Indices); mTriangleVertexArray2->getTriangleVerticesIndices(1, triangle1Indices);
test(triangle1Indices[0] == static_cast<uint>(mIndices2[3])); rp3d_test(triangle1Indices[0] == static_cast<uint>(mIndices2[3]));
test(triangle1Indices[1] == static_cast<uint>(mIndices2[4])); rp3d_test(triangle1Indices[1] == static_cast<uint>(mIndices2[4]));
test(triangle1Indices[2] == static_cast<uint>(mIndices2[5])); rp3d_test(triangle1Indices[2] == static_cast<uint>(mIndices2[5]));
// Get triangle vertices // Get triangle vertices
mTriangleVertexArray2->getTriangleVertices(0, triangle0Vertices); mTriangleVertexArray2->getTriangleVertices(0, triangle0Vertices);
test(approxEqual(triangle0Vertices[0], mVertex4, decimal(0.0000001))); rp3d_test(approxEqual(triangle0Vertices[0], mVertex4, decimal(0.0000001)));
test(approxEqual(triangle0Vertices[1], mVertex5, decimal(0.0000001))); rp3d_test(approxEqual(triangle0Vertices[1], mVertex5, decimal(0.0000001)));
test(approxEqual(triangle0Vertices[2], mVertex6, decimal(0.0000001))); rp3d_test(approxEqual(triangle0Vertices[2], mVertex6, decimal(0.0000001)));
mTriangleVertexArray2->getTriangleVertices(1, triangle1Vertices); mTriangleVertexArray2->getTriangleVertices(1, triangle1Vertices);
test(approxEqual(triangle1Vertices[0], mVertex4, decimal(0.0000001))); rp3d_test(approxEqual(triangle1Vertices[0], mVertex4, decimal(0.0000001)));
test(approxEqual(triangle1Vertices[1], mVertex7, decimal(0.0000001))); rp3d_test(approxEqual(triangle1Vertices[1], mVertex7, decimal(0.0000001)));
test(approxEqual(triangle1Vertices[2], mVertex5, decimal(0.0000001))); rp3d_test(approxEqual(triangle1Vertices[2], mVertex5, decimal(0.0000001)));
// Get triangle normals // Get triangle normals
mTriangleVertexArray2->getTriangleVerticesNormals(0, triangle0Normals); mTriangleVertexArray2->getTriangleVerticesNormals(0, triangle0Normals);
mTriangleVertexArray2->getTriangleVerticesNormals(1, triangle1Normals); mTriangleVertexArray2->getTriangleVerticesNormals(1, triangle1Normals);
test(approxEqual(triangle0Normals[0], mNormal0, decimal(0.000001))); rp3d_test(approxEqual(triangle0Normals[0], mNormal0, decimal(0.000001)));
test(approxEqual(triangle0Normals[1], mNormal1, decimal(0.000001))); rp3d_test(approxEqual(triangle0Normals[1], mNormal1, decimal(0.000001)));
test(approxEqual(triangle0Normals[2], mNormal2, decimal(0.000001))); rp3d_test(approxEqual(triangle0Normals[2], mNormal2, decimal(0.000001)));
test(approxEqual(triangle1Normals[0], mNormal0, decimal(0.000001))); rp3d_test(approxEqual(triangle1Normals[0], mNormal0, decimal(0.000001)));
test(approxEqual(triangle1Normals[1], mNormal3, decimal(0.000001))); rp3d_test(approxEqual(triangle1Normals[1], mNormal3, decimal(0.000001)));
test(approxEqual(triangle1Normals[2], mNormal1, decimal(0.000001))); rp3d_test(approxEqual(triangle1Normals[2], mNormal1, decimal(0.000001)));
} }
}; };

View File

@ -73,42 +73,42 @@ class TestList : public Test {
// ----- Constructors ----- // // ----- Constructors ----- //
List<int> list1(mAllocator); List<int> list1(mAllocator);
test(list1.capacity() == 0); rp3d_test(list1.capacity() == 0);
test(list1.size() == 0); rp3d_test(list1.size() == 0);
List<int> list2(mAllocator, 100); List<int> list2(mAllocator, 100);
test(list2.capacity() == 100); rp3d_test(list2.capacity() == 100);
test(list2.size() == 0); rp3d_test(list2.size() == 0);
List<int> list3(mAllocator); List<int> list3(mAllocator);
list3.add(1); list3.add(1);
list3.add(2); list3.add(2);
list3.add(3); list3.add(3);
test(list3.capacity() == 4); rp3d_test(list3.capacity() == 4);
test(list3.size() == 3); rp3d_test(list3.size() == 3);
// ----- Copy Constructors ----- // // ----- Copy Constructors ----- //
List<int> list4(list1); List<int> list4(list1);
test(list4.capacity() == 0); rp3d_test(list4.capacity() == 0);
test(list4.size() == 0); rp3d_test(list4.size() == 0);
List<int> list5(list3); List<int> list5(list3);
test(list5.capacity() == list3.size()); rp3d_test(list5.capacity() == list3.size());
test(list5.size() == list3.size()); rp3d_test(list5.size() == list3.size());
for (uint i=0; i<list3.size(); i++) { for (uint i=0; i<list3.size(); i++) {
test(list5[i] == list3[i]); rp3d_test(list5[i] == list3[i]);
} }
// ----- Test capacity grow ----- // // ----- Test capacity grow ----- //
List<std::string> list6(mAllocator, 20); List<std::string> list6(mAllocator, 20);
test(list6.capacity() == 20); rp3d_test(list6.capacity() == 20);
for (uint i=0; i<20; i++) { for (uint i=0; i<20; i++) {
list6.add("test"); list6.add("test");
} }
test(list6.capacity() == 20); rp3d_test(list6.capacity() == 20);
list6.add("test"); list6.add("test");
test(list6.capacity() == 40); rp3d_test(list6.capacity() == 40);
} }
void testAddRemoveClear() { void testAddRemoveClear() {
@ -117,12 +117,12 @@ class TestList : public Test {
List<int> list1(mAllocator); List<int> list1(mAllocator);
list1.add(4); list1.add(4);
test(list1.size() == 1); rp3d_test(list1.size() == 1);
test(list1[0] == 4); rp3d_test(list1[0] == 4);
list1.add(9); list1.add(9);
test(list1.size() == 2); rp3d_test(list1.size() == 2);
test(list1[0] == 4); rp3d_test(list1[0] == 4);
test(list1[1] == 9); rp3d_test(list1[1] == 9);
const int arraySize = 15; const int arraySize = 15;
int arrayTest[arraySize] = {3, 145, -182, 34, 12, 95, -1834, 4143, -111, -111, 4343, 234, 22983, -3432, 753}; int arrayTest[arraySize] = {3, 145, -182, 34, 12, 95, -1834, 4143, -111, -111, 4343, 234, 22983, -3432, 753};
@ -130,9 +130,9 @@ class TestList : public Test {
for (uint i=0; i<arraySize; i++) { for (uint i=0; i<arraySize; i++) {
list2.add(arrayTest[i]); list2.add(arrayTest[i]);
} }
test(list2.size() == arraySize); rp3d_test(list2.size() == arraySize);
for (uint i=0; i<arraySize; i++) { for (uint i=0; i<arraySize; i++) {
test(list2[i] == arrayTest[i]); rp3d_test(list2[i] == arrayTest[i]);
} }
// ----- Test remove() ----- // // ----- Test remove() ----- //
@ -144,51 +144,51 @@ class TestList : public Test {
list3.add(4); list3.add(4);
auto it = list3.removeAt(3); auto it = list3.removeAt(3);
test(list3.size() == 3); rp3d_test(list3.size() == 3);
test(list3.capacity() == 4); rp3d_test(list3.capacity() == 4);
test(it == list3.end()); rp3d_test(it == list3.end());
test(list3[0] == 1); rp3d_test(list3[0] == 1);
test(list3[1] == 2); rp3d_test(list3[1] == 2);
test(list3[2] == 3); rp3d_test(list3[2] == 3);
it = list3.removeAt(1); it = list3.removeAt(1);
test(list3.size() == 2); rp3d_test(list3.size() == 2);
test(list3.capacity() == 4); rp3d_test(list3.capacity() == 4);
test(list3[0] == 1); rp3d_test(list3[0] == 1);
test(list3[1] == 3); rp3d_test(list3[1] == 3);
test(*it == 3); rp3d_test(*it == 3);
list3.removeAt(0); list3.removeAt(0);
test(list3.size() == 1); rp3d_test(list3.size() == 1);
test(list3.capacity() == 4); rp3d_test(list3.capacity() == 4);
test(list3[0] == 3); rp3d_test(list3[0] == 3);
it = list3.removeAt(0); it = list3.removeAt(0);
test(list3.size() == 0); rp3d_test(list3.size() == 0);
test(list3.capacity() == 4); rp3d_test(list3.capacity() == 4);
test(it == list3.end()); rp3d_test(it == list3.end());
list3.add(1); list3.add(1);
list3.add(2); list3.add(2);
list3.add(3); list3.add(3);
it = list3.begin(); it = list3.begin();
list3.remove(it); list3.remove(it);
test(list3.size() == 2); rp3d_test(list3.size() == 2);
test(list3[0] == 2); rp3d_test(list3[0] == 2);
test(list3[1] == 3); rp3d_test(list3[1] == 3);
it = list3.find(3); it = list3.find(3);
list3.remove(it); list3.remove(it);
test(list3.size() == 1); rp3d_test(list3.size() == 1);
test(list3[0] == 2); rp3d_test(list3[0] == 2);
list3.add(5); list3.add(5);
list3.add(6); list3.add(6);
list3.add(7); list3.add(7);
it = list3.remove(7); it = list3.remove(7);
test(it == list3.end()); rp3d_test(it == list3.end());
test(list3.size() == 3); rp3d_test(list3.size() == 3);
it = list3.remove(5); it = list3.remove(5);
test((*it) == 6); rp3d_test((*it) == 6);
// ----- Test addRange() ----- // // ----- Test addRange() ----- //
@ -203,17 +203,17 @@ class TestList : public Test {
List<int> list6(mAllocator); List<int> list6(mAllocator);
list6.addRange(list5); list6.addRange(list5);
test(list6.size() == list5.size()); rp3d_test(list6.size() == list5.size());
test(list6[0] == 4); rp3d_test(list6[0] == 4);
test(list6[1] == 5); rp3d_test(list6[1] == 5);
list4.addRange(list5); list4.addRange(list5);
test(list4.size() == 3 + list5.size()); rp3d_test(list4.size() == 3 + list5.size());
test(list4[0] == 1); rp3d_test(list4[0] == 1);
test(list4[1] == 2); rp3d_test(list4[1] == 2);
test(list4[2] == 3); rp3d_test(list4[2] == 3);
test(list4[3] == 4); rp3d_test(list4[3] == 4);
test(list4[4] == 5); rp3d_test(list4[4] == 5);
// ----- Test clear() ----- // // ----- Test clear() ----- //
@ -222,10 +222,10 @@ class TestList : public Test {
list7.add("test2"); list7.add("test2");
list7.add("test3"); list7.add("test3");
list7.clear(); list7.clear();
test(list7.size() == 0); rp3d_test(list7.size() == 0);
list7.add("new"); list7.add("new");
test(list7.size() == 1); rp3d_test(list7.size() == 1);
test(list7[0] == "new"); rp3d_test(list7[0] == "new");
} }
void testAssignment() { void testAssignment() {
@ -250,20 +250,20 @@ class TestList : public Test {
list5.add(3); list5.add(3);
list3 = list2; list3 = list2;
test(list2.size() == list3.size()); rp3d_test(list2.size() == list3.size());
test(list2[0] == list3[0]); rp3d_test(list2[0] == list3[0]);
test(list2[1] == list3[1]); rp3d_test(list2[1] == list3[1]);
list4 = list1; list4 = list1;
test(list4.size() == list1.size()) rp3d_test(list4.size() == list1.size())
test(list4[0] == list1[0]); rp3d_test(list4[0] == list1[0]);
test(list4[1] == list1[1]); rp3d_test(list4[1] == list1[1]);
test(list4[2] == list1[2]); rp3d_test(list4[2] == list1[2]);
list5 = list2; list5 = list2;
test(list5.size() == list2.size()); rp3d_test(list5.size() == list2.size());
test(list5[0] == list2[0]); rp3d_test(list5[0] == list2[0]);
test(list5[1] == list2[1]); rp3d_test(list5[1] == list2[1]);
} }
void testIndexing() { void testIndexing() {
@ -273,27 +273,27 @@ class TestList : public Test {
list1.add(2); list1.add(2);
list1.add(3); list1.add(3);
test(list1[0] == 1); rp3d_test(list1[0] == 1);
test(list1[1] == 2); rp3d_test(list1[1] == 2);
test(list1[2] == 3); rp3d_test(list1[2] == 3);
list1[0] = 6; list1[0] = 6;
list1[1] = 7; list1[1] = 7;
list1[2] = 8; list1[2] = 8;
test(list1[0] == 6); rp3d_test(list1[0] == 6);
test(list1[1] == 7); rp3d_test(list1[1] == 7);
test(list1[2] == 8); rp3d_test(list1[2] == 8);
const int a = list1[0]; const int a = list1[0];
const int b = list1[1]; const int b = list1[1];
test(a == 6); rp3d_test(a == 6);
test(b == 7); rp3d_test(b == 7);
list1[0]++; list1[0]++;
list1[1]++; list1[1]++;
test(list1[0] == 7); rp3d_test(list1[0] == 7);
test(list1[1] == 8); rp3d_test(list1[1] == 8);
} }
void testFind() { void testFind() {
@ -305,9 +305,9 @@ class TestList : public Test {
list1.add(4); list1.add(4);
list1.add(5); list1.add(5);
test(list1.find(1) == list1.begin()); rp3d_test(list1.find(1) == list1.begin());
test(*(list1.find(2)) == 2); rp3d_test(*(list1.find(2)) == 2);
test(*(list1.find(5)) == 5); rp3d_test(*(list1.find(5)) == 5);
} }
void testEquality() { void testEquality() {
@ -331,40 +331,40 @@ class TestList : public Test {
list4.add(5); list4.add(5);
list4.add(3); list4.add(3);
test(list1 == list1); rp3d_test(list1 == list1);
test(list1 != list2); rp3d_test(list1 != list2);
test(list1 == list3); rp3d_test(list1 == list3);
test(list1 != list4); rp3d_test(list1 != list4);
test(list2 != list4); rp3d_test(list2 != list4);
} }
void testReserve() { void testReserve() {
List<int> list1(mAllocator); List<int> list1(mAllocator);
list1.reserve(10); list1.reserve(10);
test(list1.size() == 0); rp3d_test(list1.size() == 0);
test(list1.capacity() == 10); rp3d_test(list1.capacity() == 10);
list1.add(1); list1.add(1);
list1.add(2); list1.add(2);
test(list1.capacity() == 10); rp3d_test(list1.capacity() == 10);
test(list1.size() == 2); rp3d_test(list1.size() == 2);
test(list1[0] == 1); rp3d_test(list1[0] == 1);
test(list1[1] == 2); rp3d_test(list1[1] == 2);
list1.reserve(1); list1.reserve(1);
test(list1.capacity() == 10); rp3d_test(list1.capacity() == 10);
list1.reserve(100); list1.reserve(100);
test(list1.capacity() == 100); rp3d_test(list1.capacity() == 100);
test(list1[0] == 1); rp3d_test(list1[0] == 1);
test(list1[1] == 2); rp3d_test(list1[1] == 2);
} }
void testIterators() { void testIterators() {
List<int> list1(mAllocator); List<int> list1(mAllocator);
test(list1.begin() == list1.end()); rp3d_test(list1.begin() == list1.end());
list1.add(5); list1.add(5);
list1.add(6); list1.add(6);
@ -375,30 +375,49 @@ class TestList : public Test {
List<int>::Iterator itEnd = list1.end(); List<int>::Iterator itEnd = list1.end();
List<int>::Iterator it = list1.begin(); List<int>::Iterator it = list1.begin();
test(itBegin == it); rp3d_test(itBegin < itEnd);
test(*it == 5); rp3d_test(itBegin <= itEnd);
test(*(it++) == 5); rp3d_test(itEnd > itBegin);
test(*it == 6); rp3d_test(itEnd >= itBegin);
test(*(it--) == 6);
test(*it == 5); rp3d_test(itBegin == it);
test(*(++it) == 6); rp3d_test(*it == 5);
test(*it == 6); rp3d_test(*(it++) == 5);
test(*(--it) == 5); rp3d_test(*it == 6);
test(*it == 5); rp3d_test(*(it--) == 6);
test(it == itBegin); rp3d_test(*it == 5);
rp3d_test(*(++it) == 6);
rp3d_test(*it == 6);
rp3d_test(*(--it) == 5);
rp3d_test(*it == 5);
rp3d_test(it == itBegin);
it = list1.end(); it = list1.end();
test(it == itEnd); rp3d_test(it == itEnd);
it--; it--;
test(*it == -1); rp3d_test(*it == -1);
it++; it++;
test(it == itEnd); rp3d_test(it == itEnd);
List<int> list2(mAllocator); List<int> list2(mAllocator);
for (auto it = list1.begin(); it != list1.end(); ++it) { for (auto it = list1.begin(); it != list1.end(); ++it) {
list2.add(*it); list2.add(*it);
} }
test(list1 == list2);
rp3d_test(list1 == list2);
it = itBegin;
rp3d_test(*(it + 2) == 8);
it += 2;
rp3d_test(*it == 8);
rp3d_test(*(it - 2) == 5);
it -= 2;
rp3d_test(*it == 5);
rp3d_test((itEnd - itBegin) == 4);
it = itBegin;
*it = 19;
rp3d_test(*it == 19);
} }
}; };

View File

@ -98,49 +98,49 @@ class TestMap : public Test {
// ----- Constructors ----- // // ----- Constructors ----- //
Map<int, std::string> map1(mAllocator); Map<int, std::string> map1(mAllocator);
test(map1.capacity() == 0); rp3d_test(map1.capacity() == 0);
test(map1.size() == 0); rp3d_test(map1.size() == 0);
Map<int, std::string> map2(mAllocator, 100); Map<int, std::string> map2(mAllocator, 100);
test(map2.capacity() >= 100); rp3d_test(map2.capacity() >= 100);
test(map2.size() == 0); rp3d_test(map2.size() == 0);
// ----- Copy Constructors ----- // // ----- Copy Constructors ----- //
Map<int, std::string> map3(map1); Map<int, std::string> map3(map1);
test(map3.capacity() == map1.capacity()); rp3d_test(map3.capacity() == map1.capacity());
test(map3.size() == map1.size()); rp3d_test(map3.size() == map1.size());
Map<int, int> map4(mAllocator); Map<int, int> map4(mAllocator);
map4.add(Pair<int, int>(1, 10)); map4.add(Pair<int, int>(1, 10));
map4.add(Pair<int, int>(2, 20)); map4.add(Pair<int, int>(2, 20));
map4.add(Pair<int, int>(3, 30)); map4.add(Pair<int, int>(3, 30));
test(map4.capacity() >= 3); rp3d_test(map4.capacity() >= 3);
test(map4.size() == 3); rp3d_test(map4.size() == 3);
Map<int, int> map5(map4); Map<int, int> map5(map4);
test(map5.capacity() == map4.capacity()); rp3d_test(map5.capacity() == map4.capacity());
test(map5.size() == map4.size()); rp3d_test(map5.size() == map4.size());
test(map5[1] == 10); rp3d_test(map5[1] == 10);
test(map5[2] == 20); rp3d_test(map5[2] == 20);
test(map5[3] == 30); rp3d_test(map5[3] == 30);
} }
void testReserve() { void testReserve() {
Map<int, std::string> map1(mAllocator); Map<int, std::string> map1(mAllocator);
map1.reserve(15); map1.reserve(15);
test(map1.capacity() >= 15); rp3d_test(map1.capacity() >= 15);
map1.add(Pair<int, std::string>(1, "test1")); map1.add(Pair<int, std::string>(1, "test1"));
map1.add(Pair<int, std::string>(2, "test2")); map1.add(Pair<int, std::string>(2, "test2"));
test(map1.capacity() >= 15); rp3d_test(map1.capacity() >= 15);
map1.reserve(10); map1.reserve(10);
test(map1.capacity() >= 15); rp3d_test(map1.capacity() >= 15);
map1.reserve(100); map1.reserve(100);
test(map1.capacity() >= 100); rp3d_test(map1.capacity() >= 100);
test(map1[1] == "test1"); rp3d_test(map1[1] == "test1");
test(map1[2] == "test2"); rp3d_test(map1[2] == "test2");
} }
void testAddRemoveClear() { void testAddRemoveClear() {
@ -151,10 +151,10 @@ class TestMap : public Test {
map1.add(Pair<int, int>(1, 10)); map1.add(Pair<int, int>(1, 10));
map1.add(Pair<int, int>(8, 80)); map1.add(Pair<int, int>(8, 80));
map1.add(Pair<int, int>(13, 130)); map1.add(Pair<int, int>(13, 130));
test(map1[1] == 10); rp3d_test(map1[1] == 10);
test(map1[8] == 80); rp3d_test(map1[8] == 80);
test(map1[13] == 130); rp3d_test(map1[13] == 130);
test(map1.size() == 3); rp3d_test(map1.size() == 3);
Map<int, int> map2(mAllocator, 15); Map<int, int> map2(mAllocator, 15);
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
@ -164,41 +164,41 @@ class TestMap : public Test {
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
if (map2[i] != i * 100) isValid = false; if (map2[i] != i * 100) isValid = false;
} }
test(isValid); rp3d_test(isValid);
map1.remove(1); map1.remove(1);
map1.add(Pair<int, int>(1, 10)); map1.add(Pair<int, int>(1, 10));
test(map1.size() == 3); rp3d_test(map1.size() == 3);
test(map1[1] == 10); rp3d_test(map1[1] == 10);
map1.add(Pair<int, int>(56, 34)); map1.add(Pair<int, int>(56, 34));
test(map1[56] == 34); rp3d_test(map1[56] == 34);
test(map1.size() == 4); rp3d_test(map1.size() == 4);
map1.add(Pair<int, int>(56, 13), true); map1.add(Pair<int, int>(56, 13), true);
test(map1[56] == 13); rp3d_test(map1[56] == 13);
test(map1.size() == 4); rp3d_test(map1.size() == 4);
// ----- Test remove() ----- // // ----- Test remove() ----- //
map1.remove(1); map1.remove(1);
test(!map1.containsKey(1)); rp3d_test(!map1.containsKey(1));
test(map1.containsKey(8)); rp3d_test(map1.containsKey(8));
test(map1.containsKey(13)); rp3d_test(map1.containsKey(13));
test(map1.size() == 3); rp3d_test(map1.size() == 3);
map1.remove(13); map1.remove(13);
test(map1.containsKey(8)); rp3d_test(map1.containsKey(8));
test(!map1.containsKey(13)); rp3d_test(!map1.containsKey(13));
test(map1.size() == 2); rp3d_test(map1.size() == 2);
map1.remove(8); map1.remove(8);
test(!map1.containsKey(8)); rp3d_test(!map1.containsKey(8));
test(map1.size() == 1); rp3d_test(map1.size() == 1);
auto it = map1.remove(56); auto it = map1.remove(56);
test(!map1.containsKey(56)); rp3d_test(!map1.containsKey(56));
test(map1.size() == 0); rp3d_test(map1.size() == 0);
test(it == map1.end()); rp3d_test(it == map1.end());
isValid = true; isValid = true;
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
@ -207,8 +207,8 @@ class TestMap : public Test {
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
if (map2.containsKey(i)) isValid = false; if (map2.containsKey(i)) isValid = false;
} }
test(isValid); rp3d_test(isValid);
test(map2.size() == 0); rp3d_test(map2.size() == 0);
Map<int, int> map3(mAllocator); Map<int, int> map3(mAllocator);
for (int i=0; i < 1000000; i++) { for (int i=0; i < 1000000; i++) {
@ -219,19 +219,19 @@ class TestMap : public Test {
map3.add(Pair<int, int>(1, 10)); map3.add(Pair<int, int>(1, 10));
map3.add(Pair<int, int>(2, 20)); map3.add(Pair<int, int>(2, 20));
map3.add(Pair<int, int>(3, 30)); map3.add(Pair<int, int>(3, 30));
test(map3.size() == 3); rp3d_test(map3.size() == 3);
it = map3.begin(); it = map3.begin();
map3.remove(it++); map3.remove(it++);
test(!map3.containsKey(1)); rp3d_test(!map3.containsKey(1));
test(map3.size() == 2); rp3d_test(map3.size() == 2);
test(it->second == 20); rp3d_test(it->second == 20);
map3.add(Pair<int, int>(56, 32)); map3.add(Pair<int, int>(56, 32));
map3.add(Pair<int, int>(23, 89)); map3.add(Pair<int, int>(23, 89));
for (it = map3.begin(); it != map3.end();) { for (it = map3.begin(); it != map3.end();) {
it = map3.remove(it); it = map3.remove(it);
} }
test(map3.size() == 0); rp3d_test(map3.size() == 0);
// ----- Test clear() ----- // // ----- Test clear() ----- //
@ -240,16 +240,16 @@ class TestMap : public Test {
map4.add(Pair<int, int>(4, 40)); map4.add(Pair<int, int>(4, 40));
map4.add(Pair<int, int>(6, 60)); map4.add(Pair<int, int>(6, 60));
map4.clear(); map4.clear();
test(map4.size() == 0); rp3d_test(map4.size() == 0);
map4.add(Pair<int, int>(2, 20)); map4.add(Pair<int, int>(2, 20));
test(map4.size() == 1); rp3d_test(map4.size() == 1);
test(map4[2] == 20); rp3d_test(map4[2] == 20);
map4.clear(); map4.clear();
test(map4.size() == 0); rp3d_test(map4.size() == 0);
Map<int, int> map5(mAllocator); Map<int, int> map5(mAllocator);
map5.clear(); map5.clear();
test(map5.size() == 0); rp3d_test(map5.size() == 0);
// ----- Test map with always same hash value for keys ----- // // ----- Test map with always same hash value for keys ----- //
@ -263,37 +263,37 @@ class TestMap : public Test {
isTestValid = false; isTestValid = false;
} }
} }
test(isTestValid); rp3d_test(isTestValid);
for (int i=0; i < 1000; i++) { for (int i=0; i < 1000; i++) {
map6.remove(TestKey(i)); map6.remove(TestKey(i));
} }
test(map6.size() == 0); rp3d_test(map6.size() == 0);
} }
void testContainsKey() { void testContainsKey() {
Map<int, int> map1(mAllocator); Map<int, int> map1(mAllocator);
test(!map1.containsKey(2)); rp3d_test(!map1.containsKey(2));
test(!map1.containsKey(4)); rp3d_test(!map1.containsKey(4));
test(!map1.containsKey(6)); rp3d_test(!map1.containsKey(6));
map1.add(Pair<int, int>(2, 20)); map1.add(Pair<int, int>(2, 20));
map1.add(Pair<int, int>(4, 40)); map1.add(Pair<int, int>(4, 40));
map1.add(Pair<int, int>(6, 60)); map1.add(Pair<int, int>(6, 60));
test(map1.containsKey(2)); rp3d_test(map1.containsKey(2));
test(map1.containsKey(4)); rp3d_test(map1.containsKey(4));
test(map1.containsKey(6)); rp3d_test(map1.containsKey(6));
map1.remove(4); map1.remove(4);
test(!map1.containsKey(4)); rp3d_test(!map1.containsKey(4));
test(map1.containsKey(2)); rp3d_test(map1.containsKey(2));
test(map1.containsKey(6)); rp3d_test(map1.containsKey(6));
map1.clear(); map1.clear();
test(!map1.containsKey(2)); rp3d_test(!map1.containsKey(2));
test(!map1.containsKey(6)); rp3d_test(!map1.containsKey(6));
} }
void testIndexing() { void testIndexing() {
@ -302,17 +302,17 @@ class TestMap : public Test {
map1.add(Pair<int, int>(2, 20)); map1.add(Pair<int, int>(2, 20));
map1.add(Pair<int, int>(4, 40)); map1.add(Pair<int, int>(4, 40));
map1.add(Pair<int, int>(6, 60)); map1.add(Pair<int, int>(6, 60));
test(map1[2] == 20); rp3d_test(map1[2] == 20);
test(map1[4] == 40); rp3d_test(map1[4] == 40);
test(map1[6] == 60); rp3d_test(map1[6] == 60);
map1[2] = 10; map1[2] = 10;
map1[4] = 20; map1[4] = 20;
map1[6] = 30; map1[6] = 30;
test(map1[2] == 10); rp3d_test(map1[2] == 10);
test(map1[4] == 20); rp3d_test(map1[4] == 20);
test(map1[6] == 30); rp3d_test(map1[6] == 30);
} }
void testFind() { void testFind() {
@ -321,18 +321,18 @@ class TestMap : public Test {
map1.add(Pair<int, int>(2, 20)); map1.add(Pair<int, int>(2, 20));
map1.add(Pair<int, int>(4, 40)); map1.add(Pair<int, int>(4, 40));
map1.add(Pair<int, int>(6, 60)); map1.add(Pair<int, int>(6, 60));
test(map1.find(2)->second == 20); rp3d_test(map1.find(2)->second == 20);
test(map1.find(4)->second == 40); rp3d_test(map1.find(4)->second == 40);
test(map1.find(6)->second == 60); rp3d_test(map1.find(6)->second == 60);
test(map1.find(45) == map1.end()); rp3d_test(map1.find(45) == map1.end());
map1[2] = 10; map1[2] = 10;
map1[4] = 20; map1[4] = 20;
map1[6] = 30; map1[6] = 30;
test(map1.find(2)->second == 10); rp3d_test(map1.find(2)->second == 10);
test(map1.find(4)->second == 20); rp3d_test(map1.find(4)->second == 20);
test(map1.find(6)->second == 30); rp3d_test(map1.find(6)->second == 30);
} }
void testEquality() { void testEquality() {
@ -340,7 +340,7 @@ class TestMap : public Test {
Map<std::string, int> map1(mAllocator, 10); Map<std::string, int> map1(mAllocator, 10);
Map<std::string, int> map2(mAllocator, 2); Map<std::string, int> map2(mAllocator, 2);
test(map1 == map2); rp3d_test(map1 == map2);
map1.add(Pair<std::string, int>("a", 1)); map1.add(Pair<std::string, int>("a", 1));
map1.add(Pair<std::string, int>("b", 2)); map1.add(Pair<std::string, int>("b", 2));
@ -350,19 +350,19 @@ class TestMap : public Test {
map2.add(Pair<std::string, int>("b", 2)); map2.add(Pair<std::string, int>("b", 2));
map2.add(Pair<std::string, int>("c", 4)); map2.add(Pair<std::string, int>("c", 4));
test(map1 == map1); rp3d_test(map1 == map1);
test(map2 == map2); rp3d_test(map2 == map2);
test(map1 != map2); rp3d_test(map1 != map2);
map2["c"] = 3; map2["c"] = 3;
test(map1 == map2); rp3d_test(map1 == map2);
Map<std::string, int> map3(mAllocator); Map<std::string, int> map3(mAllocator);
map3.add(Pair<std::string, int>("a", 1)); map3.add(Pair<std::string, int>("a", 1));
test(map1 != map3); rp3d_test(map1 != map3);
test(map2 != map3); rp3d_test(map2 != map3);
} }
void testAssignment() { void testAssignment() {
@ -374,40 +374,40 @@ class TestMap : public Test {
Map<int, int> map2(mAllocator); Map<int, int> map2(mAllocator);
map2 = map1; map2 = map1;
test(map2.size() == map1.size()); rp3d_test(map2.size() == map1.size());
test(map1 == map2); rp3d_test(map1 == map2);
test(map2[1] == 3); rp3d_test(map2[1] == 3);
test(map2[2] == 6); rp3d_test(map2[2] == 6);
test(map2[10] == 30); rp3d_test(map2[10] == 30);
Map<int, int> map3(mAllocator, 100); Map<int, int> map3(mAllocator, 100);
map3 = map1; map3 = map1;
test(map3.size() == map1.size()); rp3d_test(map3.size() == map1.size());
test(map3 == map1); rp3d_test(map3 == map1);
test(map3[1] == 3); rp3d_test(map3[1] == 3);
test(map3[2] == 6); rp3d_test(map3[2] == 6);
test(map3[10] == 30); rp3d_test(map3[10] == 30);
Map<int, int> map4(mAllocator); Map<int, int> map4(mAllocator);
map3 = map4; map3 = map4;
test(map3.size() == 0); rp3d_test(map3.size() == 0);
test(map3 == map4); rp3d_test(map3 == map4);
Map<int, int> map5(mAllocator); Map<int, int> map5(mAllocator);
map5.add(Pair<int, int>(7, 8)); map5.add(Pair<int, int>(7, 8));
map5.add(Pair<int, int>(19, 70)); map5.add(Pair<int, int>(19, 70));
map1 = map5; map1 = map5;
test(map5.size() == map1.size()); rp3d_test(map5.size() == map1.size());
test(map5 == map1); rp3d_test(map5 == map1);
test(map1[7] == 8); rp3d_test(map1[7] == 8);
test(map1[19] == 70); rp3d_test(map1[19] == 70);
} }
void testIterators() { void testIterators() {
Map<int, int> map1(mAllocator); Map<int, int> map1(mAllocator);
test(map1.begin() == map1.end()); rp3d_test(map1.begin() == map1.end());
map1.add(Pair<int, int>(1, 5)); map1.add(Pair<int, int>(1, 5));
map1.add(Pair<int, int>(2, 6)); map1.add(Pair<int, int>(2, 6));
@ -417,14 +417,14 @@ class TestMap : public Test {
Map<int, int>::Iterator itBegin = map1.begin(); Map<int, int>::Iterator itBegin = map1.begin();
Map<int, int>::Iterator it = map1.begin(); Map<int, int>::Iterator it = map1.begin();
test(itBegin == it); rp3d_test(itBegin == it);
int size = 0; int size = 0;
for (auto it = map1.begin(); it != map1.end(); ++it) { for (auto it = map1.begin(); it != map1.end(); ++it) {
test(map1.containsKey(it->first)); rp3d_test(map1.containsKey(it->first));
size++; size++;
} }
test(map1.size() == size); rp3d_test(map1.size() == size);
} }
}; };

View File

@ -97,51 +97,51 @@ class TestSet : public Test {
// ----- Constructors ----- // // ----- Constructors ----- //
Set<std::string> set1(mAllocator); Set<std::string> set1(mAllocator);
test(set1.capacity() == 0); rp3d_test(set1.capacity() == 0);
test(set1.size() == 0); rp3d_test(set1.size() == 0);
Set<std::string> set2(mAllocator, 100); Set<std::string> set2(mAllocator, 100);
test(set2.capacity() >= 100); rp3d_test(set2.capacity() >= 100);
test(set2.size() == 0); rp3d_test(set2.size() == 0);
// ----- Copy Constructors ----- // // ----- Copy Constructors ----- //
Set<std::string> set3(set1); Set<std::string> set3(set1);
test(set3.capacity() == set1.capacity()); rp3d_test(set3.capacity() == set1.capacity());
test(set3.size() == set1.size()); rp3d_test(set3.size() == set1.size());
Set<int> set4(mAllocator); Set<int> set4(mAllocator);
set4.add(10); set4.add(10);
set4.add(20); set4.add(20);
set4.add(30); set4.add(30);
test(set4.capacity() >= 3); rp3d_test(set4.capacity() >= 3);
test(set4.size() == 3); rp3d_test(set4.size() == 3);
set4.add(30); set4.add(30);
test(set4.size() == 3); rp3d_test(set4.size() == 3);
Set<int> set5(set4); Set<int> set5(set4);
test(set5.capacity() == set4.capacity()); rp3d_test(set5.capacity() == set4.capacity());
test(set5.size() == set4.size()); rp3d_test(set5.size() == set4.size());
test(set5.contains(10)); rp3d_test(set5.contains(10));
test(set5.contains(20)); rp3d_test(set5.contains(20));
test(set5.contains(30)); rp3d_test(set5.contains(30));
} }
void testReserve() { void testReserve() {
Set<std::string> set1(mAllocator); Set<std::string> set1(mAllocator);
set1.reserve(15); set1.reserve(15);
test(set1.capacity() >= 15); rp3d_test(set1.capacity() >= 15);
set1.add("test1"); set1.add("test1");
set1.add("test2"); set1.add("test2");
test(set1.capacity() >= 15); rp3d_test(set1.capacity() >= 15);
set1.reserve(10); set1.reserve(10);
test(set1.capacity() >= 15); rp3d_test(set1.capacity() >= 15);
set1.reserve(100); set1.reserve(100);
test(set1.capacity() >= 100); rp3d_test(set1.capacity() >= 100);
test(set1.contains("test1")); rp3d_test(set1.contains("test1"));
test(set1.contains("test2")); rp3d_test(set1.contains("test2"));
} }
void testAddRemoveClear() { void testAddRemoveClear() {
@ -152,18 +152,18 @@ class TestSet : public Test {
bool add1 = set1.add(10); bool add1 = set1.add(10);
bool add2 = set1.add(80); bool add2 = set1.add(80);
bool add3 = set1.add(130); bool add3 = set1.add(130);
test(add1); rp3d_test(add1);
test(add2); rp3d_test(add2);
test(add3); rp3d_test(add3);
test(set1.contains(10)); rp3d_test(set1.contains(10));
test(set1.contains(80)); rp3d_test(set1.contains(80));
test(set1.contains(130)); rp3d_test(set1.contains(130));
test(set1.size() == 3); rp3d_test(set1.size() == 3);
bool add4 = set1.add(80); bool add4 = set1.add(80);
test(!add4); rp3d_test(!add4);
test(set1.contains(80)); rp3d_test(set1.contains(80));
test(set1.size() == 3); rp3d_test(set1.size() == 3);
Set<int> set2(mAllocator, 15); Set<int> set2(mAllocator, 15);
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
@ -173,41 +173,41 @@ class TestSet : public Test {
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
if (!set2.contains(i)) isValid = false; if (!set2.contains(i)) isValid = false;
} }
test(isValid); rp3d_test(isValid);
set1.remove(10); set1.remove(10);
bool add = set1.add(10); bool add = set1.add(10);
test(add); rp3d_test(add);
test(set1.size() == 3); rp3d_test(set1.size() == 3);
test(set1.contains(10)); rp3d_test(set1.contains(10));
set1.add(34); set1.add(34);
test(set1.contains(34)); rp3d_test(set1.contains(34));
test(set1.size() == 4); rp3d_test(set1.size() == 4);
// ----- Test remove() ----- // // ----- Test remove() ----- //
set1.remove(10); set1.remove(10);
test(!set1.contains(10)); rp3d_test(!set1.contains(10));
test(set1.contains(80)); rp3d_test(set1.contains(80));
test(set1.contains(130)); rp3d_test(set1.contains(130));
test(set1.contains(34)); rp3d_test(set1.contains(34));
test(set1.size() == 3); rp3d_test(set1.size() == 3);
set1.remove(80); set1.remove(80);
test(!set1.contains(80)); rp3d_test(!set1.contains(80));
test(set1.contains(130)); rp3d_test(set1.contains(130));
test(set1.contains(34)); rp3d_test(set1.contains(34));
test(set1.size() == 2); rp3d_test(set1.size() == 2);
set1.remove(130); set1.remove(130);
test(!set1.contains(130)); rp3d_test(!set1.contains(130));
test(set1.contains(34)); rp3d_test(set1.contains(34));
test(set1.size() == 1); rp3d_test(set1.size() == 1);
set1.remove(34); set1.remove(34);
test(!set1.contains(34)); rp3d_test(!set1.contains(34));
test(set1.size() == 0); rp3d_test(set1.size() == 0);
isValid = true; isValid = true;
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
@ -216,8 +216,8 @@ class TestSet : public Test {
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
if (set2.contains(i)) isValid = false; if (set2.contains(i)) isValid = false;
} }
test(isValid); rp3d_test(isValid);
test(set2.size() == 0); rp3d_test(set2.size() == 0);
Set<int> set3(mAllocator); Set<int> set3(mAllocator);
for (int i=0; i < 1000000; i++) { for (int i=0; i < 1000000; i++) {
@ -228,12 +228,12 @@ class TestSet : public Test {
set3.add(1); set3.add(1);
set3.add(2); set3.add(2);
set3.add(3); set3.add(3);
test(set3.size() == 3); rp3d_test(set3.size() == 3);
auto it = set3.begin(); auto it = set3.begin();
set3.remove(it++); set3.remove(it++);
test(!set3.contains(1)); rp3d_test(!set3.contains(1));
test(set3.size() == 2); rp3d_test(set3.size() == 2);
test(*it == 2); rp3d_test(*it == 2);
set3.add(6); set3.add(6);
set3.add(7); set3.add(7);
@ -241,7 +241,7 @@ class TestSet : public Test {
for (it = set3.begin(); it != set3.end();) { for (it = set3.begin(); it != set3.end();) {
it = set3.remove(it); it = set3.remove(it);
} }
test(set3.size() == 0); rp3d_test(set3.size() == 0);
// ----- Test clear() ----- // // ----- Test clear() ----- //
@ -250,16 +250,16 @@ class TestSet : public Test {
set4.add(4); set4.add(4);
set4.add(6); set4.add(6);
set4.clear(); set4.clear();
test(set4.size() == 0); rp3d_test(set4.size() == 0);
set4.add(2); set4.add(2);
test(set4.size() == 1); rp3d_test(set4.size() == 1);
test(set4.contains(2)); rp3d_test(set4.contains(2));
set4.clear(); set4.clear();
test(set4.size() == 0); rp3d_test(set4.size() == 0);
Set<int> set5(mAllocator); Set<int> set5(mAllocator);
set5.clear(); set5.clear();
test(set5.size() == 0); rp3d_test(set5.size() == 0);
// ----- Test map with always same hash value for keys ----- // // ----- Test map with always same hash value for keys ----- //
@ -273,37 +273,37 @@ class TestSet : public Test {
isTestValid = false; isTestValid = false;
} }
} }
test(isTestValid); rp3d_test(isTestValid);
for (int i=0; i < 1000; i++) { for (int i=0; i < 1000; i++) {
set6.remove(TestValueSet(i)); set6.remove(TestValueSet(i));
} }
test(set6.size() == 0); rp3d_test(set6.size() == 0);
} }
void testContains() { void testContains() {
Set<int> set1(mAllocator); Set<int> set1(mAllocator);
test(!set1.contains(2)); rp3d_test(!set1.contains(2));
test(!set1.contains(4)); rp3d_test(!set1.contains(4));
test(!set1.contains(6)); rp3d_test(!set1.contains(6));
set1.add(2); set1.add(2);
set1.add(4); set1.add(4);
set1.add(6); set1.add(6);
test(set1.contains(2)); rp3d_test(set1.contains(2));
test(set1.contains(4)); rp3d_test(set1.contains(4));
test(set1.contains(6)); rp3d_test(set1.contains(6));
set1.remove(4); set1.remove(4);
test(!set1.contains(4)); rp3d_test(!set1.contains(4));
test(set1.contains(2)); rp3d_test(set1.contains(2));
test(set1.contains(6)); rp3d_test(set1.contains(6));
set1.clear(); set1.clear();
test(!set1.contains(2)); rp3d_test(!set1.contains(2));
test(!set1.contains(6)); rp3d_test(!set1.contains(6));
} }
void testFind() { void testFind() {
@ -312,14 +312,14 @@ class TestSet : public Test {
set1.add(2); set1.add(2);
set1.add(4); set1.add(4);
set1.add(6); set1.add(6);
test(set1.find(2) != set1.end()); rp3d_test(set1.find(2) != set1.end());
test(set1.find(4) != set1.end()); rp3d_test(set1.find(4) != set1.end());
test(set1.find(6) != set1.end()); rp3d_test(set1.find(6) != set1.end());
test(set1.find(45) == set1.end()); rp3d_test(set1.find(45) == set1.end());
set1.remove(2); set1.remove(2);
test(set1.find(2) == set1.end()); rp3d_test(set1.find(2) == set1.end());
} }
void testEquality() { void testEquality() {
@ -327,7 +327,7 @@ class TestSet : public Test {
Set<std::string> set1(mAllocator, 10); Set<std::string> set1(mAllocator, 10);
Set<std::string> set2(mAllocator, 2); Set<std::string> set2(mAllocator, 2);
test(set1 == set2); rp3d_test(set1 == set2);
set1.add("a"); set1.add("a");
set1.add("b"); set1.add("b");
@ -337,25 +337,25 @@ class TestSet : public Test {
set2.add("b"); set2.add("b");
set2.add("h"); set2.add("h");
test(set1 == set1); rp3d_test(set1 == set1);
test(set2 == set2); rp3d_test(set2 == set2);
test(set1 != set2); rp3d_test(set1 != set2);
test(set2 != set1); rp3d_test(set2 != set1);
set1.add("a"); set1.add("a");
set2.remove("h"); set2.remove("h");
set2.add("c"); set2.add("c");
test(set1 == set2); rp3d_test(set1 == set2);
test(set2 == set1); rp3d_test(set2 == set1);
Set<std::string> set3(mAllocator); Set<std::string> set3(mAllocator);
set3.add("a"); set3.add("a");
test(set1 != set3); rp3d_test(set1 != set3);
test(set2 != set3); rp3d_test(set2 != set3);
test(set3 != set1); rp3d_test(set3 != set1);
test(set3 != set2); rp3d_test(set3 != set2);
} }
void testAssignment() { void testAssignment() {
@ -367,40 +367,40 @@ class TestSet : public Test {
Set<int> set2(mAllocator); Set<int> set2(mAllocator);
set2 = set1; set2 = set1;
test(set2.size() == set1.size()); rp3d_test(set2.size() == set1.size());
test(set2.contains(1)); rp3d_test(set2.contains(1));
test(set2.contains(2)); rp3d_test(set2.contains(2));
test(set2.contains(10)); rp3d_test(set2.contains(10));
test(set1 == set2); rp3d_test(set1 == set2);
Set<int> set3(mAllocator, 100); Set<int> set3(mAllocator, 100);
set3 = set1; set3 = set1;
test(set3.size() == set1.size()); rp3d_test(set3.size() == set1.size());
test(set3 == set1); rp3d_test(set3 == set1);
test(set3.contains(1)); rp3d_test(set3.contains(1));
test(set3.contains(2)); rp3d_test(set3.contains(2));
test(set3.contains(10)); rp3d_test(set3.contains(10));
Set<int> set4(mAllocator); Set<int> set4(mAllocator);
set3 = set4; set3 = set4;
test(set3.size() == 0); rp3d_test(set3.size() == 0);
test(set3 == set4); rp3d_test(set3 == set4);
Set<int> set5(mAllocator); Set<int> set5(mAllocator);
set5.add(7); set5.add(7);
set5.add(19); set5.add(19);
set1 = set5; set1 = set5;
test(set5.size() == set1.size()); rp3d_test(set5.size() == set1.size());
test(set1 == set5); rp3d_test(set1 == set5);
test(set1.contains(7)); rp3d_test(set1.contains(7));
test(set1.contains(19)); rp3d_test(set1.contains(19));
} }
void testIterators() { void testIterators() {
Set<int> set1(mAllocator); Set<int> set1(mAllocator);
test(set1.begin() == set1.end()); rp3d_test(set1.begin() == set1.end());
set1.add(1); set1.add(1);
set1.add(2); set1.add(2);
@ -410,14 +410,14 @@ class TestSet : public Test {
Set<int>::Iterator itBegin = set1.begin(); Set<int>::Iterator itBegin = set1.begin();
Set<int>::Iterator it = set1.begin(); Set<int>::Iterator it = set1.begin();
test(itBegin == it); rp3d_test(itBegin == it);
int size = 0; int size = 0;
for (auto it = set1.begin(); it != set1.end(); ++it) { for (auto it = set1.begin(); it != set1.end(); ++it) {
test(set1.contains(*it)); rp3d_test(set1.contains(*it));
size++; size++;
} }
test(set1.size() == size); rp3d_test(set1.size() == size);
} }
}; };

View File

@ -56,52 +56,52 @@ class TestMathematicsFunctions : public Test {
void run() { void run() {
// Test approxEqual() // Test approxEqual()
test(approxEqual(2, 7, 5.2)); rp3d_test(approxEqual(2, 7, 5.2));
test(approxEqual(7, 2, 5.2)); rp3d_test(approxEqual(7, 2, 5.2));
test(approxEqual(6, 6)); rp3d_test(approxEqual(6, 6));
test(!approxEqual(1, 5)); rp3d_test(!approxEqual(1, 5));
test(!approxEqual(1, 5, 3)); rp3d_test(!approxEqual(1, 5, 3));
test(approxEqual(-2, -2)); rp3d_test(approxEqual(-2, -2));
test(approxEqual(-2, -7, 6)); rp3d_test(approxEqual(-2, -7, 6));
test(!approxEqual(-2, 7, 2)); rp3d_test(!approxEqual(-2, 7, 2));
test(approxEqual(-3, 8, 12)); rp3d_test(approxEqual(-3, 8, 12));
test(!approxEqual(-3, 8, 6)); rp3d_test(!approxEqual(-3, 8, 6));
// Test clamp() // Test clamp()
test(clamp(4, -3, 5) == 4); rp3d_test(clamp(4, -3, 5) == 4);
test(clamp(-3, 1, 8) == 1); rp3d_test(clamp(-3, 1, 8) == 1);
test(clamp(45, -6, 7) == 7); rp3d_test(clamp(45, -6, 7) == 7);
test(clamp(-5, -2, -1) == -2); rp3d_test(clamp(-5, -2, -1) == -2);
test(clamp(-5, -9, -1) == -5); rp3d_test(clamp(-5, -9, -1) == -5);
test(clamp(6, 6, 9) == 6); rp3d_test(clamp(6, 6, 9) == 6);
test(clamp(9, 6, 9) == 9); rp3d_test(clamp(9, 6, 9) == 9);
test(clamp(decimal(4), decimal(-3), decimal(5)) == decimal(4)); rp3d_test(clamp(decimal(4), decimal(-3), decimal(5)) == decimal(4));
test(clamp(decimal(-3), decimal(1), decimal(8)) == decimal(1)); rp3d_test(clamp(decimal(-3), decimal(1), decimal(8)) == decimal(1));
test(clamp(decimal(45), decimal(-6), decimal(7)) == decimal(7)); rp3d_test(clamp(decimal(45), decimal(-6), decimal(7)) == decimal(7));
test(clamp(decimal(-5), decimal(-2), decimal(-1)) == decimal(-2)); rp3d_test(clamp(decimal(-5), decimal(-2), decimal(-1)) == decimal(-2));
test(clamp(decimal(-5), decimal(-9), decimal(-1)) == decimal(-5)); rp3d_test(clamp(decimal(-5), decimal(-9), decimal(-1)) == decimal(-5));
test(clamp(decimal(6), decimal(6), decimal(9)) == decimal(6)); rp3d_test(clamp(decimal(6), decimal(6), decimal(9)) == decimal(6));
test(clamp(decimal(9), decimal(6), decimal(9)) == decimal(9)); rp3d_test(clamp(decimal(9), decimal(6), decimal(9)) == decimal(9));
// Test min3() // Test min3()
test(min3(1, 5, 7) == 1); rp3d_test(min3(1, 5, 7) == 1);
test(min3(-4, 2, 4) == -4); rp3d_test(min3(-4, 2, 4) == -4);
test(min3(-1, -5, -7) == -7); rp3d_test(min3(-1, -5, -7) == -7);
test(min3(13, 5, 47) == 5); rp3d_test(min3(13, 5, 47) == 5);
test(min3(4, 4, 4) == 4); rp3d_test(min3(4, 4, 4) == 4);
// Test max3() // Test max3()
test(max3(1, 5, 7) == 7); rp3d_test(max3(1, 5, 7) == 7);
test(max3(-4, 2, 4) == 4); rp3d_test(max3(-4, 2, 4) == 4);
test(max3(-1, -5, -7) == -1); rp3d_test(max3(-1, -5, -7) == -1);
test(max3(13, 5, 47) == 47); rp3d_test(max3(13, 5, 47) == 47);
test(max3(4, 4, 4) == 4); rp3d_test(max3(4, 4, 4) == 4);
// Test sameSign() // Test sameSign()
test(sameSign(4, 53)); rp3d_test(sameSign(4, 53));
test(sameSign(-4, -8)); rp3d_test(sameSign(-4, -8));
test(!sameSign(4, -7)); rp3d_test(!sameSign(4, -7));
test(!sameSign(-4, 53)); rp3d_test(!sameSign(-4, 53));
// Test computePointToPlaneDistance() // Test computePointToPlaneDistance()
Vector3 p(8, 4, 0); Vector3 p(8, 4, 0);
@ -109,9 +109,9 @@ class TestMathematicsFunctions : public Test {
Vector3 n2(-1, 0, 0); Vector3 n2(-1, 0, 0);
Vector3 q1(1, 54, 0); Vector3 q1(1, 54, 0);
Vector3 q2(8, 17, 0); Vector3 q2(8, 17, 0);
test(approxEqual(computePointToPlaneDistance(q1, n1, p), decimal(-7))); rp3d_test(approxEqual(computePointToPlaneDistance(q1, n1, p), decimal(-7)));
test(approxEqual(computePointToPlaneDistance(q1, n2, p), decimal(7))); rp3d_test(approxEqual(computePointToPlaneDistance(q1, n2, p), decimal(7)));
test(approxEqual(computePointToPlaneDistance(q2, n2, p), decimal(0.0))); rp3d_test(approxEqual(computePointToPlaneDistance(q2, n2, p), decimal(0.0)));
// Test computeBarycentricCoordinatesInTriangle() // Test computeBarycentricCoordinatesInTriangle()
Vector3 a(0, 0, 0); Vector3 a(0, 0, 0);
@ -120,66 +120,66 @@ class TestMathematicsFunctions : public Test {
Vector3 testPoint(4, 0, 1); Vector3 testPoint(4, 0, 1);
decimal u,v,w; decimal u,v,w;
computeBarycentricCoordinatesInTriangle(a, b, c, a, u, v, w); computeBarycentricCoordinatesInTriangle(a, b, c, a, u, v, w);
test(approxEqual(u, 1.0, 0.000001)); rp3d_test(approxEqual(u, 1.0, 0.000001));
test(approxEqual(v, 0.0, 0.000001)); rp3d_test(approxEqual(v, 0.0, 0.000001));
test(approxEqual(w, 0.0, 0.000001)); rp3d_test(approxEqual(w, 0.0, 0.000001));
computeBarycentricCoordinatesInTriangle(a, b, c, b, u, v, w); computeBarycentricCoordinatesInTriangle(a, b, c, b, u, v, w);
test(approxEqual(u, 0.0, 0.000001)); rp3d_test(approxEqual(u, 0.0, 0.000001));
test(approxEqual(v, 1.0, 0.000001)); rp3d_test(approxEqual(v, 1.0, 0.000001));
test(approxEqual(w, 0.0, 0.000001)); rp3d_test(approxEqual(w, 0.0, 0.000001));
computeBarycentricCoordinatesInTriangle(a, b, c, c, u, v, w); computeBarycentricCoordinatesInTriangle(a, b, c, c, u, v, w);
test(approxEqual(u, 0.0, 0.000001)); rp3d_test(approxEqual(u, 0.0, 0.000001));
test(approxEqual(v, 0.0, 0.000001)); rp3d_test(approxEqual(v, 0.0, 0.000001));
test(approxEqual(w, 1.0, 0.000001)); rp3d_test(approxEqual(w, 1.0, 0.000001));
computeBarycentricCoordinatesInTriangle(a, b, c, testPoint, u, v, w); computeBarycentricCoordinatesInTriangle(a, b, c, testPoint, u, v, w);
test(approxEqual(u + v + w, 1.0, 0.000001)); rp3d_test(approxEqual(u + v + w, 1.0, 0.000001));
// Test computeClosestPointBetweenTwoSegments() // Test computeClosestPointBetweenTwoSegments()
Vector3 closestSeg1, closestSeg2; Vector3 closestSeg1, closestSeg2;
computeClosestPointBetweenTwoSegments(Vector3(4, 0, 0), Vector3(6, 0, 0), Vector3(8, 0, 0), Vector3(8, 6, 0), closestSeg1, closestSeg2); computeClosestPointBetweenTwoSegments(Vector3(4, 0, 0), Vector3(6, 0, 0), Vector3(8, 0, 0), Vector3(8, 6, 0), closestSeg1, closestSeg2);
test(approxEqual(closestSeg1.x, 6.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.x, 6.0, 0.000001));
test(approxEqual(closestSeg1.y, 0.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.y, 0.0, 0.000001));
test(approxEqual(closestSeg1.z, 0.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.z, 0.0, 0.000001));
test(approxEqual(closestSeg2.x, 8.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.x, 8.0, 0.000001));
test(approxEqual(closestSeg2.y, 0.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.y, 0.0, 0.000001));
test(approxEqual(closestSeg2.z, 0.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.z, 0.0, 0.000001));
computeClosestPointBetweenTwoSegments(Vector3(4, 6, 5), Vector3(4, 6, 5), Vector3(8, 3, -9), Vector3(8, 3, -9), closestSeg1, closestSeg2); computeClosestPointBetweenTwoSegments(Vector3(4, 6, 5), Vector3(4, 6, 5), Vector3(8, 3, -9), Vector3(8, 3, -9), closestSeg1, closestSeg2);
test(approxEqual(closestSeg1.x, 4.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.x, 4.0, 0.000001));
test(approxEqual(closestSeg1.y, 6.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.y, 6.0, 0.000001));
test(approxEqual(closestSeg1.z, 5.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.z, 5.0, 0.000001));
test(approxEqual(closestSeg2.x, 8.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.x, 8.0, 0.000001));
test(approxEqual(closestSeg2.y, 3.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.y, 3.0, 0.000001));
test(approxEqual(closestSeg2.z, -9.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.z, -9.0, 0.000001));
computeClosestPointBetweenTwoSegments(Vector3(0, -5, 0), Vector3(0, 8, 0), Vector3(6, 3, 0), Vector3(10, -3, 0), closestSeg1, closestSeg2); computeClosestPointBetweenTwoSegments(Vector3(0, -5, 0), Vector3(0, 8, 0), Vector3(6, 3, 0), Vector3(10, -3, 0), closestSeg1, closestSeg2);
test(approxEqual(closestSeg1.x, 0.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.x, 0.0, 0.000001));
test(approxEqual(closestSeg1.y, 3.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.y, 3.0, 0.000001));
test(approxEqual(closestSeg1.z, 0.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.z, 0.0, 0.000001));
test(approxEqual(closestSeg2.x, 6.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.x, 6.0, 0.000001));
test(approxEqual(closestSeg2.y, 3.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.y, 3.0, 0.000001));
test(approxEqual(closestSeg2.z, 0.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.z, 0.0, 0.000001));
computeClosestPointBetweenTwoSegments(Vector3(1, -4, -5), Vector3(1, 4, -5), Vector3(-6, 5, -5), Vector3(6, 5, -5), closestSeg1, closestSeg2); computeClosestPointBetweenTwoSegments(Vector3(1, -4, -5), Vector3(1, 4, -5), Vector3(-6, 5, -5), Vector3(6, 5, -5), closestSeg1, closestSeg2);
test(approxEqual(closestSeg1.x, 1.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.x, 1.0, 0.000001));
test(approxEqual(closestSeg1.y, 4.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.y, 4.0, 0.000001));
test(approxEqual(closestSeg1.z, -5.0, 0.000001)); rp3d_test(approxEqual(closestSeg1.z, -5.0, 0.000001));
test(approxEqual(closestSeg2.x, 1.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.x, 1.0, 0.000001));
test(approxEqual(closestSeg2.y, 5.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.y, 5.0, 0.000001));
test(approxEqual(closestSeg2.z, -5.0, 0.000001)); rp3d_test(approxEqual(closestSeg2.z, -5.0, 0.000001));
// Test computePlaneSegmentIntersection(); // Test computePlaneSegmentIntersection();
test(approxEqual(computePlaneSegmentIntersection(Vector3(-6, 3, 0), Vector3(6, 3, 0), 0.0, Vector3(-1, 0, 0)), 0.5, 0.000001)); rp3d_test(approxEqual(computePlaneSegmentIntersection(Vector3(-6, 3, 0), Vector3(6, 3, 0), 0.0, Vector3(-1, 0, 0)), 0.5, 0.000001));
test(approxEqual(computePlaneSegmentIntersection(Vector3(-6, 3, 0), Vector3(6, 3, 0), 0.0, Vector3(1, 0, 0)), 0.5, 0.000001)); rp3d_test(approxEqual(computePlaneSegmentIntersection(Vector3(-6, 3, 0), Vector3(6, 3, 0), 0.0, Vector3(1, 0, 0)), 0.5, 0.000001));
test(approxEqual(computePlaneSegmentIntersection(Vector3(5, 12, 0), Vector3(5, 4, 0), 6, Vector3(0, 1, 0)), 0.75, 0.000001)); rp3d_test(approxEqual(computePlaneSegmentIntersection(Vector3(5, 12, 0), Vector3(5, 4, 0), 6, Vector3(0, 1, 0)), 0.75, 0.000001));
test(approxEqual(computePlaneSegmentIntersection(Vector3(5, 4, 8), Vector3(9, 14, 8), 4, Vector3(0, 1, 0)), 0.0, 0.000001)); rp3d_test(approxEqual(computePlaneSegmentIntersection(Vector3(5, 4, 8), Vector3(9, 14, 8), 4, Vector3(0, 1, 0)), 0.0, 0.000001));
decimal tIntersect = computePlaneSegmentIntersection(Vector3(5, 4, 0), Vector3(9, 4, 0), 4, Vector3(0, 1, 0)); decimal tIntersect = computePlaneSegmentIntersection(Vector3(5, 4, 0), Vector3(9, 4, 0), 4, Vector3(0, 1, 0));
test(tIntersect < 0.0 || tIntersect > 1.0); rp3d_test(tIntersect < 0.0 || tIntersect > 1.0);
// Test computePointToLineDistance() // Test computePointToLineDistance()
test(approxEqual(computePointToLineDistance(Vector3(6, 0, 0), Vector3(14, 0, 0), Vector3(5, 3, 0)), 3.0, 0.000001)); rp3d_test(approxEqual(computePointToLineDistance(Vector3(6, 0, 0), Vector3(14, 0, 0), Vector3(5, 3, 0)), 3.0, 0.000001));
test(approxEqual(computePointToLineDistance(Vector3(6, -5, 0), Vector3(10, -5, 0), Vector3(4, 3, 0)), 8.0, 0.000001)); rp3d_test(approxEqual(computePointToLineDistance(Vector3(6, -5, 0), Vector3(10, -5, 0), Vector3(4, 3, 0)), 8.0, 0.000001));
test(approxEqual(computePointToLineDistance(Vector3(6, -5, 0), Vector3(10, -5, 0), Vector3(-43, 254, 0)), 259.0, 0.000001)); rp3d_test(approxEqual(computePointToLineDistance(Vector3(6, -5, 0), Vector3(10, -5, 0), Vector3(-43, 254, 0)), 259.0, 0.000001));
test(approxEqual(computePointToLineDistance(Vector3(6, -5, 8), Vector3(10, -5, -5), Vector3(6, -5, 8)), 0.0, 0.000001)); rp3d_test(approxEqual(computePointToLineDistance(Vector3(6, -5, 8), Vector3(10, -5, -5), Vector3(6, -5, 8)), 0.0, 0.000001));
test(approxEqual(computePointToLineDistance(Vector3(6, -5, 8), Vector3(10, -5, -5), Vector3(10, -5, -5)), 0.0, 0.000001)); rp3d_test(approxEqual(computePointToLineDistance(Vector3(6, -5, 8), Vector3(10, -5, -5), Vector3(10, -5, -5)), 0.0, 0.000001));
// Test clipSegmentWithPlanes() // Test clipSegmentWithPlanes()
std::vector<Vector3> segmentVertices; std::vector<Vector3> segmentVertices;
@ -193,46 +193,46 @@ class TestMathematicsFunctions : public Test {
List<Vector3> clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1], List<Vector3> clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1],
planesPoints, planesNormals, mAllocator); planesPoints, planesNormals, mAllocator);
test(clipSegmentVertices.size() == 2); rp3d_test(clipSegmentVertices.size() == 2);
test(approxEqual(clipSegmentVertices[0].x, -6, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].x, -6, 0.000001));
test(approxEqual(clipSegmentVertices[0].y, 3, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].y, 3, 0.000001));
test(approxEqual(clipSegmentVertices[0].z, 0, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].z, 0, 0.000001));
test(approxEqual(clipSegmentVertices[1].x, 4, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].x, 4, 0.000001));
test(approxEqual(clipSegmentVertices[1].y, 3, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].y, 3, 0.000001));
test(approxEqual(clipSegmentVertices[1].z, 0, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].z, 0, 0.000001));
segmentVertices.clear(); segmentVertices.clear();
segmentVertices.push_back(Vector3(8, 3, 0)); segmentVertices.push_back(Vector3(8, 3, 0));
segmentVertices.push_back(Vector3(-6, 3, 0)); segmentVertices.push_back(Vector3(-6, 3, 0));
clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1], planesPoints, planesNormals, mAllocator); clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1], planesPoints, planesNormals, mAllocator);
test(clipSegmentVertices.size() == 2); rp3d_test(clipSegmentVertices.size() == 2);
test(approxEqual(clipSegmentVertices[0].x, 4, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].x, 4, 0.000001));
test(approxEqual(clipSegmentVertices[0].y, 3, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].y, 3, 0.000001));
test(approxEqual(clipSegmentVertices[0].z, 0, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].z, 0, 0.000001));
test(approxEqual(clipSegmentVertices[1].x, -6, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].x, -6, 0.000001));
test(approxEqual(clipSegmentVertices[1].y, 3, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].y, 3, 0.000001));
test(approxEqual(clipSegmentVertices[1].z, 0, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].z, 0, 0.000001));
segmentVertices.clear(); segmentVertices.clear();
segmentVertices.push_back(Vector3(-6, 3, 0)); segmentVertices.push_back(Vector3(-6, 3, 0));
segmentVertices.push_back(Vector3(3, 3, 0)); segmentVertices.push_back(Vector3(3, 3, 0));
clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1], planesPoints, planesNormals, mAllocator); clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1], planesPoints, planesNormals, mAllocator);
test(clipSegmentVertices.size() == 2); rp3d_test(clipSegmentVertices.size() == 2);
test(approxEqual(clipSegmentVertices[0].x, -6, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].x, -6, 0.000001));
test(approxEqual(clipSegmentVertices[0].y, 3, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].y, 3, 0.000001));
test(approxEqual(clipSegmentVertices[0].z, 0, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[0].z, 0, 0.000001));
test(approxEqual(clipSegmentVertices[1].x, 3, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].x, 3, 0.000001));
test(approxEqual(clipSegmentVertices[1].y, 3, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].y, 3, 0.000001));
test(approxEqual(clipSegmentVertices[1].z, 0, 0.000001)); rp3d_test(approxEqual(clipSegmentVertices[1].z, 0, 0.000001));
segmentVertices.clear(); segmentVertices.clear();
segmentVertices.push_back(Vector3(5, 3, 0)); segmentVertices.push_back(Vector3(5, 3, 0));
segmentVertices.push_back(Vector3(8, 3, 0)); segmentVertices.push_back(Vector3(8, 3, 0));
clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1], planesPoints, planesNormals, mAllocator); clipSegmentVertices = clipSegmentWithPlanes(segmentVertices[0], segmentVertices[1], planesPoints, planesNormals, mAllocator);
test(clipSegmentVertices.size() == 0); rp3d_test(clipSegmentVertices.size() == 0);
// Test clipPolygonWithPlanes() // Test clipPolygonWithPlanes()
List<Vector3> polygonVertices(mAllocator); List<Vector3> polygonVertices(mAllocator);
@ -253,19 +253,19 @@ class TestMathematicsFunctions : public Test {
polygonPlanesPoints.add(Vector3(10, 5, 0)); polygonPlanesPoints.add(Vector3(10, 5, 0));
List<Vector3> clipPolygonVertices = clipPolygonWithPlanes(polygonVertices, polygonPlanesPoints, polygonPlanesNormals, mAllocator); List<Vector3> clipPolygonVertices = clipPolygonWithPlanes(polygonVertices, polygonPlanesPoints, polygonPlanesNormals, mAllocator);
test(clipPolygonVertices.size() == 4); rp3d_test(clipPolygonVertices.size() == 4);
test(approxEqual(clipPolygonVertices[0].x, 0, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[0].x, 0, 0.000001));
test(approxEqual(clipPolygonVertices[0].y, 2, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[0].y, 2, 0.000001));
test(approxEqual(clipPolygonVertices[0].z, 0, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[0].z, 0, 0.000001));
test(approxEqual(clipPolygonVertices[1].x, 7, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[1].x, 7, 0.000001));
test(approxEqual(clipPolygonVertices[1].y, 2, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[1].y, 2, 0.000001));
test(approxEqual(clipPolygonVertices[1].z, 0, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[1].z, 0, 0.000001));
test(approxEqual(clipPolygonVertices[2].x, 7, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[2].x, 7, 0.000001));
test(approxEqual(clipPolygonVertices[2].y, 4, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[2].y, 4, 0.000001));
test(approxEqual(clipPolygonVertices[2].z, 0, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[2].z, 0, 0.000001));
test(approxEqual(clipPolygonVertices[3].x, 0, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[3].x, 0, 0.000001));
test(approxEqual(clipPolygonVertices[3].y, 4, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[3].y, 4, 0.000001));
test(approxEqual(clipPolygonVertices[3].z, 0, 0.000001)); rp3d_test(approxEqual(clipPolygonVertices[3].z, 0, 0.000001));
} }

View File

@ -76,17 +76,17 @@ class TestMatrix2x2 : public Test {
Matrix2x2 test2(2, 3, 4, 5); Matrix2x2 test2(2, 3, 4, 5);
Matrix2x2 test3(mMatrix1); Matrix2x2 test3(mMatrix1);
test(test1[0][0] == 5); rp3d_test(test1[0][0] == 5);
test(test1[0][1] == 5); rp3d_test(test1[0][1] == 5);
test(test1[1][0] == 5); rp3d_test(test1[1][0] == 5);
test(test1[1][1] == 5); rp3d_test(test1[1][1] == 5);
test(test2[0][0] == 2); rp3d_test(test2[0][0] == 2);
test(test2[0][1] == 3); rp3d_test(test2[0][1] == 3);
test(test2[1][0] == 4); rp3d_test(test2[1][0] == 4);
test(test2[1][1] == 5); rp3d_test(test2[1][1] == 5);
test(test3 == mMatrix1); rp3d_test(test3 == mMatrix1);
} }
/// Test the getter and setter methods /// Test the getter and setter methods
@ -95,23 +95,23 @@ class TestMatrix2x2 : public Test {
// Test method to set all the values // Test method to set all the values
Matrix2x2 test2; Matrix2x2 test2;
test2.setAllValues(2, 24, -4, 5); test2.setAllValues(2, 24, -4, 5);
test(test2 == mMatrix1); rp3d_test(test2 == mMatrix1);
// Test method to set to zero // Test method to set to zero
test2.setToZero(); test2.setToZero();
test(test2 == Matrix2x2(0, 0, 0, 0)); rp3d_test(test2 == Matrix2x2(0, 0, 0, 0));
// Test method that returns a column // Test method that returns a column
Vector2 column1 = mMatrix1.getColumn(0); Vector2 column1 = mMatrix1.getColumn(0);
Vector2 column2 = mMatrix1.getColumn(1); Vector2 column2 = mMatrix1.getColumn(1);
test(column1 == Vector2(2, -4)); rp3d_test(column1 == Vector2(2, -4));
test(column2 == Vector2(24, 5)); rp3d_test(column2 == Vector2(24, 5));
// Test method that returns a row // Test method that returns a row
Vector2 row1 = mMatrix1.getRow(0); Vector2 row1 = mMatrix1.getRow(0);
Vector2 row2 = mMatrix1.getRow(1); Vector2 row2 = mMatrix1.getRow(1);
test(row1 == Vector2(2, 24)); rp3d_test(row1 == Vector2(2, 24));
test(row2 == Vector2(-4, 5)); rp3d_test(row2 == Vector2(-4, 5));
} }
/// Test the identity methods /// Test the identity methods
@ -121,12 +121,12 @@ class TestMatrix2x2 : public Test {
Matrix2x2 test1; Matrix2x2 test1;
test1.setToIdentity(); test1.setToIdentity();
test(identity[0][0] == 1); rp3d_test(identity[0][0] == 1);
test(identity[0][1] == 0); rp3d_test(identity[0][1] == 0);
test(identity[1][0] == 0); rp3d_test(identity[1][0] == 0);
test(identity[1][1] == 1); rp3d_test(identity[1][1] == 1);
test(test1 == Matrix2x2::identity()); rp3d_test(test1 == Matrix2x2::identity());
} }
/// Test the zero method /// Test the zero method
@ -134,10 +134,10 @@ class TestMatrix2x2 : public Test {
Matrix2x2 zero = Matrix2x2::zero(); Matrix2x2 zero = Matrix2x2::zero();
test(zero[0][0] == 0); rp3d_test(zero[0][0] == 0);
test(zero[0][1] == 0); rp3d_test(zero[0][1] == 0);
test(zero[1][0] == 0); rp3d_test(zero[1][0] == 0);
test(zero[1][1] == 0); rp3d_test(zero[1][1] == 0);
} }
/// Test others methods /// Test others methods
@ -145,36 +145,36 @@ class TestMatrix2x2 : public Test {
// Test transpose // Test transpose
Matrix2x2 transpose = mMatrix1.getTranspose(); Matrix2x2 transpose = mMatrix1.getTranspose();
test(transpose == Matrix2x2(2, -4, 24, 5)); rp3d_test(transpose == Matrix2x2(2, -4, 24, 5));
// Test trace // Test trace
test(mMatrix1.getTrace() ==7); rp3d_test(mMatrix1.getTrace() ==7);
test(Matrix2x2::identity().getTrace() == 2); rp3d_test(Matrix2x2::identity().getTrace() == 2);
// Test determinant // Test determinant
Matrix2x2 matrix(-24, 64, 253, -35); Matrix2x2 matrix(-24, 64, 253, -35);
test(mMatrix1.getDeterminant() == 106); rp3d_test(mMatrix1.getDeterminant() == 106);
test(matrix.getDeterminant() == -15352); rp3d_test(matrix.getDeterminant() == -15352);
test(mIdentity.getDeterminant() == 1); rp3d_test(mIdentity.getDeterminant() == 1);
// Test inverse // Test inverse
Matrix2x2 matrix2(1, 2, 3, 4); Matrix2x2 matrix2(1, 2, 3, 4);
Matrix2x2 inverseMatrix = matrix2.getInverse(); Matrix2x2 inverseMatrix = matrix2.getInverse();
test(approxEqual(inverseMatrix[0][0], decimal(-2), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[0][0], decimal(-2), decimal(10e-6)));
test(approxEqual(inverseMatrix[0][1], decimal(1), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[0][1], decimal(1), decimal(10e-6)));
test(approxEqual(inverseMatrix[1][0], decimal(1.5), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[1][0], decimal(1.5), decimal(10e-6)));
test(approxEqual(inverseMatrix[1][1], decimal(-0.5), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[1][1], decimal(-0.5), decimal(10e-6)));
Matrix2x2 inverseMatrix1 = mMatrix1.getInverse(); Matrix2x2 inverseMatrix1 = mMatrix1.getInverse();
test(approxEqual(inverseMatrix1[0][0], decimal(0.047169811), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[0][0], decimal(0.047169811), decimal(10e-6)));
test(approxEqual(inverseMatrix1[0][1], decimal(-0.226415094), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[0][1], decimal(-0.226415094), decimal(10e-6)));
test(approxEqual(inverseMatrix1[1][0], decimal(0.037735849), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[1][0], decimal(0.037735849), decimal(10e-6)));
test(approxEqual(inverseMatrix1[1][1], decimal(0.018867925), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[1][1], decimal(0.018867925), decimal(10e-6)));
// Test absolute matrix // Test absolute matrix
Matrix2x2 matrix3(-2, -3, -4, -5); Matrix2x2 matrix3(-2, -3, -4, -5);
test(matrix.getAbsoluteMatrix() == Matrix2x2(24, 64, 253, 35)); rp3d_test(matrix.getAbsoluteMatrix() == Matrix2x2(24, 64, 253, 35));
Matrix2x2 absoluteMatrix = matrix3.getAbsoluteMatrix(); Matrix2x2 absoluteMatrix = matrix3.getAbsoluteMatrix();
test(absoluteMatrix == Matrix2x2(2, 3, 4, 5)); rp3d_test(absoluteMatrix == Matrix2x2(2, 3, 4, 5));
} }
/// Test the operators /// Test the operators
@ -186,54 +186,54 @@ class TestMatrix2x2 : public Test {
Matrix2x2 addition1 = matrix1 + matrix2; Matrix2x2 addition1 = matrix1 + matrix2;
Matrix2x2 addition2(matrix1); Matrix2x2 addition2(matrix1);
addition2 += matrix2; addition2 += matrix2;
test(addition1 == Matrix2x2(0, 6, -1, 15)); rp3d_test(addition1 == Matrix2x2(0, 6, -1, 15));
test(addition2 == Matrix2x2(0, 6, -1, 15)); rp3d_test(addition2 == Matrix2x2(0, 6, -1, 15));
// Test substraction // Test substraction
Matrix2x2 substraction1 = matrix1 - matrix2; Matrix2x2 substraction1 = matrix1 - matrix2;
Matrix2x2 substraction2(matrix1); Matrix2x2 substraction2(matrix1);
substraction2 -= matrix2; substraction2 -= matrix2;
test(substraction1 == Matrix2x2(4, 0, 9, -5)); rp3d_test(substraction1 == Matrix2x2(4, 0, 9, -5));
test(substraction2 == Matrix2x2(4, 0, 9, -5)); rp3d_test(substraction2 == Matrix2x2(4, 0, 9, -5));
// Test negative operator // Test negative operator
Matrix2x2 negative = -matrix1; Matrix2x2 negative = -matrix1;
test(negative == Matrix2x2(-2, -3, -4, -5)); rp3d_test(negative == Matrix2x2(-2, -3, -4, -5));
// Test multiplication with a number // Test multiplication with a number
Matrix2x2 multiplication1 = 3 * matrix1; Matrix2x2 multiplication1 = 3 * matrix1;
Matrix2x2 multiplication2 = matrix1 * 3; Matrix2x2 multiplication2 = matrix1 * 3;
Matrix2x2 multiplication3(matrix1); Matrix2x2 multiplication3(matrix1);
multiplication3 *= 3; multiplication3 *= 3;
test(multiplication1 == Matrix2x2(6, 9, 12, 15)); rp3d_test(multiplication1 == Matrix2x2(6, 9, 12, 15));
test(multiplication2 == Matrix2x2(6, 9, 12, 15)); rp3d_test(multiplication2 == Matrix2x2(6, 9, 12, 15));
test(multiplication3 == Matrix2x2(6, 9, 12, 15)); rp3d_test(multiplication3 == Matrix2x2(6, 9, 12, 15));
// Test multiplication with a matrix // Test multiplication with a matrix
Matrix2x2 multiplication4 = matrix1 * matrix2; Matrix2x2 multiplication4 = matrix1 * matrix2;
Matrix2x2 multiplication5 = matrix2 * matrix1; Matrix2x2 multiplication5 = matrix2 * matrix1;
test(multiplication4 == Matrix2x2(-19, 36, -33, 62)); rp3d_test(multiplication4 == Matrix2x2(-19, 36, -33, 62));
test(multiplication5 == Matrix2x2(8, 9, 30, 35)); rp3d_test(multiplication5 == Matrix2x2(8, 9, 30, 35));
// Test multiplication with a vector // Test multiplication with a vector
Vector2 vector1(3, -32); Vector2 vector1(3, -32);
Vector2 vector2(-31, -422); Vector2 vector2(-31, -422);
Vector2 test1 = matrix1 * vector1; Vector2 test1 = matrix1 * vector1;
Vector2 test2 = matrix2 * vector2; Vector2 test2 = matrix2 * vector2;
test(test1 == Vector2(-90, -148)); rp3d_test(test1 == Vector2(-90, -148));
test(test2 == Vector2(-1204, -4065)); rp3d_test(test2 == Vector2(-1204, -4065));
// Test equality operators // Test equality operators
test(Matrix2x2(34, 38, 43, 64) == rp3d_test(Matrix2x2(34, 38, 43, 64) ==
Matrix2x2(34, 38, 43, 64)); Matrix2x2(34, 38, 43, 64));
test(Matrix2x2(34, 64, 43, 7) != rp3d_test(Matrix2x2(34, 64, 43, 7) !=
Matrix2x2(34, 38, 43, 64)); Matrix2x2(34, 38, 43, 64));
// Test operator to read a value // Test operator to read a value
test(mMatrix1[0][0] == 2); rp3d_test(mMatrix1[0][0] == 2);
test(mMatrix1[0][1] == 24); rp3d_test(mMatrix1[0][1] == 24);
test(mMatrix1[1][0] == -4); rp3d_test(mMatrix1[1][0] == -4);
test(mMatrix1[1][1] == 5); rp3d_test(mMatrix1[1][1] == 5);
// Test operator to set a value // Test operator to set a value
Matrix2x2 test3; Matrix2x2 test3;
@ -241,7 +241,7 @@ class TestMatrix2x2 : public Test {
test3[0][1] = 24; test3[0][1] = 24;
test3[1][0] = -4; test3[1][0] = -4;
test3[1][1] = 5; test3[1][1] = 5;
test(test3 == mMatrix1); rp3d_test(test3 == mMatrix1);
} }
}; };

View File

@ -77,27 +77,27 @@ class TestMatrix3x3 : public Test {
Matrix3x3 test1(5.0); Matrix3x3 test1(5.0);
Matrix3x3 test2(2, 3, 4, 5, 6, 7, 8, 9, 10); Matrix3x3 test2(2, 3, 4, 5, 6, 7, 8, 9, 10);
Matrix3x3 test3(mMatrix1); Matrix3x3 test3(mMatrix1);
test(test1[0][0] == 5); rp3d_test(test1[0][0] == 5);
test(test1[0][1] == 5); rp3d_test(test1[0][1] == 5);
test(test1[0][2] == 5); rp3d_test(test1[0][2] == 5);
test(test1[1][0] == 5); rp3d_test(test1[1][0] == 5);
test(test1[1][1] == 5); rp3d_test(test1[1][1] == 5);
test(test1[1][2] == 5); rp3d_test(test1[1][2] == 5);
test(test1[2][0] == 5); rp3d_test(test1[2][0] == 5);
test(test1[2][1] == 5); rp3d_test(test1[2][1] == 5);
test(test1[2][2] == 5); rp3d_test(test1[2][2] == 5);
test(test2[0][0] == 2); rp3d_test(test2[0][0] == 2);
test(test2[0][1] == 3); rp3d_test(test2[0][1] == 3);
test(test2[0][2] == 4); rp3d_test(test2[0][2] == 4);
test(test2[1][0] == 5); rp3d_test(test2[1][0] == 5);
test(test2[1][1] == 6); rp3d_test(test2[1][1] == 6);
test(test2[1][2] == 7); rp3d_test(test2[1][2] == 7);
test(test2[2][0] == 8); rp3d_test(test2[2][0] == 8);
test(test2[2][1] == 9); rp3d_test(test2[2][1] == 9);
test(test2[2][2] == 10); rp3d_test(test2[2][2] == 10);
test(test3 == mMatrix1); rp3d_test(test3 == mMatrix1);
} }
/// Test the getter and setter methods /// Test the getter and setter methods
@ -106,27 +106,27 @@ class TestMatrix3x3 : public Test {
// Test method to set all the values // Test method to set all the values
Matrix3x3 test2; Matrix3x3 test2;
test2.setAllValues(2, 24, 4, 5, -6, 234, -15, 11, 66); test2.setAllValues(2, 24, 4, 5, -6, 234, -15, 11, 66);
test(test2 == mMatrix1); rp3d_test(test2 == mMatrix1);
// Test method to set to zero // Test method to set to zero
test2.setToZero(); test2.setToZero();
test(test2 == Matrix3x3(0, 0, 0, 0, 0, 0, 0, 0, 0)); rp3d_test(test2 == Matrix3x3(0, 0, 0, 0, 0, 0, 0, 0, 0));
// Test method that returns a column // Test method that returns a column
Vector3 column1 = mMatrix1.getColumn(0); Vector3 column1 = mMatrix1.getColumn(0);
Vector3 column2 = mMatrix1.getColumn(1); Vector3 column2 = mMatrix1.getColumn(1);
Vector3 column3 = mMatrix1.getColumn(2); Vector3 column3 = mMatrix1.getColumn(2);
test(column1 == Vector3(2, 5, -15)); rp3d_test(column1 == Vector3(2, 5, -15));
test(column2 == Vector3(24, -6, 11)); rp3d_test(column2 == Vector3(24, -6, 11));
test(column3 == Vector3(4, 234, 66)); rp3d_test(column3 == Vector3(4, 234, 66));
// Test method that returns a row // Test method that returns a row
Vector3 row1 = mMatrix1.getRow(0); Vector3 row1 = mMatrix1.getRow(0);
Vector3 row2 = mMatrix1.getRow(1); Vector3 row2 = mMatrix1.getRow(1);
Vector3 row3 = mMatrix1.getRow(2); Vector3 row3 = mMatrix1.getRow(2);
test(row1 == Vector3(2, 24, 4)); rp3d_test(row1 == Vector3(2, 24, 4));
test(row2 == Vector3(5, -6, 234)); rp3d_test(row2 == Vector3(5, -6, 234));
test(row3 == Vector3(-15, 11, 66)); rp3d_test(row3 == Vector3(-15, 11, 66));
} }
/// Test the identity methods /// Test the identity methods
@ -136,17 +136,17 @@ class TestMatrix3x3 : public Test {
Matrix3x3 test1; Matrix3x3 test1;
test1.setToIdentity(); test1.setToIdentity();
test(identity[0][0] == 1); rp3d_test(identity[0][0] == 1);
test(identity[0][1] == 0); rp3d_test(identity[0][1] == 0);
test(identity[0][2] == 0); rp3d_test(identity[0][2] == 0);
test(identity[1][0] == 0); rp3d_test(identity[1][0] == 0);
test(identity[1][1] == 1); rp3d_test(identity[1][1] == 1);
test(identity[1][2] == 0); rp3d_test(identity[1][2] == 0);
test(identity[2][0] == 0); rp3d_test(identity[2][0] == 0);
test(identity[2][1] == 0); rp3d_test(identity[2][1] == 0);
test(identity[2][2] == 1); rp3d_test(identity[2][2] == 1);
test(test1 == Matrix3x3::identity()); rp3d_test(test1 == Matrix3x3::identity());
} }
/// Test the zero method /// Test the zero method
@ -154,15 +154,15 @@ class TestMatrix3x3 : public Test {
Matrix3x3 zero = Matrix3x3::zero(); Matrix3x3 zero = Matrix3x3::zero();
test(zero[0][0] == 0); rp3d_test(zero[0][0] == 0);
test(zero[0][1] == 0); rp3d_test(zero[0][1] == 0);
test(zero[0][2] == 0); rp3d_test(zero[0][2] == 0);
test(zero[1][0] == 0); rp3d_test(zero[1][0] == 0);
test(zero[1][1] == 0); rp3d_test(zero[1][1] == 0);
test(zero[1][2] == 0); rp3d_test(zero[1][2] == 0);
test(zero[2][0] == 0); rp3d_test(zero[2][0] == 0);
test(zero[2][1] == 0); rp3d_test(zero[2][1] == 0);
test(zero[2][2] == 0); rp3d_test(zero[2][2] == 0);
} }
/// Test others methods /// Test others methods
@ -170,54 +170,54 @@ class TestMatrix3x3 : public Test {
// Test transpose // Test transpose
Matrix3x3 transpose = mMatrix1.getTranspose(); Matrix3x3 transpose = mMatrix1.getTranspose();
test(transpose == Matrix3x3(2, 5, -15, 24, -6, 11, 4, 234, 66)); rp3d_test(transpose == Matrix3x3(2, 5, -15, 24, -6, 11, 4, 234, 66));
// Test trace // Test trace
test(mMatrix1.getTrace() == 62); rp3d_test(mMatrix1.getTrace() == 62);
test(Matrix3x3::identity().getTrace() == 3); rp3d_test(Matrix3x3::identity().getTrace() == 3);
// Test determinant // Test determinant
Matrix3x3 matrix(-24, 64, 253, -35, 52, 72, 21, -35, -363); Matrix3x3 matrix(-24, 64, 253, -35, 52, 72, 21, -35, -363);
test(mMatrix1.getDeterminant() == -98240); rp3d_test(mMatrix1.getDeterminant() == -98240);
test(matrix.getDeterminant() == -290159); rp3d_test(matrix.getDeterminant() == -290159);
test(mIdentity.getDeterminant() == 1); rp3d_test(mIdentity.getDeterminant() == 1);
// Test inverse // Test inverse
Matrix3x3 inverseMatrix = matrix.getInverse(); Matrix3x3 inverseMatrix = matrix.getInverse();
test(approxEqual(inverseMatrix[0][0], decimal(0.056369), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[0][0], decimal(0.056369), decimal(10e-6)));
test(approxEqual(inverseMatrix[0][1], decimal(-0.049549), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[0][1], decimal(-0.049549), decimal(10e-6)));
test(approxEqual(inverseMatrix[0][2], decimal(0.029460), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[0][2], decimal(0.029460), decimal(10e-6)));
test(approxEqual(inverseMatrix[1][0], decimal(0.038575), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[1][0], decimal(0.038575), decimal(10e-6)));
test(approxEqual(inverseMatrix[1][1], decimal(-0.011714), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[1][1], decimal(-0.011714), decimal(10e-6)));
test(approxEqual(inverseMatrix[1][2], decimal(0.024562), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[1][2], decimal(0.024562), decimal(10e-6)));
test(approxEqual(inverseMatrix[2][0], decimal(-0.000458), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[2][0], decimal(-0.000458), decimal(10e-6)));
test(approxEqual(inverseMatrix[2][1], decimal(-0.001737), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[2][1], decimal(-0.001737), decimal(10e-6)));
test(approxEqual(inverseMatrix[2][2], decimal(-0.003419), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix[2][2], decimal(-0.003419), decimal(10e-6)));
Matrix3x3 inverseMatrix1 = mMatrix1.getInverse(); Matrix3x3 inverseMatrix1 = mMatrix1.getInverse();
test(approxEqual(inverseMatrix1[0][0], decimal(0.030232), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[0][0], decimal(0.030232), decimal(10e-6)));
test(approxEqual(inverseMatrix1[0][1], decimal(0.015676), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[0][1], decimal(0.015676), decimal(10e-6)));
test(approxEqual(inverseMatrix1[0][2], decimal(-0.057410), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[0][2], decimal(-0.057410), decimal(10e-6)));
test(approxEqual(inverseMatrix1[1][0], decimal(0.039088), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[1][0], decimal(0.039088), decimal(10e-6)));
test(approxEqual(inverseMatrix1[1][1], decimal(-0.001954), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[1][1], decimal(-0.001954), decimal(10e-6)));
test(approxEqual(inverseMatrix1[1][2], decimal(0.004560), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[1][2], decimal(0.004560), decimal(10e-6)));
test(approxEqual(inverseMatrix1[2][0], decimal(0.000356), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[2][0], decimal(0.000356), decimal(10e-6)));
test(approxEqual(inverseMatrix1[2][1], decimal(0.003888), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[2][1], decimal(0.003888), decimal(10e-6)));
test(approxEqual(inverseMatrix1[2][2], decimal(0.001344), decimal(10e-6))); rp3d_test(approxEqual(inverseMatrix1[2][2], decimal(0.001344), decimal(10e-6)));
// Test absolute matrix // Test absolute matrix
Matrix3x3 matrix2(-2, -3, -4, -5, -6, -7, -8, -9, -10); Matrix3x3 matrix2(-2, -3, -4, -5, -6, -7, -8, -9, -10);
test(matrix.getAbsoluteMatrix() == Matrix3x3(24, 64, 253, 35, 52, 72, 21, 35, 363)); rp3d_test(matrix.getAbsoluteMatrix() == Matrix3x3(24, 64, 253, 35, 52, 72, 21, 35, 363));
Matrix3x3 absoluteMatrix = matrix2.getAbsoluteMatrix(); Matrix3x3 absoluteMatrix = matrix2.getAbsoluteMatrix();
test(absoluteMatrix == Matrix3x3(2, 3, 4, 5, 6, 7, 8, 9, 10)); rp3d_test(absoluteMatrix == Matrix3x3(2, 3, 4, 5, 6, 7, 8, 9, 10));
// Test method that computes skew-symmetric matrix for cross product // Test method that computes skew-symmetric matrix for cross product
Vector3 vector1(3, -5, 6); Vector3 vector1(3, -5, 6);
Vector3 vector2(73, 42, 26); Vector3 vector2(73, 42, 26);
Matrix3x3 skewMatrix = Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(vector1); Matrix3x3 skewMatrix = Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(vector1);
test(skewMatrix == Matrix3x3(0, -6, -5, 6, 0, -3, 5, 3, 0)); rp3d_test(skewMatrix == Matrix3x3(0, -6, -5, 6, 0, -3, 5, 3, 0));
Vector3 crossProduct1 = vector1.cross(vector2); Vector3 crossProduct1 = vector1.cross(vector2);
Vector3 crossProduct2 = skewMatrix * vector2; Vector3 crossProduct2 = skewMatrix * vector2;
test(crossProduct1 == crossProduct2); rp3d_test(crossProduct1 == crossProduct2);
} }
/// Test the operators /// Test the operators
@ -229,59 +229,59 @@ class TestMatrix3x3 : public Test {
Matrix3x3 addition1 = matrix1 + matrix2; Matrix3x3 addition1 = matrix1 + matrix2;
Matrix3x3 addition2(matrix1); Matrix3x3 addition2(matrix1);
addition2 += matrix2; addition2 += matrix2;
test(addition1 == Matrix3x3(0, 6, -1, 15, 10, 14, 10, 14, 18)); rp3d_test(addition1 == Matrix3x3(0, 6, -1, 15, 10, 14, 10, 14, 18));
test(addition2 == Matrix3x3(0, 6, -1, 15, 10, 14, 10, 14, 18)); rp3d_test(addition2 == Matrix3x3(0, 6, -1, 15, 10, 14, 10, 14, 18));
// Test substraction // Test substraction
Matrix3x3 substraction1 = matrix1 - matrix2; Matrix3x3 substraction1 = matrix1 - matrix2;
Matrix3x3 substraction2(matrix1); Matrix3x3 substraction2(matrix1);
substraction2 -= matrix2; substraction2 -= matrix2;
test(substraction1 == Matrix3x3(4, 0, 9, -5, 2, 0, 6, 4, 2)); rp3d_test(substraction1 == Matrix3x3(4, 0, 9, -5, 2, 0, 6, 4, 2));
test(substraction2 == Matrix3x3(4, 0, 9, -5, 2, 0, 6, 4, 2)); rp3d_test(substraction2 == Matrix3x3(4, 0, 9, -5, 2, 0, 6, 4, 2));
// Test negative operator // Test negative operator
Matrix3x3 negative = -matrix1; Matrix3x3 negative = -matrix1;
test(negative == Matrix3x3(-2, -3, -4, -5, -6, -7, -8, -9, -10)); rp3d_test(negative == Matrix3x3(-2, -3, -4, -5, -6, -7, -8, -9, -10));
// Test multiplication with a number // Test multiplication with a number
Matrix3x3 multiplication1 = 3 * matrix1; Matrix3x3 multiplication1 = 3 * matrix1;
Matrix3x3 multiplication2 = matrix1 * 3; Matrix3x3 multiplication2 = matrix1 * 3;
Matrix3x3 multiplication3(matrix1); Matrix3x3 multiplication3(matrix1);
multiplication3 *= 3; multiplication3 *= 3;
test(multiplication1 == Matrix3x3(6, 9, 12, 15, 18, 21, 24, 27, 30)); rp3d_test(multiplication1 == Matrix3x3(6, 9, 12, 15, 18, 21, 24, 27, 30));
test(multiplication2 == Matrix3x3(6, 9, 12, 15, 18, 21, 24, 27, 30)); rp3d_test(multiplication2 == Matrix3x3(6, 9, 12, 15, 18, 21, 24, 27, 30));
test(multiplication3 == Matrix3x3(6, 9, 12, 15, 18, 21, 24, 27, 30)); rp3d_test(multiplication3 == Matrix3x3(6, 9, 12, 15, 18, 21, 24, 27, 30));
// Test multiplication with a matrix // Test multiplication with a matrix
Matrix3x3 multiplication4 = matrix1 * matrix2; Matrix3x3 multiplication4 = matrix1 * matrix2;
Matrix3x3 multiplication5 = matrix2 * matrix1; Matrix3x3 multiplication5 = matrix2 * matrix1;
test(multiplication4 == Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103)); rp3d_test(multiplication4 == Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103));
test(multiplication5 == Matrix3x3(-29, -33, -37, 96, 117, 138, 93, 108, 123)); rp3d_test(multiplication5 == Matrix3x3(-29, -33, -37, 96, 117, 138, 93, 108, 123));
// Test multiplication with a vector // Test multiplication with a vector
Vector3 vector1(3, -32, 59); Vector3 vector1(3, -32, 59);
Vector3 vector2(-31, -422, 34); Vector3 vector2(-31, -422, 34);
Vector3 test1 = matrix1 * vector1; Vector3 test1 = matrix1 * vector1;
Vector3 test2 = matrix2 * vector2; Vector3 test2 = matrix2 * vector2;
test(test1 == Vector3(146, 236, 326)); rp3d_test(test1 == Vector3(146, 236, 326));
test(test2 == Vector3(-1374, -1760, -1900)); rp3d_test(test2 == Vector3(-1374, -1760, -1900));
// Test equality operators // Test equality operators
test(Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103) == rp3d_test(Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103) ==
Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103)); Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103));
test(Matrix3x3(34, 64, 43, 7, -1, 73, 94, 110, 103) != rp3d_test(Matrix3x3(34, 64, 43, 7, -1, 73, 94, 110, 103) !=
Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103)); Matrix3x3(34, 38, 43, 64, 74, 73, 94, 110, 103));
// Test operator to read a value // Test operator to read a value
test(mMatrix1[0][0] == 2); rp3d_test(mMatrix1[0][0] == 2);
test(mMatrix1[0][1] == 24); rp3d_test(mMatrix1[0][1] == 24);
test(mMatrix1[0][2] == 4); rp3d_test(mMatrix1[0][2] == 4);
test(mMatrix1[1][0] == 5); rp3d_test(mMatrix1[1][0] == 5);
test(mMatrix1[1][1] == -6); rp3d_test(mMatrix1[1][1] == -6);
test(mMatrix1[1][2] == 234); rp3d_test(mMatrix1[1][2] == 234);
test(mMatrix1[2][0] == -15); rp3d_test(mMatrix1[2][0] == -15);
test(mMatrix1[2][1] == 11); rp3d_test(mMatrix1[2][1] == 11);
test(mMatrix1[2][2] == 66); rp3d_test(mMatrix1[2][2] == 66);
// Test operator to set a value // Test operator to set a value
Matrix3x3 test3; Matrix3x3 test3;
@ -294,7 +294,7 @@ class TestMatrix3x3 : public Test {
test3[2][0] = -15; test3[2][0] = -15;
test3[2][1] = 11; test3[2][1] = 11;
test3[2][2] = 66; test3[2][2] = 66;
test(test3 == mMatrix1); rp3d_test(test3 == mMatrix1);
} }
}; };

View File

@ -76,19 +76,19 @@ class TestQuaternion : public Test {
void testConstructors() { void testConstructors() {
Quaternion quaternion1(mQuaternion1); Quaternion quaternion1(mQuaternion1);
test(mQuaternion1 == quaternion1); rp3d_test(mQuaternion1 == quaternion1);
Quaternion quaternion2(4, 5, 6, 7); Quaternion quaternion2(4, 5, 6, 7);
test(quaternion2 == Quaternion(4, 5, 6, 7)); rp3d_test(quaternion2 == Quaternion(4, 5, 6, 7));
Quaternion quaternion3(8, Vector3(3, 5, 2)); Quaternion quaternion3(8, Vector3(3, 5, 2));
test(quaternion3 == Quaternion(3, 5, 2, 8)); rp3d_test(quaternion3 == Quaternion(3, 5, 2, 8));
Quaternion quaternion4(mQuaternion1.getMatrix()); Quaternion quaternion4(mQuaternion1.getMatrix());
test(approxEqual(quaternion4.x, mQuaternion1.x)); rp3d_test(approxEqual(quaternion4.x, mQuaternion1.x));
test(approxEqual(quaternion4.y, mQuaternion1.y)); rp3d_test(approxEqual(quaternion4.y, mQuaternion1.y));
test(approxEqual(quaternion4.z, mQuaternion1.z)); rp3d_test(approxEqual(quaternion4.z, mQuaternion1.z));
test(approxEqual(quaternion4.w, mQuaternion1.w)); rp3d_test(approxEqual(quaternion4.w, mQuaternion1.w));
// Test conversion from Euler angles to quaternion // Test conversion from Euler angles to quaternion
@ -97,26 +97,26 @@ class TestQuaternion : public Test {
Quaternion quaternion5 = Quaternion::fromEulerAngles(PI_OVER_2, 0, 0); Quaternion quaternion5 = Quaternion::fromEulerAngles(PI_OVER_2, 0, 0);
Quaternion quaternionTest5(std::sin(PI_OVER_4), 0, 0, std::cos(PI_OVER_4)); Quaternion quaternionTest5(std::sin(PI_OVER_4), 0, 0, std::cos(PI_OVER_4));
quaternionTest5.normalize(); quaternionTest5.normalize();
test(approxEqual(quaternion5.x, quaternionTest5.x)); rp3d_test(approxEqual(quaternion5.x, quaternionTest5.x));
test(approxEqual(quaternion5.y, quaternionTest5.y)); rp3d_test(approxEqual(quaternion5.y, quaternionTest5.y));
test(approxEqual(quaternion5.z, quaternionTest5.z)); rp3d_test(approxEqual(quaternion5.z, quaternionTest5.z));
test(approxEqual(quaternion5.w, quaternionTest5.w)); rp3d_test(approxEqual(quaternion5.w, quaternionTest5.w));
Quaternion quaternion6 = Quaternion::fromEulerAngles(0, PI_OVER_2, 0); Quaternion quaternion6 = Quaternion::fromEulerAngles(0, PI_OVER_2, 0);
Quaternion quaternionTest6(0, std::sin(PI_OVER_4), 0, std::cos(PI_OVER_4)); Quaternion quaternionTest6(0, std::sin(PI_OVER_4), 0, std::cos(PI_OVER_4));
quaternionTest6.normalize(); quaternionTest6.normalize();
test(approxEqual(quaternion6.x, quaternionTest6.x)); rp3d_test(approxEqual(quaternion6.x, quaternionTest6.x));
test(approxEqual(quaternion6.y, quaternionTest6.y)); rp3d_test(approxEqual(quaternion6.y, quaternionTest6.y));
test(approxEqual(quaternion6.z, quaternionTest6.z)); rp3d_test(approxEqual(quaternion6.z, quaternionTest6.z));
test(approxEqual(quaternion6.w, quaternionTest6.w)); rp3d_test(approxEqual(quaternion6.w, quaternionTest6.w));
Quaternion quaternion7 = Quaternion::fromEulerAngles(Vector3(0, 0, PI_OVER_2)); Quaternion quaternion7 = Quaternion::fromEulerAngles(Vector3(0, 0, PI_OVER_2));
Quaternion quaternionTest7(0, 0, std::sin(PI_OVER_4), std::cos(PI_OVER_4)); Quaternion quaternionTest7(0, 0, std::sin(PI_OVER_4), std::cos(PI_OVER_4));
quaternionTest7.normalize(); quaternionTest7.normalize();
test(approxEqual(quaternion7.x, quaternionTest7.x)); rp3d_test(approxEqual(quaternion7.x, quaternionTest7.x));
test(approxEqual(quaternion7.y, quaternionTest7.y)); rp3d_test(approxEqual(quaternion7.y, quaternionTest7.y));
test(approxEqual(quaternion7.z, quaternionTest7.z)); rp3d_test(approxEqual(quaternion7.z, quaternionTest7.z));
test(approxEqual(quaternion7.w, quaternionTest7.w)); rp3d_test(approxEqual(quaternion7.w, quaternionTest7.w));
} }
/// Test unit, length, normalize methods /// Test unit, length, normalize methods
@ -124,15 +124,15 @@ class TestQuaternion : public Test {
// Test method that returns the length // Test method that returns the length
Quaternion quaternion(2, 3, -4, 5); Quaternion quaternion(2, 3, -4, 5);
test(approxEqual(quaternion.length(), std::sqrt(decimal(54.0)))); rp3d_test(approxEqual(quaternion.length(), std::sqrt(decimal(54.0))));
// Test method that returns a unit quaternion // Test method that returns a unit quaternion
test(approxEqual(quaternion.getUnit().length(), 1.0)); rp3d_test(approxEqual(quaternion.getUnit().length(), 1.0));
// Test the normalization method // Test the normalization method
Quaternion quaternion2(4, 5, 6, 7); Quaternion quaternion2(4, 5, 6, 7);
quaternion2.normalize(); quaternion2.normalize();
test(approxEqual(quaternion2.length(), 1.0)); rp3d_test(approxEqual(quaternion2.length(), 1.0));
} }
/// Test others methods /// Test others methods
@ -141,80 +141,80 @@ class TestQuaternion : public Test {
// Test the method to set the values // Test the method to set the values
Quaternion quaternion; Quaternion quaternion;
quaternion.setAllValues(1, 2, 3, 4); quaternion.setAllValues(1, 2, 3, 4);
test(quaternion == Quaternion(1, 2, 3, 4)); rp3d_test(quaternion == Quaternion(1, 2, 3, 4));
// Test the method to set the quaternion to zero // Test the method to set the quaternion to zero
quaternion.setToZero(); quaternion.setToZero();
test(quaternion == Quaternion(0, 0, 0, 0)); rp3d_test(quaternion == Quaternion(0, 0, 0, 0));
// Tes the methods to get or set to identity // Tes the methods to get or set to identity
Quaternion identity1(1, 2, 3, 4); Quaternion identity1(1, 2, 3, 4);
identity1.setToIdentity(); identity1.setToIdentity();
test(identity1 == Quaternion(0, 0, 0, 1)); rp3d_test(identity1 == Quaternion(0, 0, 0, 1));
test(Quaternion::identity() == Quaternion(0, 0, 0, 1)); rp3d_test(Quaternion::identity() == Quaternion(0, 0, 0, 1));
// Test the method to get the vector (x, y, z) // Test the method to get the vector (x, y, z)
Vector3 v = mQuaternion1.getVectorV(); Vector3 v = mQuaternion1.getVectorV();
test(v.x == mQuaternion1.x); rp3d_test(v.x == mQuaternion1.x);
test(v.y == mQuaternion1.y); rp3d_test(v.y == mQuaternion1.y);
test(v.z == mQuaternion1.z); rp3d_test(v.z == mQuaternion1.z);
// Test the conjugate method // Test the conjugate method
Quaternion conjugate = mQuaternion1.getConjugate(); Quaternion conjugate = mQuaternion1.getConjugate();
test(conjugate.x == -mQuaternion1.x); rp3d_test(conjugate.x == -mQuaternion1.x);
test(conjugate.y == -mQuaternion1.y); rp3d_test(conjugate.y == -mQuaternion1.y);
test(conjugate.z == -mQuaternion1.z); rp3d_test(conjugate.z == -mQuaternion1.z);
test(conjugate.w == mQuaternion1.w); rp3d_test(conjugate.w == mQuaternion1.w);
// Test the inverse methods // Test the inverse methods
Quaternion inverse1 = mQuaternion1.getInverse(); Quaternion inverse1 = mQuaternion1.getInverse();
Quaternion inverse2(mQuaternion1); Quaternion inverse2(mQuaternion1);
inverse2.inverse(); inverse2.inverse();
test(inverse2 == inverse1); rp3d_test(inverse2 == inverse1);
Quaternion product = mQuaternion1 * inverse1; Quaternion product = mQuaternion1 * inverse1;
test(approxEqual(product.x, mIdentity.x, decimal(10e-6))); rp3d_test(approxEqual(product.x, mIdentity.x, decimal(10e-6)));
test(approxEqual(product.y, mIdentity.y, decimal(10e-6))); rp3d_test(approxEqual(product.y, mIdentity.y, decimal(10e-6)));
test(approxEqual(product.z, mIdentity.z, decimal(10e-6))); rp3d_test(approxEqual(product.z, mIdentity.z, decimal(10e-6)));
test(approxEqual(product.w, mIdentity.w, decimal(10e-6))); rp3d_test(approxEqual(product.w, mIdentity.w, decimal(10e-6)));
// Test the dot product // Test the dot product
Quaternion quaternion1(2, 3, 4, 5); Quaternion quaternion1(2, 3, 4, 5);
Quaternion quaternion2(6, 7, 8, 9); Quaternion quaternion2(6, 7, 8, 9);
decimal dotProduct = quaternion1.dot(quaternion2); decimal dotProduct = quaternion1.dot(quaternion2);
test(dotProduct == 110); rp3d_test(dotProduct == 110);
// Test the method that returns the rotation angle and axis // Test the method that returns the rotation angle and axis
Vector3 axis; Vector3 axis;
decimal angle; decimal angle;
Vector3 originalAxis = Vector3(2, 3, 4).getUnit(); Vector3 originalAxis = Vector3(2, 3, 4).getUnit();
mQuaternion1.getRotationAngleAxis(angle, axis); mQuaternion1.getRotationAngleAxis(angle, axis);
test(approxEqual(axis.x, originalAxis.x)); rp3d_test(approxEqual(axis.x, originalAxis.x));
test(approxEqual(angle, decimal(PI/4.0), decimal(10e-6))); rp3d_test(approxEqual(angle, decimal(PI/4.0), decimal(10e-6)));
// Test the method that returns the corresponding matrix // Test the method that returns the corresponding matrix
Matrix3x3 matrix = mQuaternion1.getMatrix(); Matrix3x3 matrix = mQuaternion1.getMatrix();
Vector3 vector(56, -2, 82); Vector3 vector(56, -2, 82);
Vector3 vector1 = matrix * vector; Vector3 vector1 = matrix * vector;
Vector3 vector2 = mQuaternion1 * vector; Vector3 vector2 = mQuaternion1 * vector;
test(approxEqual(vector1.x, vector2.x, decimal(10e-6))); rp3d_test(approxEqual(vector1.x, vector2.x, decimal(10e-6)));
test(approxEqual(vector1.y, vector2.y, decimal(10e-6))); rp3d_test(approxEqual(vector1.y, vector2.y, decimal(10e-6)));
test(approxEqual(vector1.z, vector2.z, decimal(10e-6))); rp3d_test(approxEqual(vector1.z, vector2.z, decimal(10e-6)));
// Test slerp method // Test slerp method
Quaternion quatStart = quaternion1.getUnit(); Quaternion quatStart = quaternion1.getUnit();
Quaternion quatEnd = quaternion2.getUnit(); Quaternion quatEnd = quaternion2.getUnit();
Quaternion test1 = Quaternion::slerp(quatStart, quatEnd, 0.0); Quaternion test1 = Quaternion::slerp(quatStart, quatEnd, 0.0);
Quaternion test2 = Quaternion::slerp(quatStart, quatEnd, 1.0); Quaternion test2 = Quaternion::slerp(quatStart, quatEnd, 1.0);
test(test1 == quatStart); rp3d_test(test1 == quatStart);
test(test2 == quatEnd); rp3d_test(test2 == quatEnd);
decimal sinA = sin(decimal(PI/4.0)); decimal sinA = sin(decimal(PI/4.0));
decimal cosA = cos(decimal(PI/4.0)); decimal cosA = cos(decimal(PI/4.0));
Quaternion quat(sinA, 0, 0, cosA); Quaternion quat(sinA, 0, 0, cosA);
Quaternion test3 = Quaternion::slerp(mIdentity, quat, decimal(0.5)); Quaternion test3 = Quaternion::slerp(mIdentity, quat, decimal(0.5));
test(approxEqual(test3.x, sin(decimal(PI/8.0)))); rp3d_test(approxEqual(test3.x, sin(decimal(PI/8.0))));
test(approxEqual(test3.y, 0.0)); rp3d_test(approxEqual(test3.y, 0.0));
test(approxEqual(test3.z, 0.0)); rp3d_test(approxEqual(test3.z, 0.0));
test(approxEqual(test3.w, cos(decimal(PI/8.0)), decimal(10e-6))); rp3d_test(approxEqual(test3.w, cos(decimal(PI/8.0)), decimal(10e-6)));
} }
/// Test overloaded operators /// Test overloaded operators
@ -226,43 +226,43 @@ class TestQuaternion : public Test {
Quaternion test1 = quat1 + quat2; Quaternion test1 = quat1 + quat2;
Quaternion test11(-6, 52, 2, 8); Quaternion test11(-6, 52, 2, 8);
test11 += quat1; test11 += quat1;
test(test1 == Quaternion(2, 12, 10, 13)); rp3d_test(test1 == Quaternion(2, 12, 10, 13));
test(test11 == Quaternion(-2, 57, 4, 18)); rp3d_test(test11 == Quaternion(-2, 57, 4, 18));
// Test substraction // Test substraction
Quaternion test2 = quat1 - quat2; Quaternion test2 = quat1 - quat2;
Quaternion test22(-73, 62, 25, 9); Quaternion test22(-73, 62, 25, 9);
test22 -= quat1; test22 -= quat1;
test(test2 == Quaternion(6, -2, -6, 7)); rp3d_test(test2 == Quaternion(6, -2, -6, 7));
test(test22 == Quaternion(-77, 57, 23, -1)); rp3d_test(test22 == Quaternion(-77, 57, 23, -1));
// Test multiplication with a number // Test multiplication with a number
Quaternion test3 = quat1 * 3.0; Quaternion test3 = quat1 * 3.0;
test(test3 == Quaternion(12, 15, 6, 30)); rp3d_test(test3 == Quaternion(12, 15, 6, 30));
// Test multiplication between two quaternions // Test multiplication between two quaternions
Quaternion test4 = quat1 * quat2; Quaternion test4 = quat1 * quat2;
Quaternion test5 = mQuaternion1 * mIdentity; Quaternion test5 = mQuaternion1 * mIdentity;
test(test4 == Quaternion(18, 49, 124, -13)); rp3d_test(test4 == Quaternion(18, 49, 124, -13));
test(test5 == mQuaternion1); rp3d_test(test5 == mQuaternion1);
// Test multiplication between a quaternion and a point // Test multiplication between a quaternion and a point
Vector3 point(5, -24, 563); Vector3 point(5, -24, 563);
Vector3 vector1 = mIdentity * point; Vector3 vector1 = mIdentity * point;
Vector3 vector2 = mQuaternion1 * point; Vector3 vector2 = mQuaternion1 * point;
Vector3 testVector2 = mQuaternion1.getMatrix() * point; Vector3 testVector2 = mQuaternion1.getMatrix() * point;
test(vector1 == point); rp3d_test(vector1 == point);
test(approxEqual(vector2.x, testVector2.x, decimal(10e-5))); rp3d_test(approxEqual(vector2.x, testVector2.x, decimal(10e-5)));
test(approxEqual(vector2.y, testVector2.y, decimal(10e-5))); rp3d_test(approxEqual(vector2.y, testVector2.y, decimal(10e-5)));
test(approxEqual(vector2.z, testVector2.z, decimal(10e-5))); rp3d_test(approxEqual(vector2.z, testVector2.z, decimal(10e-5)));
// Test assignment operator // Test assignment operator
Quaternion quaternion; Quaternion quaternion;
quaternion = mQuaternion1; quaternion = mQuaternion1;
test(quaternion == mQuaternion1); rp3d_test(quaternion == mQuaternion1);
// Test equality operator // Test equality operator
test(mQuaternion1 == mQuaternion1); rp3d_test(mQuaternion1 == mQuaternion1);
} }
}; };

View File

@ -90,25 +90,25 @@ class TestTransform : public Test {
Transform transform1(Vector3(1, 2, 3), Quaternion(6, 7, 8, 9)); Transform transform1(Vector3(1, 2, 3), Quaternion(6, 7, 8, 9));
Transform transform2(Vector3(4, 5, 6), Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1)); Transform transform2(Vector3(4, 5, 6), Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1));
Transform transform3(transform1); Transform transform3(transform1);
test(transform1.getPosition() == Vector3(1, 2, 3)); rp3d_test(transform1.getPosition() == Vector3(1, 2, 3));
test(transform1.getOrientation() == Quaternion(6, 7, 8, 9)); rp3d_test(transform1.getOrientation() == Quaternion(6, 7, 8, 9));
test(transform2.getPosition() == Vector3(4, 5, 6)); rp3d_test(transform2.getPosition() == Vector3(4, 5, 6));
test(transform2.getOrientation() == Quaternion::identity()); rp3d_test(transform2.getOrientation() == Quaternion::identity());
test(transform3 == transform1); rp3d_test(transform3 == transform1);
} }
/// Test getter and setter /// Test getter and setter
void testGetSet() { void testGetSet() {
test(mIdentityTransform.getPosition() == Vector3(0, 0, 0)); rp3d_test(mIdentityTransform.getPosition() == Vector3(0, 0, 0));
test(mIdentityTransform.getOrientation() == Quaternion::identity()); rp3d_test(mIdentityTransform.getOrientation() == Quaternion::identity());
Transform transform; Transform transform;
transform.setPosition(Vector3(5, 7, 8)); transform.setPosition(Vector3(5, 7, 8));
transform.setOrientation(Quaternion(1, 2, 3, 1)); transform.setOrientation(Quaternion(1, 2, 3, 1));
test(transform.getPosition() == Vector3(5, 7, 8)); rp3d_test(transform.getPosition() == Vector3(5, 7, 8));
test(transform.getOrientation() == Quaternion(1, 2, 3, 1)); rp3d_test(transform.getOrientation() == Quaternion(1, 2, 3, 1));
transform.setToIdentity(); transform.setToIdentity();
test(transform.getPosition() == Vector3(0, 0, 0)); rp3d_test(transform.getPosition() == Vector3(0, 0, 0));
test(transform.getOrientation() == Quaternion::identity()); rp3d_test(transform.getOrientation() == Quaternion::identity());
} }
/// Test the inverse /// Test the inverse
@ -117,9 +117,9 @@ class TestTransform : public Test {
Vector3 vector(2, 3, 4); Vector3 vector(2, 3, 4);
Vector3 tempVector = mTransform1 * vector; Vector3 tempVector = mTransform1 * vector;
Vector3 tempVector2 = inverseTransform * tempVector; Vector3 tempVector2 = inverseTransform * tempVector;
test(approxEqual(tempVector2.x, vector.x, decimal(10e-6))); rp3d_test(approxEqual(tempVector2.x, vector.x, decimal(10e-6)));
test(approxEqual(tempVector2.y, vector.y, decimal(10e-6))); rp3d_test(approxEqual(tempVector2.y, vector.y, decimal(10e-6)));
test(approxEqual(tempVector2.z, vector.z, decimal(10e-6))); rp3d_test(approxEqual(tempVector2.z, vector.z, decimal(10e-6)));
} }
/// Test methods to set and get transform matrix from and to OpenGL /// Test methods to set and get transform matrix from and to OpenGL
@ -137,30 +137,30 @@ class TestTransform : public Test {
transform.setFromOpenGL(openglMatrix); transform.setFromOpenGL(openglMatrix);
decimal openglMatrix2[16]; decimal openglMatrix2[16];
transform.getOpenGLMatrix(openglMatrix2); transform.getOpenGLMatrix(openglMatrix2);
test(approxEqual(openglMatrix2[0], orientation[0][0])); rp3d_test(approxEqual(openglMatrix2[0], orientation[0][0]));
test(approxEqual(openglMatrix2[1], orientation[1][0])); rp3d_test(approxEqual(openglMatrix2[1], orientation[1][0]));
test(approxEqual(openglMatrix2[2], orientation[2][0])); rp3d_test(approxEqual(openglMatrix2[2], orientation[2][0]));
test(approxEqual(openglMatrix2[3], 0)); rp3d_test(approxEqual(openglMatrix2[3], 0));
test(approxEqual(openglMatrix2[4], orientation[0][1])); rp3d_test(approxEqual(openglMatrix2[4], orientation[0][1]));
test(approxEqual(openglMatrix2[5], orientation[1][1])); rp3d_test(approxEqual(openglMatrix2[5], orientation[1][1]));
test(approxEqual(openglMatrix2[6], orientation[2][1])); rp3d_test(approxEqual(openglMatrix2[6], orientation[2][1]));
test(approxEqual(openglMatrix2[7], 0)); rp3d_test(approxEqual(openglMatrix2[7], 0));
test(approxEqual(openglMatrix2[8], orientation[0][2])); rp3d_test(approxEqual(openglMatrix2[8], orientation[0][2]));
test(approxEqual(openglMatrix2[9], orientation[1][2])); rp3d_test(approxEqual(openglMatrix2[9], orientation[1][2]));
test(approxEqual(openglMatrix2[10], orientation[2][2])); rp3d_test(approxEqual(openglMatrix2[10], orientation[2][2]));
test(approxEqual(openglMatrix2[11], 0)); rp3d_test(approxEqual(openglMatrix2[11], 0));
test(approxEqual(openglMatrix2[12], position.x)); rp3d_test(approxEqual(openglMatrix2[12], position.x));
test(approxEqual(openglMatrix2[13], position.y)); rp3d_test(approxEqual(openglMatrix2[13], position.y));
test(approxEqual(openglMatrix2[14], position.z)); rp3d_test(approxEqual(openglMatrix2[14], position.z));
test(approxEqual(openglMatrix2[15], 1)); rp3d_test(approxEqual(openglMatrix2[15], 1));
} }
/// Test the method to interpolate transforms /// Test the method to interpolate transforms
void testInterpolateTransform() { void testInterpolateTransform() {
Transform transformStart = Transform::interpolateTransforms(mTransform1, mTransform2,0); Transform transformStart = Transform::interpolateTransforms(mTransform1, mTransform2,0);
Transform transformEnd = Transform::interpolateTransforms(mTransform1, mTransform2,1); Transform transformEnd = Transform::interpolateTransforms(mTransform1, mTransform2,1);
test(transformStart == mTransform1); rp3d_test(transformStart == mTransform1);
test(transformEnd == mTransform2); rp3d_test(transformEnd == mTransform2);
decimal sinA = sin(PI/3.0f); decimal sinA = sin(PI/3.0f);
decimal cosA = cos(PI/3.0f); decimal cosA = cos(PI/3.0f);
@ -171,46 +171,46 @@ class TestTransform : public Test {
Transform transform = Transform::interpolateTransforms(transform1, transform2, 0.5); Transform transform = Transform::interpolateTransforms(transform1, transform2, 0.5);
Vector3 position = transform.getPosition(); Vector3 position = transform.getPosition();
Quaternion orientation = transform.getOrientation(); Quaternion orientation = transform.getOrientation();
test(approxEqual(position.x, 6)); rp3d_test(approxEqual(position.x, 6));
test(approxEqual(position.y, 8)); rp3d_test(approxEqual(position.y, 8));
test(approxEqual(position.z, 11)); rp3d_test(approxEqual(position.z, 11));
test(approxEqual(orientation.x, sinB)); rp3d_test(approxEqual(orientation.x, sinB));
test(approxEqual(orientation.y, sinB)); rp3d_test(approxEqual(orientation.y, sinB));
test(approxEqual(orientation.z, sinB)); rp3d_test(approxEqual(orientation.z, sinB));
test(approxEqual(orientation.w, cosB)); rp3d_test(approxEqual(orientation.w, cosB));
} }
/// Test the identity methods /// Test the identity methods
void testIdentity() { void testIdentity() {
Transform transform = Transform::identity(); Transform transform = Transform::identity();
test(transform.getPosition() == Vector3(0, 0, 0)); rp3d_test(transform.getPosition() == Vector3(0, 0, 0));
test(transform.getOrientation() == Quaternion::identity()); rp3d_test(transform.getOrientation() == Quaternion::identity());
Transform transform2(Vector3(5, 6, 2), Quaternion(3, 5, 1, 6)); Transform transform2(Vector3(5, 6, 2), Quaternion(3, 5, 1, 6));
transform2.setToIdentity(); transform2.setToIdentity();
test(transform2.getPosition() == Vector3(0, 0, 0)); rp3d_test(transform2.getPosition() == Vector3(0, 0, 0));
test(transform2.getOrientation() == Quaternion::identity()); rp3d_test(transform2.getOrientation() == Quaternion::identity());
} }
/// Test the overloaded operators /// Test the overloaded operators
void testOperators() { void testOperators() {
// Equality, inequality operator // Equality, inequality operator
test(mTransform1 == mTransform1); rp3d_test(mTransform1 == mTransform1);
test(mTransform1 != mTransform2); rp3d_test(mTransform1 != mTransform2);
// Assignment operator // Assignment operator
Transform transform; Transform transform;
transform = mTransform1; transform = mTransform1;
test(transform == mTransform1); rp3d_test(transform == mTransform1);
// Multiplication // Multiplication
Vector3 vector(7, 53, 5); Vector3 vector(7, 53, 5);
Vector3 vector2 = mTransform2 * (mTransform1 * vector); Vector3 vector2 = mTransform2 * (mTransform1 * vector);
Vector3 vector3 = (mTransform2 * mTransform1) * vector; Vector3 vector3 = (mTransform2 * mTransform1) * vector;
test(approxEqual(vector2.x, vector3.x, decimal(10e-6))); rp3d_test(approxEqual(vector2.x, vector3.x, decimal(10e-6)));
test(approxEqual(vector2.y, vector3.y, decimal(10e-6))); rp3d_test(approxEqual(vector2.y, vector3.y, decimal(10e-6)));
test(approxEqual(vector2.z, vector3.z, decimal(10e-6))); rp3d_test(approxEqual(vector2.z, vector3.z, decimal(10e-6)));
} }
}; };

View File

@ -69,46 +69,46 @@ class TestVector2 : public Test {
void testConstructors() { void testConstructors() {
// Test constructor // Test constructor
test(mVectorZero.x == 0.0); rp3d_test(mVectorZero.x == 0.0);
test(mVectorZero.y == 0.0); rp3d_test(mVectorZero.y == 0.0);
test(mVector34.x == 3.0); rp3d_test(mVector34.x == 3.0);
test(mVector34.y == 4.0); rp3d_test(mVector34.y == 4.0);
// Test copy-constructor // Test copy-constructor
Vector2 newVector(mVector34); Vector2 newVector(mVector34);
test(newVector.x == 3.0); rp3d_test(newVector.x == 3.0);
test(newVector.y == 4.0); rp3d_test(newVector.y == 4.0);
// Test method to set values // Test method to set values
Vector2 newVector2; Vector2 newVector2;
newVector2.setAllValues(decimal(6.1), decimal(7.2)); newVector2.setAllValues(decimal(6.1), decimal(7.2));
test(approxEqual(newVector2.x, decimal(6.1))); rp3d_test(approxEqual(newVector2.x, decimal(6.1)));
test(approxEqual(newVector2.y, decimal(7.2))); rp3d_test(approxEqual(newVector2.y, decimal(7.2)));
// Test method to set to zero // Test method to set to zero
newVector2.setToZero(); newVector2.setToZero();
test(newVector2 == Vector2(0, 0)); rp3d_test(newVector2 == Vector2(0, 0));
} }
/// Test the length, unit vector and normalize methods /// Test the length, unit vector and normalize methods
void testLengthMethods() { void testLengthMethods() {
// Test length methods // Test length methods
test(mVectorZero.length() == 0.0); rp3d_test(mVectorZero.length() == 0.0);
test(mVectorZero.lengthSquare() == 0.0); rp3d_test(mVectorZero.lengthSquare() == 0.0);
test(Vector2(1, 0).length() == 1.0); rp3d_test(Vector2(1, 0).length() == 1.0);
test(Vector2(0, 1).length() == 1.0); rp3d_test(Vector2(0, 1).length() == 1.0);
test(mVector34.lengthSquare() == 25.0); rp3d_test(mVector34.lengthSquare() == 25.0);
// Test unit vector methods // Test unit vector methods
test(Vector2(1, 0).isUnit()); rp3d_test(Vector2(1, 0).isUnit());
test(Vector2(0, 1).isUnit()); rp3d_test(Vector2(0, 1).isUnit());
test(!mVector34.isUnit()); rp3d_test(!mVector34.isUnit());
test(Vector2(5, 0).getUnit() == Vector2(1, 0)); rp3d_test(Vector2(5, 0).getUnit() == Vector2(1, 0));
test(Vector2(0, 5).getUnit() == Vector2(0, 1)); rp3d_test(Vector2(0, 5).getUnit() == Vector2(0, 1));
test(!mVector34.isZero()); rp3d_test(!mVector34.isZero());
test(mVectorZero.isZero()); rp3d_test(mVectorZero.isZero());
// Test normalization method // Test normalization method
Vector2 mVector10(1, 0); Vector2 mVector10(1, 0);
@ -119,100 +119,100 @@ class TestVector2 : public Test {
mVector01.normalize(); mVector01.normalize();
mVector50.normalize(); mVector50.normalize();
mVector05.normalize(); mVector05.normalize();
test(mVector10 == Vector2(1, 0)); rp3d_test(mVector10 == Vector2(1, 0));
test(mVector01 == Vector2(0, 1)); rp3d_test(mVector01 == Vector2(0, 1));
test(mVector50 == Vector2(1, 0)); rp3d_test(mVector50 == Vector2(1, 0));
test(mVector05 == Vector2(0, 1)); rp3d_test(mVector05 == Vector2(0, 1));
} }
/// Test the dot product /// Test the dot product
void testDotProduct() { void testDotProduct() {
// Test the dot product // Test the dot product
test(Vector2(5, 0).dot(Vector2(0, 8)) == 0); rp3d_test(Vector2(5, 0).dot(Vector2(0, 8)) == 0);
test(Vector2(5, 8).dot(Vector2(0, 0)) == 0); rp3d_test(Vector2(5, 8).dot(Vector2(0, 0)) == 0);
test(Vector2(12, 45).dot(Vector2(0, 0)) == 0); rp3d_test(Vector2(12, 45).dot(Vector2(0, 0)) == 0);
test(Vector2(5, 7).dot(Vector2(5, 7)) == 74); rp3d_test(Vector2(5, 7).dot(Vector2(5, 7)) == 74);
test(Vector2(3, 6).dot(Vector2(-3, -6)) == -45); rp3d_test(Vector2(3, 6).dot(Vector2(-3, -6)) == -45);
test(Vector2(2, 3).dot(Vector2(-7, 4)) == -2); rp3d_test(Vector2(2, 3).dot(Vector2(-7, 4)) == -2);
test(Vector2(4, 3).dot(Vector2(8, 9)) == 59); rp3d_test(Vector2(4, 3).dot(Vector2(8, 9)) == 59);
} }
/// Test others methods /// Test others methods
void testOthersMethods() { void testOthersMethods() {
// Test the method that returns the absolute vector // Test the method that returns the absolute vector
test(Vector2(4, 5).getAbsoluteVector() == Vector2(4, 5)); rp3d_test(Vector2(4, 5).getAbsoluteVector() == Vector2(4, 5));
test(Vector2(-7, -24).getAbsoluteVector() == Vector2(7, 24)); rp3d_test(Vector2(-7, -24).getAbsoluteVector() == Vector2(7, 24));
// Test the method that returns the minimal element // Test the method that returns the minimal element
test(Vector2(6, 35).getMinAxis() == 0); rp3d_test(Vector2(6, 35).getMinAxis() == 0);
test(Vector2(564, 45).getMinAxis() == 1); rp3d_test(Vector2(564, 45).getMinAxis() == 1);
test(Vector2(98, 23).getMinAxis() == 1); rp3d_test(Vector2(98, 23).getMinAxis() == 1);
test(Vector2(-53, -25).getMinAxis() == 0); rp3d_test(Vector2(-53, -25).getMinAxis() == 0);
// Test the method that returns the maximal element // Test the method that returns the maximal element
test(Vector2(6, 35).getMaxAxis() == 1); rp3d_test(Vector2(6, 35).getMaxAxis() == 1);
test(Vector2(7, 537).getMaxAxis() == 1); rp3d_test(Vector2(7, 537).getMaxAxis() == 1);
test(Vector2(98, 23).getMaxAxis() == 0); rp3d_test(Vector2(98, 23).getMaxAxis() == 0);
test(Vector2(-53, -25).getMaxAxis() == 1); rp3d_test(Vector2(-53, -25).getMaxAxis() == 1);
// Test the methot that return a max/min vector // Test the methot that return a max/min vector
Vector2 vec1(-5, 4); Vector2 vec1(-5, 4);
Vector2 vec2(-8, 6); Vector2 vec2(-8, 6);
test(Vector2::min(vec1, vec2) == Vector2(-8, 4)); rp3d_test(Vector2::min(vec1, vec2) == Vector2(-8, 4));
test(Vector2::max(vec1, vec2) == Vector2(-5, 6)); rp3d_test(Vector2::max(vec1, vec2) == Vector2(-5, 6));
} }
/// Test the operators /// Test the operators
void testOperators() { void testOperators() {
// Test the [] operator // Test the [] operator
test(mVector34[0] == 3); rp3d_test(mVector34[0] == 3);
test(mVector34[1] == 4); rp3d_test(mVector34[1] == 4);
// Assignment operator // Assignment operator
Vector2 newVector(6, 4); Vector2 newVector(6, 4);
newVector = Vector2(7, 8); newVector = Vector2(7, 8);
test(newVector == Vector2(7, 8)); rp3d_test(newVector == Vector2(7, 8));
// Equality, inequality operators // Equality, inequality operators
test(Vector2(5, 7) == Vector2(5, 7)); rp3d_test(Vector2(5, 7) == Vector2(5, 7));
test(Vector2(63, 64) != Vector2(63, 84)); rp3d_test(Vector2(63, 64) != Vector2(63, 84));
test(Vector2(63, 64) != Vector2(12, 64)); rp3d_test(Vector2(63, 64) != Vector2(12, 64));
// Addition, substraction // Addition, substraction
Vector2 vector1(6, 33); Vector2 vector1(6, 33);
Vector2 vector2(7, 68); Vector2 vector2(7, 68);
test(Vector2(63, 24) + Vector2(3, 4) == Vector2(66, 28)); rp3d_test(Vector2(63, 24) + Vector2(3, 4) == Vector2(66, 28));
test(Vector2(63, 24) - Vector2(3, 4) == Vector2(60, 20)); rp3d_test(Vector2(63, 24) - Vector2(3, 4) == Vector2(60, 20));
vector1 += Vector2(5, 10); vector1 += Vector2(5, 10);
vector2 -= Vector2(10, 21); vector2 -= Vector2(10, 21);
test(vector1 == Vector2(11, 43)); rp3d_test(vector1 == Vector2(11, 43));
test(vector2 == Vector2(-3, 47)); rp3d_test(vector2 == Vector2(-3, 47));
// Multiplication, division // Multiplication, division
Vector2 vector3(6, 33); Vector2 vector3(6, 33);
Vector2 vector4(15, 60); Vector2 vector4(15, 60);
test(Vector2(63, 24) * 3 == Vector2(189, 72)); rp3d_test(Vector2(63, 24) * 3 == Vector2(189, 72));
test(3 * Vector2(63, 24) == Vector2(189, 72)); rp3d_test(3 * Vector2(63, 24) == Vector2(189, 72));
test(Vector2(14, 8) / 2 == Vector2(7, 4)); rp3d_test(Vector2(14, 8) / 2 == Vector2(7, 4));
vector3 *= 10; vector3 *= 10;
vector4 /= 3; vector4 /= 3;
test(vector3 == Vector2(60, 330)); rp3d_test(vector3 == Vector2(60, 330));
test(vector4 == Vector2(5, 20)); rp3d_test(vector4 == Vector2(5, 20));
Vector2 vector5(21, 80); Vector2 vector5(21, 80);
Vector2 vector6(7, 10); Vector2 vector6(7, 10);
Vector2 vector7 = vector5 * vector6; Vector2 vector7 = vector5 * vector6;
test(vector7 == Vector2(147, 800)); rp3d_test(vector7 == Vector2(147, 800));
Vector2 vector8 = vector5 / vector6; Vector2 vector8 = vector5 / vector6;
test(approxEqual(vector8.x, 3)); rp3d_test(approxEqual(vector8.x, 3));
test(approxEqual(vector8.y, 8)); rp3d_test(approxEqual(vector8.y, 8));
// Negative operator // Negative operator
Vector2 vector9(-34, 5); Vector2 vector9(-34, 5);
Vector2 negative = -vector9; Vector2 negative = -vector9;
test(negative == Vector2(34, -5)); rp3d_test(negative == Vector2(34, -5));
} }
}; };

View File

@ -69,53 +69,53 @@ class TestVector3 : public Test {
void testConstructors() { void testConstructors() {
// Test constructor // Test constructor
test(mVectorZero.x == 0.0); rp3d_test(mVectorZero.x == 0.0);
test(mVectorZero.y == 0.0); rp3d_test(mVectorZero.y == 0.0);
test(mVectorZero.z == 0.0); rp3d_test(mVectorZero.z == 0.0);
test(mVector345.x == 3.0); rp3d_test(mVector345.x == 3.0);
test(mVector345.y == 4.0); rp3d_test(mVector345.y == 4.0);
test(mVector345.z == 5.0); rp3d_test(mVector345.z == 5.0);
// Test copy-constructor // Test copy-constructor
Vector3 newVector(mVector345); Vector3 newVector(mVector345);
test(newVector.x == 3.0); rp3d_test(newVector.x == 3.0);
test(newVector.y == 4.0); rp3d_test(newVector.y == 4.0);
test(newVector.z == 5.0); rp3d_test(newVector.z == 5.0);
// Test method to set values // Test method to set values
Vector3 newVector2; Vector3 newVector2;
newVector2.setAllValues(decimal(6.1), decimal(7.2), decimal(8.6)); newVector2.setAllValues(decimal(6.1), decimal(7.2), decimal(8.6));
test(approxEqual(newVector2.x, decimal(6.1))); rp3d_test(approxEqual(newVector2.x, decimal(6.1)));
test(approxEqual(newVector2.y, decimal(7.2))); rp3d_test(approxEqual(newVector2.y, decimal(7.2)));
test(approxEqual(newVector2.z, decimal(8.6))); rp3d_test(approxEqual(newVector2.z, decimal(8.6)));
// Test method to set to zero // Test method to set to zero
newVector2.setToZero(); newVector2.setToZero();
test(newVector2 == Vector3(0, 0, 0)); rp3d_test(newVector2 == Vector3(0, 0, 0));
} }
/// Test the length, unit vector and normalize methods /// Test the length, unit vector and normalize methods
void testLengthMethods() { void testLengthMethods() {
// Test length methods // Test length methods
test(mVectorZero.length() == 0.0); rp3d_test(mVectorZero.length() == 0.0);
test(mVectorZero.lengthSquare() == 0.0); rp3d_test(mVectorZero.lengthSquare() == 0.0);
test(Vector3(1, 0, 0).length() == 1.0); rp3d_test(Vector3(1, 0, 0).length() == 1.0);
test(Vector3(0, 1, 0).length() == 1.0); rp3d_test(Vector3(0, 1, 0).length() == 1.0);
test(Vector3(0, 0, 1).length() == 1.0); rp3d_test(Vector3(0, 0, 1).length() == 1.0);
test(mVector345.lengthSquare() == 50.0); rp3d_test(mVector345.lengthSquare() == 50.0);
// Test unit vector methods // Test unit vector methods
test(Vector3(1, 0, 0).isUnit()); rp3d_test(Vector3(1, 0, 0).isUnit());
test(Vector3(0, 1, 0).isUnit()); rp3d_test(Vector3(0, 1, 0).isUnit());
test(Vector3(0, 0, 1).isUnit()); rp3d_test(Vector3(0, 0, 1).isUnit());
test(!mVector345.isUnit()); rp3d_test(!mVector345.isUnit());
test(Vector3(5, 0, 0).getUnit() == Vector3(1, 0, 0)); rp3d_test(Vector3(5, 0, 0).getUnit() == Vector3(1, 0, 0));
test(Vector3(0, 5, 0).getUnit() == Vector3(0, 1, 0)); rp3d_test(Vector3(0, 5, 0).getUnit() == Vector3(0, 1, 0));
test(Vector3(0, 0, 5).getUnit() == Vector3(0, 0, 1)); rp3d_test(Vector3(0, 0, 5).getUnit() == Vector3(0, 0, 1));
test(!mVector345.isZero()); rp3d_test(!mVector345.isZero());
test(mVectorZero.isZero()); rp3d_test(mVectorZero.isZero());
// Test normalization method // Test normalization method
Vector3 mVector100(1, 0, 0); Vector3 mVector100(1, 0, 0);
@ -130,114 +130,114 @@ class TestVector3 : public Test {
mVector500.normalize(); mVector500.normalize();
mVector050.normalize(); mVector050.normalize();
mVector005.normalize(); mVector005.normalize();
test(mVector100 == Vector3(1, 0, 0)); rp3d_test(mVector100 == Vector3(1, 0, 0));
test(mVector010 == Vector3(0, 1, 0)); rp3d_test(mVector010 == Vector3(0, 1, 0));
test(mVector001 == Vector3(0, 0, 1)); rp3d_test(mVector001 == Vector3(0, 0, 1));
test(mVector500 == Vector3(1, 0, 0)); rp3d_test(mVector500 == Vector3(1, 0, 0));
test(mVector050 == Vector3(0, 1, 0)); rp3d_test(mVector050 == Vector3(0, 1, 0));
test(mVector005 == Vector3(0, 0, 1)); rp3d_test(mVector005 == Vector3(0, 0, 1));
} }
/// Test the dot and cross products /// Test the dot and cross products
void testDotCrossProducts() { void testDotCrossProducts() {
// Test the dot product // Test the dot product
test(Vector3(5, 0, 0).dot(Vector3(0, 8, 0)) == 0); rp3d_test(Vector3(5, 0, 0).dot(Vector3(0, 8, 0)) == 0);
test(Vector3(5, 8, 0).dot(Vector3(0, 0, 6)) == 0); rp3d_test(Vector3(5, 8, 0).dot(Vector3(0, 0, 6)) == 0);
test(Vector3(12, 45, 83).dot(Vector3(0, 0, 0)) == 0); rp3d_test(Vector3(12, 45, 83).dot(Vector3(0, 0, 0)) == 0);
test(Vector3(5, 7, 8).dot(Vector3(5, 7, 8)) == 138); rp3d_test(Vector3(5, 7, 8).dot(Vector3(5, 7, 8)) == 138);
test(Vector3(3, 6, 78).dot(Vector3(-3, -6, -78)) == -6129); rp3d_test(Vector3(3, 6, 78).dot(Vector3(-3, -6, -78)) == -6129);
test(Vector3(2, 3, 5).dot(Vector3(2, 3, 5)) == 38); rp3d_test(Vector3(2, 3, 5).dot(Vector3(2, 3, 5)) == 38);
test(Vector3(4, 3, 2).dot(Vector3(8, 9, 10)) == 79); rp3d_test(Vector3(4, 3, 2).dot(Vector3(8, 9, 10)) == 79);
// Test the cross product // Test the cross product
test(Vector3(0, 0, 0).cross(Vector3(0, 0, 0)) == Vector3(0, 0, 0)); rp3d_test(Vector3(0, 0, 0).cross(Vector3(0, 0, 0)) == Vector3(0, 0, 0));
test(Vector3(6, 7, 2).cross(Vector3(6, 7, 2)) == Vector3(0, 0, 0)); rp3d_test(Vector3(6, 7, 2).cross(Vector3(6, 7, 2)) == Vector3(0, 0, 0));
test(Vector3(1, 0, 0).cross(Vector3(0, 1, 0)) == Vector3(0, 0, 1)); rp3d_test(Vector3(1, 0, 0).cross(Vector3(0, 1, 0)) == Vector3(0, 0, 1));
test(Vector3(0, 1, 0).cross(Vector3(0, 0, 1)) == Vector3(1, 0, 0)); rp3d_test(Vector3(0, 1, 0).cross(Vector3(0, 0, 1)) == Vector3(1, 0, 0));
test(Vector3(0, 0, 1).cross(Vector3(0, 1, 0)) == Vector3(-1, 0, 0)); rp3d_test(Vector3(0, 0, 1).cross(Vector3(0, 1, 0)) == Vector3(-1, 0, 0));
test(Vector3(4, 7, 24).cross(Vector3(8, 13, 11)) == Vector3(-235, 148, -4)); rp3d_test(Vector3(4, 7, 24).cross(Vector3(8, 13, 11)) == Vector3(-235, 148, -4));
test(Vector3(-4, 42, -2).cross(Vector3(35, 7, -21)) == Vector3(-868, -154, -1498)); rp3d_test(Vector3(-4, 42, -2).cross(Vector3(35, 7, -21)) == Vector3(-868, -154, -1498));
} }
/// Test others methods /// Test others methods
void testOthersMethods() { void testOthersMethods() {
// Test the method that returns the absolute vector // Test the method that returns the absolute vector
test(Vector3(4, 5, 6).getAbsoluteVector() == Vector3(4, 5, 6)); rp3d_test(Vector3(4, 5, 6).getAbsoluteVector() == Vector3(4, 5, 6));
test(Vector3(-7, -24, -12).getAbsoluteVector() == Vector3(7, 24, 12)); rp3d_test(Vector3(-7, -24, -12).getAbsoluteVector() == Vector3(7, 24, 12));
// Test the method that returns the minimal element // Test the method that returns the minimal element
test(Vector3(6, 35, 82).getMinAxis() == 0); rp3d_test(Vector3(6, 35, 82).getMinAxis() == 0);
test(Vector3(564, 45, 532).getMinAxis() == 1); rp3d_test(Vector3(564, 45, 532).getMinAxis() == 1);
test(Vector3(98, 23, 3).getMinAxis() == 2); rp3d_test(Vector3(98, 23, 3).getMinAxis() == 2);
test(Vector3(-53, -25, -63).getMinAxis() == 2); rp3d_test(Vector3(-53, -25, -63).getMinAxis() == 2);
// Test the method that returns the maximal element // Test the method that returns the maximal element
test(Vector3(6, 35, 82).getMaxAxis() == 2); rp3d_test(Vector3(6, 35, 82).getMaxAxis() == 2);
test(Vector3(7, 533, 36).getMaxAxis() == 1); rp3d_test(Vector3(7, 533, 36).getMaxAxis() == 1);
test(Vector3(98, 23, 3).getMaxAxis() == 0); rp3d_test(Vector3(98, 23, 3).getMaxAxis() == 0);
test(Vector3(-53, -25, -63).getMaxAxis() == 1); rp3d_test(Vector3(-53, -25, -63).getMaxAxis() == 1);
// Test the methot that return a max/min vector // Test the methot that return a max/min vector
Vector3 vec1(-5, 4, 2); Vector3 vec1(-5, 4, 2);
Vector3 vec2(-8, 6, -1); Vector3 vec2(-8, 6, -1);
test(Vector3::min(vec1, vec2) == Vector3(-8, 4, -1)); rp3d_test(Vector3::min(vec1, vec2) == Vector3(-8, 4, -1));
test(Vector3::max(vec1, vec2) == Vector3(-5, 6, 2)); rp3d_test(Vector3::max(vec1, vec2) == Vector3(-5, 6, 2));
} }
/// Test the operators /// Test the operators
void testOperators() { void testOperators() {
// Test the [] operator // Test the [] operator
test(mVector345[0] == 3); rp3d_test(mVector345[0] == 3);
test(mVector345[1] == 4); rp3d_test(mVector345[1] == 4);
test(mVector345[2] == 5); rp3d_test(mVector345[2] == 5);
// Assignment operator // Assignment operator
Vector3 newVector(6, 4, 2); Vector3 newVector(6, 4, 2);
newVector = Vector3(7, 8, 9); newVector = Vector3(7, 8, 9);
test(newVector == Vector3(7, 8, 9)); rp3d_test(newVector == Vector3(7, 8, 9));
// Equality, inequality operators // Equality, inequality operators
test(Vector3(5, 7, 3) == Vector3(5, 7, 3)); rp3d_test(Vector3(5, 7, 3) == Vector3(5, 7, 3));
test(Vector3(63, 64, 24) != Vector3(63, 64, 5)); rp3d_test(Vector3(63, 64, 24) != Vector3(63, 64, 5));
test(Vector3(63, 64, 24) != Vector3(12, 64, 24)); rp3d_test(Vector3(63, 64, 24) != Vector3(12, 64, 24));
test(Vector3(63, 64, 24) != Vector3(63, 8, 24)); rp3d_test(Vector3(63, 64, 24) != Vector3(63, 8, 24));
// Addition, substraction // Addition, substraction
Vector3 vector1(6, 33, 62); Vector3 vector1(6, 33, 62);
Vector3 vector2(7, 68, 35); Vector3 vector2(7, 68, 35);
test(Vector3(63, 24, 5) + Vector3(3, 4, 2) == Vector3(66, 28, 7)); rp3d_test(Vector3(63, 24, 5) + Vector3(3, 4, 2) == Vector3(66, 28, 7));
test(Vector3(63, 24, 5) - Vector3(3, 4, 2) == Vector3(60, 20, 3)); rp3d_test(Vector3(63, 24, 5) - Vector3(3, 4, 2) == Vector3(60, 20, 3));
vector1 += Vector3(5, 10, 12); vector1 += Vector3(5, 10, 12);
vector2 -= Vector3(10, 21, 5); vector2 -= Vector3(10, 21, 5);
test(vector1 == Vector3(11, 43, 74)); rp3d_test(vector1 == Vector3(11, 43, 74));
test(vector2 == Vector3(-3, 47, 30)); rp3d_test(vector2 == Vector3(-3, 47, 30));
// Multiplication, division // Multiplication, division
Vector3 vector3(6, 33, 62); Vector3 vector3(6, 33, 62);
Vector3 vector4(15, 60, 33); Vector3 vector4(15, 60, 33);
test(Vector3(63, 24, 5) * 3 == Vector3(189, 72, 15)); rp3d_test(Vector3(63, 24, 5) * 3 == Vector3(189, 72, 15));
test(3 * Vector3(63, 24, 5) == Vector3(189, 72, 15)); rp3d_test(3 * Vector3(63, 24, 5) == Vector3(189, 72, 15));
test(Vector3(14, 8, 50) / 2 == Vector3(7, 4, 25)); rp3d_test(Vector3(14, 8, 50) / 2 == Vector3(7, 4, 25));
vector3 *= 10; vector3 *= 10;
vector4 /= 3; vector4 /= 3;
test(vector3 == Vector3(60, 330, 620)); rp3d_test(vector3 == Vector3(60, 330, 620));
test(vector4 == Vector3(5, 20, 11)); rp3d_test(vector4 == Vector3(5, 20, 11));
Vector3 vector5(21, 80, 45); Vector3 vector5(21, 80, 45);
Vector3 vector6(7, 10, 3); Vector3 vector6(7, 10, 3);
Vector3 vector7 = vector5 * vector6; Vector3 vector7 = vector5 * vector6;
test(vector7 == Vector3(147, 800, 135)); rp3d_test(vector7 == Vector3(147, 800, 135));
Vector3 vector8 = vector5 / vector6; Vector3 vector8 = vector5 / vector6;
test(approxEqual(vector8.x, 3)); rp3d_test(approxEqual(vector8.x, 3));
test(approxEqual(vector8.y, 8)); rp3d_test(approxEqual(vector8.y, 8));
test(approxEqual(vector8.z, 15)); rp3d_test(approxEqual(vector8.z, 15));
// Negative operator // Negative operator
Vector3 vector9(-34, 5, 422); Vector3 vector9(-34, 5, 422);
Vector3 negative = -vector9; Vector3 negative = -vector9;
test(negative == Vector3(34, -5, -422)); rp3d_test(negative == Vector3(34, -5, -422));
} }
}; };