Changing size of a rectangle geometry

Topics: User Forum
Apr 7, 2010 at 6:25 AM

How is it I you change the size of a rectangle mid simulation? Make it wider/taller based on a dynamic variable?

Apr 8, 2010 at 12:52 AM

excuse the double post, but is there infact a way to do this?

Apr 8, 2010 at 3:03 AM

If your using 2.1.x version and are using Distance grid collision then you must rebuild the rectangle every time it changes. If your using my SAT based collision then you should be able to simply change the vertex positions, but this is untested in both cases as far as I know.

If your using 3.x version then you must rebuild the Fixture. This is a pretty fast operation, but it can slow down the Xbox, just like everything except drawing lol.

Apr 8, 2010 at 6:56 AM
Edited Apr 8, 2010 at 6:57 AM

When you say rebuild the fixture, do you mean the geometry?

see the character in my game is just a square, and it resizes based on how much ammo you have.


geometry initially defined with

sqrGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, sqrBody, 32, 32);

so your saying on the step, if its size needs to be changed i simply redo the code as in

sqrGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, sqrBody, 32+32*ammo/maxammo, 32 + 32*ammo/maxammo);

varying between sizes 32x32 - 64x64

Is this the correct way to do this?

Apr 8, 2010 at 4:19 PM

You'll also need to remove the old geometry from the body and physics simulation.  If you don't, you'll just be putting multiple geometries onto the body at the same time.

Apr 8, 2010 at 7:34 PM

alright i got it working. just did sqrGeom.Dispose then recreated it, and its only happening at most 5-10 times in a second, not every step, any chance with 4 players resizing at this rate i'll have performance issues?

Apr 9, 2010 at 1:21 AM

I wouldn't worry about performance until the frame rate drops to an unplayable level (< 30). But if you do start noticing problems you could pre-create a bunch of geoms, one for every ammo amount, and then you should have no problems with performance. The Pooling demo in the AdvancedSamples shows a method of doing this.

Apr 9, 2010 at 4:39 AM

cool! alright thanks guys.