Search in sources :

Example 1 with PhysicsComponent

use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.

the class PhysicsContactListener method addBodyToContacts.

/**
	 * Adds the body to the entity contacts.
	 * 
	 * @param e
	 *            The entity to add the contact to.
	 * @param body
	 *            The body to add to the contacts.
	 * @param contact
	 *            The real contact, used internally to get some data like normals and stuff.
	 */
private void addBodyToContacts(Entity e, Contact contact, boolean fixtureA) {
    if (e == null)
        return;
    PhysicsComponent physicsComponent = PhysicsComponent.get(e);
    if (physicsComponent == null)
        return;
    physicsComponent.getContact().addContact(contact, fixtureA);
    ImmediateModePhysicsListener physicsListener = physicsComponent.physicsListener;
    if (physicsListener != null)
        physicsListener.beginContact(e, contact, fixtureA);
}
Also used : ImmediateModePhysicsListener(com.gemserk.commons.artemis.components.PhysicsComponent.ImmediateModePhysicsListener) PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent)

Example 2 with PhysicsComponent

use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.

the class PhysicsContactListener method executePreSolveListener.

private void executePreSolveListener(Entity e, Contact contact, boolean fixtureA) {
    if (e == null)
        return;
    PhysicsComponent physicsComponent = PhysicsComponent.get(e);
    if (physicsComponent == null)
        return;
    ImmediateModePhysicsListener physicsListener = physicsComponent.physicsListener;
    if (physicsListener != null)
        physicsListener.preSolve(e, contact, fixtureA);
}
Also used : ImmediateModePhysicsListener(com.gemserk.commons.artemis.components.PhysicsComponent.ImmediateModePhysicsListener) PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent)

Example 3 with PhysicsComponent

use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.

the class PhysicsSystem method removed.

@Override
protected void removed(Entity e) {
    PhysicsComponent physicsComponent = Components.getPhysicsComponent(e);
    if (physicsComponent == null)
        return;
    Body body = physicsComponent.getBody();
    body.setUserData(null);
    // removes contact from the other entity
    PhysicsUtils.releaseContacts(physicsComponent.getContact());
    physicsWorld.destroyBody(body);
}
Also used : PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent) Body(com.badlogic.gdx.physics.box2d.Body)

Example 4 with PhysicsComponent

use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.

the class PhysicsSystem method enabled.

@Override
protected void enabled(Entity e) {
    PhysicsComponent physicsComponent = Components.getPhysicsComponent(e);
    physicsComponent.getBody().setActive(true);
}
Also used : PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent)

Example 5 with PhysicsComponent

use of com.gemserk.commons.artemis.components.PhysicsComponent in project commons-gdx by gemserk.

the class PhysicsSystem method disabled.

@Override
protected void disabled(Entity e) {
    PhysicsComponent physicsComponent = Components.getPhysicsComponent(e);
    physicsComponent.getBody().setActive(false);
    PhysicsUtils.releaseContacts(physicsComponent.getContact());
}
Also used : PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent)

Aggregations

PhysicsComponent (com.gemserk.commons.artemis.components.PhysicsComponent)11 Body (com.badlogic.gdx.physics.box2d.Body)4 ImmediateModePhysicsListener (com.gemserk.commons.artemis.components.PhysicsComponent.ImmediateModePhysicsListener)3 Vector2 (com.badlogic.gdx.math.Vector2)2 Entity (com.artemis.Entity)1 Fixture (com.badlogic.gdx.physics.box2d.Fixture)1 HitComponent (com.gemserk.commons.artemis.components.HitComponent)1 LinearVelocityLimitComponent (com.gemserk.commons.artemis.components.LinearVelocityLimitComponent)1 Trigger (com.gemserk.commons.artemis.triggers.Trigger)1 Contacts (com.gemserk.commons.gdx.box2d.Contacts)1 Contact (com.gemserk.commons.gdx.box2d.Contacts.Contact)1