Search in sources :

Example 1 with MouseJointDef

use of com.badlogic.gdx.physics.box2d.joints.MouseJointDef in project libgdx by libgdx.

the class Box2DTest method touchDown.

@Override
public boolean touchDown(int x, int y, int pointer, int newParam) {
    // translate the mouse coordinates to world coordinates
    testPoint.set(x, y, 0);
    camera.unproject(testPoint);
    // ask the world which bodies are within the given
    // bounding box around the mouse pointer
    hitBody = null;
    world.QueryAABB(callback, testPoint.x - 0.1f, testPoint.y - 0.1f, testPoint.x + 0.1f, testPoint.y + 0.1f);
    // and attach it to the hit body.
    if (hitBody != null) {
        MouseJointDef def = new MouseJointDef();
        def.bodyA = groundBody;
        def.bodyB = hitBody;
        def.collideConnected = true;
        def.target.set(testPoint.x, testPoint.y);
        def.maxForce = 1000.0f * hitBody.getMass();
        mouseJoint = (MouseJoint) world.createJoint(def);
        hitBody.setAwake(true);
    } else {
        for (Body box : boxes) world.destroyBody(box);
        boxes.clear();
        createBoxes();
    }
    return false;
}
Also used : Body(com.badlogic.gdx.physics.box2d.Body) MouseJointDef(com.badlogic.gdx.physics.box2d.joints.MouseJointDef)

Example 2 with MouseJointDef

use of com.badlogic.gdx.physics.box2d.joints.MouseJointDef in project libgdx by libgdx.

the class Box2DTest method touchDown.

@Override
public boolean touchDown(int x, int y, int pointer, int button) {
    // translate the mouse coordinates to world coordinates
    camera.unproject(testPoint.set(x, y, 0));
    // ask the world which bodies are within the given
    // bounding box around the mouse pointer
    hitBody = null;
    world.QueryAABB(callback, testPoint.x - 0.0001f, testPoint.y - 0.0001f, testPoint.x + 0.0001f, testPoint.y + 0.0001f);
    if (hitBody == groundBody)
        hitBody = null;
    // ignore kinematic bodies, they don't work with the mouse joint
    if (hitBody != null && hitBody.getType() == BodyType.KinematicBody)
        return false;
    // and attach it to the hit body.
    if (hitBody != null) {
        MouseJointDef def = new MouseJointDef();
        def.bodyA = groundBody;
        def.bodyB = hitBody;
        def.collideConnected = true;
        def.target.set(testPoint.x, testPoint.y);
        def.maxForce = 1000.0f * hitBody.getMass();
        mouseJoint = (MouseJoint) world.createJoint(def);
        hitBody.setAwake(true);
    }
    return false;
}
Also used : MouseJointDef(com.badlogic.gdx.physics.box2d.joints.MouseJointDef)

Example 3 with MouseJointDef

use of com.badlogic.gdx.physics.box2d.joints.MouseJointDef in project Entitas-Java by Rubentxu.

the class InputManagerGDX method update.

@Override
public void update(float deltaTime) {
    //for every keystate, set pressed and released to false.
    for (int i = 0; i < 256; i++) {
        KeyState k = inputStateData.keyStates[i];
        k.pressed = false;
        k.released = false;
    }
    for (int i = 0; i < inputStateData.pointerStates.length; i++) {
        PointerState<Vector2, Vector3> t = inputStateData.pointerStates[i];
        if (t.down && !t.pressed)
            t.clickTime += deltaTime;
        t.pressed = false;
        t.released = false;
        t.displacement.x = 0;
        t.displacement.y = 0;
    }
    if (entitas.actuator.hasDragActuator() && jointDef == null) {
        this.dragActuator = entitas.actuator.getDragActuator();
        jointDef = new MouseJointDef();
        jointDef.bodyA = Indexed.getInteractiveEntity(dragActuator.targetEntity).getRigidBody().body;
        jointDef.collideConnected = dragActuator.collideConnected;
        jointDef.maxForce = dragActuator.maxForce;
    }
    for (GameController controller : controllers) {
        controller.update(this, entitas);
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) GameController(ilargia.egdx.api.GameController) Vector3(com.badlogic.gdx.math.Vector3) KeyState(ilargia.egdx.api.managers.data.KeyState) MouseJoint(com.badlogic.gdx.physics.box2d.joints.MouseJoint) MouseJointDef(com.badlogic.gdx.physics.box2d.joints.MouseJointDef)

Aggregations

MouseJointDef (com.badlogic.gdx.physics.box2d.joints.MouseJointDef)3 Vector2 (com.badlogic.gdx.math.Vector2)1 Vector3 (com.badlogic.gdx.math.Vector3)1 Body (com.badlogic.gdx.physics.box2d.Body)1 MouseJoint (com.badlogic.gdx.physics.box2d.joints.MouseJoint)1 GameController (ilargia.egdx.api.GameController)1 KeyState (ilargia.egdx.api.managers.data.KeyState)1