use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.
the class PhysicsUtils method releaseContacts.
public static void releaseContacts(Contacts contacts) {
// removes contact from the other entity
for (int i = 0; i < contacts.getContactCount(); i++) {
Contact contact = contacts.getContact(i);
Fixture myFixture = contact.getMyFixture();
Fixture otherFixture = contact.getOtherFixture();
contactsToRemove.add(contact);
Body otherBody = otherFixture.getBody();
if (otherBody == null)
continue;
Entity otherEntity = (Entity) otherBody.getUserData();
if (otherEntity == null)
continue;
// entitiesInContact.add(otherEntity);
// removes the contact from the other entity.
PhysicsComponent otherPhyiscsComponent = Components.getPhysicsComponent(otherEntity);
otherPhyiscsComponent.getContact().removeContact(otherFixture, myFixture);
}
for (int i = 0; i < contactsToRemove.size; i++) {
Contact contact = contactsToRemove.get(i);
contacts.removeContact(contact.getMyFixture(), contact.getOtherFixture());
}
contactsToRemove.clear();
}
use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.
the class HitDetectionSystem method process.
@Override
protected void process(Entity e) {
HitComponent hitComponent = e.getComponent(HitComponent.class);
PhysicsComponent physicsComponent = e.getComponent(PhysicsComponent.class);
Contacts contact = physicsComponent.getContact();
Trigger trigger = hitComponent.getTrigger();
if (!contact.isInContact())
return;
if (trigger.isAlreadyTriggered())
return;
trigger.trigger(e);
}
use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.
the class LimitLinearVelocitySystem method process.
@Override
protected void process(Entity e) {
PhysicsComponent physicsComponent = Components.getPhysicsComponent(e);
Body body = physicsComponent.getPhysics().getBody();
LinearVelocityLimitComponent limitComponent = e.getComponent(LinearVelocityLimitComponent.class);
Vector2 linearVelocity = body.getLinearVelocity();
float speed = linearVelocity.len();
float maxSpeed = limitComponent.getLimit();
if (speed > maxSpeed) {
float factor = maxSpeed / speed;
linearVelocity.mul(factor);
body.setLinearVelocity(linearVelocity);
}
}
use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.
the class PhysicsContactListener method removeBodyFromContacts.
/**
* Removes body from entity contacts.
*
* @param e
* The entity to remove the contact from.
* @param body
* The body to be removed from contacts.
*/
private void removeBodyFromContacts(Entity e, Contact contact, boolean fixtureA) {
if (e == null)
return;
PhysicsComponent physicsComponent = PhysicsComponent.get(e);
if (physicsComponent == null)
return;
physicsComponent.getContact().removeContact(contact, fixtureA);
ImmediateModePhysicsListener physicsListener = physicsComponent.physicsListener;
if (physicsListener != null)
physicsListener.endContact(e, contact, fixtureA);
}
use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.
the class PhysicsUtils method releaseContacts.
public static void releaseContacts(Entity entity) {
PhysicsComponent physicsComponent = Components.getPhysicsComponent(entity);
releaseContacts(physicsComponent.getContact());
}
Aggregations