r3-legacy/src/game-lib-d3-api-rigid-body.js

182 lines
4.2 KiB
JavaScript
Raw Normal View History

2017-06-24 02:42:28 +02:00
/**
* Raw RigidBody API object - should always correspond with the RigidBody Schema
* @param id
* @param name
* @param mass
* @param friction
* @param position
* @param quaternion
* @param velocity
* @param angularVelocity
* @param linearDamping
* @param angularDamping
* @param allowSleep
* @param sleepSpeedLimit
* @param sleepTimeLimit
* @param collisionFilterGroup
* @param collisionFilterMask
* @param fixedRotation
2017-06-30 14:20:22 +02:00
* @param shapes
2017-06-24 02:42:28 +02:00
* @param kinematic
2017-09-05 05:22:52 +02:00
* @param parentMesh
2017-06-24 02:42:28 +02:00
* @param parentEntity
* @constructor
*/
GameLib.D3.API.RigidBody = function(
id,
name,
mass,
friction,
position,
quaternion,
velocity,
angularVelocity,
linearDamping,
angularDamping,
allowSleep,
sleepSpeedLimit,
sleepTimeLimit,
collisionFilterGroup,
collisionFilterMask,
fixedRotation,
2017-06-30 14:20:22 +02:00
shapes,
2017-06-24 02:42:28 +02:00
kinematic,
2017-09-05 05:22:52 +02:00
parentMesh,
2017-06-24 02:42:28 +02:00
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'RigidBody (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(mass)) {
mass = 0;
}
this.mass = mass;
if (GameLib.Utils.UndefinedOrNull(friction)) {
friction = 5;
}
this.friction = friction;
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(0,0,0);
}
this.position = position;
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
quaternion = new GameLib.API.Quaternion();
}
this.quaternion = quaternion;
if (GameLib.Utils.UndefinedOrNull(velocity)) {
velocity = new GameLib.API.Vector3();
}
this.velocity = velocity;
if (GameLib.Utils.UndefinedOrNull(angularVelocity)) {
angularVelocity = new GameLib.API.Vector3();
}
this.angularVelocity = angularVelocity;
if (GameLib.Utils.UndefinedOrNull(linearDamping)) {
linearDamping = 0.01;
}
this.linearDamping = linearDamping;
if (GameLib.Utils.UndefinedOrNull(angularDamping)) {
angularDamping = 0.01;
}
this.angularDamping = angularDamping;
if (GameLib.Utils.UndefinedOrNull(allowSleep)) {
allowSleep = true;
}
this.allowSleep = allowSleep;
if (GameLib.Utils.UndefinedOrNull(sleepSpeedLimit)) {
sleepSpeedLimit = 0.1;
}
this.sleepSpeedLimit = sleepSpeedLimit;
if (GameLib.Utils.UndefinedOrNull(sleepTimeLimit)) {
sleepTimeLimit = 1.0;
}
this.sleepTimeLimit = sleepTimeLimit;
if (GameLib.Utils.UndefinedOrNull(collisionFilterGroup)) {
collisionFilterGroup = 1;
}
this.collisionFilterGroup = collisionFilterGroup;
if (GameLib.Utils.UndefinedOrNull(collisionFilterMask)) {
collisionFilterMask = 1;
}
this.collisionFilterMask = collisionFilterMask;
if (GameLib.Utils.UndefinedOrNull(fixedRotation)) {
fixedRotation = false;
}
this.fixedRotation = fixedRotation;
2017-06-30 14:20:22 +02:00
if (GameLib.Utils.UndefinedOrNull(shapes)) {
shapes = [];
2017-06-24 02:42:28 +02:00
}
2017-06-30 14:20:22 +02:00
this.shapes = shapes;
2017-06-24 02:42:28 +02:00
if (GameLib.Utils.UndefinedOrNull(kinematic)) {
kinematic = false;
}
this.kinematic = kinematic;
2017-09-05 05:22:52 +02:00
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
parentMesh = null;
}
this.parentMesh = parentMesh;
2017-06-24 02:42:28 +02:00
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.RigidBody.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.RigidBody.prototype.constructor = GameLib.D3.API.RigidBody;
/**
* Creates an API RigidBody from an Object RigidBody
* @param objectRigidBody
* @constructor
*/
GameLib.D3.API.RigidBody.FromObject = function(objectRigidBody) {
return new GameLib.D3.API.RigidBody(
objectRigidBody.id,
objectRigidBody.name,
objectRigidBody.mass,
objectRigidBody.friction,
objectRigidBody.position,
objectRigidBody.quaternion,
objectRigidBody.velocity,
objectRigidBody.angularVelocity,
objectRigidBody.linearDamping,
objectRigidBody.angularDamping,
objectRigidBody.allowSleep,
objectRigidBody.sleepSpeedLimit,
objectRigidBody.sleepTimeLimit,
objectRigidBody.collisionFilterGroup,
objectRigidBody.collisionFilterMask,
objectRigidBody.fixedRotation,
2017-06-30 14:20:22 +02:00
objectRigidBody.shapes,
2017-06-24 02:42:28 +02:00
objectRigidBody.kinematic,
2017-09-05 05:22:52 +02:00
objectRigidBody.parentMesh,
2017-06-24 02:42:28 +02:00
objectRigidBody.parentEntity
);
};