Skip to content

Commit 39c69db

Browse files
committed
1. make all Joint classes extends b2Joint
1. add b2Joint.GetType() 1. add b2Joint.GetAnchorA() 1. add b2Joint.GetAnchorB() - move bodyA/bodyB into b2Joint as source C does it. - add GetReactionForce() - add GetReactionTorque() - add IsActive() - add GetCollideConnected() make up b2DistanceJoint methods make up b2FrictionJoint methods make up b2GearJoint methods. make up b2MtorJoint methods make up b2MouseJoint methods make up b2PrismaticJoint methods make up b2PulleyJoint methods make up b2RevoluteJoint methods make up b2RopeJoint methods add limit_state enums make up b2WeldJoint methods make up b2WheelJoint methods change indents to 2 spaces
1 parent 7f20402 commit 39c69db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2105
-1307
lines changed

liquidfun/Box2D/lfjs/Makefile

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ B2BODY = \
8787
'_b2Body_SetLinearVelocity', \
8888
'_b2Body_SetMassData', \
8989
'_b2Body_SetTransform', \
90-
'_b2Body_SetType',\
91-
'_b2Body_SetGravityScale',\
90+
'_b2Body_SetType', \
91+
'_b2Body_SetGravityScale', \
9292
'_b2Body_GetGravityScale'
9393

9494
B2CHAINSHAPE = \
@@ -108,7 +108,10 @@ B2CONTACT = \
108108

109109
B2DISTANCEJOINT = \
110110
'_b2DistanceJointDef_Create', \
111-
'_b2DistanceJointDef_InitializeAndCreate' \
111+
'_b2DistanceJointDef_InitializeAndCreate', \
112+
'_b2DistanceJoint_SetLength', \
113+
'_b2DistanceJoint_SetFrequency', \
114+
'_b2DistanceJoint_SetDampingRatio' \
112115

113116
B2EDGESHAPE = \
114117
'_b2EdgeShape_CreateFixture'
@@ -119,25 +122,40 @@ B2FIXTURE = \
119122

120123
B2FRICTIONJOINT = \
121124
'_b2FrictionJointDef_Create', \
122-
'_b2FrictionJointDef_InitializeAndCreate' \
125+
'_b2FrictionJointDef_InitializeAndCreate', \
126+
'_b2FrictionJoint_SetMaxForce', \
127+
'_b2FrictionJoint_SetMaxTorque' \
123128

124129
B2GEARJOINT = \
125-
'_b2GearJoint_GetRatio', \
130+
'_b2GearJoint_SetRatio', \
126131
'_b2GearJointDef_Create', \
127132
'_b2GearJointDef_InitializeAndCreate'
128133

129134
B2JOINT = \
130135
'_b2Joint_GetBodyA', \
131-
'_b2Joint_GetBodyB'
136+
'_b2Joint_GetBodyB', \
137+
'_b2Joint_GetAnchorA', \
138+
'_b2Joint_GetAnchorB', \
139+
'_b2Joint_GetReactionForce', \
140+
'_b2Joint_GetReactionTorque', \
141+
'_b2Joint_GetType', \
142+
'_b2Joint_GetCollideConnected', \
143+
'_b2Joint_IsActive' \
132144

133145
B2MOTORJOINT = \
134146
'_b2MotorJoint_SetAngularOffset', \
135147
'_b2MotorJoint_SetLinearOffset', \
148+
'_b2MotorJoint_SetMaxForce', \
149+
'_b2MotorJoint_SetMaxTorque', \
150+
'_b2MotorJoint_SetCorrectionFactor', \
136151
'_b2MotorJointDef_Create', \
137152
'_b2MotorJointDef_InitializeAndCreate'
138153

139154
B2MOUSEJOINT = \
140155
'_b2MouseJoint_SetTarget', \
156+
'_b2MouseJoint_SetMaxForce', \
157+
'_b2MouseJoint_SetFrequency', \
158+
'_b2MouseJoint_SetDampingRatio', \
141159
'_b2MouseJointDef_Create'
142160

143161
B2PARTICLEGROUP = \
@@ -167,7 +185,7 @@ B2POLYGONSHAPE = \
167185
'_b2PolygonShape_CreateFixture_5', \
168186
'_b2PolygonShape_CreateFixture_6', \
169187
'_b2PolygonShape_CreateFixture_7', \
170-
'_b2PolygonShape_CreateFixture_8', \
188+
'_b2PolygonShape_CreateFixture_8', \
171189
'_b2PolygonShape_CreateParticleGroup_4', \
172190
'_b2PolygonShape_DestroyParticlesInShape_4'
173191

