box2d icon indicating copy to clipboard operation
box2d copied to clipboard

Allow "b2ChainSegment" to be created without a chain, managing the ghosts/lifetime explicitly.

Open MelvMay-Unity opened this issue 2 months ago • 0 comments

As per these conversations: https://discord.com/channels/460295137705197568/1250865746494619650/1348280720832991262 https://discord.com/channels/460295137705197568/1250865746494619650/1440247289879986268

B2_API b2ShapeId b2CreateChainSegmentShape(b2BodyId bodyId, const b2ShapeDef* def, b2ChainSegment* chainSegment);

b2ShapeId b2CreateChainSegmentShape(b2BodyId bodyId, const b2ShapeDef* def, b2ChainSegment* chainSegment)
{
    float lengthSqr = b2DistanceSquared(chainSegment->segment.point1, chainSegment->segment.point2);
    if (lengthSqr <= B2_LINEAR_SLOP * B2_LINEAR_SLOP)
    {
        B2_ASSERT(false);
        return b2_nullShapeId;
    }

    // Ensure the chain segment is orphaned.
    chainSegment->chainId = B2_NULL_INDEX;

    return b2CreateShape(bodyId, def, chainSegment, b2_chainSegmentShape);

MelvMay-Unity avatar Nov 18 '25 17:11 MelvMay-Unity