Saturday, November 2, 2019

andengine - Rotation angle based on touch move


I want to rotate my stick based on the movement of the touch on the screen. From my calculation I did not able to find correct angle in degree. So please provide guidance, my code snippet for that are below.


if (pSceneTouchEvent.isActionMove()) {
pValueX = pSceneTouchEvent.getX();
pValueY = CAMERA_HEIGHT - pSceneTouchEvent.getY();
rotationAngle = (float) Math.atan2(pValueX, pValueY);

stick.setRotation((float) MathUtils.radToDeg(rotationAngle));

}

Answer



The answer for the above question is as below


    if (pSceneTouchEvent.isActionMove()) {

pValueX = pSceneTouchEvent.getX();
pValueY = CAMERA_HEIGHT - pSceneTouchEvent.getY();


directionX = pValueX - stick.getX();
directionY = (CAMERA_HEIGHT - pValueY) - stick.getY();

rotationAngle = (float) Math.atan2(directionY, directionX);

stick.setRotation(MathUtils.radToDeg(rotationAngle));

}

No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...