89 lines
2.0 KiB
JavaScript
89 lines
2.0 KiB
JavaScript
|
/**
|
||
|
* Raycast Vehicles :)
|
||
|
* @param engine GameLib.D3.Engine
|
||
|
* @param chassisBody GameLib.D3.RigidBody
|
||
|
* @param wheels GameLib.D3.RaycastWheel[]
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.RaycastVehicle = function(
|
||
|
engine,
|
||
|
chassisBody,
|
||
|
wheels,
|
||
|
wheelBodies
|
||
|
) {
|
||
|
this.engine = engine;
|
||
|
this.engine.isNotCannonThrow();
|
||
|
|
||
|
this.id = GameLib.Utils.RandomId();
|
||
|
|
||
|
this.chassisBody = chassisBody;
|
||
|
|
||
|
if (typeof wheels == 'undefined') {
|
||
|
wheels = [];
|
||
|
}
|
||
|
this.wheels = wheels;
|
||
|
|
||
|
if(GameLib.Utils.UndefinedOrNull(wheelBodies)) {
|
||
|
wheelBodies = [];
|
||
|
}
|
||
|
this.wheelBodies = wheelBodies;
|
||
|
|
||
|
this.instance = this.createInstance();
|
||
|
|
||
|
GameLib.Utils.Extend(GameLib.D3.RaycastVehicle, GameLib.Component);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* private
|
||
|
* @returns {GameLib.D3.RaycastVehicle|GameLib.D3.Physics.RaycastVehicle|*}
|
||
|
*/
|
||
|
GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
|
||
|
return new this.engine.instance.RaycastVehicle({
|
||
|
chassisBody: this.chassisBody.instance
|
||
|
});
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Adds a raycast wheel to this vehicle
|
||
|
* @param wheel GameLib.D3.RaycastWheel
|
||
|
* @param wheelRigidBody GameLib.D3.RigidBody
|
||
|
*/
|
||
|
GameLib.D3.RaycastVehicle.prototype.addWheel = function (
|
||
|
wheel,
|
||
|
wheelRigidBody
|
||
|
) {
|
||
|
this.wheels.push(wheel);
|
||
|
this.wheelBodies.push(wheelRigidBody);
|
||
|
wheel.wheelIndex = this.instance.addWheel(wheel.instance);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Returns updated wheel info
|
||
|
* @returns {*}
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.RaycastVehicle.prototype.getWheelInfo = function() {
|
||
|
return this.instance.wheelInfos;
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
// Override component methods //
|
||
|
GameLib.D3.RaycastVehicle.prototype.onUpdate = function(
|
||
|
deltaTime,
|
||
|
parentEntity
|
||
|
) {
|
||
|
for (var i = 0; i < this.getWheelInfo().length; i++) {
|
||
|
this.instance.updateWheelTransform(i);
|
||
|
var t = this.getWheelInfo()[i].worldTransform;
|
||
|
var wheelBody = this.wheelBodies[i].instance;
|
||
|
wheelBody.position.copy(t.position);
|
||
|
wheelBody.quaternion.copy(t.quaternion);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
GameLib.D3.RaycastVehicle.prototype.onRegistered = function(
|
||
|
parentScene
|
||
|
) {
|
||
|
|
||
|
};
|