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