ソースを参照

more comments

Paul Smith 13 年 前
コミット
b4eec23553

+ 27 - 20
Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h

@@ -38,7 +38,9 @@ namespace Polycode {
             PhysicsScreenEntity() { collisionOnly = false; }
         
 			PhysicsScreenEntity(ScreenEntity *entity, b2World *world, Number worldScale, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex = 0);
-			virtual ~PhysicsScreenEntity();		
+			virtual ~PhysicsScreenEntity();
+
+			virtual void Update();
 			
 			/**
 			* Returns the screen entity associated with this physics entity.
@@ -51,32 +53,37 @@ namespace Polycode {
 			void applyTorque(Number torque);
 			
 			/**
-			* Applies force to the physics entity		
-			*/			
+			 * Applies force to the physics entity		
+			 */			
 			void applyForce(Vector2 force);
-		
-			void setTransform(Vector2 pos, Number angle);
+
+			/**
+			 * Applies an impulse to the physics entity		
+			 */
+			void applyImpulse(Number fx, Number fy);
 			
-			virtual void Update();
+			/**
+			 * Sets the position and rotation of entity
+			 */
+			void setTransform(Vector2 pos, Number angle);
 			
+			/**
+             * Sets the velocity of the physics entity
+             */
 			void setVelocity(Number fx, Number fy);	
 			void setVelocityX( Number fx);	
 			void setVelocityY(Number fy);				
         
-			void applyImpulse(Number fx, Number fy);
-			
             /**
-             * Sets the damping of the physics entity
+             * Sets the dampening of the physics entity
              */
-        
             void setLinearDamping(Number damping);
             void setAngularDamping(Number damping);
             void setFriction(Number friction);
         
             /**
-             * Returns damping information
+             * Returns dampening information
              */ 
-        
             Number getLinearDamping();
             Number getAngularDamping();
             Number getFriction();
@@ -84,7 +91,6 @@ namespace Polycode {
             /**
              * Sets physics entity density
              */
-        
             void setDensity(Number density);
             Number getDensity();
         
@@ -94,14 +100,12 @@ namespace Polycode {
              * Collision mask specifies which bits the physics entity will collide with. default 65535 (or 0xFFFF, or "1111111111111111", or everything)
              * If a physics entity's mask bits don't line up with any of an overlapping entity's category bits, their collisions will be skipped
              */
-            
             void setCollisionCategory(int categoryBits);
             void setCollisionMask(int maskBits);
-        
             void setCollisionGroupIndex(int group);
 
 			/**
-			 * Gets a specific fixture via it's index position
+			 * Gets a specific fixture based on it's index position
 			 */
 			b2Fixture* getFixture(unsigned short index);
 			/**
@@ -118,12 +122,15 @@ namespace Polycode {
 			*/ 			
 			static const int ENTITY_CIRCLE = 2;	
 			/**
-			* Mesh entity.
+			* Mesh physics entity.
 			*/ 						
 			static const int ENTITY_MESH = 3;
-        
+			/**
+			* Edge phyiscs Entity
+			*/ 
             static const int ENTITY_EDGE = 4;
 
+
 			b2Body *body;			
 			b2Fixture *fixture;		
 			
@@ -131,8 +138,8 @@ namespace Polycode {
 
 		protected:
         
-		Number worldScale;        
-        ScreenEntity *screenEntity;   		
+			Number worldScale;        
+			ScreenEntity *screenEntity;   		
 	};
 
 }

+ 6 - 18
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -54,7 +54,7 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 	else
 		bodyDef.type = b2_dynamicBody;
 
-		// Create the body
+	// Create the body
 	body = world->CreateBody(&bodyDef);
 	body->SetUserData(this);
 	
@@ -65,15 +65,13 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 	fDef.density = density;
 	fDef.isSensor = isSensor;
 	fDef.filter.groupIndex = groupIndex;
-	fDef.userData = screenEntity;
 
 	// Create Shape definition (Circle/Rectangle/Polygon)---------------------------
 	switch(entType) {
 		case ENTITY_CIRCLE: {
 			b2CircleShape Shape;
-			// Set fixture shape to shape definition
 			fDef.shape = &Shape;
-			// Create the shape
+			// Set the shape
 			Shape.m_radius = screenEntity->getWidth()/(worldScale*2.0f);
 			// Create the fixture
 			fixture = body->CreateFixture(&fDef);
@@ -81,9 +79,8 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 		}
 		case ENTITY_RECT: {
 			b2PolygonShape Shape;
-			// Set fixture shape to shape definition
 			fDef.shape = &Shape;
-			// Create the shape
+			// Set the shape
 			Shape.SetAsBox(screenEntity->getWidth()/(worldScale*2.0f) * entityScale.x, screenEntity->getHeight()/(worldScale*2.0f) * entityScale.y);
 			// Create the fixture
 			fixture = body->CreateFixture(&fDef);
@@ -100,31 +97,23 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
         break;
 		case ENTITY_MESH: {
 			b2PolygonShape Shape;
-			// Set fixture shape to shape definition
 			fDef.shape = &Shape;
-			// Get the screenmesh of the entity
 			ScreenMesh* screenMesh = dynamic_cast<ScreenMesh*>(entity);
 		
 			if(screenMesh) {
 				for(short i=0, polycount=screenMesh->getMesh()->getPolygonCount(); i < polycount; i++) {
-					// Get the next polygon
 					Polygon* poly = screenMesh->getMesh()->getPolygon(i);
-					// Get the vertex count of current polygon
 					unsigned short vertexcount = poly->getVertexCount();
-
 					if (vertexcount >= 3 && vertexcount <= 8) {
-						// Create new vertices array based on vertexcount
 						b2Vec2* vertices = new b2Vec2[vertexcount];
-						// and copy from the screenmesh
 						for(short index=0; index < vertexcount; index++) {
 							vertices[index].x = poly->getVertex(index)->x/worldScale;
 							vertices[index].y = poly->getVertex(index)->y/worldScale;						
 						}
-						// Create the shape
+						// Set the shape
 						Shape.Set(vertices, vertexcount);
 						// Create the fixture
 						fixture = body->CreateFixture(&fDef);
-
 						delete []vertices;
 					}
 					else { Logger::log("Between 3 and 8 vertices allowed per polygon\n"); }
@@ -205,7 +194,7 @@ void PhysicsScreenEntity::setFriction(Number friction) {
     }
 }
 
-void PhysicsScreenEntity::setDensity(Number density){
+void PhysicsScreenEntity::setDensity(Number density) {
     if(fixture) {
         fixture->SetDensity(density);
     }
@@ -290,8 +279,7 @@ b2Fixture* PhysicsScreenEntity::getFixture() { return fixture; }
 // I believe that at runtime you are not supposed to edit Shapes; However you still can
 // by getting a fixture(above) and then adding "->GetShape()" on the end to get the fixtures shape
 
-PhysicsScreenEntity::~PhysicsScreenEntity()
-{
+PhysicsScreenEntity::~PhysicsScreenEntity() {
 	if(body)
 		body->GetWorld()->DestroyBody(body);	// DestroyBody deletes fixtures and shapes automaticaly according to box2d documentation
 }