From 4c64f4d17735a7dfab2ba2e6eb678dd6ddcecb68 Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Sat, 18 Mar 2023 13:12:58 +0100 Subject: [PATCH 1/8] refactor: minor refactorings --- src/collision/Distance.ts | 3 +-- src/collision/shape/ChainShape.ts | 4 ++++ src/dynamics/Contact.ts | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/collision/Distance.ts b/src/collision/Distance.ts index ffbf32a3..9f8a2349 100644 --- a/src/collision/Distance.ts +++ b/src/collision/Distance.ts @@ -112,7 +112,6 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i let saveCount = 0; let distanceSqr1 = Infinity; - let distanceSqr2 = Infinity; // Main iteration loop. let iter = 0; @@ -133,7 +132,7 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i // Compute closest point. const p = simplex.getClosestPoint(); - distanceSqr2 = p.lengthSquared(); + const distanceSqr2 = p.lengthSquared(); // Ensure progress if (distanceSqr2 >= distanceSqr1) { diff --git a/src/collision/shape/ChainShape.ts b/src/collision/shape/ChainShape.ts index 9b4c12a4..c2141a84 100644 --- a/src/collision/shape/ChainShape.ts +++ b/src/collision/shape/ChainShape.ts @@ -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]; diff --git a/src/dynamics/Contact.ts b/src/dynamics/Contact.ts index a945ea43..c6c6a530 100644 --- a/src/dynamics/Contact.ts +++ b/src/dynamics/Contact.ts @@ -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; /** @@ -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 From 0a35b42e407e89ad19d51c0e46aa6a68b8b5d33a Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Thu, 3 Aug 2023 20:18:08 +0200 Subject: [PATCH 2/8] refactor: remove dead code --- src/collision/Distance.ts | 12 ------------ src/collision/shape/PolygonShape.ts | 1 + src/dynamics/Contact.ts | 2 +- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/collision/Distance.ts b/src/collision/Distance.ts index 9f8a2349..4b02e76e 100644 --- a/src/collision/Distance.ts +++ b/src/collision/Distance.ts @@ -111,8 +111,6 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i const saveB = []; // int[3] let saveCount = 0; - let distanceSqr1 = Infinity; - // Main iteration loop. let iter = 0; while (iter < k_maxIters) { @@ -130,16 +128,6 @@ export const Distance = function (output: DistanceOutput, cache: SimplexCache, i break; } - // Compute closest point. - const p = simplex.getClosestPoint(); - const distanceSqr2 = p.lengthSquared(); - - // Ensure progress - if (distanceSqr2 >= distanceSqr1) { - // break; - } - distanceSqr1 = distanceSqr2; - // Get search direction. const d = simplex.getSearchDirection(); diff --git a/src/collision/shape/PolygonShape.ts b/src/collision/shape/PolygonShape.ts index 174b4ad3..35939637 100644 --- a/src/collision/shape/PolygonShape.ts +++ b/src/collision/shape/PolygonShape.ts @@ -206,6 +206,7 @@ export class PolygonShape extends Shape { let ih = i0; while (true) { + _ASSERT && console.assert(m < Settings.maxPolygonVertices); hull[m] = ih; let ie = 0; diff --git a/src/dynamics/Contact.ts b/src/dynamics/Contact.ts index c6c6a530..df4842fd 100644 --- a/src/dynamics/Contact.ts +++ b/src/dynamics/Contact.ts @@ -86,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); From f79b3080147f34e011ac739d3c8b4857178958d7 Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Thu, 3 Aug 2023 20:27:08 +0200 Subject: [PATCH 3/8] refactor: polygonal radius clarity --- src/collision/Shape.ts | 5 +++++ src/collision/shape/CollideEdgePolygon.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/collision/Shape.ts b/src/collision/Shape.ts index b5b1c3b2..3a0cd28d 100644 --- a/src/collision/Shape.ts +++ b/src/collision/Shape.ts @@ -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 */ diff --git a/src/collision/shape/CollideEdgePolygon.ts b/src/collision/shape/CollideEdgePolygon.ts index b68f9ba5..ae2a8dba 100644 --- a/src/collision/shape/CollideEdgePolygon.ts +++ b/src/collision/shape/CollideEdgePolygon.ts @@ -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; From 83c949afae995b352fe0be296e3a7313624cdbde Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Thu, 3 Aug 2023 20:54:11 +0200 Subject: [PATCH 4/8] feat: body.setAwake now resets the sleep timer even if the body is awake --- src/dynamics/Body.ts | 6 ++---- src/dynamics/Solver.ts | 4 ++-- src/dynamics/joint/MouseJoint.ts | 4 ++-- src/dynamics/joint/PrismaticJoint.ts | 24 +++++++++++++++--------- src/dynamics/joint/RevoluteJoint.ts | 24 +++++++++++++++--------- src/dynamics/joint/WheelJoint.ts | 24 +++++++++++++++--------- 6 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/dynamics/Body.ts b/src/dynamics/Body.ts index 7c12f1bf..18d95565 100644 --- a/src/dynamics/Body.ts +++ b/src/dynamics/Body.ts @@ -467,10 +467,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; diff --git a/src/dynamics/Solver.ts b/src/dynamics/Solver.ts index aaa2dc6d..67e4ac97 100644 --- a/src/dynamics/Solver.ts +++ b/src/dynamics/Solver.ts @@ -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. diff --git a/src/dynamics/joint/MouseJoint.ts b/src/dynamics/joint/MouseJoint.ts index c9eb2a84..6452f472 100644 --- a/src/dynamics/joint/MouseJoint.ts +++ b/src/dynamics/joint/MouseJoint.ts @@ -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 { diff --git a/src/dynamics/joint/PrismaticJoint.ts b/src/dynamics/joint/PrismaticJoint.ts index 46e753fb..1cfa832b 100644 --- a/src/dynamics/joint/PrismaticJoint.ts +++ b/src/dynamics/joint/PrismaticJoint.ts @@ -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 { diff --git a/src/dynamics/joint/RevoluteJoint.ts b/src/dynamics/joint/RevoluteJoint.ts index b6b64ced..6d03c48d 100644 --- a/src/dynamics/joint/RevoluteJoint.ts +++ b/src/dynamics/joint/RevoluteJoint.ts @@ -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; + } } /** @@ -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; + } } /** @@ -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 { diff --git a/src/dynamics/joint/WheelJoint.ts b/src/dynamics/joint/WheelJoint.ts index 1c527c70..4245a3c7 100644 --- a/src/dynamics/joint/WheelJoint.ts +++ b/src/dynamics/joint/WheelJoint.ts @@ -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) { + 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; + } } /** @@ -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 { From 110576ee54ead0e492ff5d120272ea5037d587a3 Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Thu, 3 Aug 2023 21:04:44 +0200 Subject: [PATCH 5/8] refactor!: remove getVertex method on shapes --- src/collision/shape/CircleShape.ts | 5 ----- src/collision/shape/PolygonShape.ts | 5 ----- 2 files changed, 10 deletions(-) diff --git a/src/collision/shape/CircleShape.ts b/src/collision/shape/CircleShape.ts index d7b7e42e..42e4218a 100644 --- a/src/collision/shape/CircleShape.ts +++ b/src/collision/shape/CircleShape.ts @@ -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. diff --git a/src/collision/shape/PolygonShape.ts b/src/collision/shape/PolygonShape.ts index 35939637..24d9641f 100644 --- a/src/collision/shape/PolygonShape.ts +++ b/src/collision/shape/PolygonShape.ts @@ -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. From 7b380f0143ac6a8f230b94c40153b8819de1e6f3 Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Thu, 3 Aug 2023 21:07:12 +0200 Subject: [PATCH 6/8] docs: added documentation of damping parameter units --- src/dynamics/Body.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dynamics/Body.ts b/src/dynamics/Body.ts index 18d95565..c0226b66 100644 --- a/src/dynamics/Body.ts +++ b/src/dynamics/Body.ts @@ -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; /** From 82e7aba5bc172854c78c2b7bad79759ecb7415d9 Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Fri, 4 Aug 2023 15:31:34 +0200 Subject: [PATCH 7/8] fix: fix anchor A formula for MotorJoint to include the offset --- src/dynamics/joint/MotorJoint.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dynamics/joint/MotorJoint.ts b/src/dynamics/joint/MotorJoint.ts index fa27368d..6edbc744 100644 --- a/src/dynamics/joint/MotorJoint.ts +++ b/src/dynamics/joint/MotorJoint.ts @@ -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 @@ -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 @@ -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; @@ -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; From abc24e36a45677a41d2f8a15397d08d6f1af32c9 Mon Sep 17 00:00:00 2001 From: Oliver Zell Date: Fri, 4 Aug 2023 15:47:05 +0200 Subject: [PATCH 8/8] refactor: use early returns --- src/dynamics/joint/MouseJoint.ts | 7 +++---- src/dynamics/joint/PrismaticJoint.ts | 27 ++++++++++++--------------- src/dynamics/joint/RevoluteJoint.ts | 27 ++++++++++++--------------- src/dynamics/joint/WheelJoint.ts | 27 ++++++++++++--------------- 4 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/dynamics/joint/MouseJoint.ts b/src/dynamics/joint/MouseJoint.ts index 6452f472..65be4499 100644 --- a/src/dynamics/joint/MouseJoint.ts +++ b/src/dynamics/joint/MouseJoint.ts @@ -194,10 +194,9 @@ export class MouseJoint extends Joint { * Use this to update the target point. */ setTarget(target: Vec2Value): void { - if (!Vec2.areEqual(target, this.m_targetA)) { - this.m_bodyB.setAwake(true); - this.m_targetA = Vec2.clone(target); - } + if (Vec2.areEqual(target, this.m_targetA)) return; + this.m_bodyB.setAwake(true); + this.m_targetA = Vec2.clone(target); } getTarget(): Vec2 { diff --git a/src/dynamics/joint/PrismaticJoint.ts b/src/dynamics/joint/PrismaticJoint.ts index 1cfa832b..0ea323e2 100644 --- a/src/dynamics/joint/PrismaticJoint.ts +++ b/src/dynamics/joint/PrismaticJoint.ts @@ -449,33 +449,30 @@ export class PrismaticJoint extends Joint { * Enable/disable the joint motor. */ enableMotor(flag: boolean): void { - if (flag != this.m_enableMotor) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_enableMotor = flag; - } + if (flag == this.m_enableMotor) return; + 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 { - if (speed != this.m_motorSpeed) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_motorSpeed = speed; - } + if (speed == this.m_motorSpeed) return; + 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 { - if (force != this.m_maxMotorForce) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_maxMotorForce = force; - } + if (force == this.m_maxMotorForce) return; + this.m_bodyA.setAwake(true); + this.m_bodyB.setAwake(true); + this.m_maxMotorForce = force; } getMaxMotorForce(): number { diff --git a/src/dynamics/joint/RevoluteJoint.ts b/src/dynamics/joint/RevoluteJoint.ts index 6d03c48d..362ebb30 100644 --- a/src/dynamics/joint/RevoluteJoint.ts +++ b/src/dynamics/joint/RevoluteJoint.ts @@ -302,11 +302,10 @@ export class RevoluteJoint extends Joint { * Enable/disable the joint motor. */ enableMotor(flag: boolean): void { - if (flag != this.m_enableMotor) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_enableMotor = flag; - } + if (flag == this.m_enableMotor) return; + this.m_bodyA.setAwake(true); + this.m_bodyB.setAwake(true); + this.m_enableMotor = flag; } /** @@ -320,11 +319,10 @@ export class RevoluteJoint extends Joint { * Set the motor speed in radians per second. */ setMotorSpeed(speed: number): void { - if (speed != this.m_motorSpeed) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_motorSpeed = speed; - } + if (speed == this.m_motorSpeed) return; + this.m_bodyA.setAwake(true); + this.m_bodyB.setAwake(true); + this.m_motorSpeed = speed; } /** @@ -338,11 +336,10 @@ export class RevoluteJoint extends Joint { * Set the maximum motor torque, usually in N-m. */ setMaxMotorTorque(torque: number): void { - if (torque != this.m_maxMotorTorque) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_maxMotorTorque = torque; - } + if (torque == this.m_maxMotorTorque) return; + this.m_bodyA.setAwake(true); + this.m_bodyB.setAwake(true); + this.m_maxMotorTorque = torque; } getMaxMotorTorque(): number { diff --git a/src/dynamics/joint/WheelJoint.ts b/src/dynamics/joint/WheelJoint.ts index 4245a3c7..8c9bae74 100644 --- a/src/dynamics/joint/WheelJoint.ts +++ b/src/dynamics/joint/WheelJoint.ts @@ -314,22 +314,20 @@ export class WheelJoint extends Joint { * Enable/disable the joint motor. */ enableMotor(flag: boolean): void { - if (flag != this.m_enableMotor) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_enableMotor = flag; - } + if (flag == this.m_enableMotor) return; + 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 { - if (speed != this.m_motorSpeed) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_motorSpeed = speed; - } + if (speed == this.m_motorSpeed) return; + this.m_bodyA.setAwake(true); + this.m_bodyB.setAwake(true); + this.m_motorSpeed = speed; } /** @@ -343,11 +341,10 @@ export class WheelJoint extends Joint { * Set/Get the maximum motor force, usually in N-m. */ setMaxMotorTorque(torque: number): void { - if (torque != this.m_maxMotorTorque) { - this.m_bodyA.setAwake(true); - this.m_bodyB.setAwake(true); - this.m_maxMotorTorque = torque; - } + if (torque == this.m_maxMotorTorque) return; + this.m_bodyA.setAwake(true); + this.m_bodyB.setAwake(true); + this.m_maxMotorTorque = torque; } getMaxMotorTorque(): number {