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

[fix] box2d shape aabb calculating bug #15565

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Changes from all commits
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
18 changes: 11 additions & 7 deletions cocos/physics-2d/box2d/shapes/shape-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { b2PhysicsWorld } from '../physics-world';
import { PhysicsGroup } from '../../../physics/framework/physics-enum';

const tempFilter = new b2.Filter();
const lowerBound = new b2.Vec2();
const upperBound = new b2.Vec2();

function getFilter (shape: b2Shape2D) {
const comp = shape.collider;
Expand Down Expand Up @@ -107,15 +109,17 @@ export class b2Shape2D implements IBaseShape {

const count = fixture.GetShape().GetChildCount();
for (let j = 0; j < count; j++) {
const aabb = fixture.GetAABB(j);
lowerBound.Copy(fixture.GetAABB(j).lowerBound);
upperBound.Copy(fixture.GetAABB(j).upperBound);
if (fixture.GetShape().m_type === 2) { //b2ShapeType.e_polygonShape
aabb.lowerBound.SelfAddXY(fixture.GetShape().m_radius, fixture.GetShape().m_radius);
aabb.upperBound.SelfSubXY(fixture.GetShape().m_radius, fixture.GetShape().m_radius);
const skinWidth = fixture.GetShape().m_radius;
lowerBound.SelfAddXY(skinWidth, skinWidth);
upperBound.SelfSubXY(skinWidth, skinWidth);
}
if (aabb.lowerBound.x < minX) minX = aabb.lowerBound.x;
if (aabb.lowerBound.y < minY) minY = aabb.lowerBound.y;
if (aabb.upperBound.x > maxX) maxX = aabb.upperBound.x;
if (aabb.upperBound.y > maxY) maxY = aabb.upperBound.y;
if (lowerBound.x < minX) minX = lowerBound.x;
if (lowerBound.y < minY) minY = lowerBound.y;
if (upperBound.x > maxX) maxX = upperBound.x;
if (upperBound.y > maxY) maxY = upperBound.y;
}
}

Expand Down