73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
|
/**
|
||
|
* Physics Rigid Body Vehicle Superset
|
||
|
* @param engine GameLib.D3.Engine
|
||
|
* @param chassisBody GameLib.D3.RigidBody
|
||
|
* @param wheels GameLib.D3.RigidWheel[]
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.RigidBodyVehicle = function(
|
||
|
engine,
|
||
|
chassisBody,
|
||
|
wheels
|
||
|
) {
|
||
|
this.id = GameLib.Utils.RandomId();
|
||
|
this.engine = engine;
|
||
|
this.engine.isNotCannonThrow();
|
||
|
|
||
|
this.chassisBody = chassisBody;
|
||
|
|
||
|
if (typeof wheels == 'undefined') {
|
||
|
wheels = [];
|
||
|
}
|
||
|
this.wheels = wheels;
|
||
|
|
||
|
this.instance = this.createInstance();
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Returns physics wheelbody info (for updates)
|
||
|
* @returns {Array}
|
||
|
*/
|
||
|
GameLib.D3.RigidBodyVehicle.prototype.getWheelInfo = function() {
|
||
|
return this.instance.wheelBodies;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @returns {GameLib.D3.RigidVehicle}
|
||
|
*/
|
||
|
GameLib.D3.RigidBodyVehicle.prototype.createInstance = function() {
|
||
|
return new this.engine.instance.RigidVehicle({
|
||
|
chassisBody: this.chassisBody.instance
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Adds a wheel to this rigid body vehicle
|
||
|
* @param wheel GameLib.D3.RigidWheel
|
||
|
*/
|
||
|
GameLib.D3.RigidBodyVehicle.prototype.addWheel = function(wheel) {
|
||
|
|
||
|
this.wheels.push(wheel);
|
||
|
|
||
|
this.instance.addWheel({
|
||
|
body: wheel.body.instance,
|
||
|
position: new this.engine.instance.Vec3(
|
||
|
wheel.position.x,
|
||
|
wheel.position.y,
|
||
|
wheel.position.z
|
||
|
),
|
||
|
axis: new this.engine.instance.Vec3(
|
||
|
wheel.axis.x,
|
||
|
wheel.axis.y,
|
||
|
wheel.axis.z
|
||
|
),
|
||
|
direction: new this.engine.instance.Vec3(
|
||
|
wheel.direction.x,
|
||
|
wheel.direction.y,
|
||
|
wheel.direction.z
|
||
|
)
|
||
|
});
|
||
|
|
||
|
};
|