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 6 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
4 changes: 2 additions & 2 deletions src/dynamics/joint/MouseJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ export class MouseJoint extends Joint {
* Use this to update the target point.
*/
setTarget(target: Vec2Value): void {
if (this.m_bodyB.isAwake() == false) {
if (!Vec2.areEqual(target, this.m_targetA)) {
this.m_bodyB.setAwake(true);
this.m_targetA = Vec2.clone(target);
}
this.m_targetA = Vec2.clone(target);
}

getTarget(): Vec2 {
Expand Down
24 changes: 15 additions & 9 deletions src/dynamics/joint/PrismaticJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,27 +449,33 @@ export class PrismaticJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
if (flag != this.m_enableMotor) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}
}

/**
* Set the motor speed, usually in meters per second.
*/
setMotorSpeed(speed: number): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
if (speed != this.m_motorSpeed) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}
}

/**
* Set the maximum motor force, usually in N.
*/
setMaxMotorForce(force: number): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorForce = force;
if (force != this.m_maxMotorForce) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorForce = force;
}
}

getMaxMotorForce(): number {
Expand Down
24 changes: 15 additions & 9 deletions src/dynamics/joint/RevoluteJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,11 @@ export class RevoluteJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
if (flag != this.m_enableMotor) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}
}

/**
Expand All @@ -318,9 +320,11 @@ export class RevoluteJoint extends Joint {
* Set the motor speed in radians per second.
*/
setMotorSpeed(speed: number): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
if (speed != this.m_motorSpeed) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}
}

/**
Expand All @@ -334,9 +338,11 @@ export class RevoluteJoint extends Joint {
* Set the maximum motor torque, usually in N-m.
*/
setMaxMotorTorque(torque: number): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
if (torque != this.m_maxMotorTorque) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
}
}

getMaxMotorTorque(): number {
Expand Down
24 changes: 15 additions & 9 deletions src/dynamics/joint/WheelJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,22 @@ export class WheelJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
if (flag != this.m_enableMotor) {
zOadT marked this conversation as resolved.
Show resolved Hide resolved
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}
}

/**
* Set the motor speed, usually in radians per second.
*/
setMotorSpeed(speed: number): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
if (speed != this.m_motorSpeed) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}
}

/**
Expand All @@ -339,9 +343,11 @@ export class WheelJoint extends Joint {
* Set/Get the maximum motor force, usually in N-m.
*/
setMaxMotorTorque(torque: number): void {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
if (torque != this.m_maxMotorTorque) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
}
}

getMaxMotorTorque(): number {
Expand Down
Loading