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

Bind functions into b2Joint, and make Joints inherited from b2Joint #91

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
76 changes: 66 additions & 10 deletions liquidfun/Box2D/lfjs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,21 @@ B2BODY = \
'_b2Body_SetLinearVelocity', \
'_b2Body_SetMassData', \
'_b2Body_SetTransform', \
'_b2Body_SetType',\
'_b2Body_SetGravityScale',\
'_b2Body_GetGravityScale'
'_b2Body_SetType', \
'_b2Body_SetGravityScale', \
'_b2Body_GetGravityScale', \
'_b2Body_SetLinearDamping', \
'_b2Body_GetLinearDamping', \
'_b2Body_SetAngularDamping', \
'_b2Body_GetAngularDamping', \
'_b2Body_IsAwake', \
'_b2Body_SetBullet', \
'_b2Body_IsBullet', \
'_b2Body_SetSleepingAllowed', \
'_b2Body_IsSleepingAllowed', \
'_b2Body_SetActive', \
'_b2Body_IsActive', \
'_boBody_IsFixedRotation'

B2CHAINSHAPE = \
'_b2ChainShape_CreateFixture'
Expand All @@ -108,7 +120,10 @@ B2CONTACT = \

B2DISTANCEJOINT = \
'_b2DistanceJointDef_Create', \
'_b2DistanceJointDef_InitializeAndCreate' \
'_b2DistanceJointDef_InitializeAndCreate', \
'_b2DistanceJoint_SetLength', \
'_b2DistanceJoint_SetFrequency', \
'_b2DistanceJoint_SetDampingRatio' \

B2EDGESHAPE = \
'_b2EdgeShape_CreateFixture'
Expand All @@ -119,25 +134,40 @@ B2FIXTURE = \

B2FRICTIONJOINT = \
'_b2FrictionJointDef_Create', \
'_b2FrictionJointDef_InitializeAndCreate' \
'_b2FrictionJointDef_InitializeAndCreate', \
'_b2FrictionJoint_SetMaxForce', \
'_b2FrictionJoint_SetMaxTorque' \

B2GEARJOINT = \
'_b2GearJoint_GetRatio', \
'_b2GearJoint_SetRatio', \
'_b2GearJointDef_Create', \
'_b2GearJointDef_InitializeAndCreate'

B2JOINT = \
'_b2Joint_GetBodyA', \
'_b2Joint_GetBodyB'
'_b2Joint_GetBodyB', \
'_b2Joint_GetAnchorA', \
'_b2Joint_GetAnchorB', \
'_b2Joint_GetReactionForce', \
'_b2Joint_GetReactionTorque', \
'_b2Joint_GetType', \
'_b2Joint_GetCollideConnected', \
'_b2Joint_IsActive' \

B2MOTORJOINT = \
'_b2MotorJoint_SetAngularOffset', \
'_b2MotorJoint_SetLinearOffset', \
'_b2MotorJoint_SetMaxForce', \
'_b2MotorJoint_SetMaxTorque', \
'_b2MotorJoint_SetCorrectionFactor', \
'_b2MotorJointDef_Create', \
'_b2MotorJointDef_InitializeAndCreate'

B2MOUSEJOINT = \
'_b2MouseJoint_SetTarget', \
'_b2MouseJoint_SetMaxForce', \
'_b2MouseJoint_SetFrequency', \
'_b2MouseJoint_SetDampingRatio', \
'_b2MouseJointDef_Create'

B2PARTICLEGROUP = \
Expand Down Expand Up @@ -167,7 +197,7 @@ B2POLYGONSHAPE = \
'_b2PolygonShape_CreateFixture_5', \
'_b2PolygonShape_CreateFixture_6', \
'_b2PolygonShape_CreateFixture_7', \
'_b2PolygonShape_CreateFixture_8', \
'_b2PolygonShape_CreateFixture_8', \
'_b2PolygonShape_CreateParticleGroup_4', \
'_b2PolygonShape_DestroyParticlesInShape_4'

