diff --git a/game-lib.js b/game-lib.js index c29dfbb..399b1e0 100644 --- a/game-lib.js +++ b/game-lib.js @@ -1194,7 +1194,16 @@ GameLib.D3.Physics.RigidBody = function( * Physics Rigid Body Vehicle Superset * @constructor */ -GameLib.D3.Physics.Vehicle = function( +GameLib.D3.Physics.RigidVehicle = function( +) { + this.vehicleObject = null; +}; + +/** + * Physics Raycast Vehicle Superset + * @constructor + */ +GameLib.D3.Physics.RaycastVehicle = function( ) { this.vehicleObject = null; }; @@ -1212,9 +1221,10 @@ GameLib.D3.Physics.Shape = function( this.scale = new GameLib.D3.Vector3(1, 1, 1); }; -GameLib.D3.Physics.Shape.TYPE_SPHERE = 1; -GameLib.D3.Physics.Shape.TYPE_BOX = 2; -GameLib.D3.Physics.Shape.TYPE_TRIMESH = 3; +GameLib.D3.Physics.Shape.TYPE_SPHERE = 1; +GameLib.D3.Physics.Shape.TYPE_BOX = 2; +GameLib.D3.Physics.Shape.TYPE_TRIMESH = 3; +GameLib.D3.Physics.Shape.TYPE_CYLINDER = 4; /** * Physics Convex Hull Shape Superset @@ -2672,19 +2682,33 @@ GameLib.D3.Physics.Shape.prototype.Update = function( GameLib.D3.Physics.World.prototype.AddShape = function( shape, // d3.physics.shape - rigidBody + rigidBody, + offset, // vec3 + orientation //quaternion ) { shape.shape = shape; if(this.engineType === GameLib.D3.Physics.Engine.TYPE_CANNON) { - rigidBody.bodyObject.addShape(shape.shapeObject); + + var _offset = null; + var _orientation = null; + + if(offset != null && typeof offset !== 'undefined') { + _offset = new CANNON.Vec3(offset.x, offset.y, offset.z); + } + + if(orientation != null && typeof orientation !== 'undefined') { + _orientation = new CANNON.Quaternion(orientation.x, orientation.y, orientation.z, orientation.w); + } + + rigidBody.bodyObject.addShape(shape.shapeObject, _offset, _orientation); } }; GameLib.D3.Physics.World.prototype.CreateRigidVehicle = function( chassisBody // Physics.RigidBody ) { - var rigidVehicle = new GameLib.D3.Physics.Vehicle(); + var rigidVehicle = new GameLib.D3.Physics.RigidVehicle(); if(this.engineType == GameLib.D3.Physics.Engine.TYPE_CANNON) { var vehicle = new CANNON.RigidVehicle({ @@ -2695,7 +2719,20 @@ GameLib.D3.Physics.World.prototype.CreateRigidVehicle = function( } }; -GameLib.D3.Physics.World.prototype.AddWheel = function( +GameLib.D3.Physics.World.prototype.CreateRaycastVehicle = function( + chassisBody // Physics.RigidBody +) { + var raycastVehicle = new GameLib.D3.Physics.RaycastVehicle(); + if(this.engineType == GameLib.D3.Physics.Engine.TYPE_CANNON) { + var vehicle = new CANNON.RaycastVehicle({ + chassisBody: chassisBody.bodyObject + }); + raycastVehicle.vehicleObject = vehicle; + return raycastVehicle; + } +}; + +GameLib.D3.Physics.World.prototype.AddWheelToRigidVehicle = function( vehicle, rigidBody, position, @@ -2712,12 +2749,32 @@ GameLib.D3.Physics.World.prototype.AddWheel = function( } }; -GameLib.D3.Physics.Vehicle.prototype.GetWheelInfo = function( +GameLib.D3.Physics.World.prototype.AddWheelToRaycastVehicle = function ( + vehicle, // physics.raycastvehicle + options // cannon options +) { + if (this.engineType == GameLib.D3.Physics.Engine.TYPE_CANNON) { + vehicle.vehicleObject.addWheel(options); + } else { + console.log("function for engine not implemented"); + } +}; + +GameLib.D3.Physics.RigidVehicle.prototype.GetWheelInfo = function( ) { + // note: need a way to determine which engine we are currently using return this.vehicleObject.wheelBodies; }; +GameLib.D3.Physics.RaycastVehicle.prototype.GetWheelInfo = function( + +) { + // note: need a way to determine which engine we are currently using + return this.vehicleObject.wheelInfos; +}; + + GameLib.D3.Physics.World.prototype.CreateRigidBody = function( mass, friction, @@ -2806,6 +2863,17 @@ GameLib.D3.Physics.World.prototype.CreateBoxShape = function( } }; +GameLib.D3.Physics.World.prototype.CreateCylinderShape = function( + radiusTop, + radiusBottom, + height, + numSegments +) { + if(this.engineType == GameLib.D3.Physics.Engine.TYPE_CANNON) { + return new GameLib.D3.Physics.Shape(new CANNON.Cylinder(radiusTop, radiusBottom, height, numSegments), GameLib.D3.Physics.Shape.TYPE_CYLINDER); + } +}; + GameLib.D3.Physics.World.prototype.AddRigidBody = function( rigidBody // Physics.RigidBody ) { @@ -2815,7 +2883,7 @@ GameLib.D3.Physics.World.prototype.AddRigidBody = function( }; GameLib.D3.Physics.World.prototype.AddVehicle = function( - vehicle // note: this is the cannon vehicle... + vehicle // note: physics.vehicle ) { if(this.engineType == GameLib.D3.Physics.Engine.TYPE_CANNON) { vehicle.vehicleObject.addToWorld(this.worldObject);