2014-12-27 23:54:34 +00:00
|
|
|
/********************************************************************************
|
2015-02-15 20:56:45 +00:00
|
|
|
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
|
2016-04-11 18:15:20 +00:00
|
|
|
* Copyright (c) 2010-2016 Daniel Chappuis *
|
2014-12-27 23:54:34 +00:00
|
|
|
*********************************************************************************
|
|
|
|
* *
|
|
|
|
* This software is provided 'as-is', without any express or implied warranty. *
|
|
|
|
* In no event will the authors be held liable for any damages arising from the *
|
|
|
|
* use of this software. *
|
|
|
|
* *
|
|
|
|
* Permission is granted to anyone to use this software for any purpose, *
|
|
|
|
* including commercial applications, and to alter it and redistribute it *
|
|
|
|
* freely, subject to the following restrictions: *
|
|
|
|
* *
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not claim *
|
|
|
|
* that you wrote the original software. If you use this software in a *
|
|
|
|
* product, an acknowledgment in the product documentation would be *
|
|
|
|
* appreciated but is not required. *
|
|
|
|
* *
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be *
|
|
|
|
* misrepresented as being the original software. *
|
|
|
|
* *
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution. *
|
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TEST_COLLISION_WORLD_H
|
|
|
|
#define TEST_COLLISION_WORLD_H
|
|
|
|
|
|
|
|
// Libraries
|
|
|
|
#include "reactphysics3d.h"
|
2017-01-09 20:34:31 +00:00
|
|
|
#include "Test.h"
|
2018-04-20 05:13:39 +00:00
|
|
|
#include "constraint/ContactPoint.h"
|
|
|
|
#include "collision/ContactManifold.h"
|
2018-02-06 06:39:56 +00:00
|
|
|
#include <map>
|
2014-12-27 23:54:34 +00:00
|
|
|
|
|
|
|
/// Reactphysics3D namespace
|
|
|
|
namespace reactphysics3d {
|
|
|
|
|
2014-12-31 00:19:14 +00:00
|
|
|
// Enumeration for categories
|
|
|
|
enum CollisionCategory {
|
|
|
|
CATEGORY_1 = 0x0001,
|
|
|
|
CATEGORY_2 = 0x0002,
|
|
|
|
CATEGORY_3 = 0x0004
|
|
|
|
};
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// Contact point collision data
|
|
|
|
struct CollisionPointData {
|
|
|
|
|
|
|
|
Vector3 localPointBody1;
|
|
|
|
Vector3 localPointBody2;
|
|
|
|
decimal penetrationDepth;
|
|
|
|
|
|
|
|
CollisionPointData(const Vector3& point1, const Vector3& point2, decimal penDepth) {
|
|
|
|
localPointBody1 = point1;
|
|
|
|
localPointBody2 = point2;
|
|
|
|
penetrationDepth = penDepth;
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
bool isContactPointSimilarTo(const Vector3& pointBody1, const Vector3& pointBody2, decimal penDepth, decimal epsilon = 0.001) const {
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
return approxEqual(pointBody1, localPointBody1, epsilon) &&
|
|
|
|
approxEqual(pointBody2, localPointBody2, epsilon) &&
|
|
|
|
approxEqual(penetrationDepth, penDepth, epsilon);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Contact manifold collision data
|
|
|
|
struct CollisionManifoldData {
|
|
|
|
|
|
|
|
std::vector<CollisionPointData> contactPoints;
|
|
|
|
|
|
|
|
int getNbContactPoints() const {
|
|
|
|
return contactPoints.size();
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
bool hasContactPointSimilarTo(const Vector3& localPointBody1, const Vector3& localPointBody2, decimal penetrationDepth, decimal epsilon = 0.001) const {
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
std::vector<CollisionPointData>::const_iterator it;
|
|
|
|
for (it = contactPoints.cbegin(); it != contactPoints.cend(); ++it) {
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
Vector3 vec = it->localPointBody1;
|
2017-12-27 19:53:09 +00:00
|
|
|
if (it->isContactPointSimilarTo(localPointBody1, localPointBody2, penetrationDepth)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Collision data between two proxy shapes
|
|
|
|
struct CollisionData {
|
|
|
|
|
|
|
|
std::pair<const ProxyShape*, const ProxyShape*> proxyShapes;
|
|
|
|
std::pair<CollisionBody*, CollisionBody*> bodies;
|
|
|
|
std::vector<CollisionManifoldData> contactManifolds;
|
|
|
|
|
|
|
|
int getNbContactManifolds() const {
|
|
|
|
return contactManifolds.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int getTotalNbContactPoints() const {
|
|
|
|
|
|
|
|
int nbPoints = 0;
|
|
|
|
|
|
|
|
std::vector<CollisionManifoldData>::const_iterator it;
|
|
|
|
for (it = contactManifolds.begin(); it != contactManifolds.end(); ++it) {
|
|
|
|
|
|
|
|
nbPoints += it->getNbContactPoints();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nbPoints;
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
const CollisionBody* getBody1() const {
|
|
|
|
return bodies.first;
|
|
|
|
}
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
const CollisionBody* getBody2() const {
|
|
|
|
return bodies.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasContactPointSimilarTo(const Vector3& localPointBody1, const Vector3& localPointBody2, decimal penetrationDepth, decimal epsilon = 0.001) const {
|
|
|
|
|
|
|
|
std::vector<CollisionManifoldData>::const_iterator it;
|
|
|
|
for (it = contactManifolds.cbegin(); it != contactManifolds.cend(); ++it) {
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
if (it->hasContactPointSimilarTo(localPointBody1, localPointBody2, penetrationDepth)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2015-09-13 11:02:05 +00:00
|
|
|
|
2014-12-27 23:54:34 +00:00
|
|
|
// Class
|
|
|
|
class WorldCollisionCallback : public CollisionCallback
|
|
|
|
{
|
2017-12-27 19:53:09 +00:00
|
|
|
private:
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
std::map<std::pair<const ProxyShape*, const ProxyShape*>, CollisionData> mCollisionDatas;
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
std::pair<const ProxyShape*, const ProxyShape*> getCollisionKeyPair(std::pair<const ProxyShape*, const ProxyShape*> pair) const {
|
|
|
|
|
|
|
|
if (pair.first > pair.second) {
|
|
|
|
return std::make_pair(pair.second, pair.first);
|
|
|
|
}
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
return pair;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-12-27 23:54:34 +00:00
|
|
|
|
|
|
|
WorldCollisionCallback()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
2018-02-06 06:39:56 +00:00
|
|
|
mCollisionDatas.clear();
|
2014-12-27 23:54:34 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
bool hasContacts() const {
|
2018-02-06 06:39:56 +00:00
|
|
|
return mCollisionDatas.size() > 0;
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool areProxyShapesColliding(const ProxyShape* proxyShape1, const ProxyShape* proxyShape2) {
|
2018-02-06 06:39:56 +00:00
|
|
|
return mCollisionDatas.find(getCollisionKeyPair(std::make_pair(proxyShape1, proxyShape2))) != mCollisionDatas.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CollisionData* getCollisionData(const ProxyShape* proxyShape1, const ProxyShape* proxyShape2) const {
|
|
|
|
std::map<std::pair<const ProxyShape*, const ProxyShape*>, CollisionData>::const_iterator it = mCollisionDatas.find(getCollisionKeyPair(std::make_pair(proxyShape1, proxyShape2)));
|
|
|
|
if (it != mCollisionDatas.end()) {
|
|
|
|
return &(it->second);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method will be called for each contact
|
2017-01-09 20:34:31 +00:00
|
|
|
virtual void notifyContact(const CollisionCallbackInfo& collisionCallbackInfo) override {
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
CollisionData collisionData;
|
|
|
|
collisionData.bodies = std::make_pair(collisionCallbackInfo.body1, collisionCallbackInfo.body2);
|
|
|
|
collisionData.proxyShapes = std::make_pair(collisionCallbackInfo.proxyShape1, collisionCallbackInfo.proxyShape2);
|
|
|
|
|
|
|
|
ContactManifoldListElement* element = collisionCallbackInfo.contactManifoldElements;
|
|
|
|
while (element != nullptr) {
|
|
|
|
|
|
|
|
ContactManifold* contactManifold = element->getContactManifold();
|
|
|
|
|
|
|
|
CollisionManifoldData collisionManifold;
|
|
|
|
|
|
|
|
ContactPoint* contactPoint = contactManifold->getContactPoints();
|
|
|
|
while (contactPoint != nullptr) {
|
|
|
|
|
|
|
|
CollisionPointData collisionPoint(contactPoint->getLocalPointOnShape1(), contactPoint->getLocalPointOnShape2(), contactPoint->getPenetrationDepth());
|
|
|
|
collisionManifold.contactPoints.push_back(collisionPoint);
|
|
|
|
|
|
|
|
contactPoint = contactPoint->getNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
collisionData.contactManifolds.push_back(collisionManifold);
|
2018-02-06 06:39:56 +00:00
|
|
|
mCollisionDatas.insert(std::make_pair(getCollisionKeyPair(collisionData.proxyShapes), collisionData));
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
element = element->getNext();
|
|
|
|
}
|
2014-12-27 23:54:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
/// Overlap callback
|
|
|
|
class WorldOverlapCallback : public OverlapCallback {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
std::vector<CollisionBody*> mOverlapBodies;
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
virtual ~WorldOverlapCallback() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This method will be called for each reported overlapping bodies
|
|
|
|
virtual void notifyOverlap(CollisionBody* collisionBody) override {
|
2018-02-06 06:39:56 +00:00
|
|
|
mOverlapBodies.push_back(collisionBody);
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
2018-02-06 06:39:56 +00:00
|
|
|
mOverlapBodies.clear();
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasOverlap() const {
|
2018-02-06 06:39:56 +00:00
|
|
|
return !mOverlapBodies.empty();
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
std::vector<CollisionBody*>& getOverlapBodies() {
|
|
|
|
return mOverlapBodies;
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-27 23:54:34 +00:00
|
|
|
// Class TestCollisionWorld
|
|
|
|
/**
|
|
|
|
* Unit test for the CollisionWorld class.
|
|
|
|
*/
|
|
|
|
class TestCollisionWorld : public Test {
|
|
|
|
|
|
|
|
private :
|
|
|
|
|
|
|
|
// ---------- Atributes ---------- //
|
|
|
|
|
|
|
|
// Physics world
|
|
|
|
CollisionWorld* mWorld;
|
|
|
|
|
|
|
|
// Bodies
|
2017-12-27 19:53:09 +00:00
|
|
|
CollisionBody* mBoxBody1;
|
|
|
|
CollisionBody* mBoxBody2;
|
|
|
|
CollisionBody* mSphereBody1;
|
|
|
|
CollisionBody* mSphereBody2;
|
2018-02-06 06:39:56 +00:00
|
|
|
CollisionBody* mCapsuleBody1;
|
|
|
|
CollisionBody* mCapsuleBody2;
|
|
|
|
CollisionBody* mConvexMeshBody1;
|
|
|
|
CollisionBody* mConvexMeshBody2;
|
|
|
|
CollisionBody* mConcaveMeshBody;
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2015-09-04 17:56:27 +00:00
|
|
|
// Collision shapes
|
2017-12-27 19:53:09 +00:00
|
|
|
BoxShape* mBoxShape1;
|
|
|
|
BoxShape* mBoxShape2;
|
|
|
|
SphereShape* mSphereShape1;
|
|
|
|
SphereShape* mSphereShape2;
|
2018-02-06 06:39:56 +00:00
|
|
|
CapsuleShape* mCapsuleShape1;
|
|
|
|
CapsuleShape* mCapsuleShape2;
|
|
|
|
ConvexMeshShape* mConvexMeshShape1;
|
|
|
|
ConvexMeshShape* mConvexMeshShape2;
|
|
|
|
ConcaveMeshShape* mConcaveMeshShape;
|
2015-09-04 17:56:27 +00:00
|
|
|
|
|
|
|
// Proxy shapes
|
2017-12-27 19:53:09 +00:00
|
|
|
ProxyShape* mBoxProxyShape1;
|
|
|
|
ProxyShape* mBoxProxyShape2;
|
|
|
|
ProxyShape* mSphereProxyShape1;
|
|
|
|
ProxyShape* mSphereProxyShape2;
|
2018-02-06 06:39:56 +00:00
|
|
|
ProxyShape* mCapsuleProxyShape1;
|
|
|
|
ProxyShape* mCapsuleProxyShape2;
|
|
|
|
ProxyShape* mConvexMeshProxyShape1;
|
|
|
|
ProxyShape* mConvexMeshProxyShape2;
|
|
|
|
ProxyShape* mConcaveMeshProxyShape;
|
|
|
|
|
|
|
|
PolygonVertexArray* mConvexMesh1PolygonVertexArray;
|
|
|
|
PolygonVertexArray* mConvexMesh2PolygonVertexArray;
|
|
|
|
PolyhedronMesh* mConvexMesh1PolyhedronMesh;
|
|
|
|
PolyhedronMesh* mConvexMesh2PolyhedronMesh;
|
|
|
|
PolygonVertexArray::PolygonFace* mConvexMeshPolygonFaces;
|
|
|
|
|
|
|
|
TriangleVertexArray* mConcaveMeshTriangleVertexArray;
|
|
|
|
Vector3 mConvexMesh1CubeVertices[8];
|
|
|
|
Vector3 mConvexMesh2CubeVertices[8];
|
|
|
|
int mConvexMeshCubeIndices[24];
|
|
|
|
|
|
|
|
Vector3 mConcaveMeshPlaneVertices[36];
|
|
|
|
int mConcaveMeshPlaneIndices[25 * 2 * 3];
|
|
|
|
TriangleMesh* mConcaveTriangleMesh;
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// Collision callback
|
2014-12-27 23:54:34 +00:00
|
|
|
WorldCollisionCallback mCollisionCallback;
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// Overlap callback
|
|
|
|
WorldOverlapCallback mOverlapCallback;
|
|
|
|
|
2014-12-27 23:54:34 +00:00
|
|
|
public :
|
|
|
|
|
|
|
|
// ---------- Methods ---------- //
|
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
TestCollisionWorld(const std::string& name) : Test(name) {
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// Create the collision world
|
2014-12-27 23:54:34 +00:00
|
|
|
mWorld = new CollisionWorld();
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// ---------- Boxes ---------- //
|
|
|
|
Transform boxTransform1(Vector3(-20, 20, 0), Quaternion::identity());
|
|
|
|
mBoxBody1 = mWorld->createCollisionBody(boxTransform1);
|
|
|
|
mBoxShape1 = new BoxShape(Vector3(3, 3, 3));
|
|
|
|
mBoxProxyShape1 = mBoxBody1->addCollisionShape(mBoxShape1, Transform::identity());
|
|
|
|
|
|
|
|
Transform boxTransform2(Vector3(-10, 20, 0), Quaternion::identity());
|
|
|
|
mBoxBody2 = mWorld->createCollisionBody(boxTransform2);
|
2018-02-06 06:39:56 +00:00
|
|
|
mBoxShape2 = new BoxShape(Vector3(4, 2, 8));
|
2018-02-13 06:20:00 +00:00
|
|
|
mBoxProxyShape2 = mBoxBody2->addCollisionShape(mBoxShape2, Transform::identity());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
// ---------- Spheres ---------- //
|
|
|
|
mSphereShape1 = new SphereShape(3.0);
|
|
|
|
Transform sphereTransform1(Vector3(10, 20, 0), Quaternion::identity());
|
|
|
|
mSphereBody1 = mWorld->createCollisionBody(sphereTransform1);
|
|
|
|
mSphereProxyShape1 = mSphereBody1->addCollisionShape(mSphereShape1, Transform::identity());
|
|
|
|
|
|
|
|
mSphereShape2 = new SphereShape(5.0);
|
|
|
|
Transform sphereTransform2(Vector3(20, 20, 0), Quaternion::identity());
|
|
|
|
mSphereBody2 = mWorld->createCollisionBody(sphereTransform2);
|
|
|
|
mSphereProxyShape2 = mSphereBody2->addCollisionShape(mSphereShape2, Transform::identity());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ---------- Capsules ---------- //
|
|
|
|
mCapsuleShape1 = new CapsuleShape(2, 6);
|
|
|
|
Transform capsuleTransform1(Vector3(-10, 0, 0), Quaternion::identity());
|
|
|
|
mCapsuleBody1 = mWorld->createCollisionBody(capsuleTransform1);
|
|
|
|
mCapsuleProxyShape1 = mCapsuleBody1->addCollisionShape(mCapsuleShape1, Transform::identity());
|
|
|
|
|
|
|
|
mCapsuleShape2 = new CapsuleShape(3, 4);
|
|
|
|
Transform capsuleTransform2(Vector3(-20, 0, 0), Quaternion::identity());
|
|
|
|
mCapsuleBody2 = mWorld->createCollisionBody(capsuleTransform2);
|
|
|
|
mCapsuleProxyShape2 = mCapsuleBody2->addCollisionShape(mCapsuleShape2, Transform::identity());
|
|
|
|
|
|
|
|
// ---------- Convex Meshes ---------- //
|
|
|
|
mConvexMesh1CubeVertices[0] = Vector3(-3, -3, 3);
|
|
|
|
mConvexMesh1CubeVertices[1] = Vector3(3, -3, 3);
|
|
|
|
mConvexMesh1CubeVertices[2] = Vector3(3, -3, -3);
|
|
|
|
mConvexMesh1CubeVertices[3] = Vector3(-3, -3, -3);
|
|
|
|
mConvexMesh1CubeVertices[4] = Vector3(-3, 3, 3);
|
|
|
|
mConvexMesh1CubeVertices[5] = Vector3(3, 3, 3);
|
|
|
|
mConvexMesh1CubeVertices[6] = Vector3(3, 3, -3);
|
|
|
|
mConvexMesh1CubeVertices[7] = Vector3(-3, 3, -3);
|
|
|
|
|
|
|
|
mConvexMeshCubeIndices[0] = 0; mConvexMeshCubeIndices[1] = 3; mConvexMeshCubeIndices[2] = 2; mConvexMeshCubeIndices[3] = 1;
|
|
|
|
mConvexMeshCubeIndices[4] = 4; mConvexMeshCubeIndices[5] = 5; mConvexMeshCubeIndices[6] = 6; mConvexMeshCubeIndices[7] = 7;
|
|
|
|
mConvexMeshCubeIndices[8] = 0; mConvexMeshCubeIndices[9] = 1; mConvexMeshCubeIndices[10] = 5; mConvexMeshCubeIndices[11] = 4;
|
|
|
|
mConvexMeshCubeIndices[12] = 1; mConvexMeshCubeIndices[13] = 2; mConvexMeshCubeIndices[14] = 6; mConvexMeshCubeIndices[15] = 5;
|
|
|
|
mConvexMeshCubeIndices[16] = 2; mConvexMeshCubeIndices[17] = 3; mConvexMeshCubeIndices[18] = 7; mConvexMeshCubeIndices[19] = 6;
|
|
|
|
mConvexMeshCubeIndices[20] = 0; mConvexMeshCubeIndices[21] = 4; mConvexMeshCubeIndices[22] = 7; mConvexMeshCubeIndices[23] = 3;
|
|
|
|
|
|
|
|
mConvexMeshPolygonFaces = new rp3d::PolygonVertexArray::PolygonFace[6];
|
|
|
|
rp3d::PolygonVertexArray::PolygonFace* face = mConvexMeshPolygonFaces;
|
|
|
|
for (int f = 0; f < 6; f++) {
|
|
|
|
face->indexBase = f * 4;
|
|
|
|
face->nbVertices = 4;
|
|
|
|
face++;
|
|
|
|
}
|
|
|
|
mConvexMesh1PolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMesh1CubeVertices[0]), sizeof(Vector3),
|
|
|
|
&(mConvexMeshCubeIndices[0]), sizeof(int), 6, mConvexMeshPolygonFaces,
|
|
|
|
rp3d::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
|
|
|
|
rp3d::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
|
|
|
|
mConvexMesh1PolyhedronMesh = new rp3d::PolyhedronMesh(mConvexMesh1PolygonVertexArray);
|
|
|
|
mConvexMeshShape1 = new rp3d::ConvexMeshShape(mConvexMesh1PolyhedronMesh);
|
|
|
|
Transform convexMeshTransform1(Vector3(10, 0, 0), Quaternion::identity());
|
|
|
|
mConvexMeshBody1 = mWorld->createCollisionBody(convexMeshTransform1);
|
|
|
|
mConvexMeshProxyShape1 = mConvexMeshBody1->addCollisionShape(mConvexMeshShape1, Transform::identity());
|
|
|
|
|
|
|
|
mConvexMesh2CubeVertices[0] = Vector3(-4, -2, 8);
|
|
|
|
mConvexMesh2CubeVertices[1] = Vector3(4, -2, 8);
|
|
|
|
mConvexMesh2CubeVertices[2] = Vector3(4, -2, -8);
|
|
|
|
mConvexMesh2CubeVertices[3] = Vector3(-4, -2, -8);
|
|
|
|
mConvexMesh2CubeVertices[4] = Vector3(-4, 2, 8);
|
|
|
|
mConvexMesh2CubeVertices[5] = Vector3(4, 2, 8);
|
|
|
|
mConvexMesh2CubeVertices[6] = Vector3(4, 2, -8);
|
|
|
|
mConvexMesh2CubeVertices[7] = Vector3(-4, 2, -8);
|
|
|
|
|
|
|
|
mConvexMesh2PolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMesh2CubeVertices[0]), sizeof(Vector3),
|
|
|
|
&(mConvexMeshCubeIndices[0]), sizeof(int), 6, mConvexMeshPolygonFaces,
|
|
|
|
rp3d::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
|
|
|
|
rp3d::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
|
|
|
|
mConvexMesh2PolyhedronMesh = new rp3d::PolyhedronMesh(mConvexMesh2PolygonVertexArray);
|
|
|
|
mConvexMeshShape2 = new rp3d::ConvexMeshShape(mConvexMesh2PolyhedronMesh);
|
|
|
|
Transform convexMeshTransform2(Vector3(20, 0, 0), Quaternion::identity());
|
|
|
|
mConvexMeshBody2 = mWorld->createCollisionBody(convexMeshTransform2);
|
|
|
|
mConvexMeshProxyShape2 = mConvexMeshBody2->addCollisionShape(mConvexMeshShape2, Transform::identity());
|
|
|
|
|
|
|
|
// ---------- Concave Meshes ---------- //
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
mConcaveMeshPlaneVertices[i * 6 + j] = Vector3(-2.5f + i, 0, -2.5f + j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int triangleIndex = 0;
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
for (int j = 0; j < 5; j++) {
|
|
|
|
|
|
|
|
// Triangle 1
|
|
|
|
mConcaveMeshPlaneIndices[triangleIndex * 3] = i * 6 + j;
|
|
|
|
mConcaveMeshPlaneIndices[triangleIndex * 3 + 1] = (i+1) * 6 + (j+1);
|
|
|
|
mConcaveMeshPlaneIndices[triangleIndex * 3 + 2] = i * 6 + (j+1);
|
|
|
|
triangleIndex++;
|
|
|
|
|
|
|
|
// Triangle 2
|
|
|
|
mConcaveMeshPlaneIndices[triangleIndex * 3] = i * 6 + j;
|
|
|
|
mConcaveMeshPlaneIndices[triangleIndex * 3 + 1] = (i+1) * 6 + j;
|
|
|
|
mConcaveMeshPlaneIndices[triangleIndex * 3 + 2] = (i+1) * 6 + (j+1);
|
|
|
|
triangleIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mConcaveMeshTriangleVertexArray = new rp3d::TriangleVertexArray(36, &(mConcaveMeshPlaneVertices[0]), sizeof(Vector3),
|
|
|
|
25, &(mConcaveMeshPlaneIndices[0]), 3 * sizeof(int),
|
|
|
|
rp3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
|
|
|
|
rp3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
|
|
|
|
|
|
|
|
// Add the triangle vertex array of the subpart to the triangle mesh
|
|
|
|
Transform concaveMeshTransform(Vector3(0, -20, 0), Quaternion::identity());
|
|
|
|
mConcaveTriangleMesh = new TriangleMesh();
|
|
|
|
mConcaveTriangleMesh->addSubpart(mConcaveMeshTriangleVertexArray);
|
|
|
|
mConcaveMeshShape = new rp3d::ConcaveMeshShape(mConcaveTriangleMesh);
|
|
|
|
mConcaveMeshBody = mWorld->createCollisionBody(concaveMeshTransform);
|
|
|
|
mConcaveMeshProxyShape = mConcaveMeshBody->addCollisionShape(mConcaveMeshShape, rp3d::Transform::identity());
|
2014-12-27 23:54:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 17:56:27 +00:00
|
|
|
/// Destructor
|
2017-02-20 15:11:13 +00:00
|
|
|
virtual ~TestCollisionWorld() {
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
delete mBoxShape1;
|
|
|
|
delete mBoxShape2;
|
|
|
|
|
|
|
|
delete mSphereShape1;
|
|
|
|
delete mSphereShape2;
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
delete mCapsuleShape1;
|
|
|
|
delete mCapsuleShape2;
|
|
|
|
|
|
|
|
delete mConvexMeshShape1;
|
|
|
|
delete mConvexMeshShape2;
|
|
|
|
delete mConvexMesh1PolyhedronMesh;
|
|
|
|
delete mConvexMesh2PolyhedronMesh;
|
|
|
|
delete mConvexMesh1PolygonVertexArray;
|
|
|
|
delete mConvexMesh2PolygonVertexArray;
|
2018-03-29 05:40:24 +00:00
|
|
|
delete[] mConvexMeshPolygonFaces;
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
delete mConcaveMeshShape;
|
|
|
|
delete mConcaveTriangleMesh;
|
|
|
|
delete mConcaveMeshTriangleVertexArray;
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
delete mWorld;
|
2015-09-04 17:56:27 +00:00
|
|
|
}
|
|
|
|
|
2014-12-27 23:54:34 +00:00
|
|
|
/// Run the tests
|
|
|
|
void run() {
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
testNoCollisions();
|
|
|
|
testNoOverlap();
|
|
|
|
testNoAABBOverlap();
|
|
|
|
|
|
|
|
testSphereVsSphereCollision();
|
|
|
|
testSphereVsBoxCollision();
|
2018-02-06 06:39:56 +00:00
|
|
|
testSphereVsCapsuleCollision();
|
|
|
|
testSphereVsConvexMeshCollision();
|
2018-02-13 06:20:00 +00:00
|
|
|
testSphereVsConcaveMeshCollision();
|
|
|
|
|
|
|
|
testBoxVsBoxCollision();
|
|
|
|
testBoxVsConvexMeshCollision();
|
|
|
|
testBoxVsCapsuleCollision();
|
2018-02-14 06:35:30 +00:00
|
|
|
testBoxVsConcaveMeshCollision();
|
|
|
|
|
|
|
|
testCapsuleVsCapsuleCollision();
|
|
|
|
testCapsuleVsConcaveMeshCollision();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
testConvexMeshVsConvexMeshCollision();
|
|
|
|
testConvexMeshVsCapsuleCollision();
|
2018-02-14 06:35:30 +00:00
|
|
|
testConvexMeshVsConcaveMeshCollision();
|
2014-12-27 23:54:34 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
void testNoCollisions() {
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// All the shapes of the world are not touching when they are created.
|
|
|
|
// Here we test that at the beginning, there is no collision at all.
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// ---------- Global test ---------- //
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// ---------- Single body test ---------- //
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody2, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody2, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
// Two bodies test
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2017-12-27 19:53:09 +00:00
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, mBoxBody2, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mSphereBody2, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, mSphereBody1, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, mSphereBody2, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody2, mSphereBody1, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody2, mSphereBody2, &mCollisionCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mCollisionCallback.hasContacts());
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testNoOverlap() {
|
|
|
|
|
|
|
|
// All the shapes of the world are not touching when they are created.
|
|
|
|
// Here we test that at the beginning, there is no overlap at all.
|
|
|
|
|
|
|
|
// ---------- Single body test ---------- //
|
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mOverlapCallback.hasOverlap());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mOverlapCallback.hasOverlap());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mOverlapCallback.hasOverlap());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mOverlapCallback.hasOverlap());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
|
|
|
// Two bodies test
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mWorld->testOverlap(mBoxBody1, mBoxBody2));
|
|
|
|
rp3d_test(!mWorld->testOverlap(mSphereBody1, mSphereBody2));
|
|
|
|
rp3d_test(!mWorld->testOverlap(mBoxBody1, mSphereBody1));
|
|
|
|
rp3d_test(!mWorld->testOverlap(mBoxBody1, mSphereBody2));
|
|
|
|
rp3d_test(!mWorld->testOverlap(mBoxBody2, mSphereBody1));
|
|
|
|
rp3d_test(!mWorld->testOverlap(mBoxBody2, mSphereBody2));
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testNoAABBOverlap() {
|
|
|
|
|
|
|
|
// All the shapes of the world are not touching when they are created.
|
|
|
|
// Here we test that at the beginning, there is no AABB overlap at all.
|
|
|
|
|
|
|
|
// Two bodies test
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mBoxBody2));
|
|
|
|
rp3d_test(!mWorld->testAABBOverlap(mSphereBody1, mSphereBody2));
|
|
|
|
rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mSphereBody1));
|
|
|
|
rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mSphereBody2));
|
|
|
|
rp3d_test(!mWorld->testAABBOverlap(mBoxBody2, mSphereBody1));
|
|
|
|
rp3d_test(!mWorld->testAABBOverlap(mBoxBody2, mSphereBody2));
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
void testSphereVsSphereCollision() {
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
Transform initTransform1 = mSphereBody1->getTransform();
|
|
|
|
Transform initTransform2 = mSphereBody2->getTransform();
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
Transform transform1(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(17, 20, 50), Quaternion::fromEulerAngles(rp3d::PI / 8.0f, rp3d::PI / 4.0f, rp3d::PI / 16.0f));
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mSphereBody2->setTransform(transform2);
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// ----- Test AABB overlap ----- //
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mSphereBody2));
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mSphereProxyShape2));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mSphereProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point(3, 0, 0);
|
|
|
|
Vector3 localBody2Point = transform2.getInverse() * Vector3(12, 20, 50);
|
|
|
|
decimal penetrationDepth = 1.0f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mSphereProxyShape2));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mSphereProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mSphereProxyShape2));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mSphereProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mSphereBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mSphereProxyShape2));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mSphereProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mSphereBody1->setTransform(initTransform1);
|
|
|
|
mSphereBody2->setTransform(initTransform2);
|
2017-12-27 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void testSphereVsBoxCollision() {
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
Transform initTransform1 = mSphereBody1->getTransform();
|
|
|
|
Transform initTransform2 = mBoxBody1->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Box Face collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(14, 20, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mBoxBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point(3, 0, 0);
|
|
|
|
Vector3 localBody2Point(-3, 0, 0);
|
|
|
|
decimal penetrationDepth = 2.0f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Box Edge collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
transform1 = Transform(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
transform2 = Transform(Vector3(14, 16, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mBoxBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
localBody1Point = std::sqrt(4.5f) * Vector3(1, -1, 0);
|
|
|
|
localBody2Point = Vector3(-3, 3, 0);
|
|
|
|
penetrationDepth = decimal(3.0) - std::sqrt(2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Box Vertex collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
transform1 = Transform(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
transform2 = Transform(Vector3(14, 16, 46), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mBoxBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
localBody1Point = std::sqrt(9.0f / 3.0f) * Vector3(1, -1, -1);
|
|
|
|
localBody2Point = Vector3(-3, 3, 3);
|
|
|
|
penetrationDepth = decimal(3.0) - std::sqrt(3);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mBoxProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mBoxProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mSphereBody1->setTransform(initTransform1);
|
|
|
|
mBoxBody1->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSphereVsCapsuleCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mSphereBody1->getTransform();
|
|
|
|
Transform initTransform2 = mCapsuleBody1->getTransform();
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Capsule (sphere side) collision *
|
|
|
|
*********************************************************************************/
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
Transform transform1(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(10, 14, 50), Quaternion::identity());
|
2014-12-27 23:54:34 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mCapsuleBody1->setTransform(transform2);
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// ----- Test AABB overlap ----- //
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mCapsuleBody1));
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point(0, -3, 0);
|
|
|
|
Vector3 localBody2Point(0, 5, 0);
|
|
|
|
decimal penetrationDepth = 2.0f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Box Capsule (cylinder side) collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
transform1 = Transform(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
transform2 = Transform(Vector3(14, 19, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mCapsuleBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mCapsuleBody1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
localBody1Point = Vector3(3, 0, 0);
|
|
|
|
localBody2Point = Vector3(-2, 1, 0);
|
|
|
|
penetrationDepth = decimal(1.0);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mCapsuleProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mSphereBody1->setTransform(initTransform1);
|
|
|
|
mCapsuleBody1->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testSphereVsConvexMeshCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mSphereBody1->getTransform();
|
|
|
|
Transform initTransform2 = mConvexMeshBody1->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Convex Mesh (Cube Face) collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(14, 20, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mConvexMeshBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point(3, 0, 0);
|
|
|
|
Vector3 localBody2Point(-3, 0, 0);
|
|
|
|
decimal penetrationDepth = 2.0f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Convex Mesh (Cube Edge) collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
transform1 = Transform(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
transform2 = Transform(Vector3(14, 16, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mConvexMeshBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
localBody1Point = std::sqrt(4.5f) * Vector3(1, -1, 0);
|
|
|
|
localBody2Point = Vector3(-3, 3, 0);
|
|
|
|
penetrationDepth = decimal(3.0) - std::sqrt(2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs ConvexMesh (Cube Vertex) collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
transform1 = Transform(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
transform2 = Transform(Vector3(14, 16, 46), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mConvexMeshBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
localBody1Point = std::sqrt(9.0f / 3.0f) * Vector3(1, -1, -1);
|
|
|
|
localBody2Point = Vector3(-3, 3, 3);
|
|
|
|
penetrationDepth = decimal(3.0) - std::sqrt(3);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-06 06:39:56 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mConvexMeshBody1, &mCollisionCallback);
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConvexMeshProxyShape1));
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConvexMeshProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-06 06:39:56 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
2014-12-31 00:19:14 +00:00
|
|
|
|
2018-02-06 06:39:56 +00:00
|
|
|
// Reset the init transforms
|
|
|
|
mSphereBody1->setTransform(initTransform1);
|
|
|
|
mConvexMeshBody1->setTransform(initTransform2);
|
2014-12-27 23:54:34 +00:00
|
|
|
}
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-13 06:20:00 +00:00
|
|
|
void testSphereVsConcaveMeshCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mSphereBody1->getTransform();
|
|
|
|
Transform initTransform2 = mConcaveMeshBody->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Sphere vs Concave Mesh
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 22.98f, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mSphereBody1->setTransform(transform1);
|
|
|
|
mConcaveMeshBody->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConcaveMeshBody));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mSphereBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConcaveMeshBody, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConcaveMeshProxyShape));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point(0, -3, 0);
|
|
|
|
Vector3 localBody2Point(0, 0, 0);
|
|
|
|
decimal penetrationDepth = 0.02f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConcaveMeshProxyShape));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConcaveMeshProxyShape));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mSphereBody1, mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mSphereProxyShape1, mConcaveMeshProxyShape));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mSphereProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mSphereBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mSphereBody1->setTransform(initTransform1);
|
|
|
|
mConcaveMeshBody->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testBoxVsBoxCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mBoxBody1->getTransform();
|
|
|
|
Transform initTransform2 = mBoxBody2->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Box vs Box Face collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(11, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(4.5, 16, 40), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mBoxBody1->setTransform(transform1);
|
|
|
|
mBoxBody2->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mBoxBody2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mBoxProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mBoxProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point1(-3, -2, -2);
|
|
|
|
Vector3 localBody2Point1(4, 2, 8);
|
|
|
|
decimal penetrationDepth1 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
Vector3 localBody1Point2(-3, -2, -3);
|
|
|
|
Vector3 localBody2Point2(4, 2, 7);
|
|
|
|
decimal penetrationDepth2 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
|
|
|
Vector3 localBody1Point3(-3, -3, -2);
|
|
|
|
Vector3 localBody2Point3(4, 1, 8);
|
|
|
|
decimal penetrationDepth3 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
|
|
|
Vector3 localBody1Point4(-3, -3, -3);
|
|
|
|
Vector3 localBody2Point4(4, 1, 7);
|
|
|
|
decimal penetrationDepth4 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mBoxProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mBoxProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mBoxProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mBoxProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, mBoxBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mBoxProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mBoxProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// reset the init transforms
|
|
|
|
mBoxBody1->setTransform(initTransform1);
|
|
|
|
mBoxBody2->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testBoxVsConvexMeshCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mBoxBody1->getTransform();
|
|
|
|
Transform initTransform2 = mConvexMeshBody2->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Box vs Convex Mesh collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(11, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(4.5, 16, 40), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mBoxBody1->setTransform(transform1);
|
|
|
|
mConvexMeshBody2->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mConvexMeshBody2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point1(-3, -2, -2);
|
|
|
|
Vector3 localBody2Point1(4, 2, 8);
|
|
|
|
decimal penetrationDepth1 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
Vector3 localBody1Point2(-3, -2, -3);
|
|
|
|
Vector3 localBody2Point2(4, 2, 7);
|
|
|
|
decimal penetrationDepth2 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
|
|
|
Vector3 localBody1Point3(-3, -3, -2);
|
|
|
|
Vector3 localBody2Point3(4, 1, 8);
|
|
|
|
decimal penetrationDepth3 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
|
|
|
Vector3 localBody1Point4(-3, -3, -3);
|
|
|
|
Vector3 localBody2Point4(4, 1, 7);
|
|
|
|
decimal penetrationDepth4 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, mConvexMeshBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// reset the init transforms
|
|
|
|
mBoxBody1->setTransform(initTransform1);
|
|
|
|
mConvexMeshBody2->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testConvexMeshVsConvexMeshCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mConvexMeshBody1->getTransform();
|
|
|
|
Transform initTransform2 = mConvexMeshBody2->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Convex Mesh vs Convex Mesh collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(11, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(4.5, 16, 40), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mConvexMeshBody1->setTransform(transform1);
|
|
|
|
mConvexMeshBody2->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mConvexMeshBody2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point1(-3, -2, -2);
|
|
|
|
Vector3 localBody2Point1(4, 2, 8);
|
|
|
|
decimal penetrationDepth1 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
Vector3 localBody1Point2(-3, -2, -3);
|
|
|
|
Vector3 localBody2Point2(4, 2, 7);
|
|
|
|
decimal penetrationDepth2 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
|
|
|
Vector3 localBody1Point3(-3, -3, -2);
|
|
|
|
Vector3 localBody2Point3(4, 1, 8);
|
|
|
|
decimal penetrationDepth3 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
|
|
|
Vector3 localBody1Point4(-3, -3, -3);
|
|
|
|
Vector3 localBody2Point4(4, 1, 7);
|
|
|
|
decimal penetrationDepth4 = 0.5f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, mConvexMeshBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConvexMeshProxyShape2));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConvexMeshProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point2 : localBody1Point2,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point2 : localBody2Point2,
|
|
|
|
penetrationDepth2));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point3 : localBody1Point3,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point3 : localBody2Point3,
|
|
|
|
penetrationDepth3));
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point4 : localBody1Point4,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point4 : localBody2Point4,
|
|
|
|
penetrationDepth4));
|
|
|
|
|
|
|
|
// reset the init transforms
|
|
|
|
mConvexMeshBody1->setTransform(initTransform1);
|
|
|
|
mConvexMeshBody2->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testBoxVsCapsuleCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mBoxBody1->getTransform();
|
|
|
|
Transform initTransform2 = mCapsuleBody1->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Box vs Capsule collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(17, 21, 50), Quaternion::fromEulerAngles(0, 0, rp3d::PI * 0.5f));
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mBoxBody1->setTransform(transform1);
|
|
|
|
mCapsuleBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mCapsuleBody1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point1(3, 1, 0);
|
|
|
|
Vector3 localBody2Point1(0, 5, 0);
|
|
|
|
decimal penetrationDepth1 = 1.0f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mBoxBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
|
|
|
|
// reset the init transforms
|
|
|
|
mBoxBody1->setTransform(initTransform1);
|
|
|
|
mCapsuleBody1->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testConvexMeshVsCapsuleCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mConvexMeshBody1->getTransform();
|
|
|
|
Transform initTransform2 = mCapsuleBody1->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
2018-02-14 06:35:30 +00:00
|
|
|
* Test Convex Mesh vs Capsule collision *
|
2018-02-13 06:20:00 +00:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(17, 21, 50), Quaternion::fromEulerAngles(0, 0, rp3d::PI * 0.5f));
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mConvexMeshBody1->setTransform(transform1);
|
|
|
|
mCapsuleBody1->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mCapsuleBody1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point1(3, 1, 0);
|
|
|
|
Vector3 localBody2Point1(0, 5, 0);
|
|
|
|
decimal penetrationDepth1 = 1.0f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mCapsuleProxyShape1));
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mCapsuleProxyShape1);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mConvexMeshBody1->getId();
|
2018-02-13 06:20:00 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point1 : localBody1Point1,
|
2018-02-13 06:20:00 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point1 : localBody2Point1,
|
|
|
|
penetrationDepth1));
|
|
|
|
|
|
|
|
// reset the init transforms
|
|
|
|
mConvexMeshBody1->setTransform(initTransform1);
|
|
|
|
mCapsuleBody1->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
2018-02-14 06:35:30 +00:00
|
|
|
void testBoxVsConcaveMeshCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mBoxBody1->getTransform();
|
|
|
|
Transform initTransform2 = mConcaveMeshBody->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Box vs Concave Mesh
|
|
|
|
*********************************************************************************/
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-14 06:35:30 +00:00
|
|
|
Transform transform1(Vector3(10, 22, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(10, 20, 50), Quaternion::identity());
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-14 06:35:30 +00:00
|
|
|
// Move spheres to collide with each other
|
|
|
|
mBoxBody1->setTransform(transform1);
|
|
|
|
mConcaveMeshBody->setTransform(transform2);
|
2017-12-27 19:53:09 +00:00
|
|
|
|
2018-02-14 06:35:30 +00:00
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mConcaveMeshBody));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mBoxBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConcaveMeshBody, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
2018-04-15 21:25:21 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
2018-04-15 21:25:21 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
2018-04-15 21:25:21 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mBoxBody1, mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mBoxProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mBoxProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-04-15 21:25:21 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mBoxBody1->setTransform(initTransform1);
|
|
|
|
mConcaveMeshBody->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testConvexMeshVsConcaveMeshCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mConvexMeshBody1->getTransform();
|
|
|
|
Transform initTransform2 = mConcaveMeshBody->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Box vs Concave Mesh
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 22, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mConvexMeshBody1->setTransform(transform1);
|
|
|
|
mConcaveMeshBody->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mConcaveMeshBody));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConcaveMeshBody, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
2018-04-16 05:54:46 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
2018-04-15 21:25:21 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
2018-04-15 21:25:21 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConvexMeshBody1, mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mConvexMeshProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mConvexMeshProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 4);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-04-15 21:25:21 +00:00
|
|
|
for (size_t i=0; i<collisionData->contactManifolds[0].contactPoints.size(); i++) {
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(approxEqual(collisionData->contactManifolds[0].contactPoints[i].penetrationDepth, 1.0f));
|
2018-02-14 06:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mConvexMeshBody1->setTransform(initTransform1);
|
|
|
|
mConcaveMeshBody->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testCapsuleVsCapsuleCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mCapsuleBody1->getTransform();
|
|
|
|
Transform initTransform2 = mCapsuleBody2->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Capsule (sphere cap) vs Capsule (sphere cap) collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(16, 23, 50), Quaternion::fromEulerAngles(0, 0, rp3d::PI * 0.5f));
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mCapsuleBody1->setTransform(transform1);
|
|
|
|
mCapsuleBody2->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mCapsuleBody2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point(2, 3, 0);
|
|
|
|
Vector3 localBody2Point(0, 5, 0);
|
|
|
|
decimal penetrationDepth = 1.0f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, mCapsuleBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Capsule (sphere cap) vs Capsule (cylinder side) collision *
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
transform1 = Transform(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
transform2 = Transform(Vector3(10, 27, 50), Quaternion::fromEulerAngles(0, 0, rp3d::PI * 0.5f));
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mCapsuleBody1->setTransform(transform1);
|
|
|
|
mCapsuleBody2->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mCapsuleBody2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody2, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
localBody1Point = Vector3(0, 5, 0);
|
|
|
|
localBody2Point = Vector3(-3, 0, 0);
|
|
|
|
penetrationDepth = decimal(1.0);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, mCapsuleBody2, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mCapsuleProxyShape2));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mCapsuleProxyShape2);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mCapsuleBody1->setTransform(initTransform1);
|
|
|
|
mCapsuleBody2->setTransform(initTransform2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testCapsuleVsConcaveMeshCollision() {
|
|
|
|
|
|
|
|
Transform initTransform1 = mCapsuleBody1->getTransform();
|
|
|
|
Transform initTransform2 = mConcaveMeshBody->getTransform();
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Test Capsule vs Concave Mesh
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
Transform transform1(Vector3(10, 24.98f, 50), Quaternion::identity());
|
|
|
|
Transform transform2(Vector3(10, 20, 50), Quaternion::identity());
|
|
|
|
|
|
|
|
// Move spheres to collide with each other
|
|
|
|
mCapsuleBody1->setTransform(transform1);
|
|
|
|
mConcaveMeshBody->setTransform(transform2);
|
|
|
|
|
|
|
|
// ----- Test AABB overlap ----- //
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mConcaveMeshBody));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
mOverlapCallback.reset();
|
|
|
|
mWorld->testOverlap(mConcaveMeshBody, &mOverlapCallback);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mOverlapCallback.hasOverlap());
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// ----- Test global collision test ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(&mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
const CollisionData* collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
bool swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
|
|
|
Vector3 localBody1Point(0, -5, 0);
|
|
|
|
Vector3 localBody2Point(0, 0, 0);
|
|
|
|
decimal penetrationDepth = 0.02f;
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 1 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against body 2 only ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// ----- Test collision against selected body 1 and 2 ----- //
|
|
|
|
|
|
|
|
mCollisionCallback.reset();
|
|
|
|
mWorld->testCollision(mCapsuleBody1, mConcaveMeshBody, &mCollisionCallback);
|
|
|
|
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(mCollisionCallback.areProxyShapesColliding(mCapsuleProxyShape1, mConcaveMeshProxyShape));
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Get collision data
|
|
|
|
collisionData = mCollisionCallback.getCollisionData(mCapsuleProxyShape1, mConcaveMeshProxyShape);
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData != nullptr);
|
|
|
|
rp3d_test(collisionData->getNbContactManifolds() == 1);
|
|
|
|
rp3d_test(collisionData->getTotalNbContactPoints() == 1);
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// True if the bodies are swapped in the collision callback response
|
2018-03-14 06:33:28 +00:00
|
|
|
swappedBodiesCollisionData = collisionData->getBody1()->getId() != mCapsuleBody1->getId();
|
2018-02-14 06:35:30 +00:00
|
|
|
|
|
|
|
// Test contact points
|
2018-08-05 14:10:13 +00:00
|
|
|
rp3d_test(collisionData->hasContactPointSimilarTo(swappedBodiesCollisionData ? localBody2Point : localBody1Point,
|
2018-02-14 06:35:30 +00:00
|
|
|
swappedBodiesCollisionData ? localBody1Point : localBody2Point,
|
|
|
|
penetrationDepth));
|
|
|
|
|
|
|
|
// Reset the init transforms
|
|
|
|
mCapsuleBody1->setTransform(initTransform1);
|
|
|
|
mConcaveMeshBody->setTransform(initTransform2);
|
|
|
|
}
|
2014-12-27 23:54:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|