raycast wheel wrapper - vehicles now have wheels

beta.r3js.org
Theunis J. Botha 2016-10-28 12:53:08 +02:00
parent 4ba7a43d0a
commit e1f949ca2e
4 changed files with 95 additions and 52 deletions

File diff suppressed because one or more lines are too long

View File

@ -2426,17 +2426,24 @@ GameLib.D3.PolyVertex.prototype.clone = function() {
*
* @param engine GamLib.D3.Engine
* @param chassisBody GamLib.D3.RigidBody
* @param wheels GameLib.D3.RaycastWheel[]
* @constructor
*/
GameLib.D3.RaycastVehicle = function(
engine,
chassisBody
chassisBody,
wheels
) {
this.engine = engine;
this.engine.isNotCannonThrow();
this.chassisBody = chassisBody;
if (typeof wheels == 'undefined') {
wheels = [];
}
this.wheels = wheels;
this.instance = this.createInstance();
};
@ -2461,31 +2468,9 @@ GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
GameLib.D3.RaycastVehicle.prototype.addWheel = function (
wheel
) {
var options = {};
for (var property in wheel) {
if (wheel.hasOwnProperty(property)){
if (property == 'engine') {
continue;
}
options[property] = wheel[property];
}
}
this.instance.addWheel(options);
this.wheels.push(wheel);
this.instance.addWheel(wheel.instance);
};
/**
* Eventually we can wrap wheels
* @returns {*}
* @constructor
*/
GameLib.D3.RaycastVehicle.prototype.getWheelInfo = function() {
return this.instance.wheelInfos;
};
GameLib.D3.RaycastWheel = function(
engine,
chassisConnectionPointLocal,
@ -2653,6 +2638,42 @@ GameLib.D3.RaycastWheel = function(
customSlidingRotationalSpeed = -0.1;
}
this.customSlidingRotationalSpeed = customSlidingRotationalSpeed;
this.instance = this.createInstance();
};
GameLib.D3.RaycastWheel.prototype.createInstance = function() {
return new this.engine.instance.WheelInfo({
chassisConnectionPointLocal : this.chassisConnectionPointLocal,
chassisConnectionPointWorld : this.chassisConnectionPointWorld,
directionLocal : this.directionLocal,
directionWorld : this.directionWorld,
axleLocal : this.axleLocal,
axleWorld : this.axleWorld,
suspensionRestLength : this.suspensionRestLength,
suspensionMaxLength : this.suspensionMaxLength,
radius : this.radius,
suspensionStiffness : this.suspensionStiffness,
dampingCompression : this.dampingCompression,
dampingRelaxation : this.dampingRelaxation,
frictionSlip : this.frictionSlip,
steering : this.steering,
rotation : this.rotation,
deltaRotation : this.deltaRotation,
rollInfluence : this.rollInfluence,
maxSuspensionForce : this.maxSuspensionForce,
isFrontWheel : this.isFrontWheel,
clippedInvContactDotSuspension : this.clippedInvContactDotSuspension,
suspensionRelativeVelocity : this.suspensionRelativeVelocity,
suspensionForce : this.suspensionForce,
skidInfo : this.skidInfo,
suspensionLength : this.suspensionLength,
maxSuspensionTravel : this.maxSuspensionTravel,
useCustomSlidingRotationalSpeed : this.useCustomSlidingRotationalSpeed,
customSlidingRotationalSpeed : this.customSlidingRotationalSpeed
});
};
/**

View File

@ -2,17 +2,24 @@
*
* @param engine GamLib.D3.Engine
* @param chassisBody GamLib.D3.RigidBody
* @param wheels GameLib.D3.RaycastWheel[]
* @constructor
*/
GameLib.D3.RaycastVehicle = function(
engine,
chassisBody
chassisBody,
wheels
) {
this.engine = engine;
this.engine.isNotCannonThrow();
this.chassisBody = chassisBody;
if (typeof wheels == 'undefined') {
wheels = [];
}
this.wheels = wheels;
this.instance = this.createInstance();
};
@ -37,27 +44,6 @@ GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
GameLib.D3.RaycastVehicle.prototype.addWheel = function (
wheel
) {
var options = {};
for (var property in wheel) {
if (wheel.hasOwnProperty(property)){
if (property == 'engine') {
continue;
}
options[property] = wheel[property];
}
}
this.instance.addWheel(options);
};
/**
* Eventually we can wrap wheels
* @returns {*}
* @constructor
*/
GameLib.D3.RaycastVehicle.prototype.getWheelInfo = function() {
return this.instance.wheelInfos;
};
this.wheels.push(wheel);
this.instance.addWheel(wheel.instance);
};

View File

@ -165,4 +165,40 @@ GameLib.D3.RaycastWheel = function(
customSlidingRotationalSpeed = -0.1;
}
this.customSlidingRotationalSpeed = customSlidingRotationalSpeed;
this.instance = this.createInstance();
};
GameLib.D3.RaycastWheel.prototype.createInstance = function() {
return new this.engine.instance.WheelInfo({
chassisConnectionPointLocal : this.chassisConnectionPointLocal,
chassisConnectionPointWorld : this.chassisConnectionPointWorld,
directionLocal : this.directionLocal,
directionWorld : this.directionWorld,
axleLocal : this.axleLocal,
axleWorld : this.axleWorld,
suspensionRestLength : this.suspensionRestLength,
suspensionMaxLength : this.suspensionMaxLength,
radius : this.radius,
suspensionStiffness : this.suspensionStiffness,
dampingCompression : this.dampingCompression,
dampingRelaxation : this.dampingRelaxation,
frictionSlip : this.frictionSlip,
steering : this.steering,
rotation : this.rotation,
deltaRotation : this.deltaRotation,
rollInfluence : this.rollInfluence,
maxSuspensionForce : this.maxSuspensionForce,
isFrontWheel : this.isFrontWheel,
clippedInvContactDotSuspension : this.clippedInvContactDotSuspension,
suspensionRelativeVelocity : this.suspensionRelativeVelocity,
suspensionForce : this.suspensionForce,
skidInfo : this.skidInfo,
suspensionLength : this.suspensionLength,
maxSuspensionTravel : this.maxSuspensionTravel,
useCustomSlidingRotationalSpeed : this.useCustomSlidingRotationalSpeed,
customSlidingRotationalSpeed : this.customSlidingRotationalSpeed
});
};