@@ -180,10 +198,18 @@ B2PRISMATICJOINT = \
180198
'_b2PrismaticJoint_IsLimitEnabled', \
181199
'_b2PrismaticJoint_IsMotorEnabled', \
182200
'_b2PrismaticJoint_SetMotorSpeed', \
201+
'_b2PrismaticJoint_GetLocalAxisA', \
202+
'_b2PrismaticJoint_GetJointSpeed', \
203+
'_b2PrismaticJoint_SetLimits', \
204+
'_b2PrismaticJoint_SetMaxMotorForce', \
183205
'_b2PrismaticJointDef_Create', \
184206
'_b2PrismaticJointDef_InitializeAndCreate' \
185207

186208
B2PULLEYJOINT = \
209+
'_b2PulleyJoint_GetGroundAnchorA', \
210+
'_b2PulleyJoint_GetGroundAnchorB', \
211+
'_b2PulleyJoint_GetCurrentLengthA', \
212+
'_b2PulleyJoint_GetCurrentLengthB', \
187213
'_b2PulleyJointDef_Create', \
188214
'_b2PulleyJointDef_InitializeAndCreate' \
189215

@@ -194,19 +220,37 @@ B2REVOLUTEJOINT = \
194220
'_b2RevoluteJoint_IsLimitEnabled', \
195221
'_b2RevoluteJoint_IsMotorEnabled', \
196222
'_b2RevoluteJoint_SetMotorSpeed', \
223+
'_b2RevoluteJoint_GetJointSpeed', \
224+
'_b2RevoluteJoint_SetLimits', \
225+
'_b2RevoluteJoint_GetMotorSpeed', \
226+
'_b2RevoluteJoint_SetMaxMotorTorque', \
227+
'_b2RevoluteJoint_GetMotorTorque', \
197228
'_b2RevoluteJointDef_Create', \
198-
'_b2RevoluteJointDef_InitializeAndCreate'
229+
'_b2RevoluteJointDef_InitializeAndCreate' \
199230

200231
B2ROPEJOINT = \
232+
'_b2RopeJoint_SetMaxLength', \
233+
'_b2RopeJoint_GetLimitState', \
201234
'_b2RopeJointDef_Create'
202235

203236
B2WELDJOINT = \
237+
'_b2WeldJoint_SetFrequency', \
238+
'_b2WeldJoint_SetDampingRatio', \
204239
'_b2WeldJointDef_Create', \
205240
'_b2WeldJointDef_InitializeAndCreate' \
206241

207242
B2WHEELJOINT = \
208243
'_b2WheelJoint_SetMotorSpeed', \
209244
'_b2WheelJoint_SetSpringFrequencyHz', \
245+
'_b2WheelJoint_GetLocalAxisA', \
246+
'_b2WheelJoint_GetJointTranslation', \
247+
'_b2WheelJoint_GetJointSpeed', \
248+
'_b2WheelJoint_IsMotorEnabled', \
249+
'_b2WheelJoint_EnableMotor', \
250+
'_b2WheelJoint_GetMotorSpeed', \
251+
'_b2WheelJoint_SetMaxMotorTorque', \
252+
'_b2WheelJoint_GetMotorTorque', \
253+
'_b2WheelJoint_SetSpringDampingRatio', \
210254
'_b2WheelJointDef_Create', \
211255
'_b2WheelJointDef_InitializeAndCreate' \
212256

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2DistanceJoint.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
var b2DistanceJoint_SetLength = Module.cwrap("b2DistanceJoint_SetLength", "null", ["number", "number"]);
2+
var b2DistanceJoint_SetFrequency = Module.cwrap("b2DistanceJoint_SetFrequency", "null", ["number", "number"]);
3+
var b2DistanceJoint_SetDampingRatio = Module.cwrap("b2DistanceJoint_SetDampingRatio", "null", ["number", "number"]);
4+
15
/**@constructor*/
26
function b2DistanceJoint(def) {
3-
this.bodyA = def.bodyA;
4-
this.bodyB = def.bodyB;
5-
this.ptr = null;
6-
this.next = null;
7+
b2Joint.call(this, def);
8+
this.length = def.length;
9+
this.frequencyHz = def.frequencyHz;
10+
this.dampingRatio = def.dampingRatio;
11+
}
12+
b2DistanceJoint.prototype = Object.create(b2Joint.prototype);
13+
b2DistanceJoint.prototype.constructor = b2DistanceJoint;
14+
15+
b2DistanceJoint.prototype.SetLength = function (length) {
16+
b2DistanceJoint_SetLength(this.ptr, length);
17+
this.length = length;
18+
}
19+
b2DistanceJoint.prototype.SetFrequency = function (hz) {
20+
b2DistanceJoint_SetFrequency(this.ptr, hz);
21+
this.frequencyHz = hz;
22+
}
23+
b2DistanceJoint.prototype.SetDampingRatio = function (ratio) {
24+
b2DistanceJoint_SetDampingRatio(this.ptr, ratio);
25+
this.dampingRatio = ratio;
726
}
827

