|
|
@@ -29,7 +29,7 @@ THE SOFTWARE.
|
|
|
|
|
|
using namespace Polycode;
|
|
|
|
|
|
-CollisionEntity::CollisionEntity(Entity *entity, int type, bool compoundChildren) {
|
|
|
+CollisionEntity::CollisionEntity(Entity *entity, int type, bool compoundChildren, MeshGeometry *collisionGeometry) {
|
|
|
this->entity = entity;
|
|
|
shape = NULL;
|
|
|
|
|
|
@@ -49,7 +49,7 @@ CollisionEntity::CollisionEntity(Entity *entity, int type, bool compoundChildren
|
|
|
|
|
|
for(int i=0; i < entity->getNumChildren(); i++) {
|
|
|
Entity *child = (Entity*)entity->getChildAtIndex(i);
|
|
|
- btCollisionShape *childShape = createCollisionShape(child, child->collisionShapeType);
|
|
|
+ btCollisionShape *childShape = createCollisionShape(child, child->collisionShapeType, collisionGeometry);
|
|
|
btTransform transform;
|
|
|
|
|
|
child->rebuildTransformMatrix();
|
|
|
@@ -67,7 +67,7 @@ CollisionEntity::CollisionEntity(Entity *entity, int type, bool compoundChildren
|
|
|
|
|
|
shape = compoundShape;
|
|
|
} else {
|
|
|
- shape = createCollisionShape(entity, type);
|
|
|
+ shape = createCollisionShape(entity, type, collisionGeometry);
|
|
|
}
|
|
|
|
|
|
if(shape) {
|
|
|
@@ -75,15 +75,9 @@ CollisionEntity::CollisionEntity(Entity *entity, int type, bool compoundChildren
|
|
|
}
|
|
|
|
|
|
collisionObject->setUserPointer((void*)this);
|
|
|
-
|
|
|
-// if(type == SHAPE_MESH) {
|
|
|
-// concaveShape = dynamic_cast<btConcaveShape*>(shape);
|
|
|
-// } else {
|
|
|
- convexShape = dynamic_cast<btConvexShape*>(shape);
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
-btCollisionShape *CollisionEntity::createCollisionShape(Entity *entity, int type) {
|
|
|
+btCollisionShape *CollisionEntity::createCollisionShape(Entity *entity, int type, MeshGeometry *collisionGeometry) {
|
|
|
|
|
|
btCollisionShape *collisionShape = NULL;
|
|
|
|
|
|
@@ -127,21 +121,16 @@ btCollisionShape *CollisionEntity::createCollisionShape(Entity *entity, int type
|
|
|
break;
|
|
|
case SHAPE_MESH:
|
|
|
{
|
|
|
- SceneMesh* sceneMesh = dynamic_cast<SceneMesh*>(entity);
|
|
|
- if(sceneMesh != NULL) {
|
|
|
+ if(collisionGeometry) {
|
|
|
btConvexHullShape *hullShape = new btConvexHullShape();
|
|
|
- Mesh *mesh = sceneMesh->getMesh();
|
|
|
- // TODO: fix to work with new mesh system
|
|
|
- /*
|
|
|
- for(int i=0; i < mesh->vertexPositionArray.data.size()-2; i += 3) {
|
|
|
+ for(int i=0; i < collisionGeometry->vertexPositionArray.data.size()-2; i += 3) {
|
|
|
|
|
|
- hullShape->addPoint(btVector3((btScalar)mesh->vertexPositionArray.data[i], (btScalar)mesh->vertexPositionArray.data[i+1],mesh->vertexPositionArray.data[i+2]));
|
|
|
+ hullShape->addPoint(btVector3((btScalar)collisionGeometry->vertexPositionArray.data[i], (btScalar)collisionGeometry->vertexPositionArray.data[i+1],collisionGeometry->vertexPositionArray.data[i+2]));
|
|
|
}
|
|
|
- */
|
|
|
collisionShape = hullShape;
|
|
|
|
|
|
} else {
|
|
|
- Logger::log("Tried to make a mesh collision object from a non-mesh\n");
|
|
|
+ Logger::log("Warning: Mesh collision data not supplied to SHAPE_MESH collision entity.\n");
|
|
|
collisionShape = new btBoxShape(btVector3(bBox.x/2.0f, bBox.y/2.0f,bBox.z/2.0f));
|
|
|
}
|
|
|
}
|