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

update code base to box2d 2.4.1 #232

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 0 additions & 13 deletions src/collision/Distance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i
const saveB = []; // int[3]
let saveCount = 0;

let distanceSqr1 = Infinity;
let distanceSqr2 = Infinity;

// Main iteration loop.
let iter = 0;
while (iter < k_maxIters) {
Expand All @@ -131,16 +128,6 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i
break;
}

// Compute closest point.
const p = simplex.getClosestPoint();
distanceSqr2 = p.lengthSquared();

// Ensure progress
if (distanceSqr2 >= distanceSqr1) {
// break;
}
distanceSqr1 = distanceSqr2;

// Get search direction.
const d = simplex.getSearchDirection();

Expand Down
5 changes: 5 additions & 0 deletions src/collision/Shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import type { Vec2Value } from '../common/Vec2';
*/
export abstract class Shape {
m_type: ShapeType;

/**
* Radius of a shape. For polygonal shapes this must be b2_polygonRadius.
* There is no support for making rounded polygons.
*/
m_radius: number;

/** @internal */
Expand Down
4 changes: 4 additions & 0 deletions src/collision/shape/ChainShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export class ChainShape extends Shape {
_createLoop(vertices: Vec2Value[]): ChainShape {
_ASSERT && console.assert(this.m_vertices.length == 0 && this.m_count == 0);
_ASSERT && console.assert(vertices.length >= 3);
if (vertices.length < 3) {
return;
}

for (let i = 1; i < vertices.length; ++i) {
const v1 = vertices[i - 1];
const v2 = vertices[i];
Expand Down
5 changes: 0 additions & 5 deletions src/collision/shape/CircleShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ export class CircleShape extends Shape {
return this.m_p;
}

getVertex(index: 0): Vec2 {
_ASSERT && console.assert(index == 0);
return this.m_p;
}

/**
* @internal
* @deprecated Shapes should be treated as immutable.
Expand Down
2 changes: 1 addition & 1 deletion src/collision/shape/CollideEdgePolygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export const CollideEdgePolygon = function (manifold: Manifold, edgeA: EdgeShape
polygonBA.normals[i] = Rot.mulVec2(xf.q, polygonB.m_normals[i]);
}

const radius = 2.0 * Settings.polygonRadius;
const radius = polygonB.m_radius + edgeA.m_radius;

manifold.pointCount = 0;

Expand Down
6 changes: 1 addition & 5 deletions src/collision/shape/PolygonShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ export class PolygonShape extends Shape {
return this.m_radius;
}

getVertex(index: number): Vec2 {
_ASSERT && console.assert(0 <= index && index < this.m_count);
return this.m_vertices[index];
}

/**
* @internal
* @deprecated Shapes should be treated as immutable.
Expand Down Expand Up @@ -206,6 +201,7 @@ export class PolygonShape extends Shape {
let ih = i0;

while (true) {
_ASSERT && console.assert(m < Settings.maxPolygonVertices);
hull[m] = ih;

let ie = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/dynamics/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ export interface BodyDef {
* Linear damping is use to reduce the linear velocity. The
* damping parameter can be larger than 1.0 but the damping effect becomes
* sensitive to the time step when the damping parameter is large.
* Units are 1/time
*/
linearDamping?: number;
/**
* Angular damping is use to reduce the angular velocity.
* The damping parameter can be larger than 1.0 but the damping effect
* becomes sensitive to the time step when the damping parameter is large.
* Units are 1/time
*/
angularDamping?: number;
/**
Expand Down Expand Up @@ -467,10 +469,8 @@ export class Body {
*/
setAwake(flag: boolean): void {
if (flag) {
if (this.m_awakeFlag == false) {
this.m_awakeFlag = true;
this.m_sleepTime = 0.0;
}
this.m_awakeFlag = true;
this.m_sleepTime = 0.0;
} else {
this.m_awakeFlag = false;
this.m_sleepTime = 0.0;
Expand Down
6 changes: 3 additions & 3 deletions src/dynamics/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ContactImpulse, TimeStep } from "./Solver";
const _ASSERT = typeof ASSERT === 'undefined' ? false : ASSERT;


// Solver debugging is normally disabled because the block solver sometimes has to deal with a poorly conditioned effective mass matrix.
const DEBUG_SOLVER = false;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ export type ContactCallback = (

/**
* Friction mixing law. The idea is to allow either fixture to drive the
* restitution to zero. For example, anything slides on ice.
* friction to zero. For example, anything slides on ice.
*/
export function mixFriction(friction1: number, friction2: number): number {
return Math.sqrt(friction1 * friction2);
Expand Down Expand Up @@ -910,8 +911,7 @@ export class Contact {
// 01/07 on Box2D_Lite).
// Build the mini LCP for this contact patch
//
// vn = A * x + b, vn >= 0, , vn >= 0, x >= 0 and vn_i * x_i = 0 with i =
// 1..2
// vn = A * x + b, vn >= 0, x >= 0 and vn_i * x_i = 0 with i = 1..2
//
// A = J * W * JT and J = ( -n, -r1 x n, n, r2 x n )
// b = vn0 - velocityBias
Expand Down
4 changes: 2 additions & 2 deletions src/dynamics/Solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export class Solver {
_ASSERT && console.assert(b.isActive() == true);
this.addBody(b);

// Make sure the body is awake.
b.setAwake(true);
// Make sure the body is awake (without resetting sleep timer).
b.m_awakeFlag = true;

// To keep islands as small as possible, we don't
// propagate islands across static bodies.
Expand Down
8 changes: 5 additions & 3 deletions src/dynamics/joint/MotorJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export class MotorJoint extends Joint {
// J = [-I -r1_skew I r2_skew ]
// Identity used:
// w k % (rx i + ry j) = w * (-ry i + rx j)
//
// r1 = offset - c1
// r2 = -c2

// Angle constraint
// Cdot = w2 - w1
Expand Down Expand Up @@ -298,11 +301,10 @@ export class MotorJoint extends Joint {
const qB = Rot.neo(aB);

// Compute the effective mass matrix.
this.m_rA = Rot.mulVec2(qA, Vec2.neg(this.m_localCenterA));
this.m_rA = Rot.mulVec2(qA, Vec2.sub(this.m_linearOffset, this.m_localCenterA));
this.m_rB = Rot.mulVec2(qB, Vec2.neg(this.m_localCenterB));

// J = [-I -r1_skew I r2_skew]
// [ 0 -1 0 1]
// r_skew = [-ry; rx]

// Matlab
Expand All @@ -315,6 +317,7 @@ export class MotorJoint extends Joint {
const iA = this.m_invIA;
const iB = this.m_invIB;

// Upper 2 by 2 of K for point to point
const K = new Mat22();
K.ex.x = mA + mB + iA * this.m_rA.y * this.m_rA.y + iB * this.m_rB.y * this.m_rB.y;
K.ex.y = -iA * this.m_rA.x * this.m_rA.y - iB * this.m_rB.x * this.m_rB.y;
Expand All @@ -331,7 +334,6 @@ export class MotorJoint extends Joint {
this.m_linearError = Vec2.zero();
this.m_linearError.addCombine(1, cB, 1, this.m_rB);
this.m_linearError.subCombine(1, cA, 1, this.m_rA);
this.m_linearError.sub(Rot.mulVec2(qA, this.m_linearOffset));

this.m_angularError = aB - aA - this.m_angularOffset;

Expand Down
5 changes: 2 additions & 3 deletions src/dynamics/joint/MouseJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ export class MouseJoint extends Joint {
* Use this to update the target point.
*/
setTarget(target: Vec2Value): void {
if (this.m_bodyB.isAwake() == false) {
this.m_bodyB.setAwake(true);
}
if (Vec2.areEqual(target, this.m_targetA)) return;
this.m_bodyB.setAwake(true);
this.m_targetA = Vec2.clone(target);
}

Expand Down
3 changes: 3 additions & 0 deletions src/dynamics/joint/PrismaticJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ export class PrismaticJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
if (flag == this.m_enableMotor) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
Expand All @@ -458,6 +459,7 @@ export class PrismaticJoint extends Joint {
* Set the motor speed, usually in meters per second.
*/
setMotorSpeed(speed: number): void {
if (speed == this.m_motorSpeed) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
Expand All @@ -467,6 +469,7 @@ export class PrismaticJoint extends Joint {
* Set the maximum motor force, usually in N.
*/
setMaxMotorForce(force: number): void {
if (force == this.m_maxMotorForce) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorForce = force;
Expand Down
3 changes: 3 additions & 0 deletions src/dynamics/joint/RevoluteJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class RevoluteJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
if (flag == this.m_enableMotor) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
Expand All @@ -318,6 +319,7 @@ export class RevoluteJoint extends Joint {
* Set the motor speed in radians per second.
*/
setMotorSpeed(speed: number): void {
if (speed == this.m_motorSpeed) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
Expand All @@ -334,6 +336,7 @@ export class RevoluteJoint extends Joint {
* Set the maximum motor torque, usually in N-m.
*/
setMaxMotorTorque(torque: number): void {
if (torque == this.m_maxMotorTorque) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
Expand Down
3 changes: 3 additions & 0 deletions src/dynamics/joint/WheelJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export class WheelJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
if (flag == this.m_enableMotor) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
Expand All @@ -323,6 +324,7 @@ export class WheelJoint extends Joint {
* Set the motor speed, usually in radians per second.
*/
setMotorSpeed(speed: number): void {
if (speed == this.m_motorSpeed) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
Expand All @@ -339,6 +341,7 @@ export class WheelJoint extends Joint {
* Set/Get the maximum motor force, usually in N-m.
*/
setMaxMotorTorque(torque: number): void {
if (torque == this.m_maxMotorTorque) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
Expand Down
Loading