I am designing a image reaction binding with box2d library. Here is how I create the shape and update position of my image.
The problem I am having is that in flex, image is ratated by the left top corner(0, 0) of the image. In box2d, it is rotated by the center of the shape. My image does look awkward when having rotation, but looks fine when it does not rotate. I searched around, flex cannot set the rotation point to the center of the image or any simple solution. How do I fix this problem? Can box2d help me on calculation the correct x, y points of the left top corner(0, 0) of the image, but still do rotation by the center of the image? or any other way to work around this problem?
EDIT:
I am not sure if I understand correctly. The box2d documentation mentioned nothing about SetAsOrientedBox(). It seems like if I create the shape using SetAsBox(), it will assume that the x, y points are at the center of the box. If I create the shape using SetAsOrientedBox(), it will assume that x, y points are left top corner(0, 0) of the box, but it will rotate according to the b2Vec I pass in to the function. Is this correct?
http://personal.boristhebrave.com/perma ... onDef.html
Code:
box2DPolygonShape.SetAsBox(component.width / 2 / ratio,
component.height / 2 / ratio);
component.height / 2 / ratio);
Code:
component.x = (element.GetPosition().x * ratio) -
(component.width / 2);
component.y = (element.GetPosition().y * ratio) -
(component.height / 2);
component.rotation = element.GetAngle() * 180 / Math.PI;
(component.width / 2);
component.y = (element.GetPosition().y * ratio) -
(component.height / 2);
component.rotation = element.GetAngle() * 180 / Math.PI;
The problem I am having is that in flex, image is ratated by the left top corner(0, 0) of the image. In box2d, it is rotated by the center of the shape. My image does look awkward when having rotation, but looks fine when it does not rotate. I searched around, flex cannot set the rotation point to the center of the image or any simple solution. How do I fix this problem? Can box2d help me on calculation the correct x, y points of the left top corner(0, 0) of the image, but still do rotation by the center of the image? or any other way to work around this problem?
EDIT:
I am not sure if I understand correctly. The box2d documentation mentioned nothing about SetAsOrientedBox(). It seems like if I create the shape using SetAsBox(), it will assume that the x, y points are at the center of the box. If I create the shape using SetAsOrientedBox(), it will assume that x, y points are left top corner(0, 0) of the box, but it will rotate according to the b2Vec I pass in to the function. Is this correct?
http://personal.boristhebrave.com/perma ... onDef.html