Jelajahi Sumber

Removed dependence on RTTI in 3D physics module

Ivan Safrin 9 tahun lalu
induk
melakukan
6dc00d5980

+ 4 - 7
include/polycode/modules/physics3D/PolyCollisionSceneEntity.h

@@ -36,12 +36,14 @@ namespace Polycode {
 	/**
 	* A wrapped around Entity that provides collision information.
 	*/
+	
+	class MeshGeometry;
 	class _PolyExport CollisionEntity {
 		public:
 			/**
 			* Main constructor.
 			*/ 
-			CollisionEntity(Entity *entity, int type, bool compoundChildren = false);
+			CollisionEntity(Entity *entity, int type, bool compoundChildren = false, MeshGeometry *collisionGeometry = NULL);
 			virtual ~CollisionEntity();
 			
 			/** @name Collision scene entity
@@ -58,8 +60,7 @@ namespace Polycode {
 			
 			virtual void Update();
 		
-			btConvexShape *getConvexShape(){ return convexShape; }					
-			btCollisionShape *createCollisionShape(Entity *entity, int type);		
+			btCollisionShape *createCollisionShape(Entity *entity, int type, MeshGeometry *collisionGeometry);
 			btCollisionObject *collisionObject;		
 			Vector3 lastPosition;
 		
@@ -112,10 +113,6 @@ namespace Polycode {
 		
 		protected:
 		
-
-			btConvexShape *convexShape;
-			btConcaveShape *concaveShape;
-		
 			int type;
 			Entity *entity;
 	

+ 4 - 1
include/polycode/modules/physics3D/PolyPhysicsSceneEntity.h

@@ -38,9 +38,12 @@ namespace Polycode {
 	/**
 	* A wrapper around Entity that provides physics information.
 	*/
+	
+	class MeshGeometry;
+	
 	class _PolyExport PhysicsEntity : public CollisionEntity {
 	public:
-		PhysicsEntity(Entity *entity, int type, Number mass, Number friction, Number restitution, bool compoundChildren = false);
+		PhysicsEntity(Entity *entity, int type, Number mass, Number friction, Number restitution, bool compoundChildren = false, MeshGeometry *collisionGeometry = NULL);
 		virtual ~PhysicsEntity();
 		virtual void Update();
 				

+ 1 - 1
lib

@@ -1 +1 @@
-Subproject commit c55c4fec1d77ab356c0cf72ba175efc88b14ed05
+Subproject commit 9ef47aab442195e5bef4b28bc114ca2244ed59e9

+ 0 - 1
src/core/PolyEventDispatcher.cpp

@@ -81,7 +81,6 @@ void EventDispatcher::removeEventListener(EventHandler *handler, int eventCode)
 }
 
 void EventDispatcher::__dispatchEvent(Event *event, int eventCode) {
-	//		event->setDispatcher(dynamic_cast<void*>(this));
 	event->setDispatcher(this);
 	event->setEventCode(eventCode);
 	for(int i=0;i<handlerEntries.size();i++) {

+ 8 - 19
src/modules/physics3D/PolyCollisionSceneEntity.cpp

@@ -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));
 			}
 		}

+ 2 - 2
src/modules/physics3D/PolyPhysicsSceneEntity.cpp

@@ -134,7 +134,7 @@ PhysicsCharacter::PhysicsCharacter(Entity *entity, Number mass, Number friction,
 	ghostObject->setFriction(friction); 
 	
 	ghostObject->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);	
-	character = new btKinematicCharacterController (ghostObject,convexShape,btScalar(stepSize));			
+	character = new btKinematicCharacterController (ghostObject,(btConvexShape*) shape,btScalar(stepSize));
 	
 }
 
@@ -181,7 +181,7 @@ PhysicsCharacter::~PhysicsCharacter() {
 	delete ghostObject; 
 }
 
-PhysicsEntity::PhysicsEntity(Entity *entity, int type, Number mass, Number friction, Number restitution, bool compoundChildren) : CollisionEntity(entity, type, compoundChildren) {
+PhysicsEntity::PhysicsEntity(Entity *entity, int type, Number mass, Number friction, Number restitution, bool compoundChildren, MeshGeometry *collisionGeometry) : CollisionEntity(entity, type, compoundChildren, collisionGeometry) {
 	enabled = true;
 	this->mass = mass;
 	btVector3 localInertia(0,0,0);