Expand All @@ -180,10 +210,18 @@ B2PRISMATICJOINT = \
'_b2PrismaticJoint_IsLimitEnabled', \
'_b2PrismaticJoint_IsMotorEnabled', \
'_b2PrismaticJoint_SetMotorSpeed', \
'_b2PrismaticJoint_GetLocalAxisA', \
'_b2PrismaticJoint_GetJointSpeed', \
'_b2PrismaticJoint_SetLimits', \
'_b2PrismaticJoint_SetMaxMotorForce', \
'_b2PrismaticJointDef_Create', \
'_b2PrismaticJointDef_InitializeAndCreate' \

B2PULLEYJOINT = \
'_b2PulleyJoint_GetGroundAnchorA', \
'_b2PulleyJoint_GetGroundAnchorB', \
'_b2PulleyJoint_GetCurrentLengthA', \
'_b2PulleyJoint_GetCurrentLengthB', \
'_b2PulleyJointDef_Create', \
'_b2PulleyJointDef_InitializeAndCreate' \

Expand All @@ -194,19 +232,37 @@ B2REVOLUTEJOINT = \
'_b2RevoluteJoint_IsLimitEnabled', \
'_b2RevoluteJoint_IsMotorEnabled', \
'_b2RevoluteJoint_SetMotorSpeed', \
'_b2RevoluteJoint_GetJointSpeed', \
'_b2RevoluteJoint_SetLimits', \
'_b2RevoluteJoint_GetMotorSpeed', \
'_b2RevoluteJoint_SetMaxMotorTorque', \
'_b2RevoluteJoint_GetMotorTorque', \
'_b2RevoluteJointDef_Create', \
'_b2RevoluteJointDef_InitializeAndCreate'
'_b2RevoluteJointDef_InitializeAndCreate' \

B2ROPEJOINT = \
'_b2RopeJoint_SetMaxLength', \
'_b2RopeJoint_GetLimitState', \
'_b2RopeJointDef_Create'

B2WELDJOINT = \
'_b2WeldJoint_SetFrequency', \
'_b2WeldJoint_SetDampingRatio', \
'_b2WeldJointDef_Create', \
'_b2WeldJointDef_InitializeAndCreate' \

B2WHEELJOINT = \
'_b2WheelJoint_SetMotorSpeed', \
'_b2WheelJoint_SetSpringFrequencyHz', \
'_b2WheelJoint_GetLocalAxisA', \
'_b2WheelJoint_GetJointTranslation', \
'_b2WheelJoint_GetJointSpeed', \
'_b2WheelJoint_IsMotorEnabled', \
'_b2WheelJoint_EnableMotor', \
'_b2WheelJoint_GetMotorSpeed', \
'_b2WheelJoint_SetMaxMotorTorque', \
'_b2WheelJoint_GetMotorTorque', \
'_b2WheelJoint_SetSpringDampingRatio', \
'_b2WheelJointDef_Create', \
'_b2WheelJointDef_InitializeAndCreate' \

Expand Down Expand Up @@ -252,4 +308,4 @@ EXPORTS = EXPORTED_FUNCTIONS="[ \
]"

bindings.js:
$(EMSCRIPTEN)/emcc -I../ -o lf_core.js jsBindings/jsBindings.cpp $(OBJECTS) -s $(EXPORTS) -s TOTAL_MEMORY=33554432 -O2 --js-library callbacks.js
$(EMSCRIPTEN)/emcc -I../ -o lf_core.js jsBindings/jsBindings.cpp $(OBJECTS) -s $(EXPORTS) -s TOTAL_MEMORY=33554432 -O2 --memory-init-file 0 --js-library callbacks.js
31 changes: 25 additions & 6 deletions liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2DistanceJoint.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
var b2DistanceJoint_SetLength = Module.cwrap("b2DistanceJoint_SetLength", "null", ["number", "number"]);
var b2DistanceJoint_SetFrequency = Module.cwrap("b2DistanceJoint_SetFrequency", "null", ["number", "number"]);
var b2DistanceJoint_SetDampingRatio = Module.cwrap("b2DistanceJoint_SetDampingRatio", "null", ["number", "number"]);

/**@constructor*/
function b2DistanceJoint(def) {
this.bodyA = def.bodyA;
this.bodyB = def.bodyB;
this.ptr = null;
this.next = null;
b2Joint.call(this, def);
this.length = def.length;
this.frequencyHz = def.frequencyHz;
this.dampingRatio = def.dampingRatio;
}
b2DistanceJoint.prototype = Object.create(b2Joint.prototype);
b2DistanceJoint.prototype.constructor = b2DistanceJoint;

