Set body angle to zero without moving vertices

Let us know if you have a nice R.U.B.E script to share!
Post Reply
iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Set body angle to zero without moving vertices

Post by iforce2d » Thu Apr 16, 2015 6:40 am

Sometimes it's necessary to set the angle of a body to zero, but leave all the vertices of the body in their current positions. This script will do that for all selected bodies:

Code: Select all

vec2 originalCursorPosition = getCursor();

body[] bs = sb();
for (uint i = 0; i < bs.length; i++) {
	body b = bs[i];
	setCursor( b.pos );
	fixture[] fs = b.getFixtures();
	for (uint k = 0; k < fs.length; k++) {
		fixture f = fs[k];
		rotate( f.getVertices(), 0, b.getAngle() );
	}
	b.setAngle( 0 );
}

setCursor( originalCursorPosition );

Post Reply