3
\$\begingroup\$

After cocos2d, I'm looking at box2d... And I have some questions:

I was wondering how to cut a body into pieces.

  1. How do I determine the intersection point of the body with the cut line?

  2. Create a new body in some "update_body_method"?

On the second question I have answer, for example between two points create vector from first point to second point.

\$\endgroup\$
2
\$\begingroup\$

There is an implementation of this in the Farseer engine (C#) which is based on Box2D:

http://farseerphysics.codeplex.com/SourceControl/changeset/view/90041#1436517

..\Source Files\Common\Polygon Manipulation\CuttingTools.cs

// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
public static void Cut(World world, Vector2 start, Vector2 end, float thickness)

// Split a fixture into 2 vertice collections using the given entry and exit-point.
public static void SplitShape(Fixture fixture, Vector2 entryPoint, Vector2 exitPoint, float splitSize, out Vertices first, out Vertices second)
\$\endgroup\$
  • \$\begingroup\$ For simple example I create one body and vector, vector construct on two points. Collision between vector and body works fine, but I still did not think how to get the intersection point of the vector and the body??? UPD: I have one idea, but... \$\endgroup\$ – Darth Vader Jul 26 '11 at 13:04
  • \$\begingroup\$ I believe you can use this method to get the intersection points : b2Shape.RayCast(...) code.google.com/p/box2d/source/browse/trunk/Box2D/Box2D/… \$\endgroup\$ – Den Jul 26 '11 at 14:04
  • \$\begingroup\$ I found this method in documentation. \$\endgroup\$ – Darth Vader Jul 26 '11 at 14:32
  • \$\begingroup\$ From documentation:**You can cast a ray at a shape to get the point of first intersection and normal vector** It is only one point, but I need two points. May I use in this case Contact Manifolds??? \$\endgroup\$ – Darth Vader Jul 27 '11 at 8:48
  • \$\begingroup\$ In Farseer they cast a reverse ray to get the exit point. You can try reversing b2RayCastInput points to cast reversed ray to get exit point. \$\endgroup\$ – Den Jul 27 '11 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.