com.badlogic.gdx.physics.box2d.joints.MouseJointDef Java Examples
The following examples show how to use
com.badlogic.gdx.physics.box2d.joints.MouseJointDef.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DragAndDropSample.java From Codelabs with MIT License | 5 votes |
/** * Creates the MouseJoint definition. * * @param body * First body of the joint (i.e. ground, walls, etc.) */ private void createMouseJointDefinition(Body body) { mouseJointDef = new MouseJointDef(); mouseJointDef.bodyA = body; mouseJointDef.collideConnected = true; mouseJointDef.maxForce = 500; }
Example #2
Source File: Box2dLightCustomShaderTest.java From box2dlights with Apache License 2.0 | 5 votes |
@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); // if we hit something we create a new mouse joint // 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; }
Example #3
Source File: Box2dLightTest.java From box2dlights with Apache License 2.0 | 5 votes |
@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); // if we hit something we create a new mouse joint // 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; }
Example #4
Source File: FluidSimulatorLiquid.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
@Override public boolean touchDown(int x, int y, int pointer, int button) { touching = true; camera.unproject(testPoint.set(x, y, 0)); testPoint2D.x = testPoint.x; testPoint2D.y = testPoint.y; oldDragPos.set(testPoint2D); if (button == Buttons.LEFT) { // Drag Mode if (isDragging) { for (Piece piece : pieces.values()) { hitBody = null; if (piece.body.getFixtureList().get(0).testPoint(testPoint2D)) { hitBody = piece.body; if (hitBody.getType() == BodyType.KinematicBody || hitBody.getType() == BodyType.StaticBody) continue; MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint2D); def.maxForce = 10.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); break; } } if (mouseJoint != null) return false; } if (!IS_DESKTOP) { isRepulsing = true; isAttracting = false; } else { isAttracting = false; isRepulsing = false; } } if (button == Buttons.RIGHT) { isAttracting = true; } if (button == Buttons.MIDDLE) { isRepulsing = true; } return false; }
Example #5
Source File: FluidSimulator.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
@Override public boolean touchDown(int x, int y, int pointer, int button) { touching = true; camera.unproject(testPoint.set(x, y, 0)); testPoint2D.x = testPoint.x; testPoint2D.y = testPoint.y; oldDragPos.set(testPoint2D); if (button == Buttons.LEFT) { // Drag Mode if (isDragging) { for (Piece piece : pieces.values()) { hitBody = null; if (piece.body.getFixtureList().get(0).testPoint(testPoint2D)) { hitBody = piece.body; if (hitBody.getType() == BodyType.KinematicBody || hitBody.getType() == BodyType.StaticBody) continue; MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint2D); def.maxForce = 10.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); break; } } if (mouseJoint != null) return false; } if (!IS_DESKTOP) { isRepulsing = true; isAttracting = false; } else { isAttracting = false; isRepulsing = false; } } if (button == Buttons.RIGHT) { isAttracting = true; } if (button == Buttons.MIDDLE) { isRepulsing = true; } return false; }
Example #6
Source File: FluidSimulatorMPM.java From fluid-simulator-v2 with Apache License 2.0 | 4 votes |
@Override public boolean touchDown(int x, int y, int pointer, int button) { touching = true; camera.unproject(testPoint.set(x, y, 0)); testPoint2D.x = testPoint.x; testPoint2D.y = testPoint.y; oldDragPos.set(testPoint2D); if (button == Buttons.LEFT) { // MPM mpmSolver.pressed = true; mpmSolver.mx = (int)testPoint2D.x; mpmSolver.my = BOX_HEIGHT - (int)testPoint2D.y; // Drag Mode if (isDragging) { for (Piece piece : pieces.values()) { hitBody = null; if (piece.body.getFixtureList().get(0).testPoint(testPoint2D)) { hitBody = piece.body; if (hitBody.getType() == BodyType.KinematicBody || hitBody.getType() == BodyType.StaticBody) continue; MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint2D); def.maxForce = 10.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); break; } } if (mouseJoint != null) return false; } if (!IS_DESKTOP) { isRepulsing = true; isAttracting = false; } else { isAttracting = false; isRepulsing = false; } } if (button == Buttons.RIGHT) { isAttracting = true; } if (button == Buttons.MIDDLE) { isRepulsing = true; } return false; }