com.jme3.bullet.objects
Class PhysicsVehicle

java.lang.Object
  extended by com.jme3.bullet.collision.PhysicsCollisionObject
      extended by com.jme3.bullet.objects.PhysicsRigidBody
          extended by com.jme3.bullet.objects.PhysicsVehicle
All Implemented Interfaces:
Savable
Direct Known Subclasses:
VehicleControl

public class PhysicsVehicle
extends PhysicsRigidBody

PhysicsVehicleNode - Special PhysicsNode that implements vehicle functions

From bullet manual:
For most vehicle simulations, it is recommended to use the simplified Bullet vehicle model as provided in btRaycastVehicle. Instead of simulation each wheel and chassis as separate rigid bodies, connected by constraints, it uses a simplified model. This simplified model has many benefits, and is widely used in commercial driving games.
The entire vehicle is represented as a single rigidbody, the chassis. The collision detection of the wheels is approximated by ray casts, and the tire friction is a basic anisotropic friction model.


Field Summary
protected  PhysicsSpace physicsSpace
           
protected  long rayCasterId
           
protected  VehicleTuning tuning
           
protected  long vehicleId
           
protected  java.util.ArrayList<VehicleWheel> wheels
           
 
Fields inherited from class com.jme3.bullet.objects.PhysicsRigidBody
joints, kinematic, mass, motionState
 
Fields inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
COLLISION_GROUP_01, COLLISION_GROUP_02, COLLISION_GROUP_03, COLLISION_GROUP_04, COLLISION_GROUP_05, COLLISION_GROUP_06, COLLISION_GROUP_07, COLLISION_GROUP_08, COLLISION_GROUP_09, COLLISION_GROUP_10, COLLISION_GROUP_11, COLLISION_GROUP_12, COLLISION_GROUP_13, COLLISION_GROUP_14, COLLISION_GROUP_15, COLLISION_GROUP_16, COLLISION_GROUP_NONE, collisionGroup, collisionGroupsMask, collisionShape, debugArrow, debugArrowGeom, debugMaterialBlue, debugMaterialGreen, debugMaterialRed, debugMaterialYellow, debugShape, objectId
 
Constructor Summary
PhysicsVehicle()
           
PhysicsVehicle(CollisionShape shape)
           
PhysicsVehicle(CollisionShape shape, float mass)
           
 
Method Summary
 void accelerate(float force)
          Apply the given engine force to all wheels, works continuously
 void accelerate(int wheel, float force)
          Apply the given engine force, works continuously
 VehicleWheel addWheel(Spatial spat, Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel)
          Add a wheel to this vehicle
 VehicleWheel addWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel)
          Add a wheel to this vehicle
 void applyWheelTransforms()
          used internally
 void brake(float force)
          Apply the given brake force to all wheels, works continuously
 void brake(int wheel, float force)
          Apply the given brake force, works continuously
 void createVehicle(PhysicsSpace space)
          Used internally, creates the actual vehicle constraint when vehicle is added to phyicsspace
protected  void finalize()
           
 float getCurrentVehicleSpeedKmHour()
          Get the current speed of the vehicle in km/h
protected  Spatial getDebugShape()
           
 Vector3f getForwardVector(Vector3f vector)
          Get the current forward vector of the vehicle in world coordinates
 float getFrictionSlip()
           
 float getMaxSuspensionForce()
           
 float getMaxSuspensionTravelCm()
           
 int getNumWheels()
           
 float getSuspensionCompression()
           
 float getSuspensionDamping()
           
 float getSuspensionStiffness()
           
 long getVehicleId()
          used internally
 VehicleWheel getWheel(int wheel)
          You can get access to the single wheels via this method.
