mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
implemented rubedoll direction flip and added meshIndex (z) swapping capability. #151
This commit is contained in:
parent
0da744f5fd
commit
a5f45ffef6
12 changed files with 483 additions and 389 deletions
|
|
@ -40,7 +40,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc, Asser
|
|||
this.holdingJoint = null;
|
||||
this.holdingItem = null;
|
||||
|
||||
this.ragDoll = {head: null, body: null};
|
||||
this.ragDoll = {head: null, body: null}; // FIXME: wtf is this? can we remove it?
|
||||
|
||||
this.createFixtures();
|
||||
this.body.SetActive(false);
|
||||
|
|
|
|||
|
|
@ -18,10 +18,27 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
this.rubeLoader = null;
|
||||
this.body = null;
|
||||
this.limbs = {};
|
||||
this.joints = null;
|
||||
this.limits = [];
|
||||
|
||||
var chest = null;
|
||||
var world = physicsEngine.getWorld();
|
||||
this.rubeLoader = new RubeLoader(RubeDollJson, world);
|
||||
|
||||
this.loadRubeDollFromScene(options);
|
||||
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
world.DestroyBody(this.body);
|
||||
this.body = this.limbs.chest;
|
||||
|
||||
this.body.SetUserData(this);
|
||||
|
||||
this.flip(options.direction);
|
||||
}
|
||||
|
||||
RubeDoll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
RubeDoll.prototype.loadRubeDollFromScene = function(options) {
|
||||
var scene = this.rubeLoader.getScene();
|
||||
|
||||
for (var i in scene.bodies) {
|
||||
|
|
@ -35,19 +52,17 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
this.limbs[body.name] = body;
|
||||
}
|
||||
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
world.DestroyBody(this.body);
|
||||
this.body = this.limbs.chest;
|
||||
this.joints = scene.joints;
|
||||
|
||||
var def = this.body.GetDefinition();
|
||||
def.userData = this;
|
||||
this.body.SetUserData(this);
|
||||
}
|
||||
|
||||
RubeDoll.prototype = Object.create(Parent.prototype);
|
||||
for (var i in this.joints) {
|
||||
this.limits[i] = {
|
||||
lower: this.joints[i].GetLowerLimit(),
|
||||
upper: this.joints[i].GetUpperLimit(),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
RubeDoll.prototype.getFixtureDef = function() {
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
return fixtureDef;
|
||||
|
|
@ -55,7 +70,28 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
|||
|
||||
RubeDoll.prototype.flip = function(direction) {
|
||||
Parent.prototype.flip.call(this, direction);
|
||||
// Extend
|
||||
|
||||
for (var i in this.joints) {
|
||||
var joint = this.joints[i];
|
||||
var limits = this.limits[i];
|
||||
|
||||
if (joint instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) {
|
||||
|
||||
if (direction > 0) {
|
||||
joint.SetLimits(limits.lower, limits.upper);
|
||||
continue;
|
||||
}
|
||||
|
||||
var a1 = limits.lower * -1;
|
||||
var a2 = limits.upper * -1;
|
||||
|
||||
if (a2 > a1) {
|
||||
joint.SetLimits(a1, a2);
|
||||
} else {
|
||||
joint.SetLimits(a2, a1);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RubeDoll.prototype.reposition = function(handPosition, direction) {
|
||||
|
|
|
|||
|
|
@ -129,22 +129,23 @@ function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll
|
|||
image: "chest.png",
|
||||
name: "RagDoll",
|
||||
rotation: 0,
|
||||
type: "ragdoll",
|
||||
type: "rubedoll",
|
||||
weight: 3,
|
||||
width: 5,
|
||||
height: 12,
|
||||
primaryColor: primaryColor
|
||||
primaryColor: primaryColor,
|
||||
direction: this.doll.lookDirection
|
||||
};
|
||||
|
||||
var ragDoll = new RubeDoll(this.physicsEngine, "ragDoll-" + this.id + "-" + ragDollId, options);
|
||||
ragDoll.setVelocities(this.doll.getVelocities());
|
||||
var rubeDoll = new RubeDoll(this.physicsEngine, "rubeDoll-" + this.id + "-" + ragDollId, options);
|
||||
rubeDoll.setVelocities(this.doll.getVelocities());
|
||||
|
||||
this.spawned = false;
|
||||
|
||||
this.doll.destroy();
|
||||
this.doll = null;
|
||||
|
||||
this.ragDoll = ragDoll;
|
||||
this.ragDoll = rubeDoll;
|
||||
};
|
||||
|
||||
Player.prototype.update = function () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue