Răsfoiți Sursa

2D Physics Merge from Doomlaser and fidelity3

This merges our changes to the 2d Phyiscs module into one
Paul Smith 13 ani în urmă
părinte
comite
183f9bbc90

+ 23 - 16
Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h

@@ -85,8 +85,13 @@ class _PolyExport PhysicsScreenEvent : public Event {
 		*/			
 		Vector2 worldCollisionPoint;
 
-			
-		/**
+		/*
+         * Raw Box2d Contact
+         */
+    
+        b2Contact *contact;
+	
+        /**
 		* Strength of the collision impact.
 		*/
 		Number impactStrength;	
@@ -152,7 +157,7 @@ public:
 	/**
 	* Creates a new physics screen.
 	*/ 
-	PhysicsScreen(Number worldScale, Number freq);
+	PhysicsScreen(Number worldScale, Number freq, int velIterations=10, int posIterations=10);
 	
 	/**
 	* Default constructor.
@@ -173,10 +178,11 @@ public:
 	* @param restitution Restitution of the physics entity. Restitution controls how bouncy the entity is.
 	* @param isSensor If this is set to true, the entity won't collide with other entities, but its collision will register.
 	* @param fixedRotation If this is set to true, the entity will always have a locked rotation.
-	* @return The physics entity wrapper.
+    * @param groupIndex is the physiscs shape's collision group. A negative number means objects of that group won't collide with eachother
+    * @return The physics entity wrapper.
 	*/
 	PhysicsScreenEntity *addPhysicsChild(ScreenEntity *newEntity, int entType, bool isStatic, Number friction=0.1, Number density=1, Number restitution = 0, bool isSensor = false, bool fixedRotation = false, int groupIndex = 0);
-
+    
 	/**
 	* Tracks a ScreenEntity as a physics enabled child. 
 	* @param newEntity Screen entity to add.
@@ -187,11 +193,11 @@ public:
 	* @param restitution Restitution of the physics entity. Restitution controls how bouncy the entity is.
 	* @param isSensor If this is set to true, the entity won't collide with other entities, but its collision will register.
 	* @param fixedRotation If this is set to true, the entity will always have a locked rotation.
+    * @param groupIndex is the physiscs shape's collision group. A negative number means objects of that group won't collide with eachother
 	* @return The physics entity wrapper.
 	*/
 	PhysicsScreenEntity *trackPhysicsChild(ScreenEntity *newEntity, int entType, bool isStatic, Number friction=0.1, Number density=1, Number restitution = 0, bool isSensor = false, bool fixedRotation = false, int groupIndex = 0);
-
-	
+    
 	/**
 	* Removes a physics child from the screen.
 	* @param entityToRemove Entity to remove from the screen.
@@ -201,14 +207,13 @@ public:
 	
 	void removeChild(ScreenEntity *entityToRemove);
 	
-	
 	/**
 	* Begins tracking collisions for a ScreenEntity and adds it to the scene.
 	* @param newEntity Entity to track collisions for.
 	* @param entType Physics shape of the entity. Possible values are PhysicsScreenEntity::ENTITY_RECT or PhysicsScreenEntity::ENTITY_CIRCLE.
 	* @param entityToRemove Entity to remove from the screen.
 	*/	
-	PhysicsScreenEntity *addCollisionChild(ScreenEntity *newEntity, int entType, int groupIndex = 0);
+	PhysicsScreenEntity *addCollisionChild(ScreenEntity *newEntity, int entType, int groupIndex = 0, bool sensorOnly = true);
 	
 	/**
 	* Begins tracking collisions for a ScreenEntity.
@@ -341,6 +346,7 @@ public:
 			
 	void BeginContact (b2Contact *contact);
 	void EndContact (b2Contact *contact);	
+    void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);    
 	void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
 
 	/**
@@ -367,7 +373,7 @@ public:
 	* @return If there specified entity overlaps the specified position, this returns true.
 	*/ 														
 	bool testEntityAtPosition(ScreenEntity *ent, Number x, Number y);
-
+    
 	/**
 	* Tests collision between two entities
 	*/
@@ -384,18 +390,19 @@ public:
 	void destroyMouseJoint(b2MouseJoint *mJoint);
 
 
+    
 protected:
 	
+    Number worldScale;
+    
+    std::vector <PhysicsScreenEntity*> physicsChildren;		
 	
-	Number worldScale;
-	
-	void init(Number worldScale, Number physicsTimeStep, int physicsIterations, Vector2 physicsGravity);
+	void init(Number worldScale, Number physicsTimeStep, int velIterations, int posIterations, Vector2 physicsGravity);
 
-	std::vector <PhysicsScreenEntity*> physicsChildren;
 	std::vector<b2Contact*> contacts;
-	b2World *world;
+    b2World *world;    
 	Number timeStep;
-	int32 iterations;
+	int32 velocityIterations, positionIterations;
 };
 
 

