30 btVector3 inertia(0, 0, 0);
33 btRigidBody::btRigidBodyConstructionInfo ci(mass, &_motion, _shape, inertia);
36 if (bullet_additional_damping) {
37 ci.m_additionalDamping =
true;
38 ci.m_additionalDampingFactor = bullet_additional_damping_linear_factor;
39 ci.m_additionalLinearDampingThresholdSqr = bullet_additional_damping_linear_threshold;
40 ci.m_additionalAngularDampingFactor = bullet_additional_damping_angular_factor;
41 ci.m_additionalAngularDampingThresholdSqr = bullet_additional_damping_angular_threshold;
45 _rigid =
new btRigidBody(ci);
46 _rigid->setUserPointer(
this);
59 _motion = copy._motion;
60 _rigid =
new btRigidBody(*copy._rigid);
61 _rigid->setUserPointer(
this);
62 _rigid->setCollisionShape(_shape);
63 _rigid->setMotionState(&_motion);
80 void BulletRigidBodyNode::
81 output(std::ostream &out)
const {
84 BulletBodyNode::do_output(out);
86 out <<
" mass=" << do_get_mass();
92 btCollisionObject *BulletRigidBodyNode::
103 void BulletRigidBodyNode::
106 do_set_mass(do_get_mass());
107 do_transform_changed();
117 void BulletRigidBodyNode::
118 do_set_mass(PN_stdfloat mass) {
120 btScalar bt_mass = mass;
121 btVector3 bt_inertia(0.0, 0.0, 0.0);
124 _rigid->getCollisionShape()->calculateLocalInertia(bt_mass, bt_inertia);
127 _rigid->setMassProps(bt_mass, bt_inertia);
128 _rigid->updateInertiaTensor();
149 PN_stdfloat BulletRigidBodyNode::
150 do_get_mass()
const {
152 btScalar inv_mass = _rigid->getInvMass();
153 btScalar mass = (inv_mass == btScalar(0.0)) ? btScalar(0.0) : btScalar(1.0) / inv_mass;
162 PN_stdfloat BulletRigidBodyNode::
166 return do_get_mass();
173 PN_stdfloat BulletRigidBodyNode::
174 get_inv_mass()
const {
177 return (PN_stdfloat)_rigid->getInvMass();
194 btVector3 inv_inertia(
195 inertia.get_x() == 0.0 ? btScalar(0.0) : btScalar(1.0 / inertia.get_x()),
196 inertia.get_y() == 0.0 ? btScalar(0.0) : btScalar(1.0 / inertia.get_y()),
197 inertia.get_z() == 0.0 ? btScalar(0.0) : btScalar(1.0 / inertia.get_z())
200 _rigid->setInvInertiaDiagLocal(inv_inertia);
201 _rigid->updateInertiaTensor();
209 LVector3 BulletRigidBodyNode::
210 get_inertia()
const {
213 btVector3 inv_inertia = _rigid->getInvInertiaDiagLocal();
215 inv_inertia.x() == btScalar(0.0) ? 0.0 : 1.0 / inv_inertia.x(),
216 inv_inertia.y() == btScalar(0.0) ? 0.0 : 1.0 / inv_inertia.y(),
217 inv_inertia.z() == btScalar(0.0) ? 0.0 : 1.0 / inv_inertia.z()
226 LVector3 BulletRigidBodyNode::
227 get_inv_inertia_diag_local()
const {
230 return btVector3_to_LVector3(_rigid->getInvInertiaDiagLocal());
236 LMatrix3 BulletRigidBodyNode::
237 get_inv_inertia_tensor_world()
const {
240 return btMatrix3x3_to_LMatrix3(_rigid->getInvInertiaTensorWorld());
246 void BulletRigidBodyNode::
247 apply_force(
const LVector3 &force,
const LPoint3 &pos) {
250 nassertv_always(!force.is_nan());
251 nassertv_always(!pos.is_nan());
253 _rigid->applyForce(LVecBase3_to_btVector3(force),
254 LVecBase3_to_btVector3(pos));
260 void BulletRigidBodyNode::
261 apply_central_force(
const LVector3 &force) {
264 nassertv_always(!force.is_nan());
266 _rigid->applyCentralForce(LVecBase3_to_btVector3(force));
272 void BulletRigidBodyNode::
273 apply_torque(
const LVector3 &torque) {
276 nassertv_always(!torque.is_nan());
278 _rigid->applyTorque(LVecBase3_to_btVector3(torque));
284 void BulletRigidBodyNode::
285 apply_torque_impulse(
const LVector3 &torque) {
288 nassertv_always(!torque.is_nan());
290 _rigid->applyTorqueImpulse(LVecBase3_to_btVector3(torque));
296 void BulletRigidBodyNode::
297 apply_impulse(
const LVector3 &impulse,
const LPoint3 &pos) {
300 nassertv_always(!impulse.is_nan());
301 nassertv_always(!pos.is_nan());
303 _rigid->applyImpulse(LVecBase3_to_btVector3(impulse),
304 LVecBase3_to_btVector3(pos));
310 void BulletRigidBodyNode::
311 apply_central_impulse(
const LVector3 &impulse) {
314 nassertv_always(!impulse.is_nan());
316 _rigid->applyCentralImpulse(LVecBase3_to_btVector3(impulse));
322 void BulletRigidBodyNode::
323 do_transform_changed() {
325 if (_motion.sync_disabled())
return;
335 _motion.set_net_transform(ts);
338 if (!(get_object()->isKinematicObject())) {
339 btTransform trans = TransformState_to_btTrans(ts);
340 _rigid->setCenterOfMassTransform(trans);
345 if (ts->has_scale()) {
346 btVector3 new_scale = LVecBase3_to_btVector3(ts->get_scale());
347 btVector3 current_scale = _shape->getLocalScaling();
348 btVector3 current_scale_inv(1.0/current_scale.x(), 1.0/current_scale.y(), 1.0/current_scale.z());
350 if (new_scale != current_scale) {
351 _shape->setLocalScaling(current_scale_inv);
352 _shape->setLocalScaling(new_scale);
357 if (!_rigid->isActive()) {
358 _rigid->activate(
true);
365 void BulletRigidBodyNode::
366 transform_changed() {
368 if (_motion.sync_disabled())
return;
372 do_transform_changed();
381 if (get_object()->isKinematicObject()) {
382 do_transform_changed();
398 LVector3 BulletRigidBodyNode::
399 get_linear_velocity()
const {
402 return btVector3_to_LVector3(_rigid->getLinearVelocity());
408 LVector3 BulletRigidBodyNode::
409 get_angular_velocity()
const {
412 return btVector3_to_LVector3(_rigid->getAngularVelocity());
418 void BulletRigidBodyNode::
419 set_linear_velocity(
const LVector3 &velocity) {
422 nassertv_always(!velocity.is_nan());
424 _rigid->setLinearVelocity(LVecBase3_to_btVector3(velocity));
430 void BulletRigidBodyNode::
431 set_angular_velocity(
const LVector3 &velocity) {
434 nassertv_always(!velocity.is_nan());
436 _rigid->setAngularVelocity(LVecBase3_to_btVector3(velocity));
442 void BulletRigidBodyNode::
443 set_linear_damping(PN_stdfloat value) {
446 _rigid->setDamping(value, _rigid->getAngularDamping());
452 void BulletRigidBodyNode::
453 set_angular_damping(PN_stdfloat value) {
456 _rigid->setDamping(_rigid->getLinearDamping(), value);
462 PN_stdfloat BulletRigidBodyNode::
463 get_linear_damping()
const {
466 return (PN_stdfloat)_rigid->getLinearDamping();
472 PN_stdfloat BulletRigidBodyNode::
473 get_angular_damping()
const {
476 return (PN_stdfloat)_rigid->getAngularDamping();
482 void BulletRigidBodyNode::
486 _rigid->clearForces();
492 PN_stdfloat BulletRigidBodyNode::
493 get_linear_sleep_threshold()
const {
496 return _rigid->getLinearSleepingThreshold();
502 PN_stdfloat BulletRigidBodyNode::
503 get_angular_sleep_threshold()
const {
506 return _rigid->getAngularSleepingThreshold();
512 void BulletRigidBodyNode::
513 set_linear_sleep_threshold(PN_stdfloat threshold) {
516 _rigid->setSleepingThresholds(threshold, _rigid->getAngularSleepingThreshold());
522 void BulletRigidBodyNode::
523 set_angular_sleep_threshold(PN_stdfloat threshold) {
526 _rigid->setSleepingThresholds(_rigid->getLinearSleepingThreshold(), threshold);
532 void BulletRigidBodyNode::
533 set_gravity(
const LVector3 &gravity) {
536 nassertv_always(!gravity.is_nan());
538 _rigid->setGravity(LVecBase3_to_btVector3(gravity));
544 LVector3 BulletRigidBodyNode::
545 get_gravity()
const {
548 return btVector3_to_LVector3(_rigid->getGravity());
554 LVector3 BulletRigidBodyNode::
555 get_linear_factor()
const {
558 return btVector3_to_LVector3(_rigid->getLinearFactor());
564 LVector3 BulletRigidBodyNode::
565 get_angular_factor()
const {
568 return btVector3_to_LVector3(_rigid->getAngularFactor());
574 void BulletRigidBodyNode::
575 set_linear_factor(
const LVector3 &factor) {
578 _rigid->setLinearFactor(LVecBase3_to_btVector3(factor));
584 void BulletRigidBodyNode::
585 set_angular_factor(
const LVector3 &factor) {
588 _rigid->setAngularFactor(LVecBase3_to_btVector3(factor));
594 LVector3 BulletRigidBodyNode::
595 get_total_force()
const {
598 return btVector3_to_LVector3(_rigid->getTotalForce());
604 LVector3 BulletRigidBodyNode::
605 get_total_torque()
const {
608 return btVector3_to_LVector3(_rigid->getTotalTorque());
614 BulletRigidBodyNode::MotionState::
617 _trans.setIdentity();
626 void BulletRigidBodyNode::MotionState::
627 getWorldTransform(btTransform &trans)
const {
635 void BulletRigidBodyNode::MotionState::
636 setWorldTransform(
const btTransform &trans) {
646 void BulletRigidBodyNode::MotionState::
652 LPoint3 p = btVector3_to_LPoint3(_trans.getOrigin());
653 LQuaternion q = btQuat_to_LQuaternion(_trans.getRotation());
669 void BulletRigidBodyNode::MotionState::
674 _trans = TransformState_to_btTrans(ts);
680 bool BulletRigidBodyNode::MotionState::
681 sync_disabled()
const {
689 bool BulletRigidBodyNode::MotionState::
692 bool rc = _was_dirty;
704 return _motion.pick_dirty_flag();
728 get_gravity().write_datagram(dg);
729 get_linear_factor().write_datagram(dg);
730 get_angular_factor().write_datagram(dg);
732 get_linear_velocity().write_datagram(dg);
733 get_angular_velocity().write_datagram(dg);
748 param->fillin(scan, manager);
757 void BulletRigidBodyNode::
759 BulletBodyNode::fillin(scan, manager);
767 LVector3 gravity, linear_factor, angular_factor;
768 gravity.read_datagram(scan);
769 linear_factor.read_datagram(scan);
770 angular_factor.read_datagram(scan);
772 set_gravity(gravity);
773 set_linear_factor(linear_factor);
774 set_angular_factor(angular_factor);
void do_sync_b2p()
Assumes the lock(bullet global lock) is held by the caller.
A basic node of the scene graph or data graph.
get_mass
Returns the total mass of a rigid body.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Base class for objects that can be written to and read from Bam files.
void do_sync_p2b()
Assumes the lock(bullet global lock) is held by the caller.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
void set_pos_quat(const LVecBase3 &pos, const LQuaternion &quat)
Sets the translation and rotation component of the transform, leaving scale untouched.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
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.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Similar to MutexHolder, but for a light mutex.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_inertia
Sets the inertia of a rigid body.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
set_mass
Sets the mass of a rigid body.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
bool pick_dirty_flag()
Returns TRUE if the transform of the rigid body has changed at least once since the last call to this...
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletRigidBodyNode.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.