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

89 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2016-10-14 12:32:53 +02:00
/**
2016-10-28 13:31:21 +02:00
* Raycast Vehicles :)
2018-04-09 10:05:13 +02:00
* @param engine R3.D3.Engine
* @param chassisBody R3.D3.RigidBody
* @param wheels R3.D3.RaycastWheel[]
2016-10-14 12:32:53 +02:00
* @constructor
*/
2018-04-09 10:05:13 +02:00
R3.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();
2018-04-09 10:05:13 +02:00
this.id = R3.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;
2018-04-09 10:05:13 +02:00
if(R3.Utils.UndefinedOrNull(wheelBodies)) {
wheelBodies = [];
}
this.wheelBodies = wheelBodies;
2016-10-28 11:47:50 +02:00
this.instance = this.createInstance();
2018-04-09 10:05:13 +02:00
R3.Utils.Extend(R3.D3.RaycastVehicle, R3.Component);
2016-10-14 12:32:53 +02:00
};
2016-10-28 11:47:50 +02:00
/**
* private
2018-04-09 10:05:13 +02:00
* @returns {R3.D3.RaycastVehicle|R3.D3.Physics.RaycastVehicle|*}
2016-10-28 11:47:50 +02:00
*/
2018-04-09 10:05:13 +02:00
R3.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
2018-04-09 10:05:13 +02:00
* @param wheel R3.D3.RaycastWheel
* @param wheelRigidBody R3.D3.RigidBody
2016-10-28 11:47:50 +02:00
*/
2018-04-09 10:05:13 +02:00
R3.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
*/
2018-04-09 10:05:13 +02:00
R3.D3.RaycastVehicle.prototype.getWheelInfo = function() {
2016-10-28 13:31:21 +02:00
return this.instance.wheelInfos;
};
// Override component methods //
2018-04-09 10:05:13 +02:00
R3.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);
}
};
2018-04-09 10:05:13 +02:00
R3.D3.RaycastVehicle.prototype.onRegistered = function(
parentScene
) {
};