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\$

1 Answer 1

2
\$\begingroup\$

There is an implementation of this in the C# library Velcro Physics (formerly Farseer Physics), which is based on Box2D: CuttingTools.cs

/src/VelcroPhysics/Tools/Cutting/Simple/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\$
7
  • \$\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\$ Commented Jul 26, 2011 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
    Commented Jul 26, 2011 at 14:04
  • \$\begingroup\$ I found this method in documentation. \$\endgroup\$ Commented Jul 26, 2011 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\$ Commented Jul 27, 2011 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
    Commented Jul 27, 2011 at 9:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .