31 btRigidBody *body = btRigidBody::upcast(chassis->get_object());
33 _raycaster =
new btDefaultVehicleRaycaster(world->get_world());
34 _vehicle =
new btRaycastVehicle(_tuning._, body, _raycaster);
49 _vehicle->setCoordinateSystem(1, 0, 2);
52 _vehicle->setCoordinateSystem(0, 1, 2);
55 _vehicle->setCoordinateSystem(0, 2, 1);
58 bullet_cat.error() <<
"invalid up axis:" << up << std::endl;
67 LVector3 BulletVehicle::
68 get_forward_vector()
const {
71 return btVector3_to_LVector3(_vehicle->getForwardVector());
81 btRigidBody *bodyPtr = _vehicle->getRigidBody();
99 PN_stdfloat BulletVehicle::
100 get_current_speed_km_hour()
const {
103 return (PN_stdfloat)_vehicle->getCurrentSpeedKmHour();
113 _vehicle->resetSuspension();
123 nassertr(idx < _vehicle->getNumWheels(), 0.0f);
124 return rad_2_deg(_vehicle->getSteeringValue(idx));
134 nassertv(idx < _vehicle->getNumWheels());
135 _vehicle->setSteeringValue(deg_2_rad(steering), idx);
145 nassertv(idx < _vehicle->getNumWheels());
146 _vehicle->applyEngineForce(force, idx);
156 nassertv(idx < _vehicle->getNumWheels());
157 _vehicle->setBrake(brake, idx);
164 set_pitch_control(PN_stdfloat pitch) {
167 _vehicle->setPitchControl(pitch);
177 btVector3 pos(0.0, 0.0, 0.0);
178 btVector3 direction = get_axis(_vehicle->getUpAxis());
179 btVector3 axle = get_axis(_vehicle->getRightAxis());
181 btScalar suspension(0.4);
182 btScalar radius(0.3);
184 btWheelInfo &info = _vehicle->addWheel(pos, direction, axle, suspension, radius, _tuning._,
false);
186 info.m_clientInfo =
nullptr;
194 btVector3 BulletVehicle::
199 return btVector3(1.0, 0.0, 0.0);
201 return btVector3(0.0, 1.0, 0.0);
203 return btVector3(0.0, 0.0, 1.0);
205 return btVector3(0.0, 0.0, 0.0);
213 get_num_wheels()
const {
216 return _vehicle->getNumWheels();
237 for (
int i=0; i < _vehicle->getNumWheels(); i++) {
238 btWheelInfo &info = _vehicle->getWheelInfo(i);
242 bool in_contact = info.m_raycastInfo.m_isInContact;
243 _vehicle->updateWheelTransform(i,
true);
244 info.m_raycastInfo.m_isInContact = in_contact;
249 CPT(
TransformState) ts = btTrans_to_TransformState(info.m_worldTransform);
264 void BulletVehicleTuning::
265 set_suspension_stiffness(PN_stdfloat value) {
268 _.m_suspensionStiffness = (btScalar)value;
274 void BulletVehicleTuning::
275 set_suspension_compression(PN_stdfloat value) {
278 _.m_suspensionCompression = (btScalar)value;
284 void BulletVehicleTuning::
285 set_suspension_damping(PN_stdfloat value) {
288 _.m_suspensionDamping = (btScalar)value;
294 void BulletVehicleTuning::
295 set_max_suspension_travel_cm(PN_stdfloat value) {
298 _.m_maxSuspensionTravelCm = (btScalar)value;
304 void BulletVehicleTuning::
305 set_friction_slip(PN_stdfloat value) {
308 _.m_frictionSlip = (btScalar)value;
314 void BulletVehicleTuning::
315 set_max_suspension_force(PN_stdfloat value) {
318 _.m_maxSuspensionForce = (btScalar)value;
324 PN_stdfloat BulletVehicleTuning::
325 get_suspension_stiffness()
const {
328 return (PN_stdfloat)_.m_suspensionStiffness;
334 PN_stdfloat BulletVehicleTuning::
335 get_suspension_compression()
const {
338 return (PN_stdfloat)_.m_suspensionCompression;
344 PN_stdfloat BulletVehicleTuning::
345 get_suspension_damping()
const {
348 return (PN_stdfloat)_.m_suspensionDamping;
354 PN_stdfloat BulletVehicleTuning::
355 get_max_suspension_travel_cm()
const {
358 return (PN_stdfloat)_.m_maxSuspensionTravelCm;
364 PN_stdfloat BulletVehicleTuning::
365 get_friction_slip()
const {
368 return (PN_stdfloat)_.m_frictionSlip;
374 PN_stdfloat BulletVehicleTuning::
375 get_max_suspension_force()
const {
378 return (PN_stdfloat)_.m_maxSuspensionForce;
void reset_suspension()
Resets the vehicle's suspension.
A basic node of the scene graph or data graph.
void set_coordinate_system(BulletUpAxis up)
Specifies which axis is "up".
get_wheel
Returns the BulletWheel with index idx.
BulletWheel create_wheel()
Factory method for creating wheels for this vehicle instance.
BulletVehicle(BulletWorld *world, BulletRigidBodyNode *chassis)
Creates a new BulletVehicle instance in the given world and with a chassis node.
static BulletWheel empty()
Named constructor intended to be used for asserts with have to return a concrete value.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Changes the complete transform object on this node.
static NodePath any_path(PandaNode *node, Thread *current_thread=Thread::get_current_thread())
Returns a new NodePath that represents any arbitrary path from the root to the indicated node.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Similar to MutexHolder, but for a light mutex.
BulletRigidBodyNode * do_get_chassis()
Returns the chassis of this vehicle.
void do_sync_b2p()
Assumes the lock(bullet global lock) is held by the caller.
void set_brake(PN_stdfloat brake, int idx)
Applies braking force to the wheel with index idx.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PN_stdfloat get_steering_value(int idx) const
Returns the steering angle of the wheel with index idx in degrees.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_steering_value(PN_stdfloat steering, int idx)
Sets the steering value (in degrees) of the wheel with index idx.
NodePath get_top(Thread *current_thread=Thread::get_current_thread()) const
Returns a singleton NodePath that represents the top of the path, or empty NodePath if this path is e...
void apply_engine_force(PN_stdfloat force, int idx)
Applies force at the wheel with index idx for acceleration.
TypeHandle is the identifier used to differentiate C++ class types.
One wheel of a BulletVehicle.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.