rigid wheels start

beta.r3js.org
Theunis J. Botha 2016-10-28 13:11:53 +02:00
parent e1f949ca2e
commit 82e25d6166
5 changed files with 94 additions and 116 deletions

File diff suppressed because one or more lines are too long

View File

@ -2452,13 +2452,9 @@ GameLib.D3.RaycastVehicle = function(
* @returns {GameLib.D3.RaycastVehicle|GameLib.D3.Physics.RaycastVehicle|*}
*/
GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
var instance = new this.engine.instance.RaycastVehicle({
return new this.engine.instance.RaycastVehicle({
chassisBody: this.chassisBody.instance
});
this.instance = instance;
return instance;
};
/**
@ -2678,77 +2674,51 @@ GameLib.D3.RaycastWheel.prototype.createInstance = function() {
/**
* Physics Rigid Body Vehicle Superset
* TODO: body + wheels[]
* @param engine
* @param chassisBody
* @param wheels
* @constructor
*/
GameLib.D3.RigidBodyVehicle = function(
engine
engine,
chassisBody,
wheels
) {
this.engine = engine;
this.engine.isNotCannonThrow();
this.instance = null;
this.chassisBody = chassisBody;
if (typeof wheels == 'undefined') {
wheels = [];
}
this.wheels = wheels;
this.instance = this.createInstance();
};
/**
*
* @returns {*}
* @returns {GameLib.D3.RigidVehicle}
*/
GameLib.D3.RigidBodyVehicle.prototype.getWheelInfo = function() {
return this.instance.wheelBodies;
};
/**
*
* @param chassisBody
* @returns {GameLib.D3.RigidVehicle|GameLib.D3.Physics.RigidVehicle}
*/
GameLib.D3.RigidBodyVehicle.prototype.createInstance = function(
chassisBody // Physics.RigidBody
) {
var vehicle = new this.engine.instance.RigidVehicle({
chassisBody: chassisBody.bodyObject
GameLib.D3.RigidBodyVehicle.prototype.createInstance = function() {
return new this.engine.instance.RigidVehicle({
chassisBody: this.chassisBody.instance
});
this.instance = vehicle;
return vehicle;
};
/**
* Adds a wheel to this rigid body vehicle
* @param rigidBody GameLib.D3.RigidBody
* @param position
* @param axis
* @param direction
* @constructor
*/
GameLib.D3.RigidBodyVehicle.prototype.addWheel = function(
rigidBody,
position,
axis,
direction
) {
this.instance.addWheel({
body: rigidBody.instance,
position: new this.engine.instance.Vec3(
position.x,
position.y,
position.z
),
axis: new this.engine.instance.Vec3(
axis.x,
axis.y,
axis.z
),
direction: new this.engine.instance.Vec3(
direction.x,
direction.y,
direction.z
)
});
/**
*
* @param wheel
*/
GameLib.D3.RigidBodyVehicle.prototype.addWheel = function(wheel) {
this.wheels.push(wheel);
this.instance.addWheel(wheel.instance);
};
/**
@ -2898,6 +2868,10 @@ GameLib.D3.RigidBody.prototype.addShape = function(
/**
* Created by tj on 28.10.16.
*/
/**
* Scenes are objects putting meshes into 'world space'
* @param id

View File

@ -28,13 +28,9 @@ GameLib.D3.RaycastVehicle = function(
* @returns {GameLib.D3.RaycastVehicle|GameLib.D3.Physics.RaycastVehicle|*}
*/
GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
var instance = new this.engine.instance.RaycastVehicle({
return new this.engine.instance.RaycastVehicle({
chassisBody: this.chassisBody.instance
});
this.instance = instance;
return instance;
};
/**

View File

@ -1,74 +1,48 @@
/**
* Physics Rigid Body Vehicle Superset
* TODO: body + wheels[]
* @param engine
* @param chassisBody
* @param wheels
* @constructor
*/
GameLib.D3.RigidBodyVehicle = function(
engine
engine,
chassisBody,
wheels
) {
this.engine = engine;
this.engine.isNotCannonThrow();
this.instance = null;
this.chassisBody = chassisBody;
if (typeof wheels == 'undefined') {
wheels = [];
}
this.wheels = wheels;
this.instance = this.createInstance();
};
/**
*
* @returns {*}
* @returns {GameLib.D3.RigidVehicle}
*/
GameLib.D3.RigidBodyVehicle.prototype.getWheelInfo = function() {
return this.instance.wheelBodies;
};
/**
*
* @param chassisBody
* @returns {GameLib.D3.RigidVehicle|GameLib.D3.Physics.RigidVehicle}
*/
GameLib.D3.RigidBodyVehicle.prototype.createInstance = function(
chassisBody // Physics.RigidBody
) {
var vehicle = new this.engine.instance.RigidVehicle({
chassisBody: chassisBody.bodyObject
GameLib.D3.RigidBodyVehicle.prototype.createInstance = function() {
return new this.engine.instance.RigidVehicle({
chassisBody: this.chassisBody.instance
});
this.instance = vehicle;
return vehicle;
};
/**
* Adds a wheel to this rigid body vehicle
* @param rigidBody GameLib.D3.RigidBody
* @param position
* @param axis
* @param direction
* @constructor
*/
GameLib.D3.RigidBodyVehicle.prototype.addWheel = function(
rigidBody,
position,
axis,
direction
) {
this.instance.addWheel({
body: rigidBody.instance,
position: new this.engine.instance.Vec3(
position.x,
position.y,
position.z
),
axis: new this.engine.instance.Vec3(
axis.x,
axis.y,
axis.z
),
direction: new this.engine.instance.Vec3(
direction.x,
direction.y,
direction.z
)
});
/**
*
* @param wheel
*/
GameLib.D3.RigidBodyVehicle.prototype.addWheel = function(wheel) {
this.wheels.push(wheel);
this.instance.addWheel(wheel.instance);
};

View File

@ -0,0 +1,34 @@
GameLib.D3.RigidWheel = function(
engine,
position,
axis,
direction
) {
this.engine = engine;
this.position = position;
this.axis = axis;
this.direction = direction;
this.instance = this.createInstance();
};
GameLib.D3.RigidWheel.prototype.createInstance = function(
//
// body: rigidBody.instance,
// position: new this.engine.instance.Vec3(
// position.x,
// position.y,
// position.z
// ),
// axis: new this.engine.instance.Vec3(
// axis.x,
// axis.y,
// axis.z
// ),
// direction: new this.engine.instance.Vec3(
// direction.x,
// direction.y,
// direction.z
// )
);