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.
Modifier and Type | Field and Description |
---|---|
protected PhysicsSpace |
physicsSpace |
protected com.bulletphysics.dynamics.vehicle.VehicleRaycaster |
rayCaster |
protected com.bulletphysics.dynamics.vehicle.VehicleTuning |
tuning |
protected com.bulletphysics.dynamics.vehicle.RaycastVehicle |
vehicle |
protected java.util.ArrayList<VehicleWheel> |
wheels |
constructionInfo, joints, kinematic, localInertia, mass, motionState, rBody, tempMatrix, tempTrans, tempVec, tempVec2
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
Modifier | Constructor and Description |
---|---|
protected |
PhysicsVehicle() |
|
PhysicsVehicle(CollisionShape shape) |
|
PhysicsVehicle(CollisionShape shape,
float mass) |
Modifier and Type | Method and Description |
---|---|
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
|
void |
destroy()
destroys this PhysicsRigidBody and removes it from memory
|
float |
getCurrentVehicleSpeedKmHour()
Get the current speed of the vehicle in km/h
|
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() |
com.bulletphysics.dynamics.vehicle.RaycastVehicle |
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)
De-serialize this body, for example when loading from a J3O file.
|
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 value caps the maximum suspension force, raise this above the default 6000 if your suspension cannot
handle the weight of your vehicle.
|
void |
setMaxSuspensionForce(int wheel,
float maxSuspensionForce)
This value caps the maximum suspension force, raise this above the default 6000 if your suspension cannot
handle the weight of your vehicle.
|
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)
Serialize this body, for example when saving to a J3O file.
|
activate, addJoint, applyCentralForce, applyForce, applyImpulse, applyTorque, applyTorqueImpulse, clearForces, getAngularDamping, getAngularFactor, getAngularSleepingThreshold, getAngularVelocity, getAngularVelocity, getCcdMotionThreshold, getCcdSquareMotionThreshold, getCcdSweptSphereRadius, getFriction, getGravity, getGravity, getInterpolatedPhysicsLocation, getInterpolatedPhysicsRotation, getJoints, getLinearDamping, getLinearSleepingThreshold, getLinearVelocity, getLinearVelocity, getMass, getMotionState, getObjectId, getPhysicsLocation, getPhysicsLocation, getPhysicsRotation, getPhysicsRotation, getPhysicsRotationMatrix, getPhysicsRotationMatrix, getRestitution, isActive, isContactResponse, isKinematic, preRebuild, rebuildRigidBody, removeJoint, setAngularDamping, setAngularFactor, setAngularSleepingThreshold, setAngularVelocity, setCcdMotionThreshold, setCcdSweptSphereRadius, setCollisionShape, setContactResponse, setDamping, setFriction, setGravity, setKinematic, setLinearDamping, setLinearSleepingThreshold, setLinearVelocity, setMass, setPhysicsLocation, setPhysicsRotation, setPhysicsRotation, setRestitution, setSleepingThresholds
addCollideWithGroup, getCollideWithGroups, getCollisionGroup, getCollisionShape, getUserObject, removeCollideWithGroup, setCollideWithGroups, setCollisionGroup, setUserObject
protected com.bulletphysics.dynamics.vehicle.RaycastVehicle vehicle
protected com.bulletphysics.dynamics.vehicle.VehicleTuning tuning
protected com.bulletphysics.dynamics.vehicle.VehicleRaycaster rayCaster
protected java.util.ArrayList<VehicleWheel> wheels
protected PhysicsSpace physicsSpace
protected PhysicsVehicle()
public PhysicsVehicle(CollisionShape shape)
public PhysicsVehicle(CollisionShape shape, float mass)
public void updateWheels()
public void applyWheelTransforms()
protected void postRebuild()
postRebuild
in class PhysicsRigidBody
public void createVehicle(PhysicsSpace space)
public VehicleWheel addWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel)
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 radiusisFrontWheel
- sets if this wheel is a front wheel (steering)public VehicleWheel addWheel(Spatial spat, Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel)
spat
- the wheel GeometryconnectionPoint
- 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 radiusisFrontWheel
- sets if this wheel is a front wheel (steering)public void removeWheel(int wheel)
wheel
- public VehicleWheel getWheel(int wheel)
wheel
- the wheel indexpublic int getNumWheels()
public float getFrictionSlip()
public void setFrictionSlip(float frictionSlip)
frictionSlip
- the frictionSlip to setpublic void setFrictionSlip(int wheel, float frictionSlip)
wheel
- frictionSlip
- public void setRollInfluence(int wheel, float rollInfluence)
public float getMaxSuspensionTravelCm()
public void setMaxSuspensionTravelCm(float maxSuspensionTravelCm)
maxSuspensionTravelCm
- the maxSuspensionTravelCm to setpublic void setMaxSuspensionTravelCm(int wheel, float maxSuspensionTravelCm)
wheel
- maxSuspensionTravelCm
- public float getMaxSuspensionForce()
public void setMaxSuspensionForce(float maxSuspensionForce)
maxSuspensionForce
- public void setMaxSuspensionForce(int wheel, float maxSuspensionForce)
wheel
- maxSuspensionForce
- public float getSuspensionCompression()
public void setSuspensionCompression(float suspensionCompression)
suspensionCompression
- the suspensionCompression to setpublic void setSuspensionCompression(int wheel, float suspensionCompression)
wheel
- suspensionCompression
- public float getSuspensionDamping()
public void setSuspensionDamping(float suspensionDamping)
suspensionDamping
- the suspensionDamping to setpublic void setSuspensionDamping(int wheel, float suspensionDamping)
wheel
- suspensionDamping
- public float getSuspensionStiffness()
public void setSuspensionStiffness(float suspensionStiffness)
suspensionStiffness
- public void setSuspensionStiffness(int wheel, float suspensionStiffness)
wheel
- suspensionStiffness
- public void resetSuspension()
public void accelerate(float force)
force
- the forcepublic void accelerate(int wheel, float force)
wheel
- the wheel to apply the force onforce
- the forcepublic void steer(float value)
value
- the steering angle of the front wheels (Pi = 360deg)public void steer(int wheel, float value)
wheel
- the wheel to set the steering onvalue
- the steering angle of the front wheels (Pi = 360deg)public void brake(float force)
force
- the forcepublic void brake(int wheel, float force)
wheel
- the wheel to apply the force onforce
- the forcepublic float getCurrentVehicleSpeedKmHour()
public Vector3f getForwardVector(Vector3f vector)
vector
- The object to write the forward vector values to.
Passing null will cause a new Vector3f
to be created.public com.bulletphysics.dynamics.vehicle.RaycastVehicle getVehicleId()
public void destroy()
PhysicsRigidBody
destroy
in class PhysicsRigidBody
public void read(JmeImporter im) throws java.io.IOException
PhysicsRigidBody
read
in interface Savable
read
in class PhysicsRigidBody
im
- importer (not null)java.io.IOException
- from importerpublic void write(JmeExporter ex) throws java.io.IOException
PhysicsRigidBody
write
in interface Savable
write
in class PhysicsRigidBody
ex
- exporter (not null)java.io.IOException
- from exporter