protected  void postRebuild()
           
 void read(JmeImporter im)
           
 void removeWheel(int wheel)
          This rebuilds the vehicle as there is no way in bullet to remove a wheel.
 void resetSuspension()
          Reset the suspension
 void setFrictionSlip(float frictionSlip)
          Use before adding wheels, this is the default used when adding wheels.
 void setFrictionSlip(int wheel, float frictionSlip)
          The coefficient of friction between the tyre and the ground.
 void setMaxSuspensionForce(float maxSuspensionForce)
          This vaue caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehcile.
 void setMaxSuspensionForce(int wheel, float maxSuspensionForce)
          This vaue caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehcile.
 void setMaxSuspensionTravelCm(float maxSuspensionTravelCm)
          Use before adding wheels, this is the default used when adding wheels.
 void setMaxSuspensionTravelCm(int wheel, float maxSuspensionTravelCm)
          The maximum distance the suspension can be compressed (centimetres)
 void setRollInfluence(int wheel, float rollInfluence)
          Reduces the rolling torque applied from the wheels that cause the vehicle to roll over.
 void setSuspensionCompression(float suspensionCompression)
          Use before adding wheels, this is the default used when adding wheels.
 void setSuspensionCompression(int wheel, float suspensionCompression)
          The damping coefficient for when the suspension is compressed.
 void setSuspensionDamping(float suspensionDamping)
          Use before adding wheels, this is the default used when adding wheels.
 void setSuspensionDamping(int wheel, float suspensionDamping)
          The damping coefficient for when the suspension is expanding.
 void setSuspensionStiffness(float suspensionStiffness)
          Use before adding wheels, this is the default used when adding wheels.
 void setSuspensionStiffness(int wheel, float suspensionStiffness)
          The stiffness constant for the suspension.
 void steer(float value)
          Set the given steering value to all front wheels (0 = forward)
 void steer(int wheel, float value)
          Set the given steering value to the given wheel (0 = forward)
 void updateWheels()
          used internally
 void write(JmeExporter ex)
           
 
Methods inherited from class com.jme3.bullet.objects.PhysicsRigidBody
activate, addJoint, applyCentralForce, applyForce, applyImpulse, applyTorque, applyTorqueImpulse, clearForces, getAngularDamping, getAngularFactor, getAngularSleepingThreshold, getAngularVelocity, getAngularVelocity, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getFriction, getGravity, getGravity, getJoints, getLinearDamping, getLinearSleepingThreshold, getLinearVelocity, getLinearVelocity, getMass, getMotionState, getPhysicsLocation, getPhysicsLocation, getPhysicsRotation, getPhysicsRotation, getPhysicsRotationMatrix, getPhysicsRotationMatrix, getRestitution, isActive, isInWorld, isKinematic, preRebuild, rebuildRigidBody, removeJoint, setAngularDamping, setAngularFactor, setAngularSleepingThreshold, setAngularVelocity, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollisionShape, setDamping, setFriction, setGravity, setKinematic, setLinearDamping, setLinearSleepingThreshold, setLinearVelocity, setMass, setPhysicsLocation, setPhysicsRotation, setPhysicsRotation, setRestitution, setSleepingThresholds
 
Methods inherited from class com.jme3.bullet.collision.PhysicsCollisionObject
addCollideWithGroup, attachCollisionShape, attachDebugShape, attachDebugShape, attachDebugShape, createDebugShape, debugShape, detachDebugShape, finalizeNative, getCollideWithGroups, getCollisionGroup, getCollisionShape, getObjectId, getUserObject, initUserPointer, removeCollideWithGroup, setCollideWithGroups, setCollisionGroup, setUserObject, updateDebugShape
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vehicleId

protected long vehicleId

rayCasterId

protected long rayCasterId

tuning

protected VehicleTuning tuning

wheels

protected java.util.ArrayList<VehicleWheel> wheels

physicsSpace

protected PhysicsSpace physicsSpace
Constructor Detail

PhysicsVehicle

public PhysicsVehicle()

PhysicsVehicle

public PhysicsVehicle(CollisionShape shape)

PhysicsVehicle

public PhysicsVehicle(CollisionShape shape,
                      float mass)
Method Detail

updateWheels

public void updateWheels()
used internally


applyWheelTransforms

public void applyWheelTransforms()
used internally


postRebuild

protected void postRebuild()
Overrides:
postRebuild in class PhysicsRigidBody

createVehicle

public void createVehicle(PhysicsSpace space)
Used internally, creates the actual vehicle constraint when vehicle is added to phyicsspace


addWheel

public VehicleWheel addWheel(Vector3f connectionPoint,
                             Vector3f direction,
                             Vector3f axle,
                             float suspensionRestLength,
                             float wheelRadius,
                             boolean isFrontWheel)
Add a wheel to this vehicle

Parameters:
connectionPoint - The starting point of the ray, where the suspension connects to the chassis (chassis space)
direction - the direction of the wheel (should be -Y / 0,-1,0 for a normal car)
axle - The axis of the wheel, pointing right in vehicle direction (should be -X / -1,0,0 for a normal car)
suspensionRestLength - The current length of the suspension (metres)
wheelRadius - the wheel radius
isFrontWheel - sets if this wheel is a front wheel (steering)
Returns:
the PhysicsVehicleWheel object to get/set infos on the wheel

addWheel

public VehicleWheel addWheel(Spatial spat,
                             Vector3f connectionPoint,
                             Vector3f direction,
                             Vector3f axle,
                             float suspensionRestLength,
                             float wheelRadius,
                             boolean isFrontWheel)
Add a wheel to this vehicle

Parameters:
spat - the wheel Geometry
connectionPoint - The starting point of the ray, where the suspension connects to the chassis (chassis space)
direction - the direction of the wheel (should be -Y / 0,-1,0 for a normal car)
axle - The axis of the wheel, pointing right in vehicle direction (should be -X / -1,0,0 for a normal car)
suspensionRestLength - The current length of the suspension (metres)
wheelRadius - the wheel radius
isFrontWheel - sets if this wheel is a front wheel (steering)
Returns:
the PhysicsVehicleWheel object to get/set infos on the wheel

removeWheel

public void removeWheel(int wheel)
This rebuilds the vehicle as there is no way in bullet to remove a wheel.

Parameters:
wheel -

getWheel

public VehicleWheel getWheel(int wheel)
You can get access to the single wheels via this method.

Parameters:
wheel - the wheel index
Returns:
the WheelInfo of the selected wheel

getNumWheels

public int getNumWheels()

getFrictionSlip

public float getFrictionSlip()
Returns:
the frictionSlip

setFrictionSlip

public void setFrictionSlip(float frictionSlip)
Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
The coefficient of friction between the tyre and the ground. Should be about 0.8 for realistic cars, but can increased for better handling. Set large (10000.0) for kart racers

Parameters:
frictionSlip - the frictionSlip to set

setFrictionSlip

public void setFrictionSlip(int wheel,
                            float frictionSlip)
The coefficient of friction between the tyre and the ground. Should be about 0.8 for realistic cars, but can increased for better handling. Set large (10000.0) for kart racers

Parameters:
wheel -
frictionSlip -

setRollInfluence

public void setRollInfluence(int wheel,
                             float rollInfluence)
Reduces the rolling torque applied from the wheels that cause the vehicle to roll over. This is a bit of a hack, but it's quite effective. 0.0 = no roll, 1.0 = physical behaviour. If m_frictionSlip is too high, you'll need to reduce this to stop the vehicle rolling over. You should also try lowering the vehicle's centre of mass


getMaxSuspensionTravelCm

public float getMaxSuspensionTravelCm()
Returns:
the maxSuspensionTravelCm

setMaxSuspensionTravelCm

public void setMaxSuspensionTravelCm(float maxSuspensionTravelCm)
Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
The maximum distance the suspension can be compressed (centimetres)

Parameters:
maxSuspensionTravelCm - the maxSuspensionTravelCm to set

setMaxSuspensionTravelCm

public void setMaxSuspensionTravelCm(int wheel,
                                     float maxSuspensionTravelCm)
The maximum distance the suspension can be compressed (centimetres)

Parameters:
wheel -
maxSuspensionTravelCm -

getMaxSuspensionForce

public float getMaxSuspensionForce()

setMaxSuspensionForce

public void setMaxSuspensionForce(float maxSuspensionForce)
This vaue caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehcile.

Parameters:
maxSuspensionForce -

setMaxSuspensionForce

public void setMaxSuspensionForce(int wheel,
                                  float maxSuspensionForce)
This vaue caps the maximum suspension force, raise this above the default 6000 if your suspension cannot handle the weight of your vehcile.

Parameters:
wheel -
maxSuspensionForce -

getSuspensionCompression

public float getSuspensionCompression()
Returns:
the suspensionCompression

setSuspensionCompression

public void setSuspensionCompression(float suspensionCompression)
Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
The damping coefficient for when the suspension is compressed. Set to k * 2.0 * FastMath.sqrt(m_suspensionStiffness) so k is proportional to critical damping.
k = 0.0 undamped & bouncy, k = 1.0 critical damping
0.1 to 0.3 are good values

Parameters:
suspensionCompression - the suspensionCompression to set

setSuspensionCompression

public void setSuspensionCompression(int wheel,
                                     float suspensionCompression)
The damping coefficient for when the suspension is compressed. Set to k * 2.0 * FastMath.sqrt(m_suspensionStiffness) so k is proportional to critical damping.
k = 0.0 undamped & bouncy, k = 1.0 critical damping
0.1 to 0.3 are good values

Parameters:
wheel -
suspensionCompression -

getSuspensionDamping

public float getSuspensionDamping()
Returns:
the suspensionDamping

setSuspensionDamping

public void setSuspensionDamping(float suspensionDamping)
Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
The damping coefficient for when the suspension is expanding. See the comments for setSuspensionCompression for how to set k.

Parameters:
suspensionDamping - the suspensionDamping to set

setSuspensionDamping

public void setSuspensionDamping(int wheel,
                                 float suspensionDamping)
The damping coefficient for when the suspension is expanding. See the comments for setSuspensionCompression for how to set k.

Parameters:
wheel -
suspensionDamping -

getSuspensionStiffness

public float getSuspensionStiffness()
Returns:
the suspensionStiffness

setSuspensionStiffness

public void setSuspensionStiffness(float suspensionStiffness)
Use before adding wheels, this is the default used when adding wheels. After adding the wheel, use direct wheel access.
The stiffness constant for the suspension. 10.0 - Offroad buggy, 50.0 - Sports car, 200.0 - F1 Car

Parameters:
suspensionStiffness -

setSuspensionStiffness

public void setSuspensionStiffness(int wheel,
                                   float suspensionStiffness)
The stiffness constant for the suspension. 10.0 - Offroad buggy, 50.0 - Sports car, 200.0 - F1 Car

Parameters:
wheel -
suspensionStiffness -

resetSuspension

public void resetSuspension()
Reset the suspension


accelerate

public void accelerate(float force)
Apply the given engine force to all wheels, works continuously

Parameters:
force - the force

accelerate

public void accelerate(int wheel,
                       float force)
Apply the given engine force, works continuously

Parameters:
wheel - the wheel to apply the force on
force - the force

steer

public void steer(float value)
Set the given steering value to all front wheels (0 = forward)

Parameters:
value - the steering angle of the front wheels (Pi = 360deg)

steer

public void steer(int wheel,
                  float value)
Set the given steering value to the given wheel (0 = forward)

Parameters:
wheel - the wheel to set the steering on
value - the steering angle of the front wheels (Pi = 360deg)

brake

public void brake(float force)
Apply the given brake force to all wheels, works continuously

Parameters:
force - the force

brake

public void brake(int wheel,
                  float force)
Apply the given brake force, works continuously

Parameters:
wheel - the wheel to apply the force on
force - the force

getCurrentVehicleSpeedKmHour

public float getCurrentVehicleSpeedKmHour()
Get the current speed of the vehicle in km/h

Returns:

getForwardVector

public Vector3f getForwardVector(Vector3f vector)
Get the current forward vector of the vehicle in world coordinates

Parameters:
vector -
Returns:

getVehicleId

public long getVehicleId()
used internally


getDebugShape

protected Spatial getDebugShape()
Overrides:
getDebugShape in class PhysicsRigidBody

read

public void read(JmeImporter im)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class PhysicsRigidBody
Throws:
java.io.IOException

write

public void write(JmeExporter ex)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class PhysicsRigidBody
Throws:
java.io.IOException

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class PhysicsCollisionObject
Throws:
java.lang.Throwable