Search in sources :

Example 6 with PhysicsComponent

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();
}
Also used : Entity(com.artemis.Entity) PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Body(com.badlogic.gdx.physics.box2d.Body) Contact(com.gemserk.commons.gdx.box2d.Contacts.Contact)

Example 7 with PhysicsComponent

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);
}
Also used : PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent) Trigger(com.gemserk.commons.artemis.triggers.Trigger) Contacts(com.gemserk.commons.gdx.box2d.Contacts) HitComponent(com.gemserk.commons.artemis.components.HitComponent)

Example 8 with PhysicsComponent

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);
    }
}
Also used : PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent) Vector2(com.badlogic.gdx.math.Vector2) Body(com.badlogic.gdx.physics.box2d.Body) LinearVelocityLimitComponent(com.gemserk.commons.artemis.components.LinearVelocityLimitComponent)

Example 9 with PhysicsComponent

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);
}
Also used : ImmediateModePhysicsListener(com.gemserk.commons.artemis.components.PhysicsComponent.ImmediateModePhysicsListener) PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent)

Example 10 with PhysicsComponent

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());
}
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