Rotate Body From Corner
Posted
by
Siddharth
on Game Development
See other posts from Game Development
or by Siddharth
Published on 2012-10-01T10:20:23Z
Indexed on
2012/10/01
15:54 UTC
Read the original article
Hit count: 577
I want to ask that how to rotate body from corner?
movableBeam.getBeamBody().setTransform(movableBeam.getBeamBody().getPosition(), angle);
The above line of code rotate the beam from center that I want rotate from one of the conner. Any member please help me.
EDIT :
float beamCenterX = movableBeam.getX() + movableBeam.getWidth()
/ 2f;
float beamCenterY = movableBeam.getY()
+ movableBeam.getHeight() / 2f;
float cornerOffsetX = movableBeam.getX() - beamCenterX;
float cornerOffsetY = movableBeam.getY() - beamCenterY;
float bodyAngle = (float) Math.atan2(cornerOffsetY,
cornerOffsetX);
float newAngle = imageAngle + bodyAngle;
float newCornerOffsetX = (float) Math.cos(Math
.toDegrees(newAngle));
float newCornerOffsetY = (float) Math.sin(Math
.toDegrees(newAngle));
cornerOffsetX = movableBeam.getX() - movableBeam.getWidth()
/ 2f;
cornerOffsetY = movableBeam.getY() - movableBeam.getHeight()
/ 2f;
Vector2 postion = new Vector2(
(newCornerOffsetX - cornerOffsetX + movableBeam.getX())
/ PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT,
(newCornerOffsetY - cornerOffsetY + movableBeam.getY())
/ PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT);
movableBeam.getBeamBody().setTransform(postion, newAngle);
© Game Development or respective owner