Skip to content

Commit 3815f52

Browse files
committed
refactor: clean up wheel joint
1 parent 4e384ba commit 3815f52

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/joints/WheelJoint.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,21 @@
3939
*/
4040
public class WheelJoint extends Joint {
4141

42-
private float m_frequencyHz;
43-
private float m_dampingRatio;
44-
4542
// Solver shared
4643
private final Vec2 m_localAnchorA = new Vec2();
4744
private final Vec2 m_localAnchorB = new Vec2();
4845
private final Vec2 m_localXAxisA = new Vec2();
4946
private final Vec2 m_localYAxisA = new Vec2();
5047

5148
private float m_impulse;
52-
private float m_motorImpulse;
49+
private float m_motorImpulse = 0.0f;
5350
private float m_springImpulse;
5451

5552
private float m_maxMotorTorque;
5653
private float m_motorSpeed;
5754
private boolean m_enableMotor;
55+
private float m_frequencyHz;
56+
private float m_dampingRatio;
5857

5958
// Solver temp
6059
private int m_indexA;
@@ -68,11 +67,13 @@ public class WheelJoint extends Joint {
6867

6968
private final Vec2 m_ax = new Vec2();
7069
private final Vec2 m_ay = new Vec2();
71-
private float m_sAx, m_sBx;
72-
private float m_sAy, m_sBy;
70+
private float m_sAx;
71+
private float m_sBx;
72+
private float m_sAy;
73+
private float m_sBy;
7374

7475
private float m_mass;
75-
private float m_motorMass;
76+
private float m_motorMass = 0.0f;
7677
private float m_springMass;
7778

7879
private float m_bias;
@@ -85,14 +86,9 @@ protected WheelJoint(IWorldPool argPool, WheelJointDef def) {
8586
m_localXAxisA.set(def.localAxisA);
8687
Vec2.crossToOutUnsafe(1.0f, m_localXAxisA, m_localYAxisA);
8788

88-
89-
m_motorMass = 0.0f;
90-
m_motorImpulse = 0.0f;
91-
9289
m_maxMotorTorque = def.maxMotorTorque;
9390
m_motorSpeed = def.motorSpeed;
9491
m_enableMotor = def.enableMotor;
95-
9692
m_frequencyHz = def.frequencyHz;
9793
m_dampingRatio = def.dampingRatio;
9894
}
@@ -340,9 +336,7 @@ public void initVelocityConstraints(SolverData data) {
340336
pool.pushRot(2);
341337
pool.pushVec2(1);
342338

343-
// data.velocities[m_indexA].v = vA;
344339
data.velocities[m_indexA].w = wA;
345-
// data.velocities[m_indexB].v = vB;
346340
data.velocities[m_indexB].w = wB;
347341
}
348342

@@ -414,9 +408,7 @@ public void solveVelocityConstraints(SolverData data) {
414408
}
415409
pool.pushVec2(2);
416410

417-
// data.velocities[m_indexA].v = vA;
418411
data.velocities[m_indexA].w = wA;
419-
// data.velocities[m_indexB].v = vB;
420412
data.velocities[m_indexB].w = wB;
421413
}
422414

@@ -470,9 +462,7 @@ public boolean solvePositionConstraints(SolverData data) {
470462

471463
pool.pushVec2(3);
472464
pool.pushRot(2);
473-
// data.positions[m_indexA].c = cA;
474465
data.positions[m_indexA].a = aA;
475-
// data.positions[m_indexB].c = cB;
476466
data.positions[m_indexB].a = aB;
477467

478468
return FXGLMath.abs(C) <= JBoxSettings.linearSlop;

fxgl-entity/src/main/java/com/almasb/fxgl/physics/box2d/dynamics/joints/WheelJointDef.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,32 @@ public class WheelJointDef extends JointDef<WheelJoint> {
3636
/**
3737
* The local translation axis in body1.
3838
*/
39-
public final Vec2 localAxisA = new Vec2();
39+
public final Vec2 localAxisA = new Vec2(1, 0);
4040

4141
/**
4242
* Enable/disable the joint motor.
4343
*/
44-
public boolean enableMotor;
44+
public boolean enableMotor = false;
4545

4646
/**
4747
* The maximum motor torque, usually in N-m.
4848
*/
49-
public float maxMotorTorque;
49+
public float maxMotorTorque = 0f;
5050

5151
/**
5252
* The desired motor speed in radians per second.
5353
*/
54-
public float motorSpeed;
54+
public float motorSpeed = 0f;
5555

5656
/**
5757
* Suspension frequency, zero indicates no suspension
5858
*/
59-
public float frequencyHz;
59+
public float frequencyHz = 0f;
6060

6161
/**
6262
* Suspension damping ratio, one indicates critical damping
6363
*/
64-
public float dampingRatio;
65-
66-
public WheelJointDef() {
67-
localAxisA.set(1, 0);
68-
enableMotor = false;
69-
maxMotorTorque = 0f;
70-
motorSpeed = 0f;
71-
}
64+
public float dampingRatio = 0f;
7265

7366
public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) {
7467
setBodyA(b1);

0 commit comments

Comments
 (0)