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