[DEV] start basic renaming rework
This commit is contained in:
parent
64b20b4963
commit
562af6c0ae
@ -45,9 +45,9 @@ using namespace reactphysics3d;
|
|||||||
TriangleVertexArray::TriangleVertexArray(uint nbVertices, void* verticesStart, int verticesStride,
|
TriangleVertexArray::TriangleVertexArray(uint nbVertices, void* verticesStart, int verticesStride,
|
||||||
uint nbTriangles, void* indexesStart, int indexesStride,
|
uint nbTriangles, void* indexesStart, int indexesStride,
|
||||||
VertexDataType vertexDataType, IndexDataType indexDataType) {
|
VertexDataType vertexDataType, IndexDataType indexDataType) {
|
||||||
mNbVertices = nbVertices;
|
m_numberVertices = nbVertices;
|
||||||
mVerticesStart = reinterpret_cast<unsigned char*>(verticesStart);
|
m_verticesStart = reinterpret_cast<unsigned char*>(verticesStart);
|
||||||
mVerticesStride = verticesStride;
|
m_verticesStride = verticesStride;
|
||||||
mNbTriangles = nbTriangles;
|
mNbTriangles = nbTriangles;
|
||||||
mIndicesStart = reinterpret_cast<unsigned char*>(indexesStart);
|
mIndicesStart = reinterpret_cast<unsigned char*>(indexesStart);
|
||||||
mIndicesStride = indexesStride;
|
mIndicesStride = indexesStride;
|
||||||
|
@ -54,14 +54,14 @@ class TriangleVertexArray {
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
/// Number of vertices in the array
|
/// Number of vertices in the array
|
||||||
uint mNbVertices;
|
uint m_numberVertices;
|
||||||
|
|
||||||
/// Pointer to the first vertex value in the array
|
/// Pointer to the first vertex value in the array
|
||||||
unsigned char* mVerticesStart;
|
unsigned char* m_verticesStart;
|
||||||
|
|
||||||
/// Stride (number of bytes) between the beginning of two vertices
|
/// Stride (number of bytes) between the beginning of two vertices
|
||||||
/// values in the array
|
/// values in the array
|
||||||
int mVerticesStride;
|
int m_verticesStride;
|
||||||
|
|
||||||
/// Number of triangles in the array
|
/// Number of triangles in the array
|
||||||
uint mNbTriangles;
|
uint mNbTriangles;
|
||||||
@ -126,7 +126,7 @@ inline TriangleVertexArray::IndexDataType TriangleVertexArray::getIndexDataType(
|
|||||||
|
|
||||||
// Return the number of vertices
|
// Return the number of vertices
|
||||||
inline uint TriangleVertexArray::getNbVertices() const {
|
inline uint TriangleVertexArray::getNbVertices() const {
|
||||||
return mNbVertices;
|
return m_numberVertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the number of triangles
|
// Return the number of triangles
|
||||||
@ -136,7 +136,7 @@ inline uint TriangleVertexArray::getNbTriangles() const {
|
|||||||
|
|
||||||
// Return the vertices stride (number of bytes)
|
// Return the vertices stride (number of bytes)
|
||||||
inline int TriangleVertexArray::getVerticesStride() const {
|
inline int TriangleVertexArray::getVerticesStride() const {
|
||||||
return mVerticesStride;
|
return m_verticesStride;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the indices stride (number of bytes)
|
// Return the indices stride (number of bytes)
|
||||||
@ -146,7 +146,7 @@ inline int TriangleVertexArray::getIndicesStride() const {
|
|||||||
|
|
||||||
// Return the pointer to the start of the vertices array
|
// Return the pointer to the start of the vertices array
|
||||||
inline unsigned char* TriangleVertexArray::getVerticesStart() const {
|
inline unsigned char* TriangleVertexArray::getVerticesStart() const {
|
||||||
return mVerticesStart;
|
return m_verticesStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the pointer to the start of the indices array
|
// Return the pointer to the start of the indices array
|
||||||
|
@ -33,7 +33,7 @@ using namespace reactphysics3d;
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection)
|
BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection)
|
||||||
:mDynamicAABBTree(DYNAMIC_TREE_AABB_GAP), mNbMovedShapes(0), mNbAllocatedMovedShapes(8),
|
:m_dynamicAABBTree(DYNAMIC_TREE_AABB_GAP), mNbMovedShapes(0), mNbAllocatedMovedShapes(8),
|
||||||
mNbNonUsedMovedShapes(0), mNbPotentialPairs(0), mNbAllocatedPotentialPairs(8),
|
mNbNonUsedMovedShapes(0), mNbPotentialPairs(0), mNbAllocatedPotentialPairs(8),
|
||||||
mCollisionDetection(collisionDetection) {
|
mCollisionDetection(collisionDetection) {
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) {
|
|||||||
void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) {
|
void BroadPhaseAlgorithm::addProxyCollisionShape(ProxyShape* proxyShape, const AABB& aabb) {
|
||||||
|
|
||||||
// Add the collision shape into the dynamic AABB tree and get its broad-phase ID
|
// Add the collision shape into the dynamic AABB tree and get its broad-phase ID
|
||||||
int nodeId = mDynamicAABBTree.addObject(aabb, proxyShape);
|
int nodeId = m_dynamicAABBTree.addObject(aabb, proxyShape);
|
||||||
|
|
||||||
// Set the broad-phase ID of the proxy shape
|
// Set the broad-phase ID of the proxy shape
|
||||||
proxyShape->mBroadPhaseID = nodeId;
|
proxyShape->mBroadPhaseID = nodeId;
|
||||||
@ -134,7 +134,7 @@ void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
|||||||
int broadPhaseID = proxyShape->mBroadPhaseID;
|
int broadPhaseID = proxyShape->mBroadPhaseID;
|
||||||
|
|
||||||
// Remove the collision shape from the dynamic AABB tree
|
// Remove the collision shape from the dynamic AABB tree
|
||||||
mDynamicAABBTree.removeObject(broadPhaseID);
|
m_dynamicAABBTree.removeObject(broadPhaseID);
|
||||||
|
|
||||||
// Remove the collision shape into the array of shapes that have moved (or have been created)
|
// Remove the collision shape into the array of shapes that have moved (or have been created)
|
||||||
// during the last simulation step
|
// during the last simulation step
|
||||||
@ -150,7 +150,7 @@ void BroadPhaseAlgorithm::updateProxyCollisionShape(ProxyShape* proxyShape, cons
|
|||||||
assert(broadPhaseID >= 0);
|
assert(broadPhaseID >= 0);
|
||||||
|
|
||||||
// Update the dynamic AABB tree according to the movement of the collision shape
|
// Update the dynamic AABB tree according to the movement of the collision shape
|
||||||
bool hasBeenReInserted = mDynamicAABBTree.updateObject(broadPhaseID, aabb, displacement, forceReinsert);
|
bool hasBeenReInserted = m_dynamicAABBTree.updateObject(broadPhaseID, aabb, displacement, forceReinsert);
|
||||||
|
|
||||||
// If the collision shape has moved out of its fat AABB (and therefore has been reinserted
|
// If the collision shape has moved out of its fat AABB (and therefore has been reinserted
|
||||||
// into the tree).
|
// into the tree).
|
||||||
@ -178,12 +178,12 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() {
|
|||||||
AABBOverlapCallback callback(*this, shapeID);
|
AABBOverlapCallback callback(*this, shapeID);
|
||||||
|
|
||||||
// Get the AABB of the shape
|
// Get the AABB of the shape
|
||||||
const AABB& shapeAABB = mDynamicAABBTree.getFatAABB(shapeID);
|
const AABB& shapeAABB = m_dynamicAABBTree.getFatAABB(shapeID);
|
||||||
|
|
||||||
// Ask the dynamic AABB tree to report all collision shapes that overlap with
|
// Ask the dynamic AABB tree to report all collision shapes that overlap with
|
||||||
// this AABB. The method BroadPhase::notifiyOverlappingPair() will be called
|
// this AABB. The method BroadPhase::notifiyOverlappingPair() will be called
|
||||||
// by the dynamic AABB tree for each potential overlapping pair.
|
// by the dynamic AABB tree for each potential overlapping pair.
|
||||||
mDynamicAABBTree.reportAllShapesOverlappingWithAABB(shapeAABB, callback);
|
m_dynamicAABBTree.reportAllShapesOverlappingWithAABB(shapeAABB, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the array of collision shapes that have move (or have been created) during the
|
// Reset the array of collision shapes that have move (or have been created) during the
|
||||||
@ -205,8 +205,8 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() {
|
|||||||
assert(pair->collisionShape1ID != pair->collisionShape2ID);
|
assert(pair->collisionShape1ID != pair->collisionShape2ID);
|
||||||
|
|
||||||
// Get the two collision shapes of the pair
|
// Get the two collision shapes of the pair
|
||||||
ProxyShape* shape1 = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(pair->collisionShape1ID));
|
ProxyShape* shape1 = static_cast<ProxyShape*>(m_dynamicAABBTree.getNodeDataPointer(pair->collisionShape1ID));
|
||||||
ProxyShape* shape2 = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(pair->collisionShape2ID));
|
ProxyShape* shape2 = static_cast<ProxyShape*>(m_dynamicAABBTree.getNodeDataPointer(pair->collisionShape2ID));
|
||||||
|
|
||||||
// Notify the collision detection about the overlapping pair
|
// Notify the collision detection about the overlapping pair
|
||||||
mCollisionDetection.broadPhaseNotifyOverlappingPair(shape1, shape2);
|
mCollisionDetection.broadPhaseNotifyOverlappingPair(shape1, shape2);
|
||||||
@ -277,15 +277,15 @@ decimal BroadPhaseRaycastCallback::raycastBroadPhaseShape(int32 nodeId, const Ra
|
|||||||
decimal hitFraction = decimal(-1.0);
|
decimal hitFraction = decimal(-1.0);
|
||||||
|
|
||||||
// Get the proxy shape from the node
|
// Get the proxy shape from the node
|
||||||
ProxyShape* proxyShape = static_cast<ProxyShape*>(mDynamicAABBTree.getNodeDataPointer(nodeId));
|
ProxyShape* proxyShape = static_cast<ProxyShape*>(m_dynamicAABBTree.getNodeDataPointer(nodeId));
|
||||||
|
|
||||||
// Check if the raycast filtering mask allows raycast against this shape
|
// Check if the raycast filtering mask allows raycast against this shape
|
||||||
if ((mRaycastWithCategoryMaskBits & proxyShape->getCollisionCategoryBits()) != 0) {
|
if ((m_raycastWithCategoryMaskBits & proxyShape->getCollisionCategoryBits()) != 0) {
|
||||||
|
|
||||||
// Ask the collision detection to perform a ray cast test against
|
// Ask the collision detection to perform a ray cast test against
|
||||||
// the proxy shape of this node because the ray is overlapping
|
// the proxy shape of this node because the ray is overlapping
|
||||||
// with the shape in the broad-phase
|
// with the shape in the broad-phase
|
||||||
hitFraction = mRaycastTest.raycastAgainstShape(proxyShape, ray);
|
hitFraction = m_raycastTest.raycastAgainstShape(proxyShape, ray);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hitFraction;
|
return hitFraction;
|
||||||
|
@ -93,19 +93,19 @@ class BroadPhaseRaycastCallback : public DynamicAABBTreeRaycastCallback {
|
|||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
const DynamicAABBTree& mDynamicAABBTree;
|
const DynamicAABBTree& m_dynamicAABBTree;
|
||||||
|
|
||||||
unsigned short mRaycastWithCategoryMaskBits;
|
unsigned short m_raycastWithCategoryMaskBits;
|
||||||
|
|
||||||
RaycastTest& mRaycastTest;
|
RaycastTest& m_raycastTest;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
BroadPhaseRaycastCallback(const DynamicAABBTree& dynamicAABBTree, unsigned short raycastWithCategoryMaskBits,
|
BroadPhaseRaycastCallback(const DynamicAABBTree& dynamicAABBTree, unsigned short raycastWithCategoryMaskBits,
|
||||||
RaycastTest& raycastTest)
|
RaycastTest& raycastTest)
|
||||||
: mDynamicAABBTree(dynamicAABBTree), mRaycastWithCategoryMaskBits(raycastWithCategoryMaskBits),
|
: m_dynamicAABBTree(dynamicAABBTree), m_raycastWithCategoryMaskBits(raycastWithCategoryMaskBits),
|
||||||
mRaycastTest(raycastTest) {
|
m_raycastTest(raycastTest) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ class BroadPhaseAlgorithm {
|
|||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Dynamic AABB tree
|
/// Dynamic AABB tree
|
||||||
DynamicAABBTree mDynamicAABBTree;
|
DynamicAABBTree m_dynamicAABBTree;
|
||||||
|
|
||||||
/// Array with the broad-phase IDs of all collision shapes that have moved (or have been
|
/// Array with the broad-phase IDs of all collision shapes that have moved (or have been
|
||||||
/// created) during the last simulation step. Those are the shapes that need to be tested
|
/// created) during the last simulation step. Those are the shapes that need to be tested
|
||||||
@ -224,8 +224,8 @@ inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1, const Broad
|
|||||||
inline bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1,
|
inline bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1,
|
||||||
const ProxyShape* shape2) const {
|
const ProxyShape* shape2) const {
|
||||||
// Get the two AABBs of the collision shapes
|
// Get the two AABBs of the collision shapes
|
||||||
const AABB& aabb1 = mDynamicAABBTree.getFatAABB(shape1->mBroadPhaseID);
|
const AABB& aabb1 = m_dynamicAABBTree.getFatAABB(shape1->mBroadPhaseID);
|
||||||
const AABB& aabb2 = mDynamicAABBTree.getFatAABB(shape2->mBroadPhaseID);
|
const AABB& aabb2 = m_dynamicAABBTree.getFatAABB(shape2->mBroadPhaseID);
|
||||||
|
|
||||||
// Check if the two AABBs are overlapping
|
// Check if the two AABBs are overlapping
|
||||||
return aabb1.testCollision(aabb2);
|
return aabb1.testCollision(aabb2);
|
||||||
@ -237,9 +237,9 @@ inline void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTes
|
|||||||
|
|
||||||
PROFILE("BroadPhaseAlgorithm::raycast()");
|
PROFILE("BroadPhaseAlgorithm::raycast()");
|
||||||
|
|
||||||
BroadPhaseRaycastCallback broadPhaseRaycastCallback(mDynamicAABBTree, raycastWithCategoryMaskBits, raycastTest);
|
BroadPhaseRaycastCallback broadPhaseRaycastCallback(m_dynamicAABBTree, raycastWithCategoryMaskBits, raycastTest);
|
||||||
|
|
||||||
mDynamicAABBTree.raycast(ray, broadPhaseRaycastCallback);
|
m_dynamicAABBTree.raycast(ray, broadPhaseRaycastCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,220 +25,179 @@
|
|||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include <ephysics/collision/shapes/ConcaveMeshShape.h>
|
#include <ephysics/collision/shapes/ConcaveMeshShape.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh)
|
ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh):
|
||||||
: ConcaveShape(CONCAVE_MESH) {
|
ConcaveShape(CONCAVE_MESH) {
|
||||||
mTriangleMesh = triangleMesh;
|
m_triangleMesh = triangleMesh;
|
||||||
mRaycastTestType = FRONT;
|
m_raycastTestType = FRONT;
|
||||||
|
// Insert all the triangles into the dynamic AABB tree
|
||||||
// Insert all the triangles into the dynamic AABB tree
|
initBVHTree();
|
||||||
initBVHTree();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
ConcaveMeshShape::~ConcaveMeshShape() {
|
ConcaveMeshShape::~ConcaveMeshShape() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert all the triangles into the dynamic AABB tree
|
// Insert all the triangles into the dynamic AABB tree
|
||||||
void ConcaveMeshShape::initBVHTree() {
|
void ConcaveMeshShape::initBVHTree() {
|
||||||
|
// TODO : Try to randomly add the triangles into the tree to obtain a better tree
|
||||||
// TODO : Try to randomly add the triangles into the tree to obtain a better tree
|
// For each sub-part of the mesh
|
||||||
|
for (uint subPart=0; subPart<m_triangleMesh->getNbSubparts(); subPart++) {
|
||||||
// For each sub-part of the mesh
|
// Get the triangle vertex array of the current sub-part
|
||||||
for (uint subPart=0; subPart<mTriangleMesh->getNbSubparts(); subPart++) {
|
TriangleVertexArray* triangleVertexArray = m_triangleMesh->getSubpart(subPart);
|
||||||
|
TriangleVertexArray::VertexDataType vertexType = triangleVertexArray->getVertexDataType();
|
||||||
// Get the triangle vertex array of the current sub-part
|
TriangleVertexArray::IndexDataType indexType = triangleVertexArray->getIndexDataType();
|
||||||
TriangleVertexArray* triangleVertexArray = mTriangleMesh->getSubpart(subPart);
|
unsigned char* verticesStart = triangleVertexArray->getVerticesStart();
|
||||||
|
unsigned char* indicesStart = triangleVertexArray->getIndicesStart();
|
||||||
TriangleVertexArray::VertexDataType vertexType = triangleVertexArray->getVertexDataType();
|
int vertexStride = triangleVertexArray->getVerticesStride();
|
||||||
TriangleVertexArray::IndexDataType indexType = triangleVertexArray->getIndexDataType();
|
int indexStride = triangleVertexArray->getIndicesStride();
|
||||||
unsigned char* verticesStart = triangleVertexArray->getVerticesStart();
|
// For each triangle of the concave mesh
|
||||||
unsigned char* indicesStart = triangleVertexArray->getIndicesStart();
|
for (uint triangleIndex=0; triangleIndex<triangleVertexArray->getNbTriangles(); triangleIndex++) {
|
||||||
int vertexStride = triangleVertexArray->getVerticesStride();
|
void* vertexIndexPointer = (indicesStart + triangleIndex * 3 * indexStride);
|
||||||
int indexStride = triangleVertexArray->getIndicesStride();
|
Vector3 trianglePoints[3];
|
||||||
|
// For each vertex of the triangle
|
||||||
// For each triangle of the concave mesh
|
for (int k=0; k < 3; k++) {
|
||||||
for (uint triangleIndex=0; triangleIndex<triangleVertexArray->getNbTriangles(); triangleIndex++) {
|
// Get the index of the current vertex in the triangle
|
||||||
|
int vertexIndex = 0;
|
||||||
void* vertexIndexPointer = (indicesStart + triangleIndex * 3 * indexStride);
|
if (indexType == TriangleVertexArray::INDEX_INTEGER_TYPE) {
|
||||||
Vector3 trianglePoints[3];
|
vertexIndex = ((uint*)vertexIndexPointer)[k];
|
||||||
|
} else if (indexType == TriangleVertexArray::INDEX_SHORT_TYPE) {
|
||||||
// For each vertex of the triangle
|
vertexIndex = ((unsigned short*)vertexIndexPointer)[k];
|
||||||
for (int k=0; k < 3; k++) {
|
} else {
|
||||||
|
assert(false);
|
||||||
// Get the index of the current vertex in the triangle
|
}
|
||||||
int vertexIndex = 0;
|
// Get the vertices components of the triangle
|
||||||
if (indexType == TriangleVertexArray::INDEX_INTEGER_TYPE) {
|
if (vertexType == TriangleVertexArray::VERTEX_FLOAT_TYPE) {
|
||||||
vertexIndex = ((uint*)vertexIndexPointer)[k];
|
const float* vertices = (float*)(verticesStart + vertexIndex * vertexStride);
|
||||||
}
|
trianglePoints[k][0] = decimal(vertices[0]) * mScaling.x;
|
||||||
else if (indexType == TriangleVertexArray::INDEX_SHORT_TYPE) {
|
trianglePoints[k][1] = decimal(vertices[1]) * mScaling.y;
|
||||||
vertexIndex = ((unsigned short*)vertexIndexPointer)[k];
|
trianglePoints[k][2] = decimal(vertices[2]) * mScaling.z;
|
||||||
}
|
} else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) {
|
||||||
else {
|
const double* vertices = (double*)(verticesStart + vertexIndex * vertexStride);
|
||||||
assert(false);
|
trianglePoints[k][0] = decimal(vertices[0]) * mScaling.x;
|
||||||
}
|
trianglePoints[k][1] = decimal(vertices[1]) * mScaling.y;
|
||||||
|
trianglePoints[k][2] = decimal(vertices[2]) * mScaling.z;
|
||||||
// Get the vertices components of the triangle
|
} else {
|
||||||
if (vertexType == TriangleVertexArray::VERTEX_FLOAT_TYPE) {
|
assert(false);
|
||||||
const float* vertices = (float*)(verticesStart + vertexIndex * vertexStride);
|
}
|
||||||
trianglePoints[k][0] = decimal(vertices[0]) * mScaling.x;
|
}
|
||||||
trianglePoints[k][1] = decimal(vertices[1]) * mScaling.y;
|
// Create the AABB for the triangle
|
||||||
trianglePoints[k][2] = decimal(vertices[2]) * mScaling.z;
|
AABB aabb = AABB::createAABBForTriangle(trianglePoints);
|
||||||
}
|
aabb.inflate(m_triangleMargin, m_triangleMargin, m_triangleMargin);
|
||||||
else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) {
|
// Add the AABB with the index of the triangle into the dynamic AABB tree
|
||||||
const double* vertices = (double*)(verticesStart + vertexIndex * vertexStride);
|
m_dynamicAABBTree.addObject(aabb, subPart, triangleIndex);
|
||||||
trianglePoints[k][0] = decimal(vertices[0]) * mScaling.x;
|
}
|
||||||
trianglePoints[k][1] = decimal(vertices[1]) * mScaling.y;
|
}
|
||||||
trianglePoints[k][2] = decimal(vertices[2]) * mScaling.z;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the AABB for the triangle
|
|
||||||
AABB aabb = AABB::createAABBForTriangle(trianglePoints);
|
|
||||||
aabb.inflate(mTriangleMargin, mTriangleMargin, mTriangleMargin);
|
|
||||||
|
|
||||||
// Add the AABB with the index of the triangle into the dynamic AABB tree
|
|
||||||
mDynamicAABBTree.addObject(aabb, subPart, triangleIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the three vertices coordinates (in the array outTriangleVertices) of a triangle
|
// Return the three vertices coordinates (in the array outTriangleVertices) of a triangle
|
||||||
// given the start vertex index pointer of the triangle
|
// given the start vertex index pointer of the triangle
|
||||||
void ConcaveMeshShape::getTriangleVerticesWithIndexPointer(int32 subPart, int32 triangleIndex,
|
void ConcaveMeshShape::getTriangleVerticesWithIndexPointer(int32 subPart, int32 triangleIndex, Vector3* outTriangleVertices) const {
|
||||||
Vector3* outTriangleVertices) const {
|
// Get the triangle vertex array of the current sub-part
|
||||||
|
TriangleVertexArray* triangleVertexArray = m_triangleMesh->getSubpart(subPart);
|
||||||
// Get the triangle vertex array of the current sub-part
|
if (triangleVertexArray == nullptr) {
|
||||||
TriangleVertexArray* triangleVertexArray = mTriangleMesh->getSubpart(subPart);
|
std::cout << "get nullptr ..." << std::endl;
|
||||||
|
}
|
||||||
TriangleVertexArray::VertexDataType vertexType = triangleVertexArray->getVertexDataType();
|
TriangleVertexArray::VertexDataType vertexType = triangleVertexArray->getVertexDataType();
|
||||||
TriangleVertexArray::IndexDataType indexType = triangleVertexArray->getIndexDataType();
|
TriangleVertexArray::IndexDataType indexType = triangleVertexArray->getIndexDataType();
|
||||||
unsigned char* verticesStart = triangleVertexArray->getVerticesStart();
|
unsigned char* verticesStart = triangleVertexArray->getVerticesStart();
|
||||||
unsigned char* indicesStart = triangleVertexArray->getIndicesStart();
|
unsigned char* indicesStart = triangleVertexArray->getIndicesStart();
|
||||||
int vertexStride = triangleVertexArray->getVerticesStride();
|
int vertexStride = triangleVertexArray->getVerticesStride();
|
||||||
int indexStride = triangleVertexArray->getIndicesStride();
|
int indexStride = triangleVertexArray->getIndicesStride();
|
||||||
|
void* vertexIndexPointer = (indicesStart + triangleIndex * 3 * indexStride);
|
||||||
void* vertexIndexPointer = (indicesStart + triangleIndex * 3 * indexStride);
|
// For each vertex of the triangle
|
||||||
|
for (int k=0; k < 3; k++) {
|
||||||
// For each vertex of the triangle
|
// Get the index of the current vertex in the triangle
|
||||||
for (int k=0; k < 3; k++) {
|
int vertexIndex = 0;
|
||||||
|
if (indexType == TriangleVertexArray::INDEX_INTEGER_TYPE) {
|
||||||
// Get the index of the current vertex in the triangle
|
vertexIndex = ((uint*)vertexIndexPointer)[k];
|
||||||
int vertexIndex = 0;
|
} else if (indexType == TriangleVertexArray::INDEX_SHORT_TYPE) {
|
||||||
if (indexType == TriangleVertexArray::INDEX_INTEGER_TYPE) {
|
vertexIndex = ((unsigned short*)vertexIndexPointer)[k];
|
||||||
vertexIndex = ((uint*)vertexIndexPointer)[k];
|
} else {
|
||||||
}
|
std::cout << "wrong type of array : " << int32_t(indexType) << std::endl;
|
||||||
else if (indexType == TriangleVertexArray::INDEX_SHORT_TYPE) {
|
assert(false);
|
||||||
vertexIndex = ((unsigned short*)vertexIndexPointer)[k];
|
}
|
||||||
}
|
// Get the vertices components of the triangle
|
||||||
else {
|
if (vertexType == TriangleVertexArray::VERTEX_FLOAT_TYPE) {
|
||||||
assert(false);
|
const float* vertices = (float*)(verticesStart + vertexIndex * vertexStride);
|
||||||
}
|
outTriangleVertices[k][0] = decimal(vertices[0]) * mScaling.x;
|
||||||
|
outTriangleVertices[k][1] = decimal(vertices[1]) * mScaling.y;
|
||||||
// Get the vertices components of the triangle
|
outTriangleVertices[k][2] = decimal(vertices[2]) * mScaling.z;
|
||||||
if (vertexType == TriangleVertexArray::VERTEX_FLOAT_TYPE) {
|
} else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) {
|
||||||
const float* vertices = (float*)(verticesStart + vertexIndex * vertexStride);
|
const double* vertices = (double*)(verticesStart + vertexIndex * vertexStride);
|
||||||
outTriangleVertices[k][0] = decimal(vertices[0]) * mScaling.x;
|
outTriangleVertices[k][0] = decimal(vertices[0]) * mScaling.x;
|
||||||
outTriangleVertices[k][1] = decimal(vertices[1]) * mScaling.y;
|
outTriangleVertices[k][1] = decimal(vertices[1]) * mScaling.y;
|
||||||
outTriangleVertices[k][2] = decimal(vertices[2]) * mScaling.z;
|
outTriangleVertices[k][2] = decimal(vertices[2]) * mScaling.z;
|
||||||
}
|
} else {
|
||||||
else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) {
|
assert(false);
|
||||||
const double* vertices = (double*)(verticesStart + vertexIndex * vertexStride);
|
}
|
||||||
outTriangleVertices[k][0] = decimal(vertices[0]) * mScaling.x;
|
}
|
||||||
outTriangleVertices[k][1] = decimal(vertices[1]) * mScaling.y;
|
|
||||||
outTriangleVertices[k][2] = decimal(vertices[2]) * mScaling.z;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a callback method on all triangles of the concave shape inside a given AABB
|
// Use a callback method on all triangles of the concave shape inside a given AABB
|
||||||
void ConcaveMeshShape::testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const {
|
void ConcaveMeshShape::testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const {
|
||||||
|
ConvexTriangleAABBOverlapCallback overlapCallback(callback, *this, m_dynamicAABBTree);
|
||||||
ConvexTriangleAABBOverlapCallback overlapCallback(callback, *this, mDynamicAABBTree);
|
// Ask the Dynamic AABB Tree to report all the triangles that are overlapping
|
||||||
|
// with the AABB of the convex shape.
|
||||||
// Ask the Dynamic AABB Tree to report all the triangles that are overlapping
|
m_dynamicAABBTree.reportAllShapesOverlappingWithAABB(localAABB, overlapCallback);
|
||||||
// with the AABB of the convex shape.
|
|
||||||
mDynamicAABBTree.reportAllShapesOverlappingWithAABB(localAABB, overlapCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raycast method with feedback information
|
// Raycast method with feedback information
|
||||||
/// Note that only the first triangle hit by the ray in the mesh will be returned, even if
|
/// Note that only the first triangle hit by the ray in the mesh will be returned, even if
|
||||||
/// the ray hits many triangles.
|
/// the ray hits many triangles.
|
||||||
bool ConcaveMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const {
|
bool ConcaveMeshShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const {
|
||||||
|
PROFILE("ConcaveMeshShape::raycast()");
|
||||||
PROFILE("ConcaveMeshShape::raycast()");
|
// Create the callback object that will compute ray casting against triangles
|
||||||
|
ConcaveMeshRaycastCallback raycastCallback(m_dynamicAABBTree, *this, proxyShape, raycastInfo, ray);
|
||||||
// Create the callback object that will compute ray casting against triangles
|
// Ask the Dynamic AABB Tree to report all AABB nodes that are hit by the ray.
|
||||||
ConcaveMeshRaycastCallback raycastCallback(mDynamicAABBTree, *this, proxyShape, raycastInfo, ray);
|
// The raycastCallback object will then compute ray casting against the triangles
|
||||||
|
// in the hit AABBs.
|
||||||
// Ask the Dynamic AABB Tree to report all AABB nodes that are hit by the ray.
|
m_dynamicAABBTree.raycast(ray, raycastCallback);
|
||||||
// The raycastCallback object will then compute ray casting against the triangles
|
raycastCallback.raycastTriangles();
|
||||||
// in the hit AABBs.
|
return raycastCallback.getIsHit();
|
||||||
mDynamicAABBTree.raycast(ray, raycastCallback);
|
|
||||||
|
|
||||||
raycastCallback.raycastTriangles();
|
|
||||||
|
|
||||||
return raycastCallback.getIsHit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect all the AABB nodes that are hit by the ray in the Dynamic AABB Tree
|
// Collect all the AABB nodes that are hit by the ray in the Dynamic AABB Tree
|
||||||
decimal ConcaveMeshRaycastCallback::raycastBroadPhaseShape(int32 nodeId, const Ray& ray) {
|
decimal ConcaveMeshRaycastCallback::raycastBroadPhaseShape(int32 nodeId, const Ray& ray) {
|
||||||
|
// Add the id of the hit AABB node into
|
||||||
// Add the id of the hit AABB node into
|
m_hitAABBNodes.push_back(nodeId);
|
||||||
mHitAABBNodes.push_back(nodeId);
|
return ray.maxFraction;
|
||||||
|
|
||||||
return ray.maxFraction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raycast all collision shapes that have been collected
|
// Raycast all collision shapes that have been collected
|
||||||
void ConcaveMeshRaycastCallback::raycastTriangles() {
|
void ConcaveMeshRaycastCallback::raycastTriangles() {
|
||||||
|
std::vector<int>::const_iterator it;
|
||||||
std::vector<int>::const_iterator it;
|
decimal smallestHitFraction = m_ray.maxFraction;
|
||||||
decimal smallestHitFraction = mRay.maxFraction;
|
for (it = m_hitAABBNodes.begin(); it != m_hitAABBNodes.end(); ++it) {
|
||||||
|
// Get the node data (triangle index and mesh subpart index)
|
||||||
for (it = mHitAABBNodes.begin(); it != mHitAABBNodes.end(); ++it) {
|
int32* data = m_dynamicAABBTree.getNodeDataInt(*it);
|
||||||
|
// Get the triangle vertices for this node from the concave mesh shape
|
||||||
// Get the node data (triangle index and mesh subpart index)
|
Vector3 trianglePoints[3];
|
||||||
int32* data = mDynamicAABBTree.getNodeDataInt(*it);
|
m_concaveMeshShape.getTriangleVerticesWithIndexPointer(data[0], data[1], trianglePoints);
|
||||||
|
// Create a triangle collision shape
|
||||||
// Get the triangle vertices for this node from the concave mesh shape
|
decimal margin = m_concaveMeshShape.getTriangleMargin();
|
||||||
Vector3 trianglePoints[3];
|
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2], margin);
|
||||||
mConcaveMeshShape.getTriangleVerticesWithIndexPointer(data[0], data[1], trianglePoints);
|
triangleShape.setRaycastTestType(m_concaveMeshShape.getRaycastTestType());
|
||||||
|
// Ray casting test against the collision shape
|
||||||
// Create a triangle collision shape
|
RaycastInfo raycastInfo;
|
||||||
decimal margin = mConcaveMeshShape.getTriangleMargin();
|
bool isTriangleHit = triangleShape.raycast(m_ray, raycastInfo, m_proxyShape);
|
||||||
TriangleShape triangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2], margin);
|
// If the ray hit the collision shape
|
||||||
triangleShape.setRaycastTestType(mConcaveMeshShape.getRaycastTestType());
|
if (isTriangleHit && raycastInfo.hitFraction <= smallestHitFraction) {
|
||||||
|
assert(raycastInfo.hitFraction >= decimal(0.0));
|
||||||
// Ray casting test against the collision shape
|
m_raycastInfo.body = raycastInfo.body;
|
||||||
RaycastInfo raycastInfo;
|
m_raycastInfo.proxyShape = raycastInfo.proxyShape;
|
||||||
bool isTriangleHit = triangleShape.raycast(mRay, raycastInfo, mProxyShape);
|
m_raycastInfo.hitFraction = raycastInfo.hitFraction;
|
||||||
|
m_raycastInfo.worldPoint = raycastInfo.worldPoint;
|
||||||
// If the ray hit the collision shape
|
m_raycastInfo.worldNormal = raycastInfo.worldNormal;
|
||||||
if (isTriangleHit && raycastInfo.hitFraction <= smallestHitFraction) {
|
m_raycastInfo.meshSubpart = data[0];
|
||||||
|
m_raycastInfo.triangleIndex = data[1];
|
||||||
assert(raycastInfo.hitFraction >= decimal(0.0));
|
smallestHitFraction = raycastInfo.hitFraction;
|
||||||
|
mIsHit = true;
|
||||||
mRaycastInfo.body = raycastInfo.body;
|
}
|
||||||
mRaycastInfo.proxyShape = raycastInfo.proxyShape;
|
}
|
||||||
mRaycastInfo.hitFraction = raycastInfo.hitFraction;
|
|
||||||
mRaycastInfo.worldPoint = raycastInfo.worldPoint;
|
|
||||||
mRaycastInfo.worldNormal = raycastInfo.worldNormal;
|
|
||||||
mRaycastInfo.meshSubpart = data[0];
|
|
||||||
mRaycastInfo.triangleIndex = data[1];
|
|
||||||
|
|
||||||
smallestHitFraction = raycastInfo.hitFraction;
|
|
||||||
mIsHit = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -42,20 +42,20 @@ class ConvexTriangleAABBOverlapCallback : public DynamicAABBTreeOverlapCallback
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TriangleCallback& mTriangleTestCallback;
|
TriangleCallback& m_triangleTestCallback;
|
||||||
|
|
||||||
// Reference to the concave mesh shape
|
// Reference to the concave mesh shape
|
||||||
const ConcaveMeshShape& mConcaveMeshShape;
|
const ConcaveMeshShape& m_concaveMeshShape;
|
||||||
|
|
||||||
// Reference to the Dynamic AABB tree
|
// Reference to the Dynamic AABB tree
|
||||||
const DynamicAABBTree& mDynamicAABBTree;
|
const DynamicAABBTree& m_dynamicAABBTree;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ConvexTriangleAABBOverlapCallback(TriangleCallback& triangleCallback, const ConcaveMeshShape& concaveShape,
|
ConvexTriangleAABBOverlapCallback(TriangleCallback& triangleCallback, const ConcaveMeshShape& concaveShape,
|
||||||
const DynamicAABBTree& dynamicAABBTree)
|
const DynamicAABBTree& dynamicAABBTree)
|
||||||
: mTriangleTestCallback(triangleCallback), mConcaveMeshShape(concaveShape), mDynamicAABBTree(dynamicAABBTree) {
|
: m_triangleTestCallback(triangleCallback), m_concaveMeshShape(concaveShape), m_dynamicAABBTree(dynamicAABBTree) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,12 +70,12 @@ class ConcaveMeshRaycastCallback : public DynamicAABBTreeRaycastCallback {
|
|||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
std::vector<int32> mHitAABBNodes;
|
std::vector<int32> m_hitAABBNodes;
|
||||||
const DynamicAABBTree& mDynamicAABBTree;
|
const DynamicAABBTree& m_dynamicAABBTree;
|
||||||
const ConcaveMeshShape& mConcaveMeshShape;
|
const ConcaveMeshShape& m_concaveMeshShape;
|
||||||
ProxyShape* mProxyShape;
|
ProxyShape* m_proxyShape;
|
||||||
RaycastInfo& mRaycastInfo;
|
RaycastInfo& m_raycastInfo;
|
||||||
const Ray& mRay;
|
const Ray& m_ray;
|
||||||
bool mIsHit;
|
bool mIsHit;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -83,8 +83,8 @@ class ConcaveMeshRaycastCallback : public DynamicAABBTreeRaycastCallback {
|
|||||||
// Constructor
|
// Constructor
|
||||||
ConcaveMeshRaycastCallback(const DynamicAABBTree& dynamicAABBTree, const ConcaveMeshShape& concaveMeshShape,
|
ConcaveMeshRaycastCallback(const DynamicAABBTree& dynamicAABBTree, const ConcaveMeshShape& concaveMeshShape,
|
||||||
ProxyShape* proxyShape, RaycastInfo& raycastInfo, const Ray& ray)
|
ProxyShape* proxyShape, RaycastInfo& raycastInfo, const Ray& ray)
|
||||||
: mDynamicAABBTree(dynamicAABBTree), mConcaveMeshShape(concaveMeshShape), mProxyShape(proxyShape),
|
: m_dynamicAABBTree(dynamicAABBTree), m_concaveMeshShape(concaveMeshShape), m_proxyShape(proxyShape),
|
||||||
mRaycastInfo(raycastInfo), mRay(ray), mIsHit(false) {
|
m_raycastInfo(raycastInfo), m_ray(ray), mIsHit(false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,10 +113,10 @@ class ConcaveMeshShape : public ConcaveShape {
|
|||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Triangle mesh
|
/// Triangle mesh
|
||||||
TriangleMesh* mTriangleMesh;
|
TriangleMesh* m_triangleMesh;
|
||||||
|
|
||||||
/// Dynamic AABB tree to accelerate collision with the triangles
|
/// Dynamic AABB tree to accelerate collision with the triangles
|
||||||
DynamicAABBTree mDynamicAABBTree;
|
DynamicAABBTree m_dynamicAABBTree;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ inline size_t ConcaveMeshShape::getSizeInBytes() const {
|
|||||||
inline void ConcaveMeshShape::getLocalBounds(Vector3& min, Vector3& max) const {
|
inline void ConcaveMeshShape::getLocalBounds(Vector3& min, Vector3& max) const {
|
||||||
|
|
||||||
// Get the AABB of the whole tree
|
// Get the AABB of the whole tree
|
||||||
AABB treeAABB = mDynamicAABBTree.getRootAABB();
|
AABB treeAABB = m_dynamicAABBTree.getRootAABB();
|
||||||
|
|
||||||
min = treeAABB.getMin();
|
min = treeAABB.getMin();
|
||||||
max = treeAABB.getMax();
|
max = treeAABB.getMax();
|
||||||
@ -192,7 +192,7 @@ inline void ConcaveMeshShape::setLocalScaling(const Vector3& scaling) {
|
|||||||
CollisionShape::setLocalScaling(scaling);
|
CollisionShape::setLocalScaling(scaling);
|
||||||
|
|
||||||
// Reset the Dynamic AABB Tree
|
// Reset the Dynamic AABB Tree
|
||||||
mDynamicAABBTree.reset();
|
m_dynamicAABBTree.reset();
|
||||||
|
|
||||||
// Rebuild Dynamic AABB Tree here
|
// Rebuild Dynamic AABB Tree here
|
||||||
initBVHTree();
|
initBVHTree();
|
||||||
@ -220,14 +220,14 @@ inline void ConcaveMeshShape::computeLocalInertiaTensor(Matrix3x3& tensor, decim
|
|||||||
inline void ConvexTriangleAABBOverlapCallback::notifyOverlappingNode(int nodeId) {
|
inline void ConvexTriangleAABBOverlapCallback::notifyOverlappingNode(int nodeId) {
|
||||||
|
|
||||||
// Get the node data (triangle index and mesh subpart index)
|
// Get the node data (triangle index and mesh subpart index)
|
||||||
int32* data = mDynamicAABBTree.getNodeDataInt(nodeId);
|
int32* data = m_dynamicAABBTree.getNodeDataInt(nodeId);
|
||||||
|
|
||||||
// Get the triangle vertices for this node from the concave mesh shape
|
// Get the triangle vertices for this node from the concave mesh shape
|
||||||
Vector3 trianglePoints[3];
|
Vector3 trianglePoints[3];
|
||||||
mConcaveMeshShape.getTriangleVerticesWithIndexPointer(data[0], data[1], trianglePoints);
|
m_concaveMeshShape.getTriangleVerticesWithIndexPointer(data[0], data[1], trianglePoints);
|
||||||
|
|
||||||
// Call the callback to test narrow-phase collision with this triangle
|
// Call the callback to test narrow-phase collision with this triangle
|
||||||
mTriangleTestCallback.testTriangle(trianglePoints);
|
m_triangleTestCallback.testTriangle(trianglePoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,8 @@ using namespace reactphysics3d;
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ConcaveShape::ConcaveShape(CollisionShapeType type)
|
ConcaveShape::ConcaveShape(CollisionShapeType type)
|
||||||
: CollisionShape(type), mIsSmoothMeshCollisionEnabled(false),
|
: CollisionShape(type), m_isSmoothMeshCollisionEnabled(false),
|
||||||
mTriangleMargin(0), mRaycastTestType(FRONT) {
|
m_triangleMargin(0), m_raycastTestType(FRONT) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,13 +61,13 @@ class ConcaveShape : public CollisionShape {
|
|||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// True if the smooth mesh collision algorithm is enabled
|
/// True if the smooth mesh collision algorithm is enabled
|
||||||
bool mIsSmoothMeshCollisionEnabled;
|
bool m_isSmoothMeshCollisionEnabled;
|
||||||
|
|
||||||
// Margin use for collision detection for each triangle
|
// Margin use for collision detection for each triangle
|
||||||
decimal mTriangleMargin;
|
decimal m_triangleMargin;
|
||||||
|
|
||||||
/// Raycast test type for the triangle (front, back, front-back)
|
/// Raycast test type for the triangle (front, back, front-back)
|
||||||
TriangleRaycastSide mRaycastTestType;
|
TriangleRaycastSide m_raycastTestType;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class ConcaveShape : public CollisionShape {
|
|||||||
|
|
||||||
// Return the triangle margin
|
// Return the triangle margin
|
||||||
inline decimal ConcaveShape::getTriangleMargin() const {
|
inline decimal ConcaveShape::getTriangleMargin() const {
|
||||||
return mTriangleMargin;
|
return m_triangleMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if the collision shape is convex, false if it is concave
|
/// Return true if the collision shape is convex, false if it is concave
|
||||||
@ -129,7 +129,7 @@ inline bool ConcaveShape::testPointInside(const Vector3& localPoint, ProxyShape*
|
|||||||
|
|
||||||
// Return true if the smooth mesh collision is enabled
|
// Return true if the smooth mesh collision is enabled
|
||||||
inline bool ConcaveShape::getIsSmoothMeshCollisionEnabled() const {
|
inline bool ConcaveShape::getIsSmoothMeshCollisionEnabled() const {
|
||||||
return mIsSmoothMeshCollisionEnabled;
|
return m_isSmoothMeshCollisionEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable/disable the smooth mesh collision algorithm
|
// Enable/disable the smooth mesh collision algorithm
|
||||||
@ -137,12 +137,12 @@ inline bool ConcaveShape::getIsSmoothMeshCollisionEnabled() const {
|
|||||||
/// of the triangle mesh. If it is enabled, collsions with the mesh will be smoother
|
/// of the triangle mesh. If it is enabled, collsions with the mesh will be smoother
|
||||||
/// but collisions computation is a bit more expensive.
|
/// but collisions computation is a bit more expensive.
|
||||||
inline void ConcaveShape::setIsSmoothMeshCollisionEnabled(bool isEnabled) {
|
inline void ConcaveShape::setIsSmoothMeshCollisionEnabled(bool isEnabled) {
|
||||||
mIsSmoothMeshCollisionEnabled = isEnabled;
|
m_isSmoothMeshCollisionEnabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the raycast test type (front, back, front-back)
|
// Return the raycast test type (front, back, front-back)
|
||||||
inline TriangleRaycastSide ConcaveShape::getRaycastTestType() const {
|
inline TriangleRaycastSide ConcaveShape::getRaycastTestType() const {
|
||||||
return mRaycastTestType;
|
return m_raycastTestType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the raycast test type (front, back, front-back)
|
// Set the raycast test type (front, back, front-back)
|
||||||
@ -150,7 +150,7 @@ inline TriangleRaycastSide ConcaveShape::getRaycastTestType() const {
|
|||||||
* @param testType Raycast test type for the triangle (front, back, front-back)
|
* @param testType Raycast test type for the triangle (front, back, front-back)
|
||||||
*/
|
*/
|
||||||
inline void ConcaveShape::setRaycastTestType(TriangleRaycastSide testType) {
|
inline void ConcaveShape::setRaycastTestType(TriangleRaycastSide testType) {
|
||||||
mRaycastTestType = testType;
|
m_raycastTestType = testType;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,17 +39,17 @@ using namespace reactphysics3d;
|
|||||||
* @param margin Collision margin (in meters) around the collision shape
|
* @param margin Collision margin (in meters) around the collision shape
|
||||||
*/
|
*/
|
||||||
ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices, int stride, decimal margin)
|
ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices, int stride, decimal margin)
|
||||||
: ConvexShape(CONVEX_MESH, margin), mNbVertices(nbVertices), mMinBounds(0, 0, 0),
|
: ConvexShape(CONVEX_MESH, margin), m_numberVertices(nbVertices), m_minBounds(0, 0, 0),
|
||||||
mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(false) {
|
m_maxBounds(0, 0, 0), m_isEdgesInformationUsed(false) {
|
||||||
assert(nbVertices > 0);
|
assert(nbVertices > 0);
|
||||||
assert(stride > 0);
|
assert(stride > 0);
|
||||||
|
|
||||||
const unsigned char* vertexPointer = (const unsigned char*) arrayVertices;
|
const unsigned char* vertexPointer = (const unsigned char*) arrayVertices;
|
||||||
|
|
||||||
// Copy all the vertices into the internal array
|
// Copy all the vertices into the internal array
|
||||||
for (uint i=0; i<mNbVertices; i++) {
|
for (uint i=0; i<m_numberVertices; i++) {
|
||||||
const decimal* newPoint = (const decimal*) vertexPointer;
|
const decimal* newPoint = (const decimal*) vertexPointer;
|
||||||
mVertices.push_back(Vector3(newPoint[0], newPoint[1], newPoint[2]));
|
m_vertices.push_back(Vector3(newPoint[0], newPoint[1], newPoint[2]));
|
||||||
vertexPointer += stride;
|
vertexPointer += stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +65,8 @@ ConvexMeshShape::ConvexMeshShape(const decimal* arrayVertices, uint nbVertices,
|
|||||||
* @param margin Collision margin (in meters) around the collision shape
|
* @param margin Collision margin (in meters) around the collision shape
|
||||||
*/
|
*/
|
||||||
ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool isEdgesInformationUsed, decimal margin)
|
ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool isEdgesInformationUsed, decimal margin)
|
||||||
: ConvexShape(CONVEX_MESH, margin), mMinBounds(0, 0, 0),
|
: ConvexShape(CONVEX_MESH, margin), m_minBounds(0, 0, 0),
|
||||||
mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(isEdgesInformationUsed) {
|
m_maxBounds(0, 0, 0), m_isEdgesInformationUsed(isEdgesInformationUsed) {
|
||||||
|
|
||||||
TriangleVertexArray::VertexDataType vertexType = triangleVertexArray->getVertexDataType();
|
TriangleVertexArray::VertexDataType vertexType = triangleVertexArray->getVertexDataType();
|
||||||
TriangleVertexArray::IndexDataType indexType = triangleVertexArray->getIndexDataType();
|
TriangleVertexArray::IndexDataType indexType = triangleVertexArray->getIndexDataType();
|
||||||
@ -84,19 +84,19 @@ ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool
|
|||||||
|
|
||||||
Vector3 vertex(vertices[0], vertices[1], vertices[2] );
|
Vector3 vertex(vertices[0], vertices[1], vertices[2] );
|
||||||
vertex = vertex * mScaling;
|
vertex = vertex * mScaling;
|
||||||
mVertices.push_back(vertex);
|
m_vertices.push_back(vertex);
|
||||||
}
|
}
|
||||||
else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) {
|
else if (vertexType == TriangleVertexArray::VERTEX_DOUBLE_TYPE) {
|
||||||
const double* vertices = (double*)(verticesStart + v * vertexStride);
|
const double* vertices = (double*)(verticesStart + v * vertexStride);
|
||||||
|
|
||||||
Vector3 vertex(vertices[0], vertices[1], vertices[2] );
|
Vector3 vertex(vertices[0], vertices[1], vertices[2] );
|
||||||
vertex = vertex * mScaling;
|
vertex = vertex * mScaling;
|
||||||
mVertices.push_back(vertex);
|
m_vertices.push_back(vertex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we need to use the edges information of the mesh
|
// If we need to use the edges information of the mesh
|
||||||
if (mIsEdgesInformationUsed) {
|
if (m_isEdgesInformationUsed) {
|
||||||
|
|
||||||
// For each triangle of the mesh
|
// For each triangle of the mesh
|
||||||
for (uint triangleIndex=0; triangleIndex<triangleVertexArray->getNbTriangles(); triangleIndex++) {
|
for (uint triangleIndex=0; triangleIndex<triangleVertexArray->getNbTriangles(); triangleIndex++) {
|
||||||
@ -127,7 +127,7 @@ ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mNbVertices = mVertices.size();
|
m_numberVertices = m_vertices.size();
|
||||||
recalculateBounds();
|
recalculateBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +135,8 @@ ConvexMeshShape::ConvexMeshShape(TriangleVertexArray* triangleVertexArray, bool
|
|||||||
/// If you use this constructor, you will need to set the vertices manually one by one using
|
/// If you use this constructor, you will need to set the vertices manually one by one using
|
||||||
/// the addVertex() method.
|
/// the addVertex() method.
|
||||||
ConvexMeshShape::ConvexMeshShape(decimal margin)
|
ConvexMeshShape::ConvexMeshShape(decimal margin)
|
||||||
: ConvexShape(CONVEX_MESH, margin), mNbVertices(0), mMinBounds(0, 0, 0),
|
: ConvexShape(CONVEX_MESH, margin), m_numberVertices(0), m_minBounds(0, 0, 0),
|
||||||
mMaxBounds(0, 0, 0), mIsEdgesInformationUsed(false) {
|
m_maxBounds(0, 0, 0), m_isEdgesInformationUsed(false) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ ConvexMeshShape::~ConvexMeshShape() {
|
|||||||
Vector3 ConvexMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direction,
|
Vector3 ConvexMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direction,
|
||||||
void** cachedCollisionData) const {
|
void** cachedCollisionData) const {
|
||||||
|
|
||||||
assert(mNbVertices == mVertices.size());
|
assert(m_numberVertices == m_vertices.size());
|
||||||
assert(cachedCollisionData != NULL);
|
assert(cachedCollisionData != NULL);
|
||||||
|
|
||||||
// Allocate memory for the cached collision data if not allocated yet
|
// Allocate memory for the cached collision data if not allocated yet
|
||||||
@ -166,28 +166,28 @@ Vector3 ConvexMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direct
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the edges information is used to speed up the collision detection
|
// If the edges information is used to speed up the collision detection
|
||||||
if (mIsEdgesInformationUsed) {
|
if (m_isEdgesInformationUsed) {
|
||||||
|
|
||||||
assert(mEdgesAdjacencyList.size() == mNbVertices);
|
assert(m_edgesAdjacencyList.size() == m_numberVertices);
|
||||||
|
|
||||||
uint maxVertex = *((int*)(*cachedCollisionData));
|
uint maxVertex = *((int*)(*cachedCollisionData));
|
||||||
decimal maxDotProduct = direction.dot(mVertices[maxVertex]);
|
decimal maxDotProduct = direction.dot(m_vertices[maxVertex]);
|
||||||
bool isOptimal;
|
bool isOptimal;
|
||||||
|
|
||||||
// Perform hill-climbing (local search)
|
// Perform hill-climbing (local search)
|
||||||
do {
|
do {
|
||||||
isOptimal = true;
|
isOptimal = true;
|
||||||
|
|
||||||
assert(mEdgesAdjacencyList.at(maxVertex).size() > 0);
|
assert(m_edgesAdjacencyList.at(maxVertex).size() > 0);
|
||||||
|
|
||||||
// For all neighbors of the current vertex
|
// For all neighbors of the current vertex
|
||||||
std::set<uint>::const_iterator it;
|
std::set<uint>::const_iterator it;
|
||||||
std::set<uint>::const_iterator itBegin = mEdgesAdjacencyList.at(maxVertex).begin();
|
std::set<uint>::const_iterator itBegin = m_edgesAdjacencyList.at(maxVertex).begin();
|
||||||
std::set<uint>::const_iterator itEnd = mEdgesAdjacencyList.at(maxVertex).end();
|
std::set<uint>::const_iterator itEnd = m_edgesAdjacencyList.at(maxVertex).end();
|
||||||
for (it = itBegin; it != itEnd; ++it) {
|
for (it = itBegin; it != itEnd; ++it) {
|
||||||
|
|
||||||
// Compute the dot product
|
// Compute the dot product
|
||||||
decimal dotProduct = direction.dot(mVertices[*it]);
|
decimal dotProduct = direction.dot(m_vertices[*it]);
|
||||||
|
|
||||||
// If the current vertex is a better vertex (larger dot product)
|
// If the current vertex is a better vertex (larger dot product)
|
||||||
if (dotProduct > maxDotProduct) {
|
if (dotProduct > maxDotProduct) {
|
||||||
@ -203,7 +203,7 @@ Vector3 ConvexMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direct
|
|||||||
*((int*)(*cachedCollisionData)) = maxVertex;
|
*((int*)(*cachedCollisionData)) = maxVertex;
|
||||||
|
|
||||||
// Return the support vertex
|
// Return the support vertex
|
||||||
return mVertices[maxVertex] * mScaling;
|
return m_vertices[maxVertex] * mScaling;
|
||||||
}
|
}
|
||||||
else { // If the edges information is not used
|
else { // If the edges information is not used
|
||||||
|
|
||||||
@ -211,10 +211,10 @@ Vector3 ConvexMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direct
|
|||||||
uint indexMaxDotProduct = 0;
|
uint indexMaxDotProduct = 0;
|
||||||
|
|
||||||
// For each vertex of the mesh
|
// For each vertex of the mesh
|
||||||
for (uint i=0; i<mNbVertices; i++) {
|
for (uint i=0; i<m_numberVertices; i++) {
|
||||||
|
|
||||||
// Compute the dot product of the current vertex
|
// Compute the dot product of the current vertex
|
||||||
double dotProduct = direction.dot(mVertices[i]);
|
double dotProduct = direction.dot(m_vertices[i]);
|
||||||
|
|
||||||
// If the current dot product is larger than the maximum one
|
// If the current dot product is larger than the maximum one
|
||||||
if (dotProduct > maxDotProduct) {
|
if (dotProduct > maxDotProduct) {
|
||||||
@ -226,7 +226,7 @@ Vector3 ConvexMeshShape::getLocalSupportPointWithoutMargin(const Vector3& direct
|
|||||||
assert(maxDotProduct >= decimal(0.0));
|
assert(maxDotProduct >= decimal(0.0));
|
||||||
|
|
||||||
// Return the vertex with the largest dot product in the support direction
|
// Return the vertex with the largest dot product in the support direction
|
||||||
return mVertices[indexMaxDotProduct] * mScaling;
|
return m_vertices[indexMaxDotProduct] * mScaling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,29 +236,29 @@ void ConvexMeshShape::recalculateBounds() {
|
|||||||
// TODO : Only works if the local origin is inside the mesh
|
// TODO : Only works if the local origin is inside the mesh
|
||||||
// => Make it more robust (init with first vertex of mesh instead)
|
// => Make it more robust (init with first vertex of mesh instead)
|
||||||
|
|
||||||
mMinBounds.setToZero();
|
m_minBounds.setToZero();
|
||||||
mMaxBounds.setToZero();
|
m_maxBounds.setToZero();
|
||||||
|
|
||||||
// For each vertex of the mesh
|
// For each vertex of the mesh
|
||||||
for (uint i=0; i<mNbVertices; i++) {
|
for (uint i=0; i<m_numberVertices; i++) {
|
||||||
|
|
||||||
if (mVertices[i].x > mMaxBounds.x) mMaxBounds.x = mVertices[i].x;
|
if (m_vertices[i].x > m_maxBounds.x) m_maxBounds.x = m_vertices[i].x;
|
||||||
if (mVertices[i].x < mMinBounds.x) mMinBounds.x = mVertices[i].x;
|
if (m_vertices[i].x < m_minBounds.x) m_minBounds.x = m_vertices[i].x;
|
||||||
|
|
||||||
if (mVertices[i].y > mMaxBounds.y) mMaxBounds.y = mVertices[i].y;
|
if (m_vertices[i].y > m_maxBounds.y) m_maxBounds.y = m_vertices[i].y;
|
||||||
if (mVertices[i].y < mMinBounds.y) mMinBounds.y = mVertices[i].y;
|
if (m_vertices[i].y < m_minBounds.y) m_minBounds.y = m_vertices[i].y;
|
||||||
|
|
||||||
if (mVertices[i].z > mMaxBounds.z) mMaxBounds.z = mVertices[i].z;
|
if (m_vertices[i].z > m_maxBounds.z) m_maxBounds.z = m_vertices[i].z;
|
||||||
if (mVertices[i].z < mMinBounds.z) mMinBounds.z = mVertices[i].z;
|
if (m_vertices[i].z < m_minBounds.z) m_minBounds.z = m_vertices[i].z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the local scaling factor
|
// Apply the local scaling factor
|
||||||
mMaxBounds = mMaxBounds * mScaling;
|
m_maxBounds = m_maxBounds * mScaling;
|
||||||
mMinBounds = mMinBounds * mScaling;
|
m_minBounds = m_minBounds * mScaling;
|
||||||
|
|
||||||
// Add the object margin to the bounds
|
// Add the object margin to the bounds
|
||||||
mMaxBounds += Vector3(mMargin, mMargin, mMargin);
|
m_maxBounds += Vector3(mMargin, mMargin, mMargin);
|
||||||
mMinBounds -= Vector3(mMargin, mMargin, mMargin);
|
m_minBounds -= Vector3(mMargin, mMargin, mMargin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raycast method with feedback information
|
// Raycast method with feedback information
|
||||||
|
@ -65,23 +65,23 @@ class ConvexMeshShape : public ConvexShape {
|
|||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
/// Array with the vertices of the mesh
|
/// Array with the vertices of the mesh
|
||||||
std::vector<Vector3> mVertices;
|
std::vector<Vector3> m_vertices;
|
||||||
|
|
||||||
/// Number of vertices in the mesh
|
/// Number of vertices in the mesh
|
||||||
uint mNbVertices;
|
uint m_numberVertices;
|
||||||
|
|
||||||
/// Mesh minimum bounds in the three local x, y and z directions
|
/// Mesh minimum bounds in the three local x, y and z directions
|
||||||
Vector3 mMinBounds;
|
Vector3 m_minBounds;
|
||||||
|
|
||||||
/// Mesh maximum bounds in the three local x, y and z directions
|
/// Mesh maximum bounds in the three local x, y and z directions
|
||||||
Vector3 mMaxBounds;
|
Vector3 m_maxBounds;
|
||||||
|
|
||||||
/// True if the shape contains the edges of the convex mesh in order to
|
/// True if the shape contains the edges of the convex mesh in order to
|
||||||
/// make the collision detection faster
|
/// make the collision detection faster
|
||||||
bool mIsEdgesInformationUsed;
|
bool m_isEdgesInformationUsed;
|
||||||
|
|
||||||
/// Adjacency list representing the edges of the mesh
|
/// Adjacency list representing the edges of the mesh
|
||||||
std::map<uint, std::set<uint> > mEdgesAdjacencyList;
|
std::map<uint, std::set<uint> > m_edgesAdjacencyList;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
@ -165,8 +165,8 @@ inline size_t ConvexMeshShape::getSizeInBytes() const {
|
|||||||
* @param max The maximum bounds of the shape in local-space coordinates
|
* @param max The maximum bounds of the shape in local-space coordinates
|
||||||
*/
|
*/
|
||||||
inline void ConvexMeshShape::getLocalBounds(Vector3& min, Vector3& max) const {
|
inline void ConvexMeshShape::getLocalBounds(Vector3& min, Vector3& max) const {
|
||||||
min = mMinBounds;
|
min = m_minBounds;
|
||||||
max = mMaxBounds;
|
max = m_maxBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the local inertia tensor of the collision shape.
|
// Return the local inertia tensor of the collision shape.
|
||||||
@ -179,7 +179,7 @@ inline void ConvexMeshShape::getLocalBounds(Vector3& min, Vector3& max) const {
|
|||||||
*/
|
*/
|
||||||
inline void ConvexMeshShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const {
|
inline void ConvexMeshShape::computeLocalInertiaTensor(Matrix3x3& tensor, decimal mass) const {
|
||||||
decimal factor = (decimal(1.0) / decimal(3.0)) * mass;
|
decimal factor = (decimal(1.0) / decimal(3.0)) * mass;
|
||||||
Vector3 realExtent = decimal(0.5) * (mMaxBounds - mMinBounds);
|
Vector3 realExtent = decimal(0.5) * (m_maxBounds - m_minBounds);
|
||||||
assert(realExtent.x > 0 && realExtent.y > 0 && realExtent.z > 0);
|
assert(realExtent.x > 0 && realExtent.y > 0 && realExtent.z > 0);
|
||||||
decimal xSquare = realExtent.x * realExtent.x;
|
decimal xSquare = realExtent.x * realExtent.x;
|
||||||
decimal ySquare = realExtent.y * realExtent.y;
|
decimal ySquare = realExtent.y * realExtent.y;
|
||||||
@ -196,16 +196,16 @@ inline void ConvexMeshShape::computeLocalInertiaTensor(Matrix3x3& tensor, decima
|
|||||||
inline void ConvexMeshShape::addVertex(const Vector3& vertex) {
|
inline void ConvexMeshShape::addVertex(const Vector3& vertex) {
|
||||||
|
|
||||||
// Add the vertex in to vertices array
|
// Add the vertex in to vertices array
|
||||||
mVertices.push_back(vertex);
|
m_vertices.push_back(vertex);
|
||||||
mNbVertices++;
|
m_numberVertices++;
|
||||||
|
|
||||||
// Update the bounds of the mesh
|
// Update the bounds of the mesh
|
||||||
if (vertex.x * mScaling.x > mMaxBounds.x) mMaxBounds.x = vertex.x * mScaling.x;
|
if (vertex.x * mScaling.x > m_maxBounds.x) m_maxBounds.x = vertex.x * mScaling.x;
|
||||||
if (vertex.x * mScaling.x < mMinBounds.x) mMinBounds.x = vertex.x * mScaling.x;
|
if (vertex.x * mScaling.x < m_minBounds.x) m_minBounds.x = vertex.x * mScaling.x;
|
||||||
if (vertex.y * mScaling.y > mMaxBounds.y) mMaxBounds.y = vertex.y * mScaling.y;
|
if (vertex.y * mScaling.y > m_maxBounds.y) m_maxBounds.y = vertex.y * mScaling.y;
|
||||||
if (vertex.y * mScaling.y < mMinBounds.y) mMinBounds.y = vertex.y * mScaling.y;
|
if (vertex.y * mScaling.y < m_minBounds.y) m_minBounds.y = vertex.y * mScaling.y;
|
||||||
if (vertex.z * mScaling.z > mMaxBounds.z) mMaxBounds.z = vertex.z * mScaling.z;
|
if (vertex.z * mScaling.z > m_maxBounds.z) m_maxBounds.z = vertex.z * mScaling.z;
|
||||||
if (vertex.z * mScaling.z < mMinBounds.z) mMinBounds.z = vertex.z * mScaling.z;
|
if (vertex.z * mScaling.z < m_minBounds.z) m_minBounds.z = vertex.z * mScaling.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an edge into the convex mesh by specifying the two vertex indices of the edge.
|
// Add an edge into the convex mesh by specifying the two vertex indices of the edge.
|
||||||
@ -219,18 +219,18 @@ inline void ConvexMeshShape::addVertex(const Vector3& vertex) {
|
|||||||
inline void ConvexMeshShape::addEdge(uint v1, uint v2) {
|
inline void ConvexMeshShape::addEdge(uint v1, uint v2) {
|
||||||
|
|
||||||
// If the entry for vertex v1 does not exist in the adjacency list
|
// If the entry for vertex v1 does not exist in the adjacency list
|
||||||
if (mEdgesAdjacencyList.count(v1) == 0) {
|
if (m_edgesAdjacencyList.count(v1) == 0) {
|
||||||
mEdgesAdjacencyList.insert(std::make_pair(v1, std::set<uint>()));
|
m_edgesAdjacencyList.insert(std::make_pair(v1, std::set<uint>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the entry for vertex v2 does not exist in the adjacency list
|
// If the entry for vertex v2 does not exist in the adjacency list
|
||||||
if (mEdgesAdjacencyList.count(v2) == 0) {
|
if (m_edgesAdjacencyList.count(v2) == 0) {
|
||||||
mEdgesAdjacencyList.insert(std::make_pair(v2, std::set<uint>()));
|
m_edgesAdjacencyList.insert(std::make_pair(v2, std::set<uint>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the edge in the adjacency list
|
// Add the edge in the adjacency list
|
||||||
mEdgesAdjacencyList[v1].insert(v2);
|
m_edgesAdjacencyList[v1].insert(v2);
|
||||||
mEdgesAdjacencyList[v2].insert(v1);
|
m_edgesAdjacencyList[v2].insert(v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the edges information is used to speed up the collision detection
|
// Return true if the edges information is used to speed up the collision detection
|
||||||
@ -238,7 +238,7 @@ inline void ConvexMeshShape::addEdge(uint v1, uint v2) {
|
|||||||
* @return True if the edges information is used and false otherwise
|
* @return True if the edges information is used and false otherwise
|
||||||
*/
|
*/
|
||||||
inline bool ConvexMeshShape::isEdgesInformationUsed() const {
|
inline bool ConvexMeshShape::isEdgesInformationUsed() const {
|
||||||
return mIsEdgesInformationUsed;
|
return m_isEdgesInformationUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the variable to know if the edges information is used to speed up the
|
// Set the variable to know if the edges information is used to speed up the
|
||||||
@ -248,7 +248,7 @@ inline bool ConvexMeshShape::isEdgesInformationUsed() const {
|
|||||||
* the collision detection with the convex mesh shape
|
* the collision detection with the convex mesh shape
|
||||||
*/
|
*/
|
||||||
inline void ConvexMeshShape::setIsEdgesInformationUsed(bool isEdgesUsed) {
|
inline void ConvexMeshShape::setIsEdgesInformationUsed(bool isEdgesUsed) {
|
||||||
mIsEdgesInformationUsed = isEdgesUsed;
|
m_isEdgesInformationUsed = isEdgesUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if a point is inside the collision shape
|
// Return true if a point is inside the collision shape
|
||||||
|
@ -246,20 +246,20 @@ void TriangleOverlapCallback::testTriangle(const Vector3* trianglePoints) {
|
|||||||
|
|
||||||
// Ray casting test against the collision shape
|
// Ray casting test against the collision shape
|
||||||
RaycastInfo raycastInfo;
|
RaycastInfo raycastInfo;
|
||||||
bool isTriangleHit = triangleShape.raycast(mRay, raycastInfo, mProxyShape);
|
bool isTriangleHit = triangleShape.raycast(m_ray, raycastInfo, m_proxyShape);
|
||||||
|
|
||||||
// If the ray hit the collision shape
|
// If the ray hit the collision shape
|
||||||
if (isTriangleHit && raycastInfo.hitFraction <= mSmallestHitFraction) {
|
if (isTriangleHit && raycastInfo.hitFraction <= mSmallestHitFraction) {
|
||||||
|
|
||||||
assert(raycastInfo.hitFraction >= decimal(0.0));
|
assert(raycastInfo.hitFraction >= decimal(0.0));
|
||||||
|
|
||||||
mRaycastInfo.body = raycastInfo.body;
|
m_raycastInfo.body = raycastInfo.body;
|
||||||
mRaycastInfo.proxyShape = raycastInfo.proxyShape;
|
m_raycastInfo.proxyShape = raycastInfo.proxyShape;
|
||||||
mRaycastInfo.hitFraction = raycastInfo.hitFraction;
|
m_raycastInfo.hitFraction = raycastInfo.hitFraction;
|
||||||
mRaycastInfo.worldPoint = raycastInfo.worldPoint;
|
m_raycastInfo.worldPoint = raycastInfo.worldPoint;
|
||||||
mRaycastInfo.worldNormal = raycastInfo.worldNormal;
|
m_raycastInfo.worldNormal = raycastInfo.worldNormal;
|
||||||
mRaycastInfo.meshSubpart = -1;
|
m_raycastInfo.meshSubpart = -1;
|
||||||
mRaycastInfo.triangleIndex = -1;
|
m_raycastInfo.triangleIndex = -1;
|
||||||
|
|
||||||
mSmallestHitFraction = raycastInfo.hitFraction;
|
mSmallestHitFraction = raycastInfo.hitFraction;
|
||||||
mIsHit = true;
|
mIsHit = true;
|
||||||
|
@ -43,9 +43,9 @@ class TriangleOverlapCallback : public TriangleCallback {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
const Ray& mRay;
|
const Ray& m_ray;
|
||||||
ProxyShape* mProxyShape;
|
ProxyShape* m_proxyShape;
|
||||||
RaycastInfo& mRaycastInfo;
|
RaycastInfo& m_raycastInfo;
|
||||||
bool mIsHit;
|
bool mIsHit;
|
||||||
decimal mSmallestHitFraction;
|
decimal mSmallestHitFraction;
|
||||||
const HeightFieldShape& mHeightFieldShape;
|
const HeightFieldShape& mHeightFieldShape;
|
||||||
@ -55,10 +55,10 @@ class TriangleOverlapCallback : public TriangleCallback {
|
|||||||
// Constructor
|
// Constructor
|
||||||
TriangleOverlapCallback(const Ray& ray, ProxyShape* proxyShape, RaycastInfo& raycastInfo,
|
TriangleOverlapCallback(const Ray& ray, ProxyShape* proxyShape, RaycastInfo& raycastInfo,
|
||||||
const HeightFieldShape& heightFieldShape)
|
const HeightFieldShape& heightFieldShape)
|
||||||
: mRay(ray), mProxyShape(proxyShape), mRaycastInfo(raycastInfo),
|
: m_ray(ray), m_proxyShape(proxyShape), m_raycastInfo(raycastInfo),
|
||||||
mHeightFieldShape (heightFieldShape) {
|
mHeightFieldShape (heightFieldShape) {
|
||||||
mIsHit = false;
|
mIsHit = false;
|
||||||
mSmallestHitFraction = mRay.maxFraction;
|
mSmallestHitFraction = m_ray.maxFraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getIsHit() const {return mIsHit;}
|
bool getIsHit() const {return mIsHit;}
|
||||||
|
@ -44,7 +44,7 @@ TriangleShape::TriangleShape(const Vector3& point1, const Vector3& point2, const
|
|||||||
mPoints[0] = point1;
|
mPoints[0] = point1;
|
||||||
mPoints[1] = point2;
|
mPoints[1] = point2;
|
||||||
mPoints[2] = point3;
|
mPoints[2] = point3;
|
||||||
mRaycastTestType = FRONT;
|
m_raycastTestType = FRONT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@ -68,32 +68,32 @@ bool TriangleShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape
|
|||||||
// product for this test.
|
// product for this test.
|
||||||
const Vector3 m = pq.cross(pc);
|
const Vector3 m = pq.cross(pc);
|
||||||
decimal u = pb.dot(m);
|
decimal u = pb.dot(m);
|
||||||
if (mRaycastTestType == FRONT) {
|
if (m_raycastTestType == FRONT) {
|
||||||
if (u < decimal(0.0)) return false;
|
if (u < decimal(0.0)) return false;
|
||||||
}
|
}
|
||||||
else if (mRaycastTestType == BACK) {
|
else if (m_raycastTestType == BACK) {
|
||||||
if (u > decimal(0.0)) return false;
|
if (u > decimal(0.0)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
decimal v = -pa.dot(m);
|
decimal v = -pa.dot(m);
|
||||||
if (mRaycastTestType == FRONT) {
|
if (m_raycastTestType == FRONT) {
|
||||||
if (v < decimal(0.0)) return false;
|
if (v < decimal(0.0)) return false;
|
||||||
}
|
}
|
||||||
else if (mRaycastTestType == BACK) {
|
else if (m_raycastTestType == BACK) {
|
||||||
if (v > decimal(0.0)) return false;
|
if (v > decimal(0.0)) return false;
|
||||||
}
|
}
|
||||||
else if (mRaycastTestType == FRONT_AND_BACK) {
|
else if (m_raycastTestType == FRONT_AND_BACK) {
|
||||||
if (!sameSign(u, v)) return false;
|
if (!sameSign(u, v)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
decimal w = pa.dot(pq.cross(pb));
|
decimal w = pa.dot(pq.cross(pb));
|
||||||
if (mRaycastTestType == FRONT) {
|
if (m_raycastTestType == FRONT) {
|
||||||
if (w < decimal(0.0)) return false;
|
if (w < decimal(0.0)) return false;
|
||||||
}
|
}
|
||||||
else if (mRaycastTestType == BACK) {
|
else if (m_raycastTestType == BACK) {
|
||||||
if (w > decimal(0.0)) return false;
|
if (w > decimal(0.0)) return false;
|
||||||
}
|
}
|
||||||
else if (mRaycastTestType == FRONT_AND_BACK) {
|
else if (m_raycastTestType == FRONT_AND_BACK) {
|
||||||
if (!sameSign(u, w)) return false;
|
if (!sameSign(u, w)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class TriangleShape : public ConvexShape {
|
|||||||
Vector3 mPoints[3];
|
Vector3 mPoints[3];
|
||||||
|
|
||||||
/// Raycast test type for the triangle (front, back, front-back)
|
/// Raycast test type for the triangle (front, back, front-back)
|
||||||
TriangleRaycastSide mRaycastTestType;
|
TriangleRaycastSide m_raycastTestType;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ inline bool TriangleShape::testPointInside(const Vector3& localPoint, ProxyShape
|
|||||||
|
|
||||||
// Return the raycast test type (front, back, front-back)
|
// Return the raycast test type (front, back, front-back)
|
||||||
inline TriangleRaycastSide TriangleShape::getRaycastTestType() const {
|
inline TriangleRaycastSide TriangleShape::getRaycastTestType() const {
|
||||||
return mRaycastTestType;
|
return m_raycastTestType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the raycast test type (front, back, front-back)
|
// Set the raycast test type (front, back, front-back)
|
||||||
@ -206,7 +206,7 @@ inline TriangleRaycastSide TriangleShape::getRaycastTestType() const {
|
|||||||
* @param testType Raycast test type for the triangle (front, back, front-back)
|
* @param testType Raycast test type for the triangle (front, back, front-back)
|
||||||
*/
|
*/
|
||||||
inline void TriangleShape::setRaycastTestType(TriangleRaycastSide testType) {
|
inline void TriangleShape::setRaycastTestType(TriangleRaycastSide testType) {
|
||||||
mRaycastTestType = testType;
|
m_raycastTestType = testType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the coordinates of a given vertex of the triangle
|
// Return the coordinates of a given vertex of the triangle
|
||||||
|
@ -28,13 +28,7 @@
|
|||||||
|
|
||||||
/// ReactPhysiscs3D namespace
|
/// ReactPhysiscs3D namespace
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
#if defined(IS_DOUBLE_PRECISION_ENABLED) // If we are compiling for double precision
|
|
||||||
typedef double decimal;
|
|
||||||
#else // If we are compiling for single precision
|
|
||||||
typedef float decimal;
|
typedef float decimal;
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -87,7 +87,7 @@ class TestDynamicAABBTree : public Test {
|
|||||||
// ---------- Atributes ---------- //
|
// ---------- Atributes ---------- //
|
||||||
|
|
||||||
OverlapCallback mOverlapCallback;
|
OverlapCallback mOverlapCallback;
|
||||||
DynamicTreeRaycastCallback mRaycastCallback;
|
DynamicTreeRaycastCallback m_raycastCallback;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -377,40 +377,40 @@ class TestDynamicAABBTree : public Test {
|
|||||||
// ---------- Tests ---------- //
|
// ---------- Tests ---------- //
|
||||||
|
|
||||||
// Ray with no hits
|
// Ray with no hits
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
Ray ray1(Vector3(4.5, -10, -5), Vector3(4.5, 10, -5));
|
Ray ray1(Vector3(4.5, -10, -5), Vector3(4.5, 10, -5));
|
||||||
tree.raycast(ray1, mRaycastCallback);
|
tree.raycast(ray1, m_raycastCallback);
|
||||||
test(!mRaycastCallback.isHit(object1Id));
|
test(!m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 1
|
// Ray that hits object 1
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
Ray ray2(Vector3(-1, -20, -2), Vector3(-1, 20, -2));
|
Ray ray2(Vector3(-1, -20, -2), Vector3(-1, 20, -2));
|
||||||
tree.raycast(ray2, mRaycastCallback);
|
tree.raycast(ray2, m_raycastCallback);
|
||||||
test(mRaycastCallback.isHit(object1Id));
|
test(m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 1 and 2
|
// Ray that hits object 1 and 2
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
Ray ray3(Vector3(-7, 6, -2), Vector3(8, 6, -2));
|
Ray ray3(Vector3(-7, 6, -2), Vector3(8, 6, -2));
|
||||||
tree.raycast(ray3, mRaycastCallback);
|
tree.raycast(ray3, m_raycastCallback);
|
||||||
test(mRaycastCallback.isHit(object1Id));
|
test(m_raycastCallback.isHit(object1Id));
|
||||||
test(mRaycastCallback.isHit(object2Id));
|
test(m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 3
|
// Ray that hits object 3
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
Ray ray4(Vector3(-7, 2, 0), Vector3(-1, 2, 0));
|
Ray ray4(Vector3(-7, 2, 0), Vector3(-1, 2, 0));
|
||||||
tree.raycast(ray4, mRaycastCallback);
|
tree.raycast(ray4, m_raycastCallback);
|
||||||
test(!mRaycastCallback.isHit(object1Id));
|
test(!m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(mRaycastCallback.isHit(object3Id));
|
test(m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- //
|
// ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- //
|
||||||
|
|
||||||
@ -420,36 +420,36 @@ class TestDynamicAABBTree : public Test {
|
|||||||
tree.updateObject(object4Id, aabb4, Vector3::zero(), false);
|
tree.updateObject(object4Id, aabb4, Vector3::zero(), false);
|
||||||
|
|
||||||
// Ray with no hits
|
// Ray with no hits
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray1, mRaycastCallback);
|
tree.raycast(ray1, m_raycastCallback);
|
||||||
test(!mRaycastCallback.isHit(object1Id));
|
test(!m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 1
|
// Ray that hits object 1
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray2, mRaycastCallback);
|
tree.raycast(ray2, m_raycastCallback);
|
||||||
test(mRaycastCallback.isHit(object1Id));
|
test(m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 1 and 2
|
// Ray that hits object 1 and 2
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray3, mRaycastCallback);
|
tree.raycast(ray3, m_raycastCallback);
|
||||||
test(mRaycastCallback.isHit(object1Id));
|
test(m_raycastCallback.isHit(object1Id));
|
||||||
test(mRaycastCallback.isHit(object2Id));
|
test(m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 3
|
// Ray that hits object 3
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray4, mRaycastCallback);
|
tree.raycast(ray4, m_raycastCallback);
|
||||||
test(!mRaycastCallback.isHit(object1Id));
|
test(!m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(mRaycastCallback.isHit(object3Id));
|
test(m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- //
|
// ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- //
|
||||||
|
|
||||||
@ -459,36 +459,36 @@ class TestDynamicAABBTree : public Test {
|
|||||||
tree.updateObject(object4Id, aabb4, Vector3::zero(), true);
|
tree.updateObject(object4Id, aabb4, Vector3::zero(), true);
|
||||||
|
|
||||||
// Ray with no hits
|
// Ray with no hits
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray1, mRaycastCallback);
|
tree.raycast(ray1, m_raycastCallback);
|
||||||
test(!mRaycastCallback.isHit(object1Id));
|
test(!m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 1
|
// Ray that hits object 1
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray2, mRaycastCallback);
|
tree.raycast(ray2, m_raycastCallback);
|
||||||
test(mRaycastCallback.isHit(object1Id));
|
test(m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 1 and 2
|
// Ray that hits object 1 and 2
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray3, mRaycastCallback);
|
tree.raycast(ray3, m_raycastCallback);
|
||||||
test(mRaycastCallback.isHit(object1Id));
|
test(m_raycastCallback.isHit(object1Id));
|
||||||
test(mRaycastCallback.isHit(object2Id));
|
test(m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 3
|
// Ray that hits object 3
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray4, mRaycastCallback);
|
tree.raycast(ray4, m_raycastCallback);
|
||||||
test(!mRaycastCallback.isHit(object1Id));
|
test(!m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(mRaycastCallback.isHit(object3Id));
|
test(m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// ---- Move objects 2 and 3 ----- //
|
// ---- Move objects 2 and 3 ----- //
|
||||||
|
|
||||||
@ -500,21 +500,21 @@ class TestDynamicAABBTree : public Test {
|
|||||||
|
|
||||||
// Ray that hits object 1, 2
|
// Ray that hits object 1, 2
|
||||||
Ray ray5(Vector3(-4, -5, 0), Vector3(-4, 12, 0));
|
Ray ray5(Vector3(-4, -5, 0), Vector3(-4, 12, 0));
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray5, mRaycastCallback);
|
tree.raycast(ray5, m_raycastCallback);
|
||||||
test(mRaycastCallback.isHit(object1Id));
|
test(m_raycastCallback.isHit(object1Id));
|
||||||
test(mRaycastCallback.isHit(object2Id));
|
test(m_raycastCallback.isHit(object2Id));
|
||||||
test(!mRaycastCallback.isHit(object3Id));
|
test(!m_raycastCallback.isHit(object3Id));
|
||||||
test(!mRaycastCallback.isHit(object4Id));
|
test(!m_raycastCallback.isHit(object4Id));
|
||||||
|
|
||||||
// Ray that hits object 3 and 4
|
// Ray that hits object 3 and 4
|
||||||
Ray ray6(Vector3(11, -3, 1), Vector3(-2, -3, 1));
|
Ray ray6(Vector3(11, -3, 1), Vector3(-2, -3, 1));
|
||||||
mRaycastCallback.reset();
|
m_raycastCallback.reset();
|
||||||
tree.raycast(ray6, mRaycastCallback);
|
tree.raycast(ray6, m_raycastCallback);
|
||||||
test(!mRaycastCallback.isHit(object1Id));
|
test(!m_raycastCallback.isHit(object1Id));
|
||||||
test(!mRaycastCallback.isHit(object2Id));
|
test(!m_raycastCallback.isHit(object2Id));
|
||||||
test(mRaycastCallback.isHit(object3Id));
|
test(m_raycastCallback.isHit(object3Id));
|
||||||
test(mRaycastCallback.isHit(object4Id));
|
test(m_raycastCallback.isHit(object4Id));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ class TestRaycast : public Test {
|
|||||||
ConvexMeshShape* mConvexMeshShapeEdgesInfo;
|
ConvexMeshShape* mConvexMeshShapeEdgesInfo;
|
||||||
CylinderShape* mCylinderShape;
|
CylinderShape* mCylinderShape;
|
||||||
TriangleShape* mTriangleShape;
|
TriangleShape* mTriangleShape;
|
||||||
ConcaveShape* mConcaveMeshShape;
|
ConcaveShape* m_concaveMeshShape;
|
||||||
HeightFieldShape* mHeightFieldShape;
|
HeightFieldShape* mHeightFieldShape;
|
||||||
|
|
||||||
// Proxy Shapes
|
// Proxy Shapes
|
||||||
@ -299,8 +299,8 @@ class TestRaycast : public Test {
|
|||||||
|
|
||||||
// Add the triangle vertex array of the subpart to the triangle mesh
|
// Add the triangle vertex array of the subpart to the triangle mesh
|
||||||
mConcaveTriangleMesh.addSubpart(mConcaveMeshVertexArray);
|
mConcaveTriangleMesh.addSubpart(mConcaveMeshVertexArray);
|
||||||
mConcaveMeshShape = new ConcaveMeshShape(&mConcaveTriangleMesh);
|
m_concaveMeshShape = new ConcaveMeshShape(&mConcaveTriangleMesh);
|
||||||
mConcaveMeshProxyShape = mConcaveMeshBody->addCollisionShape(mConcaveMeshShape, mShapeTransform);
|
mConcaveMeshProxyShape = mConcaveMeshBody->addCollisionShape(m_concaveMeshShape, mShapeTransform);
|
||||||
|
|
||||||
|
|
||||||
// Heightfield shape (plane height field at height=4)
|
// Heightfield shape (plane height field at height=4)
|
||||||
@ -333,7 +333,7 @@ class TestRaycast : public Test {
|
|||||||
delete mConvexMeshShapeEdgesInfo;
|
delete mConvexMeshShapeEdgesInfo;
|
||||||
delete mCylinderShape;
|
delete mCylinderShape;
|
||||||
delete mTriangleShape;
|
delete mTriangleShape;
|
||||||
delete mConcaveMeshShape;
|
delete m_concaveMeshShape;
|
||||||
delete mHeightFieldShape;
|
delete mHeightFieldShape;
|
||||||
|
|
||||||
delete mConcaveMeshVertexArray;
|
delete mConcaveMeshVertexArray;
|
||||||
|
@ -145,7 +145,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add the collision shape to the body
|
// Add the collision shape to the body
|
||||||
mProxyShape = mBody->addCollisionShape(mBoxShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mBoxShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
// If the Vertex Buffer object has not been created yet
|
// If the Vertex Buffer object has not been created yet
|
||||||
if (totalNbBoxes == 0) {
|
if (totalNbBoxes == 0) {
|
||||||
@ -194,7 +194,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3& p
|
|||||||
rp3d::RigidBody* body = world->createRigidBody(transform);
|
rp3d::RigidBody* body = world->createRigidBody(transform);
|
||||||
|
|
||||||
// Add the collision shape to the body
|
// Add the collision shape to the body
|
||||||
mProxyShape = body->addCollisionShape(mBoxShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mBoxShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -333,7 +333,7 @@ void Box::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void Box::setScaling(const openglframework::Vector3& scaling) {
|
void Box::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(mSize[0] * scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(mSize[0] * scaling.x, 0, 0, 0,
|
||||||
|
@ -42,7 +42,7 @@ class Box : public openglframework::Object3D, public PhysicsObject {
|
|||||||
float mSize[3];
|
float mSize[3];
|
||||||
|
|
||||||
rp3d::BoxShape* mBoxShape;
|
rp3d::BoxShape* mBoxShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Scaling matrix (applied to a cube to obtain the correct box dimensions)
|
/// Scaling matrix (applied to a cube to obtain the correct box dimensions)
|
||||||
openglframework::Matrix4 mScalingMatrix;
|
openglframework::Matrix4 mScalingMatrix;
|
||||||
|
@ -70,7 +70,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = mBody->addCollisionShape(mCapsuleShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mCapsuleShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos
|
|||||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = body->addCollisionShape(mCapsuleShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mCapsuleShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ void Capsule::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ void Capsule::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void Capsule::setScaling(const openglframework::Vector3& scaling) {
|
void Capsule::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
||||||
|
@ -49,7 +49,7 @@ class Capsule : public openglframework::Mesh, public PhysicsObject {
|
|||||||
|
|
||||||
/// Collision shape
|
/// Collision shape
|
||||||
rp3d::CapsuleShape* mCapsuleShape;
|
rp3d::CapsuleShape* mCapsuleShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Previous transform (for interpolation)
|
/// Previous transform (for interpolation)
|
||||||
rp3d::Transform mPreviousTransform;
|
rp3d::Transform mPreviousTransform;
|
||||||
|
@ -51,7 +51,7 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position,
|
|||||||
|
|
||||||
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
||||||
rp3d::TriangleVertexArray* vertexArray =
|
rp3d::TriangleVertexArray* vertexArray =
|
||||||
new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3),
|
new rp3d::TriangleVertexArray(getNbVertices(), &(m_vertices[0]), sizeof(openglframework::Vector3),
|
||||||
getNbFaces(i), &(mIndices[i][0]), sizeof(int),
|
getNbFaces(i), &(mIndices[i][0]), sizeof(int),
|
||||||
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
||||||
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
||||||
@ -75,7 +75,7 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position,
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the collision shape
|
// Add a collision shape to the body and specify the mass of the collision shape
|
||||||
mProxyShape = mBody->addCollisionShape(mConcaveShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mConcaveShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
// Create the VBOs and VAO
|
// Create the VBOs and VAO
|
||||||
createVBOAndVAO();
|
createVBOAndVAO();
|
||||||
@ -108,7 +108,7 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, float mass,
|
|||||||
|
|
||||||
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
||||||
rp3d::TriangleVertexArray* vertexArray =
|
rp3d::TriangleVertexArray* vertexArray =
|
||||||
new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3),
|
new rp3d::TriangleVertexArray(getNbVertices(), &(m_vertices[0]), sizeof(openglframework::Vector3),
|
||||||
getNbFaces(i), &(mIndices[i][0]), sizeof(int),
|
getNbFaces(i), &(mIndices[i][0]), sizeof(int),
|
||||||
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
||||||
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
||||||
@ -132,7 +132,7 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, float mass,
|
|||||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the collision shape
|
// Add a collision shape to the body and specify the mass of the collision shape
|
||||||
mProxyShape = body->addCollisionShape(mConcaveShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mConcaveShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ void ConcaveMesh::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ void ConcaveMesh::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void ConcaveMesh::setScaling(const openglframework::Vector3& scaling) {
|
void ConcaveMesh::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
||||||
|
@ -43,7 +43,7 @@ class ConcaveMesh : public openglframework::Mesh, public PhysicsObject {
|
|||||||
|
|
||||||
/// Collision shape
|
/// Collision shape
|
||||||
rp3d::ConcaveMeshShape* mConcaveShape;
|
rp3d::ConcaveMeshShape* mConcaveShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Scaling matrix
|
/// Scaling matrix
|
||||||
openglframework::Matrix4 mScalingMatrix;
|
openglframework::Matrix4 mScalingMatrix;
|
||||||
|
@ -69,7 +69,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = mBody->addCollisionShape(mConeShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mConeShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position,
|
|||||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = body->addCollisionShape(mConeShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mConeShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ void Cone::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ void Cone::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void Cone::setScaling(const openglframework::Vector3& scaling) {
|
void Cone::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
||||||
|
@ -46,7 +46,7 @@ class Cone : public openglframework::Mesh, public PhysicsObject {
|
|||||||
|
|
||||||
/// Collision shape
|
/// Collision shape
|
||||||
rp3d::ConeShape* mConeShape;
|
rp3d::ConeShape* mConeShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Scaling matrix (applied to a sphere to obtain the correct cone dimensions)
|
/// Scaling matrix (applied to a sphere to obtain the correct cone dimensions)
|
||||||
openglframework::Matrix4 mScalingMatrix;
|
openglframework::Matrix4 mScalingMatrix;
|
||||||
|
@ -49,7 +49,7 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
|
|||||||
|
|
||||||
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
||||||
mPhysicsTriangleVertexArray =
|
mPhysicsTriangleVertexArray =
|
||||||
new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3),
|
new rp3d::TriangleVertexArray(getNbVertices(), &(m_vertices[0]), sizeof(openglframework::Vector3),
|
||||||
getNbFaces(0), &(mIndices[0][0]), sizeof(int),
|
getNbFaces(0), &(mIndices[0][0]), sizeof(int),
|
||||||
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
||||||
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
||||||
@ -69,7 +69,7 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position,
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the collision shape
|
// Add a collision shape to the body and specify the mass of the collision shape
|
||||||
mProxyShape = mBody->addCollisionShape(mConvexShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mConvexShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
// Create the VBOs and VAO
|
// Create the VBOs and VAO
|
||||||
createVBOAndVAO();
|
createVBOAndVAO();
|
||||||
@ -99,7 +99,7 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass,
|
|||||||
|
|
||||||
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
// Vertex and Indices array for the triangle mesh (data in shared and not copied)
|
||||||
mPhysicsTriangleVertexArray =
|
mPhysicsTriangleVertexArray =
|
||||||
new rp3d::TriangleVertexArray(getNbVertices(), &(mVertices[0]), sizeof(openglframework::Vector3),
|
new rp3d::TriangleVertexArray(getNbVertices(), &(m_vertices[0]), sizeof(openglframework::Vector3),
|
||||||
getNbFaces(0), &(mIndices[0][0]), sizeof(int),
|
getNbFaces(0), &(mIndices[0][0]), sizeof(int),
|
||||||
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE,
|
||||||
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE);
|
||||||
@ -117,7 +117,7 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass,
|
|||||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the collision shape
|
// Add a collision shape to the body and specify the mass of the collision shape
|
||||||
mProxyShape = body->addCollisionShape(mConvexShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mConvexShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ void ConvexMesh::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ void ConvexMesh::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void ConvexMesh::setScaling(const openglframework::Vector3& scaling) {
|
void ConvexMesh::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
||||||
|
@ -45,7 +45,7 @@ class ConvexMesh : public openglframework::Mesh, public PhysicsObject {
|
|||||||
|
|
||||||
/// Collision shape
|
/// Collision shape
|
||||||
rp3d::ConvexMeshShape* mConvexShape;
|
rp3d::ConvexMeshShape* mConvexShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Scaling matrix
|
/// Scaling matrix
|
||||||
openglframework::Matrix4 mScalingMatrix;
|
openglframework::Matrix4 mScalingMatrix;
|
||||||
|
@ -69,7 +69,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = mBody->addCollisionShape(mCylinderShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mCylinderShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p
|
|||||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = body->addCollisionShape(mCylinderShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mCylinderShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ void Cylinder::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ void Cylinder::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void Cylinder::setScaling(const openglframework::Vector3& scaling) {
|
void Cylinder::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
||||||
|
@ -52,7 +52,7 @@ class Cylinder : public openglframework::Mesh, public PhysicsObject {
|
|||||||
|
|
||||||
/// Collision shape
|
/// Collision shape
|
||||||
rp3d::CylinderShape* mCylinderShape;
|
rp3d::CylinderShape* mCylinderShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Vertex Buffer Object for the vertices data
|
/// Vertex Buffer Object for the vertices data
|
||||||
static openglframework::VertexBufferObject mVBOVertices;
|
static openglframework::VertexBufferObject mVBOVertices;
|
||||||
|
@ -88,9 +88,9 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
|||||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transformBody);
|
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transformBody);
|
||||||
|
|
||||||
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
||||||
mProxyShapeSphere1 = body->addCollisionShape(mSphereShape, transformSphereShape1, massSphere);
|
m_proxyShapeSphere1 = body->addCollisionShape(mSphereShape, transformSphereShape1, massSphere);
|
||||||
mProxyShapeSphere2 = body->addCollisionShape(mSphereShape, transformSphereShape2, massSphere);
|
m_proxyShapeSphere2 = body->addCollisionShape(mSphereShape, transformSphereShape2, massSphere);
|
||||||
mProxyShapeCylinder = body->addCollisionShape(mCylinderShape, transformCylinderShape, massCylinder);
|
m_proxyShapeCylinder = body->addCollisionShape(mCylinderShape, transformCylinderShape, massCylinder);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -155,9 +155,9 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position,
|
|||||||
mBody = world->createCollisionBody(transformBody);
|
mBody = world->createCollisionBody(transformBody);
|
||||||
|
|
||||||
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
// Add the three collision shapes to the body and specify the mass and transform of the shapes
|
||||||
mProxyShapeSphere1 = mBody->addCollisionShape(mSphereShape, transformSphereShape1);
|
m_proxyShapeSphere1 = mBody->addCollisionShape(mSphereShape, transformSphereShape1);
|
||||||
mProxyShapeSphere2 = mBody->addCollisionShape(mSphereShape, transformSphereShape2);
|
m_proxyShapeSphere2 = mBody->addCollisionShape(mSphereShape, transformSphereShape2);
|
||||||
mProxyShapeCylinder = mBody->addCollisionShape(mCylinderShape, transformCylinderShape);
|
m_proxyShapeCylinder = mBody->addCollisionShape(mCylinderShape, transformCylinderShape);
|
||||||
|
|
||||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ void Dumbbell::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -326,9 +326,9 @@ void Dumbbell::setScaling(const openglframework::Vector3& scaling) {
|
|||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
rp3d::Vector3 newScaling(scaling.x, scaling.y, scaling.z);
|
rp3d::Vector3 newScaling(scaling.x, scaling.y, scaling.z);
|
||||||
mProxyShapeCylinder->setLocalScaling(newScaling);
|
m_proxyShapeCylinder->setLocalScaling(newScaling);
|
||||||
mProxyShapeSphere1->setLocalScaling(newScaling);
|
m_proxyShapeSphere1->setLocalScaling(newScaling);
|
||||||
mProxyShapeSphere2->setLocalScaling(newScaling);
|
m_proxyShapeSphere2->setLocalScaling(newScaling);
|
||||||
|
|
||||||
mDistanceBetweenSphere = (mDistanceBetweenSphere / mScalingMatrix.getValue(1, 1)) * scaling.y;
|
mDistanceBetweenSphere = (mDistanceBetweenSphere / mScalingMatrix.getValue(1, 1)) * scaling.y;
|
||||||
|
|
||||||
@ -338,8 +338,8 @@ void Dumbbell::setScaling(const openglframework::Vector3& scaling) {
|
|||||||
// Initial transform of the second sphere collision shape of the dumbell (in local-space)
|
// Initial transform of the second sphere collision shape of the dumbell (in local-space)
|
||||||
rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
|
rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity());
|
||||||
|
|
||||||
mProxyShapeSphere1->setLocalToBodyTransform(transformSphereShape1);
|
m_proxyShapeSphere1->setLocalToBodyTransform(transformSphereShape1);
|
||||||
mProxyShapeSphere2->setLocalToBodyTransform(transformSphereShape2);
|
m_proxyShapeSphere2->setLocalToBodyTransform(transformSphereShape2);
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
||||||
|
@ -44,9 +44,9 @@ class Dumbbell : public openglframework::Mesh, public PhysicsObject {
|
|||||||
/// Collision shapes
|
/// Collision shapes
|
||||||
rp3d::CylinderShape* mCylinderShape;
|
rp3d::CylinderShape* mCylinderShape;
|
||||||
rp3d::SphereShape* mSphereShape;
|
rp3d::SphereShape* mSphereShape;
|
||||||
rp3d::ProxyShape* mProxyShapeCylinder;
|
rp3d::ProxyShape* m_proxyShapeCylinder;
|
||||||
rp3d::ProxyShape* mProxyShapeSphere1;
|
rp3d::ProxyShape* m_proxyShapeSphere1;
|
||||||
rp3d::ProxyShape* mProxyShapeSphere2;
|
rp3d::ProxyShape* m_proxyShapeSphere2;
|
||||||
|
|
||||||
/// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions)
|
/// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions)
|
||||||
openglframework::Matrix4 mScalingMatrix;
|
openglframework::Matrix4 mScalingMatrix;
|
||||||
|
@ -62,7 +62,7 @@ HeightField::HeightField(const openglframework::Vector3 &position,
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the collision shape
|
// Add a collision shape to the body and specify the mass of the collision shape
|
||||||
mProxyShape = mBody->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
// Create the VBOs and VAO
|
// Create the VBOs and VAO
|
||||||
createVBOAndVAO();
|
createVBOAndVAO();
|
||||||
@ -103,7 +103,7 @@ HeightField::HeightField(const openglframework::Vector3 &position, float mass,
|
|||||||
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
rp3d::RigidBody* body = dynamicsWorld->createRigidBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the collision shape
|
// Add a collision shape to the body and specify the mass of the collision shape
|
||||||
mProxyShape = body->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mHeightFieldShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ void HeightField::generateGraphicsMesh() {
|
|||||||
float height = originHeight + mHeightData[j * NB_POINTS_WIDTH + i];
|
float height = originHeight + mHeightData[j * NB_POINTS_WIDTH + i];
|
||||||
openglframework::Vector3 vertex(-(NB_POINTS_WIDTH - 1) * 0.5f + i, height, -(NB_POINTS_LENGTH - 1) * 0.5f + j);
|
openglframework::Vector3 vertex(-(NB_POINTS_WIDTH - 1) * 0.5f + i, height, -(NB_POINTS_LENGTH - 1) * 0.5f + j);
|
||||||
|
|
||||||
mVertices.push_back(vertex);
|
m_vertices.push_back(vertex);
|
||||||
|
|
||||||
// Triangle indices
|
// Triangle indices
|
||||||
if ((i < NB_POINTS_WIDTH - 1) && (j < NB_POINTS_LENGTH - 1)) {
|
if ((i < NB_POINTS_WIDTH - 1) && (j < NB_POINTS_LENGTH - 1)) {
|
||||||
@ -271,7 +271,7 @@ void HeightField::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ void HeightField::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void HeightField::setScaling(const openglframework::Vector3& scaling) {
|
void HeightField::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(scaling.x, 0, 0, 0,
|
||||||
|
@ -50,7 +50,7 @@ class HeightField : public openglframework::Mesh, public PhysicsObject {
|
|||||||
|
|
||||||
/// Collision shape
|
/// Collision shape
|
||||||
rp3d::HeightFieldShape* mHeightFieldShape;
|
rp3d::HeightFieldShape* mHeightFieldShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Scaling matrix
|
/// Scaling matrix
|
||||||
openglframework::Matrix4 mScalingMatrix;
|
openglframework::Matrix4 mScalingMatrix;
|
||||||
|
@ -70,7 +70,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
|
|||||||
mBody = world->createCollisionBody(transform);
|
mBody = world->createCollisionBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity());
|
m_proxyShape = mBody->addCollisionShape(mCollisionShape, rp3d::Transform::identity());
|
||||||
|
|
||||||
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
mTransformMatrix = mTransformMatrix * mScalingMatrix;
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position,
|
|||||||
rp3d::RigidBody* body = world->createRigidBody(transform);
|
rp3d::RigidBody* body = world->createRigidBody(transform);
|
||||||
|
|
||||||
// Add a collision shape to the body and specify the mass of the shape
|
// Add a collision shape to the body and specify the mass of the shape
|
||||||
mProxyShape = body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass);
|
m_proxyShape = body->addCollisionShape(mCollisionShape, rp3d::Transform::identity(), mass);
|
||||||
|
|
||||||
mBody = body;
|
mBody = body;
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ void Sphere::createVBOAndVAO() {
|
|||||||
// Create the VBO for the vertices data
|
// Create the VBO for the vertices data
|
||||||
mVBOVertices.create();
|
mVBOVertices.create();
|
||||||
mVBOVertices.bind();
|
mVBOVertices.bind();
|
||||||
size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3);
|
size_t sizeVertices = m_vertices.size() * sizeof(openglframework::Vector3);
|
||||||
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW);
|
||||||
mVBOVertices.unbind();
|
mVBOVertices.unbind();
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ void Sphere::resetTransform(const rp3d::Transform& transform) {
|
|||||||
void Sphere::setScaling(const openglframework::Vector3& scaling) {
|
void Sphere::setScaling(const openglframework::Vector3& scaling) {
|
||||||
|
|
||||||
// Scale the collision shape
|
// Scale the collision shape
|
||||||
mProxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
m_proxyShape->setLocalScaling(rp3d::Vector3(scaling.x, scaling.y, scaling.z));
|
||||||
|
|
||||||
// Scale the graphics object
|
// Scale the graphics object
|
||||||
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
mScalingMatrix = openglframework::Matrix4(mRadius * scaling.x, 0, 0, 0,
|
||||||
|
@ -43,7 +43,7 @@ class Sphere : public openglframework::Mesh, public PhysicsObject {
|
|||||||
|
|
||||||
/// Collision shape
|
/// Collision shape
|
||||||
rp3d::SphereShape* mCollisionShape;
|
rp3d::SphereShape* mCollisionShape;
|
||||||
rp3d::ProxyShape* mProxyShape;
|
rp3d::ProxyShape* m_proxyShape;
|
||||||
|
|
||||||
/// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions)
|
/// Scaling matrix (applied to a sphere to obtain the correct sphere dimensions)
|
||||||
openglframework::Matrix4 mScalingMatrix;
|
openglframework::Matrix4 mScalingMatrix;
|
||||||
|
@ -43,7 +43,7 @@ Mesh::~Mesh() {
|
|||||||
// Destroy the mesh
|
// Destroy the mesh
|
||||||
void Mesh::destroy() {
|
void Mesh::destroy() {
|
||||||
|
|
||||||
mVertices.clear();
|
m_vertices.clear();
|
||||||
mNormals.clear();
|
mNormals.clear();
|
||||||
mTangents.clear();
|
mTangents.clear();
|
||||||
mIndices.clear();
|
mIndices.clear();
|
||||||
@ -139,15 +139,15 @@ void Mesh::calculateTangents() {
|
|||||||
void Mesh::calculateBoundingBox(Vector3& min, Vector3& max) const {
|
void Mesh::calculateBoundingBox(Vector3& min, Vector3& max) const {
|
||||||
|
|
||||||
// If the mesh contains vertices
|
// If the mesh contains vertices
|
||||||
if (!mVertices.empty()) {
|
if (!m_vertices.empty()) {
|
||||||
|
|
||||||
min = mVertices[0];
|
min = m_vertices[0];
|
||||||
max = mVertices[0];
|
max = m_vertices[0];
|
||||||
|
|
||||||
std::vector<Vector3>::const_iterator it(mVertices.begin());
|
std::vector<Vector3>::const_iterator it(m_vertices.begin());
|
||||||
|
|
||||||
// For each vertex of the mesh
|
// For each vertex of the mesh
|
||||||
for (; it != mVertices.end(); ++it) {
|
for (; it != m_vertices.end(); ++it) {
|
||||||
|
|
||||||
if( (*it).x < min.x ) min.x = (*it).x;
|
if( (*it).x < min.x ) min.x = (*it).x;
|
||||||
else if ( (*it).x > max.x ) max.x = (*it).x;
|
else if ( (*it).x > max.x ) max.x = (*it).x;
|
||||||
@ -171,6 +171,6 @@ void Mesh::scaleVertices(float factor) {
|
|||||||
|
|
||||||
// For each vertex
|
// For each vertex
|
||||||
for (uint i=0; i<getNbVertices(); i++) {
|
for (uint i=0; i<getNbVertices(); i++) {
|
||||||
mVertices.at(i) *= factor;
|
m_vertices.at(i) *= factor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class Mesh : public Object3D {
|
|||||||
std::vector<std::vector<unsigned int> > mIndices;
|
std::vector<std::vector<unsigned int> > mIndices;
|
||||||
|
|
||||||
// Vertices coordinates (local space)
|
// Vertices coordinates (local space)
|
||||||
std::vector<Vector3> mVertices;
|
std::vector<Vector3> m_vertices;
|
||||||
|
|
||||||
// Normals coordinates
|
// Normals coordinates
|
||||||
std::vector<Vector3> mNormals;
|
std::vector<Vector3> mNormals;
|
||||||
@ -209,7 +209,7 @@ inline uint Mesh::getNbFaces(uint part) const {
|
|||||||
|
|
||||||
// Return the number of vertices
|
// Return the number of vertices
|
||||||
inline uint Mesh::getNbVertices() const {
|
inline uint Mesh::getNbVertices() const {
|
||||||
return mVertices.size();
|
return m_vertices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the number of parts in the mesh
|
// Return the number of parts in the mesh
|
||||||
@ -219,12 +219,12 @@ inline uint Mesh::getNbParts() const {
|
|||||||
|
|
||||||
// Return a reference to the vertices
|
// Return a reference to the vertices
|
||||||
inline const std::vector<Vector3>& Mesh::getVertices() const {
|
inline const std::vector<Vector3>& Mesh::getVertices() const {
|
||||||
return mVertices;
|
return m_vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the vertices of the mesh
|
// Set the vertices of the mesh
|
||||||
inline void Mesh::setVertices(std::vector<Vector3>& vertices) {
|
inline void Mesh::setVertices(std::vector<Vector3>& vertices) {
|
||||||
mVertices = vertices;
|
m_vertices = vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a reference to the normals
|
// Return a reference to the normals
|
||||||
@ -260,13 +260,13 @@ inline void Mesh::setIndices(std::vector<std::vector<uint> >& indices) {
|
|||||||
// Return the coordinates of a given vertex
|
// Return the coordinates of a given vertex
|
||||||
inline const Vector3& Mesh::getVertex(uint i) const {
|
inline const Vector3& Mesh::getVertex(uint i) const {
|
||||||
assert(i < getNbVertices());
|
assert(i < getNbVertices());
|
||||||
return mVertices[i];
|
return m_vertices[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the coordinates of a given vertex
|
// Set the coordinates of a given vertex
|
||||||
inline void Mesh::setVertex(uint i, const Vector3& vertex) {
|
inline void Mesh::setVertex(uint i, const Vector3& vertex) {
|
||||||
assert(i < getNbVertices());
|
assert(i < getNbVertices());
|
||||||
mVertices[i] = vertex;
|
m_vertices[i] = vertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the coordinates of a given normal
|
// Return the coordinates of a given normal
|
||||||
@ -292,10 +292,10 @@ inline void Mesh::setVertexColor(uint i, const Color& color) {
|
|||||||
|
|
||||||
// If the color array does not have the same size as
|
// If the color array does not have the same size as
|
||||||
// the vertices array
|
// the vertices array
|
||||||
if (mColors.size() != mVertices.size()) {
|
if (mColors.size() != m_vertices.size()) {
|
||||||
|
|
||||||
// Create the color array with the same size
|
// Create the color array with the same size
|
||||||
mColors = std::vector<Color>(mVertices.size());
|
mColors = std::vector<Color>(m_vertices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
mColors[i] = color;
|
mColors[i] = color;
|
||||||
@ -306,13 +306,13 @@ inline void Mesh::setColorToAllVertices(const Color& color) {
|
|||||||
|
|
||||||
// If the color array does not have the same size as
|
// If the color array does not have the same size as
|
||||||
// the vertices array
|
// the vertices array
|
||||||
if (mColors.size() != mVertices.size()) {
|
if (mColors.size() != m_vertices.size()) {
|
||||||
|
|
||||||
// Create the color array with the same size
|
// Create the color array with the same size
|
||||||
mColors = std::vector<Color>(mVertices.size());
|
mColors = std::vector<Color>(m_vertices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t v=0; v<mVertices.size(); v++) {
|
for (size_t v=0; v<m_vertices.size(); v++) {
|
||||||
mColors[v] = color;
|
mColors[v] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,22 +336,22 @@ inline uint Mesh::getVertexIndexInFace(uint faceIndex, uint i, uint part) const
|
|||||||
|
|
||||||
// Return true if the mesh has normals
|
// Return true if the mesh has normals
|
||||||
inline bool Mesh::hasNormals() const {
|
inline bool Mesh::hasNormals() const {
|
||||||
return mNormals.size() == mVertices.size();
|
return mNormals.size() == m_vertices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the mesh has tangents
|
// Return true if the mesh has tangents
|
||||||
inline bool Mesh::hasTangents() const {
|
inline bool Mesh::hasTangents() const {
|
||||||
return mTangents.size() == mVertices.size();
|
return mTangents.size() == m_vertices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the mesh has vertex colors
|
// Return true if the mesh has vertex colors
|
||||||
inline bool Mesh::hasColors() const {
|
inline bool Mesh::hasColors() const {
|
||||||
return mColors.size() == mVertices.size();
|
return mColors.size() == m_vertices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the mesh has UV texture coordinates
|
// Return true if the mesh has UV texture coordinates
|
||||||
inline bool Mesh::hasUVTextureCoordinates() const {
|
inline bool Mesh::hasUVTextureCoordinates() const {
|
||||||
return mUVs.size() == mVertices.size();
|
return mUVs.size() == m_vertices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the mesh has a texture for a given part of the mesh and if it
|
// Return true if the mesh has a texture for a given part of the mesh and if it
|
||||||
@ -368,7 +368,7 @@ inline bool Mesh::hasTexture() const {
|
|||||||
|
|
||||||
// Return a pointer to the vertices data
|
// Return a pointer to the vertices data
|
||||||
inline void* Mesh::getVerticesPointer() {
|
inline void* Mesh::getVerticesPointer() {
|
||||||
return &(mVertices[0]);
|
return &(m_vertices[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a pointer to the normals data
|
// Return a pointer to the normals data
|
||||||
|
@ -33,7 +33,7 @@ using namespace raycastscene;
|
|||||||
// Constructor
|
// Constructor
|
||||||
RaycastScene::RaycastScene(const std::string& name)
|
RaycastScene::RaycastScene(const std::string& name)
|
||||||
: SceneDemo(name, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
|
: SceneDemo(name, SCENE_RADIUS, false), mMeshFolderPath("meshes/"),
|
||||||
mRaycastManager(mPhongShader, mMeshFolderPath), mCurrentBodyIndex(-1),
|
m_raycastManager(mPhongShader, mMeshFolderPath), mCurrentBodyIndex(-1),
|
||||||
mAreNormalsDisplayed(false), mVBOVertices(GL_ARRAY_BUFFER) {
|
mAreNormalsDisplayed(false), mVBOVertices(GL_ARRAY_BUFFER) {
|
||||||
|
|
||||||
mIsContactPointsDisplayed = true;
|
mIsContactPointsDisplayed = true;
|
||||||
@ -278,7 +278,7 @@ RaycastScene::~RaycastScene() {
|
|||||||
// Destroy the convex mesh
|
// Destroy the convex mesh
|
||||||
delete mHeightField;
|
delete mHeightField;
|
||||||
|
|
||||||
mRaycastManager.resetPoints();
|
m_raycastManager.resetPoints();
|
||||||
|
|
||||||
// Destroy the static data for the visual contact points
|
// Destroy the static data for the visual contact points
|
||||||
VisualContactPoint::destroyStaticData();
|
VisualContactPoint::destroyStaticData();
|
||||||
@ -306,7 +306,7 @@ void RaycastScene::updatePhysics() {
|
|||||||
// Take a step for the simulation
|
// Take a step for the simulation
|
||||||
void RaycastScene::update() {
|
void RaycastScene::update() {
|
||||||
|
|
||||||
mRaycastManager.resetPoints();
|
m_raycastManager.resetPoints();
|
||||||
|
|
||||||
// For each line of the scene
|
// For each line of the scene
|
||||||
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end();
|
for (std::vector<Line*>::iterator it = mLines.begin(); it != mLines.end();
|
||||||
@ -324,7 +324,7 @@ void RaycastScene::update() {
|
|||||||
|
|
||||||
// Perform a raycast query on the physics world by passing a raycast
|
// Perform a raycast query on the physics world by passing a raycast
|
||||||
// callback class in argument.
|
// callback class in argument.
|
||||||
mCollisionWorld->raycast(ray, &mRaycastManager);
|
mCollisionWorld->raycast(ray, &m_raycastManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneDemo::update();
|
SceneDemo::update();
|
||||||
|
@ -125,7 +125,7 @@ class RaycastScene : public SceneDemo {
|
|||||||
std::string mMeshFolderPath;
|
std::string mMeshFolderPath;
|
||||||
|
|
||||||
/// Raycast manager
|
/// Raycast manager
|
||||||
RaycastManager mRaycastManager;
|
RaycastManager m_raycastManager;
|
||||||
|
|
||||||
/// All the raycast lines
|
/// All the raycast lines
|
||||||
std::vector<Line*> mLines;
|
std::vector<Line*> mLines;
|
||||||
@ -228,7 +228,7 @@ inline void RaycastScene::setIsContactPointsDisplayed(bool display) {
|
|||||||
|
|
||||||
// Return all the contact points of the scene
|
// Return all the contact points of the scene
|
||||||
inline std::vector<ContactPoint> RaycastScene::getContactPoints() const {
|
inline std::vector<ContactPoint> RaycastScene::getContactPoints() const {
|
||||||
return mRaycastManager.getHitPoints();
|
return m_raycastManager.getHitPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user