Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to set the origin of a box2d shape. By default, a shape rotates around the center. But I'm trying to get it to rotate around the left of the shape. Like a clock for example.

I've heard of things like SetXForm but that function doesn't seem to even exist. I'm using C++ just in case you needed to know that.

Thanks in advanced, any help is appreciated.

share|improve this question

2 Answers 2

There are two kinds of shapes and three ways to make them in Box2D.

A b2CircleShape always has its center at the center of the circle. If you want to make a "lopsided circle" you must fix the circle to another object (e.g. a tiny circle inside it) with a joint.

A b2PolygonShape may be initialized with SetAsBox. SetAsBox by default places the origin in the middle of the rectangle, but you can pass a b2Vec2 as the third argument to place the origin elsewhere.

A non-box b2PolygonShape is initialized with the origin at local coordinates 0,0. To make a shape that extents only one direction, e.g. right and up, simply specify coordinates like (0, 0), (0, 5), (5, 5), (5, 0), constructing the shape only along local coordinates that move up and right (and in CCW winding order).

Remember, the origin of the shape is always local coordinate (0, 0). If you try to think of it as "moving the origin" you are just going to confuse yourself - what you are doing is offsetting the other vertices relative to the origin.

share|improve this answer

Never mind, I fount the answer. Apparently in the b2PolygonShape, when you call the function

SetAsBox()

There's a 2 overloads. And one of them is:

SetAsBox(halfwidth, halfheight, center, angle);

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.