Search in sources :

Example 1 with ClosestRayResultCallback

use of com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback in project libgdx by libgdx.

the class RayCastTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap a box to ray cast\nLong press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
    // Create the entities
    world.add("ground", -7f, 0f, -7f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    for (int x = 0; x < BOXCOUNT_X; x++) {
        for (int y = 0; y < BOXCOUNT_Y; y++) {
            for (int z = 0; z < BOXCOUNT_Z; z++) {
                world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
            }
        }
    }
    rayTestCB = new ClosestRayResultCallback(Vector3.Zero, Vector3.Z);
}
Also used : ClosestRayResultCallback(com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)

Example 2 with ClosestRayResultCallback

use of com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback in project libgdx by libgdx.

the class RayPickRagdollTest method touchDown.

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    boolean result = false;
    if (button == Buttons.LEFT) {
        Ray ray = camera.getPickRay(screenX, screenY);
        tmpV1.set(ray.direction).scl(10f).add(ray.origin);
        ClosestRayResultCallback cb = new ClosestRayResultCallback(ray.origin, tmpV1);
        world.collisionWorld.rayTest(ray.origin, tmpV1, cb);
        if (cb.hasHit()) {
            btRigidBody body = (btRigidBody) (cb.getCollisionObject());
            if (body != null && !body.isStaticObject() && !body.isKinematicObject()) {
                pickedBody = body;
                body.setActivationState(Collision.DISABLE_DEACTIVATION);
                cb.getHitPointWorld(tmpV);
                tmpV.mul(body.getCenterOfMassTransform().inv());
                pickConstraint = new btPoint2PointConstraint(body, tmpV);
                btConstraintSetting setting = pickConstraint.getSetting();
                setting.setImpulseClamp(30f);
                setting.setTau(0.001f);
                pickConstraint.setSetting(setting);
                ((btDynamicsWorld) world.collisionWorld).addConstraint(pickConstraint);
                pickDistance = tmpV1.sub(camera.position).len();
                result = true;
            }
        }
        cb.dispose();
    }
    return result ? result : super.touchDown(screenX, screenY, pointer, button);
}
Also used : com.badlogic.gdx.physics.bullet.dynamics.btRigidBody(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody) com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld) com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint(com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint) Ray(com.badlogic.gdx.math.collision.Ray) com.badlogic.gdx.physics.bullet.dynamics.btConstraintSetting(com.badlogic.gdx.physics.bullet.dynamics.btConstraintSetting) ClosestRayResultCallback(com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)

Aggregations

ClosestRayResultCallback (com.badlogic.gdx.physics.bullet.collision.ClosestRayResultCallback)2 Ray (com.badlogic.gdx.math.collision.Ray)1 com.badlogic.gdx.physics.bullet.dynamics.btConstraintSetting (com.badlogic.gdx.physics.bullet.dynamics.btConstraintSetting)1 com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld (com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld)1 com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint (com.badlogic.gdx.physics.bullet.dynamics.btPoint2PointConstraint)1 com.badlogic.gdx.physics.bullet.dynamics.btRigidBody (com.badlogic.gdx.physics.bullet.dynamics.btRigidBody)1