Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Rotation relative to the midpoint of the two touches #20

Open
bycross028 opened this issue Oct 3, 2015 · 0 comments
Open

Fix: Rotation relative to the midpoint of the two touches #20

bycross028 opened this issue Oct 3, 2015 · 0 comments

Comments

@bycross028
Copy link

MultiTouchController.java:

public class MultiTouchController<T> {
     ...
     float mStartAbsoluteAng; // <----------
     ...
    private void anchorAtThisPositionAndScale() {
        ...
        /* add at the end of the function */
        mStartAbsoluteAng = mCurrXform.angle;  // <----------
    }

   ...
   private void performDragOrPinch() {
        /* Don't do anything if we're not dragging anything*/
        if (selectedObject == null)
            return;

        /* Calc new position of dragged object*/
        float currScale = !mCurrXform.updateScale ? 1.0f : mCurrXform.scale == 0.0f ? 1.0f : mCurrXform.scale;
        extractCurrPtInfo();

        float newPosX = mCurrPtX - startPosX * currScale;
        float newPosY = mCurrPtY - startPosY * currScale;
        float newScale = startScaleOverPinchDiam * mCurrPtDiam;
        float newScaleX = startScaleXOverPinchWidth * mCurrPtWidth;
        float newScaleY = startScaleYOverPinchHeight * mCurrPtHeight;
        float newAngle = startAngleMinusPinchAngle + mCurrPtAng;

        /*
        * Fix: Rotation relative to the midpoint start
        */

        float[] deltaPosition = new float[2];
        deltaPosition[0] =  newPosX - mCurrPtX;
        deltaPosition[1] =  newPosY - mCurrPtY;

        float deltaAngle = newAngle - mStartAbsoluteAng;

        float[] deltaRotate = new float[2];
            deltaRotate[0] = (float)( deltaPosition[0] * Math.cos(deltaAngle)) -
                (float) ( deltaPosition[1] * Math.sin(deltaAngle));
        deltaRotate[1] = (float)( deltaPosition[0] * Math.sin(deltaAngle)) +
                (float) ( deltaPosition[1] * Math.cos(deltaAngle));

        newPosX = mCurrPtX + deltaRotate[0];
        newPosY = mCurrPtY + deltaRotate[1];

        /*
         * Fix: Rotation relative to the midpoint end
         */

        // Set the new obj coords, scale, and angle as appropriate (notifying the subclass of the change).
        mCurrXform.set(newPosX, newPosY, newScale, newScaleX, newScaleY, newAngle);

        boolean success = objectCanvas.setPositionAndScale(selectedObject, mCurrXform, mCurrPt);
        if (!success)
            ; // If we could't set those params, do nothing currently
    }

       ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant