Skip to content

Strange anomalies in code #978

@MWstudios

Description

@MWstudios

Greetings. I've been porting Box2D to C#. During the porting, I've discovered a few strange anomalies in the C++ original and I'd like to know if these were intended or typos:

  1. In contact.cs, line 710: The function doesn't check if the function is primary and swap the shapes, so if shapeA is a circle and shapeB is a polygon, the function does not swap them around and fails.
b2Manifold b2ComputeManifold( b2Shape* shapeA, b2Transform transformA, b2Shape* shapeB, b2Transform transformB )
{
	b2ManifoldFcn* fcn = s_registers[shapeA->type][shapeB->type].fcn;
	b2SimplexCache cache = { 0 };
	return fcn( shapeA, transformA, shapeB, transformB, &cache );
}
  1. In contact_solver.cs, line 1852 and 1904: The first and second penetration point compute impulses differently. I don't know whether that's intentional.
b2FloatW negImpulse = b2AddW( b2MulW( c->normalMass1, b2AddW( b2MulW( pointMassScale, vn ), bias ) ),
							  b2MulW( pointImpulseScale, c->normalImpulse1 ) );
b2FloatW negImpulse = b2AddW( b2MulW( c->normalMass2, b2MulW( pointMassScale, b2AddW( vn, bias ) ) ),
							  b2MulW( pointImpulseScale, c->normalImpulse2 ) );
  1. In solver.cs, line 383: Both offsets are calculated from p1. Again, I don't know if that's intentional.
b2Vec2 p1 = b2TransformPoint( transform, shape->segment.point1 );
b2Vec2 p2 = b2TransformPoint( transform, shape->segment.point2 );
b2Vec2 e = b2Sub( p2, p1 );
b2Vec2 c1 = continuousContext->centroid1;
b2Vec2 c2 = continuousContext->centroid2;
float offset1 = b2Cross( b2Sub( c1, p1 ), e );
float offset2 = b2Cross( b2Sub( c2, p1 ), e );

Also, I'd like to know if InterlockedFetchAddInt() returns the value before or after addition. I'm under the impression that it's the value before addition, which means it behaves differently than C#. Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions