/** * Physics Rigid Body Vehicle Superset * @param engine R3.D3.Engine * @param chassisBody R3.D3.RigidBody * @param wheels R3.D3.RigidWheel[] * @constructor */ R3.D3.RigidBodyVehicle = function( engine, chassisBody, wheels ) { this.id = R3.Utils.RandomId(); this.engine = engine; this.engine.isNotCannonThrow(); this.chassisBody = chassisBody; if (typeof wheels == 'undefined') { wheels = []; } this.wheels = wheels; this.instance = this.createInstance(); }; /** * Returns physics wheelbody info (for updates) * @returns {Array} */ R3.D3.RigidBodyVehicle.prototype.getWheelInfo = function() { return this.instance.wheelBodies; }; /** * * @returns {R3.D3.RigidVehicle} */ R3.D3.RigidBodyVehicle.prototype.createInstance = function() { return new this.engine.instance.RigidVehicle({ chassisBody: this.chassisBody.instance }); }; /** * Adds a wheel to this rigid body vehicle * @param wheel R3.D3.RigidWheel */ R3.D3.RigidBodyVehicle.prototype.addWheel = function(wheel) { this.wheels.push(wheel); this.instance.addWheel({ body: wheel.body.instance, position: new this.engine.instance.Vec3( wheel.position.x, wheel.position.y, wheel.position.z ), axis: new this.engine.instance.Vec3( wheel.axis.x, wheel.axis.y, wheel.axis.z ), direction: new this.engine.instance.Vec3( wheel.direction.x, wheel.direction.y, wheel.direction.z ) }); };