2010-09-09 22:27:01 +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 *
|
2010-09-09 22:27:01 +00:00
|
|
|
*********************************************************************************
|
|
|
|
* *
|
2011-11-13 17:49:03 +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. *
|
2010-09-09 22:27:01 +00:00
|
|
|
* *
|
2011-11-13 17:49:03 +00:00
|
|
|
* 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. *
|
2010-09-09 22:27:01 +00:00
|
|
|
* *
|
|
|
|
********************************************************************************/
|
|
|
|
|
2013-04-18 20:54:36 +00:00
|
|
|
#ifndef REACTPHYSICS3D_COLLISION_SHAPE_H
|
|
|
|
#define REACTPHYSICS3D_COLLISION_SHAPE_H
|
2010-09-09 22:27:01 +00:00
|
|
|
|
|
|
|
// Libraries
|
2011-07-09 16:58:50 +00:00
|
|
|
#include <cassert>
|
2013-09-12 20:45:43 +00:00
|
|
|
#include <typeinfo>
|
2014-08-07 19:38:31 +00:00
|
|
|
#include "mathematics/Vector3.h"
|
|
|
|
#include "mathematics/Matrix3x3.h"
|
|
|
|
#include "mathematics/Ray.h"
|
2013-03-14 21:47:59 +00:00
|
|
|
#include "AABB.h"
|
2014-08-07 19:38:31 +00:00
|
|
|
#include "collision/RaycastInfo.h"
|
|
|
|
#include "memory/MemoryAllocator.h"
|
2010-09-09 22:27:01 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// ReactPhysics3D namespace
|
2010-09-09 22:27:01 +00:00
|
|
|
namespace reactphysics3d {
|
2012-01-25 22:57:27 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Type of the collision shape
|
2016-02-01 17:49:45 +00:00
|
|
|
enum CollisionShapeType {TRIANGLE, BOX, SPHERE, CONE, CYLINDER,
|
|
|
|
CAPSULE, CONVEX_MESH, CONCAVE_MESH, HEIGHTFIELD};
|
|
|
|
const int NB_COLLISION_SHAPE_TYPES = 9;
|
2010-09-09 22:27:01 +00:00
|
|
|
|
2011-07-09 16:58:50 +00:00
|
|
|
// Declarations
|
2014-04-11 21:50:00 +00:00
|
|
|
class ProxyShape;
|
2014-08-04 20:46:58 +00:00
|
|
|
class CollisionBody;
|
2011-07-09 16:58:50 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
// Class CollisionShape
|
|
|
|
/**
|
|
|
|
* This abstract class represents the collision shape associated with a
|
|
|
|
* body that is used during the narrow-phase collision detection.
|
|
|
|
*/
|
2012-08-03 22:34:30 +00:00
|
|
|
class CollisionShape {
|
2012-01-25 22:57:27 +00:00
|
|
|
|
2010-09-09 22:27:01 +00:00
|
|
|
protected :
|
2012-10-09 20:21:02 +00:00
|
|
|
|
|
|
|
// -------------------- Attributes -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Type of the collision shape
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionShapeType mType;
|
2015-11-19 06:20:43 +00:00
|
|
|
|
|
|
|
/// Scaling vector of the collision shape
|
|
|
|
Vector3 mScaling;
|
2012-01-25 22:57:27 +00:00
|
|
|
|
2012-10-09 20:21:02 +00:00
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Private copy-constructor
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionShape(const CollisionShape& shape);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Private assignment operator
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionShape& operator=(const CollisionShape& shape);
|
|
|
|
|
2014-08-04 20:46:58 +00:00
|
|
|
/// Return true if a point is inside the collision shape
|
2014-08-09 08:28:37 +00:00
|
|
|
virtual bool testPointInside(const Vector3& worldPoint, ProxyShape* proxyShape) const=0;
|
2014-08-04 20:46:58 +00:00
|
|
|
|
|
|
|
/// Raycast method with feedback information
|
2014-10-21 20:26:40 +00:00
|
|
|
virtual bool raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const=0;
|
2014-08-04 20:46:58 +00:00
|
|
|
|
2015-02-12 21:31:26 +00:00
|
|
|
/// Return the number of bytes used by the collision shape
|
|
|
|
virtual size_t getSizeInBytes() const = 0;
|
|
|
|
|
2010-09-09 22:27:01 +00:00
|
|
|
public :
|
|
|
|
|
2012-10-09 20:21:02 +00:00
|
|
|
// -------------------- Methods -------------------- //
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Constructor
|
2015-08-31 15:33:34 +00:00
|
|
|
CollisionShape(CollisionShapeType type);
|
2012-10-09 20:21:02 +00:00
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Destructor
|
2012-10-09 20:21:02 +00:00
|
|
|
virtual ~CollisionShape();
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the type of the collision shapes
|
2012-10-09 20:21:02 +00:00
|
|
|
CollisionShapeType getType() const;
|
|
|
|
|
2015-08-31 15:33:34 +00:00
|
|
|
/// Return true if the collision shape is convex, false if it is concave
|
|
|
|
virtual bool isConvex() const=0;
|
2013-07-03 20:50:00 +00:00
|
|
|
|
2013-07-15 17:09:07 +00:00
|
|
|
/// Return the local bounds of the shape in x, y and z directions
|
|
|
|
virtual void getLocalBounds(Vector3& min, Vector3& max) const=0;
|
2013-03-03 15:24:46 +00:00
|
|
|
|
2015-11-19 06:20:43 +00:00
|
|
|
/// Return the scaling vector of the collision shape
|
|
|
|
Vector3 getScaling() const;
|
|
|
|
|
|
|
|
/// Set the local scaling vector of the collision shape
|
|
|
|
virtual void setLocalScaling(const Vector3& scaling);
|
|
|
|
|
2013-03-05 22:09:50 +00:00
|
|
|
/// Return the local inertia tensor of the collision shapes
|
2012-10-09 20:21:02 +00:00
|
|
|
virtual void computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const=0;
|
2013-03-14 21:47:59 +00:00
|
|
|
|
2014-04-11 21:50:00 +00:00
|
|
|
/// Compute the world-space AABB of the collision shape given a transform
|
|
|
|
virtual void computeAABB(AABB& aabb, const Transform& transform) const;
|
2013-04-22 19:25:40 +00:00
|
|
|
|
2015-09-10 05:30:50 +00:00
|
|
|
/// Return true if the collision shape type is a convex shape
|
|
|
|
static bool isConvex(CollisionShapeType shapeType);
|
|
|
|
|
2015-10-08 19:28:37 +00:00
|
|
|
/// Return the maximum number of contact manifolds in an overlapping pair given two shape types
|
|
|
|
static int computeNbMaxContactManifolds(CollisionShapeType shapeType1,
|
|
|
|
CollisionShapeType shapeType2);
|
|
|
|
|
2014-08-04 20:46:58 +00:00
|
|
|
// -------------------- Friendship -------------------- //
|
2014-08-01 10:36:32 +00:00
|
|
|
|
2014-08-04 20:46:58 +00:00
|
|
|
friend class ProxyShape;
|
2015-02-12 21:31:26 +00:00
|
|
|
friend class CollisionWorld;
|
2014-04-11 21:50:00 +00:00
|
|
|
};
|
|
|
|
|
2012-08-03 22:34:30 +00:00
|
|
|
// Return the type of the collision shape
|
2015-02-12 21:31:26 +00:00
|
|
|
/**
|
|
|
|
* @return The type of the collision shape (box, sphere, cylinder, ...)
|
|
|
|
*/
|
2012-08-03 22:34:30 +00:00
|
|
|
inline CollisionShapeType CollisionShape::getType() const {
|
2012-10-09 20:21:02 +00:00
|
|
|
return mType;
|
2013-03-14 21:47:59 +00:00
|
|
|
}
|
2012-01-25 22:57:27 +00:00
|
|
|
|
2015-09-10 05:30:50 +00:00
|
|
|
// Return true if the collision shape type is a convex shape
|
|
|
|
inline bool CollisionShape::isConvex(CollisionShapeType shapeType) {
|
2016-02-01 17:49:45 +00:00
|
|
|
return shapeType != CONCAVE_MESH && shapeType != HEIGHTFIELD;
|
2015-09-10 05:30:50 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 06:20:43 +00:00
|
|
|
// Return the scaling vector of the collision shape
|
|
|
|
inline Vector3 CollisionShape::getScaling() const {
|
|
|
|
return mScaling;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the scaling vector of the collision shape
|
|
|
|
inline void CollisionShape::setLocalScaling(const Vector3& scaling) {
|
|
|
|
mScaling = scaling;
|
|
|
|
}
|
|
|
|
|
2015-10-08 19:28:37 +00:00
|
|
|
// Return the maximum number of contact manifolds allowed in an overlapping
|
|
|
|
// pair wit the given two collision shape types
|
|
|
|
inline int CollisionShape::computeNbMaxContactManifolds(CollisionShapeType shapeType1,
|
|
|
|
CollisionShapeType shapeType2) {
|
|
|
|
// If both shapes are convex
|
|
|
|
if (isConvex(shapeType1) && isConvex(shapeType2)) {
|
|
|
|
return NB_MAX_CONTACT_MANIFOLDS_CONVEX_SHAPE;
|
|
|
|
} // If there is at least one concave shape
|
|
|
|
else {
|
|
|
|
return NB_MAX_CONTACT_MANIFOLDS_CONCAVE_SHAPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 22:27:01 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 22:34:30 +00:00
|
|
|
#endif
|