CuttingTool causes object freezing

Topics: Developer Forum
Apr 30, 2011 at 7:20 PM
Edited Apr 30, 2011 at 7:30 PM

Hi,

 I'm trying to use the CuttingTool in Silverlight (with the Physics Helper). Whenever I cut the block (a simple rectangle), the block completley freezes and no longer takes part in any collisions. I'm using the code below:

 

//You can ignore the inefficiency of new points being created, this is just a test project (It's there to convert 'start' and 'end' from Vector2 to Points).

CuttingTools.Cut(world, physicsController.ScreenToWorld(new System.Windows.Point(start.X, start.Y)), physicsController.ScreenToWorld(new System.Windows.Point(end.X, end.Y)), 0.4f);

 

No errors are thrown, but the block just stops moving. I tried looking into the CuttingTool code and figured

 

world.RemoveBody(fixtures[i].Body); //Line 196 Common/PolygonManipulation/CuttingTools.cs

 

is trying to remove the body, but not removing the rectangle object it's associated with.

Does the body have to be breakable or am I missing something?

Thanks

(Wasn't sure if I should post it here or in the Physics Helper discussions section, but thought it might be more related to Farseer directly)

Apr 30, 2011 at 10:00 PM

I haven't tried the cutting methods in FP, but I think it would give you two new bodies to replace the original... So the challenge is getting those two new bodies to be tied to Physics Helper elements.

There is nothing in the Physics Helper to support cutting so this would all be manual - you would need to create new PhysicsSprite elements to represent the two new pieces and add them into the simulation.

At least that's what I am guessing, again I haven't played with the Cutting stuff.

Apr 30, 2011 at 10:10 PM

Thanks Andy, I'll take a look at how Physics Helper is currently interacting with Farseer and see if I can get the CuttingTools working. If I manage to get something up and running, I'll post the code up.

If anyone has any ideas, I'm happy to hear them :)

May 4, 2011 at 10:41 PM
Edited May 4, 2011 at 10:42 PM

I've managed to get a hack going in which I change the cutting function to return the two fixtures of the split body and create Silverlight polygons from the fixture's vertices. However I've run into a positioning problem and can't seem to figure out what I need to do. The returned fixtures position themselves in the center of the screen, instead of where the original body was. I'm using Canvas.SetLeft in order to position the two 'broken' polygons, but I can't seem to get them to be positioned over the origina body (short of hard coding, but I need the positions to be dynamic in game).

I took a look at the values returned in each fixture's 'body.position' property and they were low digits (e.g. -2,4,1 etc..). I tried converting it to world coordinates, but that sent the fixture far right of the original body. When using the 'mouse picker' in the Physics Helper, I noticed that the black line didn't originate from the center of the object to my mouse (as it does with other 'normal' physics objects). Instead, it originated at some seemingly random location in space. Could this be a hint to what's causing the positioning problem? Any ideas would be great as I seem to have run out of ideas.

Thanks!

May 7, 2011 at 12:18 AM

Quick update. I just noticed that if I substract 400 (half the width of the phone in landscape) and then add the current new (broken) fixture position, it positions it correctly. Therefore, for some reason, the coordinate system for the fixture is defaulting to the centre of the phone instead the top left hand corner. Whilst I can just substract half the width all the time, is there a reason why the coordinate system for the fixture shifts to the center of the phone?