Jelajahi Sumber

Added ENTITY_CAPSULE and ENTITY_TRIPLE_CIRCLE entity types to 2d physics

Ivan Safrin 12 tahun lalu
induk
melakukan
5e9aebe160

+ 9 - 0
Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h

@@ -129,6 +129,15 @@ namespace Polycode {
 			* Edge phyiscs Entity
 			*/ 
             static const int ENTITY_EDGE = 4;
+			/**
+			* Capsule entity. 
+			*/ 
+            static const int ENTITY_CAPSULE = 5;
+
+			/**
+			* Three vertical circles.
+			*/ 
+            static const int ENTITY_TRIPLE_CIRCLE = 6;
 
 
 			b2Body *body;			

+ 35 - 1
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -94,7 +94,41 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 			fixture = body->CreateFixture(&fDef);
 			break;
         }
-        break;
+		case ENTITY_CAPSULE: {
+		
+			Number rectSize = (screenEntity->getHeight()/(worldScale*2.0f) * entityScale.y) - (screenEntity->getWidth()/(worldScale*2.0f * entityScale.y));
+					
+			b2CircleShape Shape;
+			fDef.shape = &Shape;
+			Shape.m_radius = screenEntity->getWidth()/(worldScale*2.0f);			
+			Shape.m_p.y = rectSize;
+			fixture = body->CreateFixture(&fDef);
+			Shape.m_p.y = -rectSize;
+			fixture = body->CreateFixture(&fDef);
+			
+			b2PolygonShape Shape2;
+			fDef.shape = &Shape2;
+			Shape2.SetAsBox(screenEntity->getWidth()/(worldScale*2.0f) * entityScale.x, rectSize);
+			fixture = body->CreateFixture(&fDef);
+			break;						
+		}
+		break;
+		case ENTITY_TRIPLE_CIRCLE: {
+		
+			Number rectSize = (screenEntity->getHeight()/(worldScale*2.0f) * entityScale.y) - (screenEntity->getWidth()/(worldScale*2.0f * entityScale.y));
+					
+			b2CircleShape Shape;
+			fDef.shape = &Shape;
+			Shape.m_radius = screenEntity->getWidth()/(worldScale*2.0f);			
+			Shape.m_p.y = rectSize;
+			fixture = body->CreateFixture(&fDef);
+			Shape.m_p.y = -rectSize;
+			fixture = body->CreateFixture(&fDef);
+			Shape.m_p.y = 0;
+			fixture = body->CreateFixture(&fDef);
+			break;						
+		}
+		break;	
 		case ENTITY_MESH: {
 			b2PolygonShape Shape;
 			fDef.shape = &Shape;