Hi,
I'm in the process of writing a level editor for my game - it's essentially just a GUI panel that pauses the game when you open it and allows you to tweak stuff to do with shapes and bodies (and sprites and various other stuff in the game). I don't plan on allowing this kind of user-editing of shapes and bodies in the game itself, and the game is paused whilst it's all happening, so I can cope with a degree of odd behaviour from Box2D during editing so long as nothing crashes or asserts or goes world-breakingly crazy.
For bodies I just hacked a couple of Set functions into b2Body so that the editor can set a body's angular and linear damping, and whether or not it has fixed rotation, without the need to completely destroy and recreate the body. Shapes seemed a little more complex, so I've been trying what seems to be the generally-accepted method of filling out a b2ShapeDef with the current shape's information, destroying the shape, and then recreating it using the b2ShapeDef. This is causing some headaches for me though, since parts of my code keep pointers to shapes around (my sprites keep pointers so they can use the vertices of b2PolygonShapes directly for rendering, for example), so I'd have to patch up all of those pointers when destroying and recreating a shape.
I'm wondering if, instead of having to fix up all of the pointers, I could just cheekily fudge b2CircleShape and b2PolygonShape to give me the non-const access I need to edit vertex positions/counts and circle radii/local positions, or perhaps just make my editor class a friend class of the b2CircleShape and b2Polygon shape so I can fiddle with stuff directly. Am I likely to run into big problems by doing things this way, and should I be aware of anything else I'd need to do to ensure that the internal states of shapes remains sensible and consistent?
I'm in the process of writing a level editor for my game - it's essentially just a GUI panel that pauses the game when you open it and allows you to tweak stuff to do with shapes and bodies (and sprites and various other stuff in the game). I don't plan on allowing this kind of user-editing of shapes and bodies in the game itself, and the game is paused whilst it's all happening, so I can cope with a degree of odd behaviour from Box2D during editing so long as nothing crashes or asserts or goes world-breakingly crazy.
For bodies I just hacked a couple of Set functions into b2Body so that the editor can set a body's angular and linear damping, and whether or not it has fixed rotation, without the need to completely destroy and recreate the body. Shapes seemed a little more complex, so I've been trying what seems to be the generally-accepted method of filling out a b2ShapeDef with the current shape's information, destroying the shape, and then recreating it using the b2ShapeDef. This is causing some headaches for me though, since parts of my code keep pointers to shapes around (my sprites keep pointers so they can use the vertices of b2PolygonShapes directly for rendering, for example), so I'd have to patch up all of those pointers when destroying and recreating a shape.
I'm wondering if, instead of having to fix up all of the pointers, I could just cheekily fudge b2CircleShape and b2PolygonShape to give me the non-const access I need to edit vertex positions/counts and circle radii/local positions, or perhaps just make my editor class a friend class of the b2CircleShape and b2Polygon shape so I can fiddle with stuff directly. Am I likely to run into big problems by doing things this way, and should I be aware of anything else I'd need to do to ensure that the internal states of shapes remains sensible and consistent?