b2DistanceJoint.prototype.SetLength = function (length) {
b2DistanceJoint_SetLength(this.ptr, length);
this.length = length;
}
b2DistanceJoint.prototype.SetFrequency = function (hz) {
b2DistanceJoint_SetFrequency(this.ptr, hz);
this.frequencyHz = hz;
}
b2DistanceJoint.prototype.SetDampingRatio = function (ratio) {
b2DistanceJoint_SetDampingRatio(this.ptr, ratio);
this.dampingRatio = ratio;
}

var b2DistanceJointDef_Create = Module.cwrap("b2DistanceJointDef_Create",
Expand Down Expand Up @@ -38,7 +57,7 @@ function b2DistanceJointDef() {
this.frequencyHz = 0;
}

b2DistanceJointDef.prototype.Create = function(world) {
b2DistanceJointDef.prototype.Create = function (world) {
var distanceJoint = new b2DistanceJoint(this);
distanceJoint.ptr = b2DistanceJointDef_Create(
world.ptr,
Expand All @@ -51,7 +70,7 @@ b2DistanceJointDef.prototype.Create = function(world) {
return distanceJoint;
};

b2DistanceJointDef.prototype.InitializeAndCreate = function(bodyA, bodyB, anchorA, anchorB) {
b2DistanceJointDef.prototype.InitializeAndCreate = function (bodyA, bodyB, anchorA, anchorB) {
this.bodyA = bodyA;
this.bodyB = bodyB;
var distanceJoint = new b2DistanceJoint(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ void* b2DistanceJointDef_InitializeAndCreate(
return ((b2World*)world)->CreateJoint(&def);

}

void b2DistanceJoint_SetLength(void* joint, double length) {
((b2DistanceJoint*)joint)->SetLength(length);
}
void b2DistanceJoint_SetFrequency(void* joint, double frequencyHz) {
((b2DistanceJoint*)joint)->SetFrequency(frequencyHz);
}
void b2DistanceJoint_SetDampingRatio(void* joint, double dampingRatio) {
((b2DistanceJoint*)joint)->SetDampingRatio(dampingRatio);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ void* b2DistanceJointDef_InitializeAndCreate(

}

void b2DistanceJoint_SetLength(void* joint, double length);
void b2DistanceJoint_SetFrequency(void* joint, double frequencyHz);
void b2DistanceJoint_SetDampingRatio(void* joint, double dampingRatio);

#endif
39 changes: 27 additions & 12 deletions liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2FrictionJoint.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var b2FrictionJointDef_Create = Module.cwrap("b2FrictionJointDef_Create",
'number',
['number',
// joint Def
'number', 'number', 'number',
// friction joint def
'number', 'number', 'number',
'number', 'number', 'number']);
// joint Def
'number', 'number', 'number',
// friction joint def
'number', 'number', 'number',
'number', 'number', 'number']);

var b2FrictionJointDef_InitializeAndCreate = Module.cwrap("b2FrictionJointDef_InitializeAndCreate",
'number',
Expand All @@ -16,6 +16,7 @@ var b2FrictionJointDef_InitializeAndCreate = Module.cwrap("b2FrictionJointDef_In
// friction joint def
'number', 'number', 'number']);

/**@constructor*/
function b2FrictionJointDef() {
// joint def
this.bodyA = null;
Expand All @@ -30,7 +31,7 @@ function b2FrictionJointDef() {
this.userData = null;
}

b2FrictionJointDef.prototype.Create = function(world) {
b2FrictionJointDef.prototype.Create = function (world) {
var frictionJoint = new b2FrictionJoint(this);
frictionJoint.ptr = b2FrictionJointDef_Create(
world.ptr,
Expand All @@ -42,7 +43,7 @@ b2FrictionJointDef.prototype.Create = function(world) {
return frictionJoint;
};

b2FrictionJointDef.prototype.InitializeAndCreate = function(bodyA, bodyB, anchor) {
b2FrictionJointDef.prototype.InitializeAndCreate = function (bodyA, bodyB, anchor) {
this.bodyA = bodyA;
this.bodyB = bodyB;
var frictionJoint = new b2FrictionJoint(this);
Expand All @@ -59,9 +60,23 @@ b2FrictionJointDef.prototype.InitializeAndCreate = function(bodyA, bodyB, ancho
return frictionJoint;
};

var b2FrictionJoint_SetMaxForce = Module.cwrap("b2FrictionJoint_SetMaxForce", "null", ["number", "number"]);
var b2FrictionJoint_SetMaxTorque = Module.cwrap("b2FrictionJoint_SetMaxTorque", "null", ["number", "number"]);

/**@constructor*/
function b2FrictionJoint(def) {
this.bodyA = def.bodyA;
this.bodyB = def.bodyB;
this.ptr = null;
this.next = null;
}
b2Joint.call(this, def);
this.maxForce = def.maxForce;
this.maxTorque = def.maxTorque;
}
b2FrictionJoint.prototype = Object.create(b2Joint.prototype);
b2FrictionJoint.prototype.constructor = b2FrictionJoint;

b2FrictionJoint.prototype.SetMaxForce = function (force) {
b2FrictionJoint_SetMaxForce(this.ptr, force);
this.maxForce = force;
}
b2FrictionJoint.prototype.SetMaxTorque = function (torque) {
b2FrictionJoint_SetMaxTorque(this.ptr, torque);
this.maxTorque = torque;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ void* b2FrictionJointDef_InitializeAndCreate(
fJoint.Initialize((b2Body*)bodyA, (b2Body*)bodyB, b2Vec2(anchorX, anchorY));
return ((b2World*)world)->CreateJoint(&fJoint);
}

void b2FrictionJoint_SetMaxForce(void* joint, double force) {
((b2FrictionJoint*)joint)->SetMaxForce(force);
}
void b2FrictionJoint_SetMaxTorque(void* joint, double torque) {
((b2FrictionJoint*)joint)->SetMaxTorque(torque);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ void* b2FrictionJointDef_InitializeAndCreate(
double maxForce, double maxTorque);
}

void b2FrictionJoint_SetMaxForce(void* joint, double force);
void b2FrictionJoint_SetMaxTorque(void* joint, double torque);

#endif
21 changes: 13 additions & 8 deletions liquidfun/Box2D/lfjs/jsBindings/Dynamics/Joints/b2GearJoint.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
var b2GearJoint_GetRatio = Module.cwrap("b2GearJoint_GetRatio", 'number',
['number']);
var b2GearJoint_SetRatio = Module.cwrap("b2GearJoint_SetRatio", 'number', ['number', 'number']);

/**@constructor*/
function b2GearJoint(def) {
this.ptr = null;
this.next = null;
b2Joint.call(this, def);
this.joint1 = def.joint1;
this.joint2 = def.joint2;
this.ratio = def.ratio;
}
b2GearJoint.prototype = Object.create(b2Joint.prototype);
b2GearJoint.prototype.constructor = b2GearJoint;

b2GearJoint.prototype.GetRatio = function() {
return b2GearJoint_GetRatio(this.ptr);
};
b2GearJoint.prototype.SetRatio = function (ratio) {
b2GearJoint_SetRatio(this.ptr, ratio);
this.ratio = ratio;
}

var b2GearJointDef_Create = Module.cwrap("b2GearJointDef_Create",
'number',
Expand All @@ -28,7 +33,7 @@ function b2GearJointDef() {
this.ratio = 0;
}

b2GearJointDef.prototype.Create = function(world) {
b2GearJointDef.prototype.Create = function (world) {
var gearJoint = new b2GearJoint(this);
gearJoint.ptr = b2GearJointDef_Create(
world.ptr,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Box2D/Box2D.h>
double b2GearJoint_GetRatio(void* joint) {
return ((b2GearJoint*)joint)->GetRatio();
void b2GearJoint_SetRatio(void* joint, double ratio) {
((b2GearJoint*)joint)->SetRatio(ratio);
}

void* b2GearJointDef_Create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define B2GEARJOINTJSBINDINGS_H

extern "C" {
double b2GearJoint_GetRatio(void* joint);
void b2GearJoint_SetRatio(void* joint, double ratio);

void* b2GearJointDef_Create(
void* world,
Expand Down
Loading