+ 54 - 17
Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h

@@ -34,8 +34,11 @@ namespace Polycode {
 	*/	
 	class _PolyExport PhysicsScreenEntity {
 		public:
+        
+            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);
-			~PhysicsScreenEntity();		
+			virtual ~PhysicsScreenEntity();		
 			
 			/**
 			* Returns the screen entity associated with this physics entity.
@@ -54,18 +57,49 @@ namespace Polycode {
 		
 			void setTransform(Vector2 pos, Number angle);
 			
-			void Update();
+			virtual void Update();
 			
 			void setVelocity(Number fx, Number fy);	
-			void setVelocityX(Number fx);
-			void setVelocityY(Number fy);
-			
+			void setVelocityX( Number fx);	
+			void setVelocityY(Number fy);				
+        
 			void applyImpulse(Number fx, Number fy);
-
-
-			b2Fixture* getFixture();						// Gets the last fixture selected (automatically set on creation)			
-			b2Fixture* getFixture(unsigned short index);	// Gets a specific fixture if there is more than one
 			
+            /**
+             * Sets the damping of the physics entity
+             */
+        
+            void setLinearDamping(Number damping);
+            void setAngularDamping(Number damping);
+            void setFriction(Number friction);
+        
+            /**
+             * Returns damping information
+             */ 
+        
+            Number getLinearDamping();
+            Number getAngularDamping();
+            Number getFriction();
+
+            /**
+             * Sets physics entity density
+             */
+        
+            void setDensity(Number density);
+            Number getDensity();
+        
+            /**
+             * Sets collision filtering
+             * Collision category specifies which bits on a 16 bit field the physics entity belongs to. default is 1 (or "0000000000000001")
+             * 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);
+            
 			/**
 			* Rectangular physics entity
 			*/ 
@@ -78,15 +112,18 @@ namespace Polycode {
 			* Mesh entity.
 			*/ 						
 			static const int ENTITY_MESH = 3;
-		
-			b2Body *body;
-			b2Fixture *fixture;								// You do not need a shape pointer
+        
+            static const int ENTITY_EDGE = 4;
 
+			b2Body *body;			
+			b2Fixture *fixture;		
+			
 			bool collisionOnly;
-		
+
 		protected:
-		
-		Number worldScale;
-		ScreenEntity *screenEntity;
+        
+		Number worldScale;        
+        ScreenEntity *screenEntity;   		
 	};
-}
+
+}

+ 53 - 27
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -43,17 +43,28 @@ ScreenEntity *PhysicsScreenEvent::getSecondEntity() {
 	return entity2;
 }
 
+void PhysicsScreen::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
+{
+    if(((PhysicsScreenEntity*)contact->GetFixtureA()->GetBody()->GetUserData())->collisionOnly ||
+       ((PhysicsScreenEntity*)contact->GetFixtureB()->GetBody()->GetUserData())->collisionOnly) {
+        contact->SetEnabled(false);
+    }    
+}
 
 void PhysicsScreen::BeginContact (b2Contact *contact) {
 
 //	if(!contact->GetFixtureA()->IsSensor() && !contact->GetFixtureB()->IsSensor()) {
 //		return;
 //	}
-	
 	PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
-	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA())->getScreenEntity();
-	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB())->getScreenEntity();			
-
+	newEvent->entity1 = (ScreenEntity*)contact->GetFixtureA()->GetUserData();
+	newEvent->entity2 = (ScreenEntity*)contact->GetFixtureB()->GetUserData();			
+
+    if(((PhysicsScreenEntity*)contact->GetFixtureA()->GetBody()->GetUserData())->collisionOnly ||
+        ((PhysicsScreenEntity*)contact->GetFixtureB()->GetBody()->GetUserData())->collisionOnly) {
+        contact->SetEnabled(false);
+    }
+       
 	b2Manifold *manifold = contact->GetManifold();
 	b2Vec2 nor = manifold->localNormal;
 	b2Vec2 point = manifold->localPoint;
