Example usage for com.badlogic.gdx.physics.box2d.joints MouseJoint setTarget

List of usage examples for com.badlogic.gdx.physics.box2d.joints MouseJoint setTarget

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d.joints MouseJoint setTarget.

Prototype

public void setTarget(Vector2 target) 

Source Link

Document

Use this to update the target point.

Usage

From source file:org.ams.testapps.paintandphysics.cardhouse.CardMover.java

License:Open Source License

@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
    if (activeCard == null)
        return false;
    if (mouseJointStorage.size < 2)
        return false;

    Vector2 worldCoordinates = CoordinateHelper.getWorldCoordinates(camera, screenX, screenY);

    MouseJoint mouseJoint = mouseJointStorage.get(mouseJointStorage.size - 2);
    MouseJoint auxMouseJoint = mouseJointStorage.get(mouseJointStorage.size - 1);

    if (turning) {
        Vector2 v = new Vector2(worldCoordinates).sub(mouseJoint.getTarget());
        float a = v.angleRad();

        angleWhenRotating = a - angleOffset;

        if (roundedTurning) {
            // rounding
            float round = angleRounding * MathUtils.degreesToRadians;
            angleWhenRotating = Util.roundToNearestN(angleWhenRotating, round);
            float f = angleAtRotateStart % round;
            angleWhenRotating -= f;//ww  w .  java 2s . co m
        }

        auxMouseJoint.setTarget(
                new Vector2(auxMouseJointDistance, 0).rotateRad(angleWhenRotating).add(mouseJoint.getTarget()));

    } else {

        if (turnCircleInner.isOutsideTurnCircle(worldCoordinates))
            return false;

        mouseJoint.setTarget(new Vector2(worldCoordinates).sub(offset));

        auxMouseJoint.setTarget(new Vector2(auxMouseJointDistance, 0).rotateRad(angleWhenRotating)
                .add(worldCoordinates).sub(offset));

        updateTurnCirclePos(mouseJoint.getTarget());
    }

    return true;
}

From source file:org.zapylaev.game.truetennis.core.model.JointControls.java

License:Open Source License

@Override
public void sendTouchDragged(float x, float y, int pointer) {
    MouseJoint joint = mMouseJoints.get(pointer);
    if (joint != null) {
        joint.setTarget(new Vector2(x, y));
    }// w w w  .ja  v a2 s.c  o  m
}