928
var b2DistanceJointDef_Create = Module.cwrap("b2DistanceJointDef_Create",
@@ -38,7 +57,7 @@ function b2DistanceJointDef() {
3857
this.frequencyHz = 0;
3958
}
4059

41-
b2DistanceJointDef.prototype.Create = function(world) {
60+
b2DistanceJointDef.prototype.Create = function (world) {
4261
var distanceJoint = new b2DistanceJoint(this);
4362
distanceJoint.ptr = b2DistanceJointDef_Create(
4463
world.ptr,
@@ -51,7 +70,7 @@ b2DistanceJointDef.prototype.Create = function(world) {
5170
return distanceJoint;
5271
};
5372

54-
b2DistanceJointDef.prototype.InitializeAndCreate = function(bodyA, bodyB, anchorA, anchorB) {
73+
b2DistanceJointDef.prototype.InitializeAndCreate = function (bodyA, bodyB, anchorA, anchorB) {
5574
this.bodyA = bodyA;
5675
this.bodyB = bodyB;
5776
var distanceJoint = new b2DistanceJoint(this);

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2DistanceJointJsBindings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,13 @@ void* b2DistanceJointDef_InitializeAndCreate(
4343
return ((b2World*)world)->CreateJoint(&def);
4444

4545
}
46+
47+
void b2DistanceJoint_SetLength(void* joint, double length) {
48+
((b2DistanceJoint*)joint)->SetLength(length);
49+
}
50+
void b2DistanceJoint_SetFrequency(void* joint, double frequencyHz) {
51+
((b2DistanceJoint*)joint)->SetFrequency(frequencyHz);
52+
}
53+
void b2DistanceJoint_SetDampingRatio(void* joint, double dampingRatio) {
54+
((b2DistanceJoint*)joint)->SetDampingRatio(dampingRatio);
55+
}

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2DistanceJointJsBindings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ void* b2DistanceJointDef_InitializeAndCreate(
2323

2424
}
2525

26+
void b2DistanceJoint_SetLength(void* joint, double length);
27+
void b2DistanceJoint_SetFrequency(void* joint, double frequencyHz);
28+
void b2DistanceJoint_SetDampingRatio(void* joint, double dampingRatio);
29+
2630
#endif

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2FrictionJoint.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
var b2FrictionJointDef_Create = Module.cwrap("b2FrictionJointDef_Create",
22
'number',
33
['number',
4-
// joint Def
5-
'number', 'number', 'number',
6-
// friction joint def
7-
'number', 'number', 'number',
8-
'number', 'number', 'number']);
4+
// joint Def
5+
'number', 'number', 'number',
6+
// friction joint def
7+
'number', 'number', 'number',
8+
'number', 'number', 'number']);
99

1010
var b2FrictionJointDef_InitializeAndCreate = Module.cwrap("b2FrictionJointDef_InitializeAndCreate",
1111
'number',
@@ -16,6 +16,7 @@ var b2FrictionJointDef_InitializeAndCreate = Module.cwrap("b2FrictionJointDef_In
1616
// friction joint def
1717
'number', 'number', 'number']);
1818

19+
/**@constructor*/
1920
function b2FrictionJointDef() {
2021
// joint def
2122
this.bodyA = null;
@@ -30,7 +31,7 @@ function b2FrictionJointDef() {
3031
this.userData = null;
3132
}
3233

33-
b2FrictionJointDef.prototype.Create = function(world) {
34+
b2FrictionJointDef.prototype.Create = function (world) {
3435
var frictionJoint = new b2FrictionJoint(this);
3536
frictionJoint.ptr = b2FrictionJointDef_Create(
3637
world.ptr,
@@ -42,7 +43,7 @@ b2FrictionJointDef.prototype.Create = function(world) {
4243
return frictionJoint;
4344
};
4445

45-
b2FrictionJointDef.prototype.InitializeAndCreate = function(bodyA, bodyB, anchor) {
46+
b2FrictionJointDef.prototype.InitializeAndCreate = function (bodyA, bodyB, anchor) {
4647
this.bodyA = bodyA;
4748
this.bodyB = bodyB;
4849
var frictionJoint = new b2FrictionJoint(this);
@@ -59,9 +60,23 @@ b2FrictionJointDef.prototype.InitializeAndCreate = function(bodyA, bodyB, ancho
5960
return frictionJoint;
6061
};
6162

63+
var b2FrictionJoint_SetMaxForce = Module.cwrap("b2FrictionJoint_SetMaxForce", "null", ["number", "number"]);
64+
var b2FrictionJoint_SetMaxTorque = Module.cwrap("b2FrictionJoint_SetMaxTorque", "null", ["number", "number"]);
65+
66+
/**@constructor*/
6267
function b2FrictionJoint(def) {
63-
this.bodyA = def.bodyA;
64-
this.bodyB = def.bodyB;
65-
this.ptr = null;
66-
this.next = null;
67-
}
68+
b2Joint.call(this, def);
69+
this.maxForce = def.maxForce;
70+
this.maxTorque = def.maxTorque;
71+
}
72+
b2FrictionJoint.prototype = Object.create(b2Joint.prototype);
73+
b2FrictionJoint.prototype.constructor = b2FrictionJoint;
74+
75+
b2FrictionJoint.prototype.SetMaxForce = function (force) {
76+
b2FrictionJoint_SetMaxForce(this.ptr, force);
77+
this.maxForce = force;
78+
}
79+
b2FrictionJoint.prototype.SetMaxTorque = function (torque) {
80+
b2FrictionJoint_SetMaxTorque(this.ptr, torque);
81+
this.maxTorque = torque;
82+
}

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2FrictionJointJsBindings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ void* b2FrictionJointDef_InitializeAndCreate(
3838
fJoint.Initialize((b2Body*)bodyA, (b2Body*)bodyB, b2Vec2(anchorX, anchorY));
3939
return ((b2World*)world)->CreateJoint(&fJoint);
4040
}
41+
42+
void b2FrictionJoint_SetMaxForce(void* joint, double force) {
43+
((b2FrictionJoint*)joint)->SetMaxForce(force);
44+
}
45+
void b2FrictionJoint_SetMaxTorque(void* joint, double torque) {
46+
((b2FrictionJoint*)joint)->SetMaxTorque(torque);
47+
}

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2FrictionJointJsBindings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ void* b2FrictionJointDef_InitializeAndCreate(
2222
double maxForce, double maxTorque);
2323
}
2424

25+
void b2FrictionJoint_SetMaxForce(void* joint, double force);
26+
void b2FrictionJoint_SetMaxTorque(void* joint, double torque);
27+
2528
#endif

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2GearJoint.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
var b2GearJoint_GetRatio = Module.cwrap("b2GearJoint_GetRatio", 'number',
2-
['number']);
1+
var b2GearJoint_SetRatio = Module.cwrap("b2GearJoint_SetRatio", 'number', ['number', 'number']);
32

3+
/**@constructor*/
44
function b2GearJoint(def) {
5-
this.ptr = null;
6-
this.next = null;
5+
b2Joint.call(this, def);
6+
this.joint1 = def.joint1;
7+
this.joint2 = def.joint2;
8+
this.ratio = def.ratio;
79
}
10+
b2GearJoint.prototype = Object.create(b2Joint.prototype);
11+
b2GearJoint.prototype.constructor = b2GearJoint;
812

9-
b2GearJoint.prototype.GetRatio = function() {
10-
return b2GearJoint_GetRatio(this.ptr);
11-
};
13+
b2GearJoint.prototype.SetRatio = function (ratio) {
14+
b2GearJoint_SetRatio(this.ptr, ratio);
15+
this.ratio = ratio;
16+
}
1217

1318
var b2GearJointDef_Create = Module.cwrap("b2GearJointDef_Create",
1419
'number',
@@ -28,7 +33,7 @@ function b2GearJointDef() {
2833
this.ratio = 0;
2934
}
3035

31-
b2GearJointDef.prototype.Create = function(world) {
36+
b2GearJointDef.prototype.Create = function (world) {
3237
var gearJoint = new b2GearJoint(this);
3338
gearJoint.ptr = b2GearJointDef_Create(
3439
world.ptr,

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2GearJointJsBindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Box2D/Box2D.h>
2-
double b2GearJoint_GetRatio(void* joint) {
3-
return ((b2GearJoint*)joint)->GetRatio();
2+
void b2GearJoint_SetRatio(void* joint, double ratio) {
3+
((b2GearJoint*)joint)->SetRatio(ratio);
44
}
55

66
void* b2GearJointDef_Create(

liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2GearJointJsBindings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define B2GEARJOINTJSBINDINGS_H
33

44
extern "C" {
5-
double b2GearJoint_GetRatio(void* joint);
5+
void b2GearJoint_SetRatio(void* joint, double ratio);
66

77
void* b2GearJointDef_Create(
88
void* world,

0 commit comments

Comments
 (0)