/** * it is important to change the method to stage coordinate */ @Override public Vector2 screenToStageCoordinates( Vector2 out) { out.set(Engine.screenToWorld(out.x, out.y)); return out; } /** max 1/60*/
@Override public boolean mouseMoved(int x, int y) { if (click == Click.FIRST) { // do move secondPoint.set(Engine.screenToWorld(x, y)); float width = secondPoint.x - worldCenter.x; float height = secondPoint.y - worldCenter.y; model.width = Math.abs(width) * 2; model.height = Math.abs(height) * 2; updateToUI(); } return super.mouseMoved(x, y); } };
@Override public boolean touchDown(int x, int y, int pointer, int button) { if (button == Buttons.LEFT) { if (Click.NONE == click) { secondPoint.set(Engine.screenToWorld(x, y)); click = Click.FIRST; // do start } else if (click == Click.FIRST) { secondPoint.set(Engine.screenToWorld(x, y)); float width = secondPoint.x - worldCenter.x; float height = secondPoint.y - worldCenter.y; model.width = Math.abs(width) * 2; model.height = Math.abs(height) * 2; updateToUI(); click = Click.NONE; // do end } } return super.touchDown(x, y, pointer, button); }
@Override public boolean touchUp(int x, int y, int pointer, int button) { tmp.set(Engine.screenToWorld(x, y)); touchDown = false; unstick(); return false; }
@Override public boolean mouseMoved(int x, int y) { snapPoint = null; for (Vector2 v : model.polygon) { if (Engine.screenToWorld(x, y).dst(v) < 10) { snapPoint = v; break; } } return super.mouseMoved(x, y); }
@Override public boolean touchDown(int x, int y, int pointer, int button) { if (button == Buttons.LEFT) { if (button == Buttons.LEFT) { if (snapPoint == null) { Vector2 newPoint = new Vector2(Engine.screenToWorld(x, y)); snapPoint = newPoint; model.polygon.add(newPoint); updateToUI(); } } } else if (button == Buttons.RIGHT) { if (null != snapPoint) { if (model.polygon.size() > 3) { model.polygon.remove(snapPoint); updateToUI(); } } } return super.touchDown(x, y, pointer, button); }
@Override public boolean mouseMoved(int x, int y) { snapPoint.set(Engine.screenToWorld(x, y)); return super.mouseMoved(x, y); }
@Override public boolean touchDragged(int x, int y, int index) { tmp.set(Engine.screenToWorld(x, y)); if (touchDown) { distance.x = tmp.x - (position.x+radius); distance.y = tmp.y - (position.y+radius); angle = (float) (Math.atan2(distance.y, distance.x)); amount = distance.len() / radius; if (amount > 1) { amount = 1; } } return hitTest(tmp.x, tmp.y); } @Override
@Override public boolean mouseMoved(int x, int y) { if (Click.FIRST == click) { // do move secondPoint.set(Engine.screenToWorld(x, y)); model.radius = worldCenter.dst(secondPoint); updateToUI(); } return super.mouseMoved(x, y); } };
@Override public boolean touchDown(int x, int y, int pointer, int button) { tmp.set(Engine.screenToWorld(x, y)); if (hitTest(tmp.x, tmp.y)) { touchDown = true; touchDragged(x, y, pointer); return true; } return false; } @Override
@Override public boolean touchDown(int x, int y, int pointer, int button) { if (button == Buttons.LEFT) { if (Click.NONE == click) { secondPoint.set(Engine.screenToWorld(x, y)); click = Click.FIRST; // do start } else if (Click.FIRST == click) { secondPoint.set(Engine.screenToWorld(x, y)); if (worldCenter.dst(secondPoint) > 0) { model.radius = worldCenter.dst(secondPoint); updateToUI(); click = Click.NONE; // do end } } } return super.touchDown(x, y, pointer, button); }
@Override public boolean touchDragged (int x, int y, int pointer) { // if a mouse joint exists we simply update // the target of the joint based on the new // mouse coordinates if (mouseJoint != null) { testPoint.set(Engine.screenToWorld(x, y).scl(1/Box2dObject.RADIO)); mouseJoint.setTarget(target.set(testPoint.x, testPoint.y)); return true; } return false; }
@Override public boolean touchUp(int x, int y, int pointer, int button) { if (button == Buttons.LEFT) { secondData = null; dragTemp.set(Engine.screenToWorld(x, y)); //find the first data // box2dAABBTestPoint.set(dragTemp).scl(1f / Box2dObject.RADIO); PhysicalWorld.WORLD.QueryAABB(callbackSecond, box2dAABBTestPoint.x - 0.1f, box2dAABBTestPoint.y - 0.1f, box2dAABBTestPoint.x + 0.1f, box2dAABBTestPoint.y + 0.1f); } return false; }
public boolean touchDragged(int screenX, int screenY, int pointer) { secondData = null; dragTemp.set(Engine.screenToWorld(screenX, screenY)); //find the first data // box2dAABBTestPoint.set(dragTemp).scl(1f / Box2dObject.RADIO); PhysicalWorld.WORLD.QueryAABB(callbackSecond, box2dAABBTestPoint.x - 0.1f, box2dAABBTestPoint.y - 0.1f, box2dAABBTestPoint.x + 0.1f, box2dAABBTestPoint.y + 0.1f); return super.touchDragged(screenX, screenY, pointer); }
@Override public boolean touchDragged(int x, int y, int pointer) { snapPoint.set(Engine.screenToWorld(x, y)); if (moveCam) { Vector2 now = new Vector2(x, y); Engine.getDefaultCamera().position.x += beginPosition.x - x; Engine.getDefaultCamera().position.y += -(beginPosition.y - y); beginPosition = now; adapter.callUI.updateCameraInfo(); } return super.touchDragged(x, y, pointer); }
@Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { dragTemp.set(Engine.screenToWorld(screenX, screenY)); secondData = null; float dst = 0; if (data != null) { dst = data.position.dst(dragTemp); } if (dst > 100 && dst < 150) { rotateOn = true; } else { data = null; //find the first data // if (button == Buttons.LEFT) { box2dAABBTestPoint.set(dragTemp).scl(1f / Box2dObject.RADIO); PhysicalWorld.WORLD.QueryAABB(callback, box2dAABBTestPoint.x - 0.1f, box2dAABBTestPoint.y - 0.1f, box2dAABBTestPoint.x + 0.1f, box2dAABBTestPoint.y + 0.1f); } } return super.touchDown(screenX, screenY, pointer, button); }
public boolean touchDown(int screenX, int screenY, int pointer, int button) { if (button == Buttons.LEFT) { jointsMenu.remove(); dragTemp.set(Engine.screenToWorld(screenX, screenY)); startPoint.set(dragTemp); data = null; secondData = null; //find the first data // if (button == Buttons.LEFT) { box2dAABBTestPoint.set(dragTemp).scl(1f / Box2dObject.RADIO); PhysicalWorld.WORLD.QueryAABB(callback, box2dAABBTestPoint.x - 0.1f, box2dAABBTestPoint.y - 0.1f, box2dAABBTestPoint.x + 0.1f, box2dAABBTestPoint.y + 0.1f); } } return super.touchDown(screenX, screenY, pointer, button); }
@Override public boolean touchDown (int x, int y, int pointer, int newParam) { if(world == null)return false; // translate the mouse coordinates to world coordinates testPoint.set(Engine.screenToWorld(x, y).scl(1/Box2dObject.RADIO)); // 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 = fixBody; 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 true; } return false; }
@Override public boolean touchDragged(int x, int y, int pointer) { if (null != data) { Vector2 current = Engine.screenToWorld(x, y); if (rotateOn) { float angle_append = current.cpy().sub(data.position).angle() - dragTemp.sub(data.position).angle(); data.degrees += angle_append; adapter.callUI.updateToUI(data); } else { secondData = null; Vector2 offset = current.cpy().sub(dragTemp); data.position.add(offset.x, offset.y); adapter.callUI.updateToUI(data); } dragTemp.set(current); } return super.touchDragged(x, y, pointer); }
public boolean touchDragged(int screenX, int screenY, int pointer) { if (null != snapPoint) { Vector2 vv = Engine.screenToWorld(screenX, screenY); for (Vector2 v : model.polygon) { if (vv.dst(v) < 10) { return false; } } snapPoint.set(vv); updateToUI(); if (vv.x > Engine.getDefaultCamera().position.x + Engine.getDefaultCamera().viewportWidth / 2) { Engine.getDefaultCamera().position.x = vv.x - Engine.getDefaultCamera().viewportWidth / 2; } else if (vv.x < Engine.getDefaultCamera().position.x - Engine.getDefaultCamera().viewportWidth / 2) { Engine.getDefaultCamera().position.x = vv.x + Engine.getDefaultCamera().viewportWidth / 2; } if (vv.y > Engine.getDefaultCamera().position.y + Engine.getDefaultCamera().viewportHeight / 2) { Engine.getDefaultCamera().position.y = vv.y - Engine.getDefaultCamera().viewportHeight / 2; } else if (vv.y < Engine.getDefaultCamera().position.y - Engine.getDefaultCamera().viewportHeight / 2) { Engine.getDefaultCamera().position.y = vv.y + Engine.getDefaultCamera().viewportHeight / 2; } } return super.touchDragged(screenX, screenY, pointer); } };