@@ -77,6 +88,8 @@ void PhysicsScreen::BeginContact (b2Contact *contact) {
 	newEvent->impactStrength = 0;
 	newEvent->frictionStrength = 0;
 
+    newEvent->contact = contact;
+    
 	dispatchEvent(newEvent, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
 	
 	contacts.push_back(contact);
@@ -84,13 +97,19 @@ void PhysicsScreen::BeginContact (b2Contact *contact) {
 
 void PhysicsScreen::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) {
 	PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
-	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA())->getScreenEntity();
-	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB())->getScreenEntity();			
+	newEvent->entity1 = (ScreenEntity*)contact->GetFixtureA()->GetUserData();
+	newEvent->entity2 = (ScreenEntity*)contact->GetFixtureB()->GetUserData();		
+
+    
+    if(((PhysicsScreenEntity*)contact->GetFixtureA()->GetBody()->GetUserData())->collisionOnly ||
+       ((PhysicsScreenEntity*)contact->GetFixtureB()->GetBody()->GetUserData())->collisionOnly) {
+        contact->SetEnabled(false);
+    }
 
+    
 	b2Manifold *manifold = contact->GetManifold();
 	b2Vec2 nor = manifold->localNormal;
 	b2Vec2 point = manifold->points[0].localPoint;
-	
 
 	b2WorldManifold w_manifold;
 	contact->GetWorldManifold(&w_manifold);
@@ -109,7 +128,8 @@ void PhysicsScreen::PostSolve(b2Contact* contact, const b2ContactImpulse* impuls
 	
 	newEvent->impactStrength = 0;
 	newEvent->frictionStrength = 0;
-
+    
+    newEvent->contact = contact;
 	for(int i=0; i < manifold->pointCount; i++) {
 		if(impulse->normalImpulses[i] > newEvent->impactStrength)
 			newEvent->impactStrength = impulse->normalImpulses[i];
@@ -123,9 +143,10 @@ void PhysicsScreen::PostSolve(b2Contact* contact, const b2ContactImpulse* impuls
 
 void PhysicsScreen::EndContact (b2Contact *contact) {
 	PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
-	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA())->getScreenEntity();
-	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB())->getScreenEntity();
-	
+	newEvent->entity1 = (ScreenEntity*)contact->GetFixtureA()->GetUserData();
+	newEvent->entity2 = (ScreenEntity*)contact->GetFixtureB()->GetUserData();	
+    newEvent->contact = contact;
+    
 	for(int i=0; i < contacts.size(); i++) {
 		if(contacts[i] == contact) {
 			contacts.erase(contacts.begin()+i);
@@ -143,9 +164,10 @@ bool PhysicsScreen::testEntityCollision(ScreenEntity *ent1, ScreenEntity *ent2)
 		return false;
 	
 	for(int i=0; i < contacts.size(); i++) {
-		ScreenEntity *cEnt1 = getPhysicsEntityByFixture(contacts[i]->GetFixtureA())->getScreenEntity();
-		ScreenEntity *cEnt2 = getPhysicsEntityByFixture(contacts[i]->GetFixtureB())->getScreenEntity();
+		ScreenEntity *cEnt1 = (ScreenEntity*)contacts[i]->GetFixtureA()->GetUserData();
+		ScreenEntity *cEnt2 = (ScreenEntity*)contacts[i]->GetFixtureB()->GetUserData();
 		
+	        
 		if((cEnt1 == ent1 && cEnt2 == ent2) || (cEnt1 == ent2 && cEnt2 == ent1)) {
 			return true;
 		}
@@ -154,31 +176,32 @@ bool PhysicsScreen::testEntityCollision(ScreenEntity *ent1, ScreenEntity *ent2)
 }
 
 PhysicsScreen::PhysicsScreen() : Screen() {
-	init(10.0f, 1.0f/60.0f,10,Vector2(0.0f, 10.0f));
+	init(10.0f, 1.0f/60.0f,10,10,Vector2(0.0f, 10.0f));
 }
 
-PhysicsScreen::PhysicsScreen(Number worldScale, Number freq) : Screen() {
-	init(worldScale, 1.0f/freq,10,Vector2(0.0f, 10.0f));	
+PhysicsScreen::PhysicsScreen(Number worldScale, Number freq, int velIterations, int posIterations): Screen() {
+	init(worldScale, 1.0f/freq,velIterations, posIterations, Vector2(0.0f, 10.0f));	
 }
 
-void PhysicsScreen::init(Number worldScale, Number physicsTimeStep, int physicsIterations, Vector2 physicsGravity) {
+void PhysicsScreen::init(Number worldScale, Number physicsTimeStep, int velIterations, int posIterations, Vector2 physicsGravity) {
 	
 	this->worldScale = worldScale;
 	
 	timeStep = physicsTimeStep;
-	iterations = physicsIterations;
+	velocityIterations = velIterations;
+    positionIterations = posIterations;
 	
 	b2Vec2 gravity(physicsGravity.x,physicsGravity.y);
 	bool doSleep = true;
 	world  = new b2World(gravity, doSleep);
-	
+    
 	world->SetContactListener(this);
 }
 
 void PhysicsScreen::setGravity(Vector2 newGravity) {
 	world->SetGravity(b2Vec2(newGravity.x, newGravity.y));
 }
-
+                                
 PhysicsScreenEntity *PhysicsScreen::getPhysicsByScreenEntity(ScreenEntity *ent) {
 	for(int i=0; i<physicsChildren.size();i++) {
 		if(physicsChildren[i]->getScreenEntity() == ent)
@@ -196,8 +219,9 @@ PhysicsJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEntit
 	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
 	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);
 	if(pEnt1 == NULL || pEnt2 == NULL)
+    {
 		return NULL;
-	
+	}
 	b2Vec2 anchor((ent1->getPosition().x+ax)/worldScale, (ent1->getPosition().y+ay)/worldScale);
 	b2RevoluteJointDef *jointDef = new b2RevoluteJointDef();
 	jointDef->collideConnected = collideConnected;
@@ -292,9 +316,10 @@ void PhysicsScreen::setVelocityY(ScreenEntity *ent, Number fy) {
 }
 
 
-PhysicsScreenEntity *PhysicsScreen::addCollisionChild(ScreenEntity *newEntity, int entType, int groupIndex) {
+PhysicsScreenEntity *PhysicsScreen::addCollisionChild(ScreenEntity *newEntity, int entType, int groupIndex, bool sensorOnly) {
 	PhysicsScreenEntity *ret;
-	ret = addPhysicsChild(newEntity, entType, false, 0,0.0,0, true, groupIndex);
+	ret = addPhysicsChild(newEntity, entType, false, 0,0,0, sensorOnly, false, groupIndex);
+    
 	ret->collisionOnly = true; 
 	return ret;
 }
@@ -333,7 +358,6 @@ void PhysicsScreen::applyImpulse(ScreenEntity *ent, Number fx, Number fy) {
 }
 
 
-
 PhysicsJoint *PhysicsScreen::createDistanceJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected) {
 	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
 	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);
@@ -424,6 +448,7 @@ void PhysicsScreen::destroyMouseJoint(b2MouseJoint *mJoint) {
 PhysicsScreenEntity *PhysicsScreen::addPhysicsChild(ScreenEntity *newEntity, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex) {
 	addChild(newEntity);
 	return trackPhysicsChild(newEntity, entType, isStatic, friction, density, restitution, isSensor, fixedRotation, groupIndex);
+
 }
 
 PhysicsScreenEntity *PhysicsScreen::trackPhysicsChild(ScreenEntity *newEntity, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex) {
@@ -434,13 +459,13 @@ PhysicsScreenEntity *PhysicsScreen::trackPhysicsChild(ScreenEntity *newEntity, i
 	return newPhysicsEntity;
 }
 
-
 void PhysicsScreen::removePhysicsChild(ScreenEntity *entityToRemove) {
 	PhysicsScreenEntity *physicsEntityToRemove = getPhysicsByScreenEntity(entityToRemove);
 	if(!physicsEntityToRemove) {
 		return;
 	}
 	world->DestroyBody(physicsEntityToRemove->body);
+    physicsEntityToRemove->body = NULL;
 	for(int i=0;i<physicsChildren.size();i++) {
 		if(physicsChildren[i] == physicsEntityToRemove) {
 			physicsChildren.erase(physicsChildren.begin()+i);
@@ -457,7 +482,6 @@ void PhysicsScreen::removeChild(ScreenEntity *entityToRemove) {
 	}
 }
 
-
 void PhysicsScreen::Shutdown() {
 
 }
@@ -494,8 +518,10 @@ void PhysicsScreen::handleEvent(Event *event) {
 }
 
 void PhysicsScreen::Update() {
+    
 	for(int i=0; i<physicsChildren.size();i++) {
 		physicsChildren[i]->Update();
 	}
-	world->Step(timeStep, iterations,iterations);	
+    
+	world->Step(timeStep, velocityIterations,positionIterations);	
 }

+ 77 - 10
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -35,6 +35,8 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 	
 	screenEntity = entity;
 
+	entity->ignoreParentMatrix = true;
+	entity->scale = entityScale;
 	Vector3 entityScale = entity->getCompoundScale();
 	this->worldScale = worldScale;
 	collisionOnly = false;
@@ -53,6 +55,7 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 
 		// Create the body
 	body = world->CreateBody(&bodyDef);
+	body->SetUserData(this);
 	
 	// Create fixture definition---------------------------------------------
 	b2FixtureDef fDef;
@@ -61,6 +64,7 @@ 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) {
@@ -84,6 +88,15 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 			fixture = body->CreateFixture(&fDef);
 			break;
 		}
+		case ENTITY_EDGE: {
+			b2PolygonShape Shape;	
+			Shape.SetAsEdge(b2Vec2(-screenEntity->getWidth()/(worldScale*2.0f),-screenEntity->getHeight()/(2.0*worldScale)),
+							b2Vec2(screenEntity->getWidth()/(worldScale*2.0f),-screenEntity->getHeight()/(2.0*worldScale)));
+			fDef.shape = &Shape;
+			fixture = body->CreateFixture(&fDef);
+			break;
+        }
+        break;
 		case ENTITY_MESH: {
 			b2PolygonShape Shape;
 			// Set fixture shape to shape definition
@@ -145,28 +158,84 @@ void PhysicsScreenEntity::setVelocity(Number fx, Number fy) {
 }
 
 void PhysicsScreenEntity::setVelocityX( Number fx) {
-	body->SetAwake(true);	
+	body->SetAwake(true);
 	b2Vec2 f = body->GetLinearVelocity();
-	f.x = fx;
+	f.x = fx;	
 	body->SetLinearVelocity(f);
 }
 
 void PhysicsScreenEntity::setVelocityY(Number fy) {
 	body->SetAwake(true);
 	b2Vec2 f = body->GetLinearVelocity();
-	f.y = fy;
-	body->SetLinearVelocity(f);
+	f.y = fy;	
+	body->SetLinearVelocity(f);	
+}
+
+
+void PhysicsScreenEntity::setCollisionCategory(int categoryBits) {
+        b2Filter filter=fixture->GetFilterData();
+        filter.categoryBits = categoryBits;
+        fixture->SetFilterData(filter);
+}
+
+void PhysicsScreenEntity::setCollisionMask(int maskBits) {
+        b2Filter filter=fixture->GetFilterData();
+        filter.maskBits = maskBits;
+        fixture->SetFilterData(filter);
+}
+
+void PhysicsScreenEntity::setCollisionGroupIndex(int group) {
+    b2Filter filter=fixture->GetFilterData();
+    filter.groupIndex = group;
+    fixture->SetFilterData(filter);    
+}
+
+void PhysicsScreenEntity::setLinearDamping(Number damping) {
+    body->SetLinearDamping(damping);
+}
+
+void PhysicsScreenEntity::setAngularDamping(Number damping) {
+    body->SetAngularDamping(damping);
 }
 
-void PhysicsScreenEntity::applyImpulse(Number fx, Number fy) {	
+void PhysicsScreenEntity::setFriction(Number friction) {
+    if(fixture) {
+        fixture->SetFriction(friction);
+    }
+}
+
+void PhysicsScreenEntity::setDensity(Number density){
+    if(fixture) {
+        fixture->SetDensity(density);
+    }
+}
+
+Number PhysicsScreenEntity::getLinearDamping() {
+    return body->GetLinearDamping();
+}
+
+Number PhysicsScreenEntity::getAngularDamping() {
+    return body->GetAngularDamping();
+}
+
+Number PhysicsScreenEntity::getFriction() {
+    return fixture->GetFriction();
+}
+
+Number PhysicsScreenEntity::getDensity() {
+    return fixture->GetDensity();
+}
+
+void PhysicsScreenEntity::applyImpulse(Number fx, Number fy) {
 	body->SetAwake(true);
 	b2Vec2 f =  b2Vec2(fx,fy);
-	b2Vec2 p = body->GetWorldPoint(b2Vec2(0.0f, 0.0f));
-	body->ApplyLinearImpulse(f, p);
+	b2Vec2 p = body->GetWorldPoint(b2Vec2(0.0f, 0.0f));	
+	body->ApplyLinearImpulse(f, p);	
 }
-
+			
 void PhysicsScreenEntity::setTransform(Vector2 pos, Number angle) {
 	body->SetTransform(b2Vec2(pos.x/worldScale, pos.y/worldScale), angle*(PI/180.0f));
+    screenEntity->setPosition(pos);
 }
 
 void PhysicsScreenEntity::Update() {
@@ -197,8 +266,6 @@ void PhysicsScreenEntity::Update() {
 
 
 
-
-
 //==============================================
 //Add on functions to access the fixture library
 //==============================================