r3-legacy/bak/game-lib-d3-raycast-vehicle.js

89 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-10-14 12:32:53 +02:00
/**
2016-10-28 13:31:21 +02:00
* Raycast Vehicles :)
* @param engine GameLib.D3.Engine
* @param chassisBody GameLib.D3.RigidBody
* @param wheels GameLib.D3.RaycastWheel[]
2016-10-14 12:32:53 +02:00
* @constructor
*/
2016-10-18 13:37:38 +02:00
GameLib.D3.RaycastVehicle = function(
2016-10-28 11:47:50 +02:00
engine,
chassisBody,
wheels,
wheelBodies
2016-10-14 12:32:53 +02:00
) {
2016-10-28 11:47:50 +02:00
this.engine = engine;
this.engine.isNotCannonThrow();
2016-12-15 14:53:39 +01:00
this.id = GameLib.Utils.RandomId();
2016-10-28 15:28:34 +02:00
2016-10-28 11:47:50 +02:00
this.chassisBody = chassisBody;
if (typeof wheels == 'undefined') {
wheels = [];
}
this.wheels = wheels;
2016-12-15 14:53:39 +01:00
if(GameLib.Utils.UndefinedOrNull(wheelBodies)) {
wheelBodies = [];
}
this.wheelBodies = wheelBodies;
2016-10-28 11:47:50 +02:00
this.instance = this.createInstance();
2016-12-15 14:53:39 +01:00
GameLib.Utils.Extend(GameLib.D3.RaycastVehicle, GameLib.Component);
2016-10-14 12:32:53 +02:00
};
2016-10-28 11:47:50 +02:00
/**
* private
* @returns {GameLib.D3.RaycastVehicle|GameLib.D3.Physics.RaycastVehicle|*}
*/
GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
2016-10-28 13:11:53 +02:00
return new this.engine.instance.RaycastVehicle({
2016-10-28 11:47:50 +02:00
chassisBody: this.chassisBody.instance
});
};
/**
* Adds a raycast wheel to this vehicle
* @param wheel GameLib.D3.RaycastWheel
* @param wheelRigidBody GameLib.D3.RigidBody
2016-10-28 11:47:50 +02:00
*/
GameLib.D3.RaycastVehicle.prototype.addWheel = function (
wheel,
wheelRigidBody
2016-10-18 13:37:38 +02:00
) {
this.wheels.push(wheel);
this.wheelBodies.push(wheelRigidBody);
wheel.wheelIndex = this.instance.addWheel(wheel.instance);
2016-10-28 13:31:21 +02:00
};
/**
* 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
) {
};