Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing changes from upstream commits d323a0e, c69eee4, df7373c (New Capsule collider) #14

Closed
wants to merge 14 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add missing changes from upstream commit d323a0e
mreinstein committed Jan 14, 2025
commit 88dbcf2d15682f88a9880246b916302382a8cf0a
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

## Next - Unreleased

* `b2Shape_RayCast(b2ShapeId shapeId, b2Vec2 origin, b2Vec2 translation)` -> `b2Shape_RayCast(b2ShapeId shapeId, b2RayCastInput* input)`
* remove `b2GetOwnerTransform`
* `b2Body_GetInertiaTensor` -> `b2Body_GetRotationalInertia`
* `b2DistanceJoint_GetHertz` -> `b2DistanceJoint_GetSpringHertz`
* `b2DistanceJoint_GetDampingRatio` -> `b2DistanceJoint_GetSpringDampingRatio
1 change: 0 additions & 1 deletion src/include/shape_h.js
Original file line number Diff line number Diff line change
@@ -93,7 +93,6 @@ export {
b2MakeShapeDistanceProxy,
b2RayCastShape,
b2ShapeCastShape,
b2GetOwnerTransform,
b2Shape_AreContactEventsEnabled,
b2Shape_AreHitEventsEnabled,
b2Shape_ArePreSolveEventsEnabled,
34 changes: 16 additions & 18 deletions src/shape_c.js
Original file line number Diff line number Diff line change
@@ -68,10 +68,6 @@ function b2GetShape(world, shapeId)
return shape;
}

export function b2GetOwnerTransform(world, shape)
{
return b2GetBodyTransform(world, shape.bodyId);
}

function b2GetChainShape(world, chainId)
{
@@ -1019,7 +1015,7 @@ export function b2Shape_TestPoint(shapeId, point)
const world = b2GetWorld(shapeId.world0);
const shape = b2GetShape(world, shapeId);

const transform = b2GetOwnerTransform(world, shape);
const transform = b2GetBodyTransform(world, shape.bodyId);
const localPoint = b2InvTransformPoint(transform, point);

switch (shape.type)
@@ -1038,60 +1034,61 @@ export function b2Shape_TestPoint(shapeId, point)
}
}


/**
* @function b2Shape_RayCast
* @description
* Performs a ray cast against a shape in world space, transforming the input/output
* between local and world coordinates.
* @param {b2ShapeId} shapeId - The identifier for the shape to test
* @param {b2Vec2} origin - The starting point of the ray in world coordinates
* @param {b2Vec2} translation - The direction and length of the ray in world coordinates
* @param {b2RayCastInput} input - The ray to cast, in world coordinates
* @returns {b2CastOutput} The ray cast results containing:
* - hit: boolean indicating if the ray intersects the shape
* - point: intersection point in world coordinates (if hit is true)
* - normal: surface normal at intersection in world coordinates (if hit is true)
* - fraction: fraction of translation where intersection occurs (if hit is true)
* @throws {Error} Throws assertion error if shape type is invalid
*/
export function b2Shape_RayCast(shapeId, origin, translation)
export function b2Shape_RayCast(shapeId, input)
{
const world = b2GetWorld(shapeId.world0);
const shape = b2GetShape(world, shapeId);

const transform = b2GetOwnerTransform(world, shape);
const transform = b2GetBodyTransform(world, shape.bodyId);

// input in local coordinates
const input = new b2RayCastInput();
input.maxFraction = 1.0;
input.origin = b2InvTransformPoint(transform, origin);
input.translation = b2InvRotateVector(transform.q, translation);
const localInput = new b2RayCastInput();
localInput.origin = b2InvTransformPoint(transform, input.origin);
localInput.translation = b2InvRotateVector(transform.q, input.translation);
localInput.maxFraction = input.maxFraction;


let output = new b2CastOutput(rayNormal, rayPoint);

switch (shape.type)
{
case b2ShapeType.b2_capsuleShape:
output = b2RayCastCapsule(input, shape.capsule);
output = b2RayCastCapsule(localInput, shape.capsule);

break;

case b2ShapeType.b2_circleShape:
output = b2RayCastCircle(input, shape.circle);
output = b2RayCastCircle(localInput, shape.circle);

break;

case b2ShapeType.b2_segmentShape:
output = b2RayCastSegment(input, shape.segment, false);
output = b2RayCastSegment(localInput, shape.segment, false);

break;

case b2ShapeType.b2_polygonShape:
output = b2RayCastPolygon(input, shape.polygon);
output = b2RayCastPolygon(localInput, shape.polygon);

break;

case b2ShapeType.b2_chainSegmentShape:
output = b2RayCastSegment(input, shape.chainSegment.segment, true);
output = b2RayCastSegment(localInput, shape.chainSegment.segment, true);

break;

@@ -1111,6 +1108,7 @@ export function b2Shape_RayCast(shapeId, origin, translation)
return output;
}


/**
* @function b2Shape_SetDensity
* @summary Sets the density of a shape and optionally updates the parent body's mass.