From 0ee060aefd238027d3eebfa9fd8a8853c6c5fc0b Mon Sep 17 00:00:00 2001 From: enn0x Date: Sun, 16 Jun 2013 06:43:38 +0000 Subject: [PATCH] Added missing methods for modifying Bullet constraint frames. --- panda/src/bullet/bulletBodyNode.cxx | 7 ++---- panda/src/bullet/bulletBodyNode.h | 2 +- panda/src/bullet/bulletConeTwistConstraint.I | 22 +++++++++++++++++++ .../src/bullet/bulletConeTwistConstraint.cxx | 20 ++++++++++++++--- panda/src/bullet/bulletConeTwistConstraint.h | 10 ++++++--- panda/src/bullet/bulletConvexHullShape.cxx | 2 +- panda/src/bullet/bulletConvexHullShape.h | 2 +- panda/src/bullet/bulletGenericConstraint.I | 22 +++++++++++++++++++ panda/src/bullet/bulletGenericConstraint.cxx | 20 ++++++++++++++--- panda/src/bullet/bulletGenericConstraint.h | 11 +++++++--- panda/src/bullet/bulletHingeConstraint.I | 22 +++++++++++++++++++ panda/src/bullet/bulletHingeConstraint.cxx | 14 ++++++++++++ panda/src/bullet/bulletHingeConstraint.h | 4 ++++ panda/src/bullet/bulletRigidBodyNode.cxx | 2 +- panda/src/bullet/bulletRigidBodyNode.h | 2 +- panda/src/bullet/bulletSliderConstraint.I | 22 +++++++++++++++++++ panda/src/bullet/bulletSliderConstraint.cxx | 20 ++++++++++++++--- panda/src/bullet/bulletSliderConstraint.h | 11 +++++++--- panda/src/bullet/bulletSphericalConstraint.h | 2 +- panda/src/bullet/bulletTriangleMesh.cxx | 2 +- panda/src/bullet/bulletTriangleMesh.h | 2 +- 21 files changed, 190 insertions(+), 31 deletions(-) diff --git a/panda/src/bullet/bulletBodyNode.cxx b/panda/src/bullet/bulletBodyNode.cxx index ca7beb7dc4..8b8060b07e 100644 --- a/panda/src/bullet/bulletBodyNode.cxx +++ b/panda/src/bullet/bulletBodyNode.cxx @@ -165,7 +165,7 @@ output(ostream &out) const { // Description: //////////////////////////////////////////////////////////////////// void BulletBodyNode:: -add_shape(BulletShape *shape, CPT(TransformState) ts) { +add_shape(BulletShape *shape, const TransformState *ts) { nassertv(get_object()); @@ -173,10 +173,7 @@ add_shape(BulletShape *shape, CPT(TransformState) ts) { && ((btConvexHullShape *)shape->ptr())->getNumVertices() == 0)); // Transform - btTransform trans = btTransform::getIdentity(); - if (ts) { - trans = TransformState_to_btTrans(ts); - } + btTransform trans = TransformState_to_btTrans(ts); // Reset the shape scaling before we add a shape, and remember the current // Scale so we can restore it later... diff --git a/panda/src/bullet/bulletBodyNode.h b/panda/src/bullet/bulletBodyNode.h index 7d2c6134e9..c5be54eb47 100644 --- a/panda/src/bullet/bulletBodyNode.h +++ b/panda/src/bullet/bulletBodyNode.h @@ -38,7 +38,7 @@ PUBLISHED: INLINE ~BulletBodyNode(); // Shapes - void add_shape(BulletShape *shape, CPT(TransformState) xform=NULL); + void add_shape(BulletShape *shape, const TransformState *xform=TransformState::make_identity()); void remove_shape(BulletShape *shape); INLINE int get_num_shapes() const; diff --git a/panda/src/bullet/bulletConeTwistConstraint.I b/panda/src/bullet/bulletConeTwistConstraint.I index 05bab00710..b8a5a66dae 100644 --- a/panda/src/bullet/bulletConeTwistConstraint.I +++ b/panda/src/bullet/bulletConeTwistConstraint.I @@ -23,3 +23,25 @@ INLINE BulletConeTwistConstraint:: delete _constraint; } +//////////////////////////////////////////////////////////////////// +// Function: BulletConeTwistConstraint::get_frame_a +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletConeTwistConstraint:: +get_frame_a() const { + + return btTrans_to_TransformState(_constraint->getAFrame()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletConeTwistConstraint::get_frame_b +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletConeTwistConstraint:: +get_frame_b() const { + + return btTrans_to_TransformState(_constraint->getBFrame()); +} + diff --git a/panda/src/bullet/bulletConeTwistConstraint.cxx b/panda/src/bullet/bulletConeTwistConstraint.cxx index b3c5eea376..2908dcbb87 100644 --- a/panda/src/bullet/bulletConeTwistConstraint.cxx +++ b/panda/src/bullet/bulletConeTwistConstraint.cxx @@ -26,7 +26,7 @@ TypeHandle BulletConeTwistConstraint::_type_handle; //////////////////////////////////////////////////////////////////// BulletConeTwistConstraint:: BulletConeTwistConstraint(const BulletRigidBodyNode *node_a, - CPT(TransformState) frame_a) { + const TransformState *frame_a) { btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object()); btTransform trans_a = TransformState_to_btTrans(frame_a); @@ -42,8 +42,8 @@ BulletConeTwistConstraint(const BulletRigidBodyNode *node_a, BulletConeTwistConstraint:: BulletConeTwistConstraint(const BulletRigidBodyNode *node_a, const BulletRigidBodyNode *node_b, - CPT(TransformState) frame_a, - CPT(TransformState) frame_b) { + const TransformState *frame_a, + const TransformState *frame_b) { btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object()); btTransform trans_a = TransformState_to_btTrans(frame_a); @@ -181,3 +181,17 @@ set_motor_target_in_constraint_space(const LQuaternion &quat) { _constraint->setMotorTargetInConstraintSpace(LQuaternion_to_btQuat(quat)); } +//////////////////////////////////////////////////////////////////// +// Function: BulletConeTwistConstraint::set_frames +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void BulletConeTwistConstraint:: +set_frames(const TransformState *ts_a, const TransformState *ts_b) { + + btTransform frame_a = TransformState_to_btTrans(ts_a); + btTransform frame_b = TransformState_to_btTrans(ts_b); + + _constraint->setFrames(frame_a, frame_b); +} + diff --git a/panda/src/bullet/bulletConeTwistConstraint.h b/panda/src/bullet/bulletConeTwistConstraint.h index 9c1397efa8..5894e63241 100644 --- a/panda/src/bullet/bulletConeTwistConstraint.h +++ b/panda/src/bullet/bulletConeTwistConstraint.h @@ -33,11 +33,11 @@ class EXPCL_PANDABULLET BulletConeTwistConstraint : public BulletConstraint { PUBLISHED: BulletConeTwistConstraint(const BulletRigidBodyNode *node_a, - CPT(TransformState) frame_a); + const TransformState *frame_a); BulletConeTwistConstraint(const BulletRigidBodyNode *node_a, const BulletRigidBodyNode *node_b, - CPT(TransformState) frame_a, - CPT(TransformState) frame_b); + const TransformState *frame_a, + const TransformState *frame_b); INLINE ~BulletConeTwistConstraint(); void set_limit(int index, PN_stdfloat value); @@ -54,6 +54,10 @@ PUBLISHED: void set_motor_target(const LQuaternion &quat); void set_motor_target_in_constraint_space(const LQuaternion &quat); + void set_frames(const TransformState *ts_a, const TransformState *ts_b); + INLINE CPT(TransformState) get_frame_a() const; + INLINE CPT(TransformState) get_frame_b() const; + public: virtual btTypedConstraint *ptr() const; diff --git a/panda/src/bullet/bulletConvexHullShape.cxx b/panda/src/bullet/bulletConvexHullShape.cxx index 28c4dbeab0..016c0b24f6 100644 --- a/panda/src/bullet/bulletConvexHullShape.cxx +++ b/panda/src/bullet/bulletConvexHullShape.cxx @@ -78,7 +78,7 @@ add_array(const PTA_LVecBase3 &points) { // Description: //////////////////////////////////////////////////////////////////// void BulletConvexHullShape:: -add_geom(const Geom *geom, CPT(TransformState) ts) { +add_geom(const Geom *geom, const TransformState *ts) { nassertv(geom); nassertv(ts); diff --git a/panda/src/bullet/bulletConvexHullShape.h b/panda/src/bullet/bulletConvexHullShape.h index dc133d81fc..a46a8c5cee 100644 --- a/panda/src/bullet/bulletConvexHullShape.h +++ b/panda/src/bullet/bulletConvexHullShape.h @@ -39,7 +39,7 @@ PUBLISHED: void add_point(const LPoint3 &p); void add_array(const PTA_LVecBase3 &points); void add_geom(const Geom *geom, - CPT(TransformState) ts=TransformState::make_identity()); + const TransformState *ts=TransformState::make_identity()); public: virtual btCollisionShape *ptr() const; diff --git a/panda/src/bullet/bulletGenericConstraint.I b/panda/src/bullet/bulletGenericConstraint.I index 55b5f396c2..80c20e4b7b 100644 --- a/panda/src/bullet/bulletGenericConstraint.I +++ b/panda/src/bullet/bulletGenericConstraint.I @@ -23,3 +23,25 @@ INLINE BulletGenericConstraint:: delete _constraint; } +//////////////////////////////////////////////////////////////////// +// Function: BulletGenericConstraint::get_frame_a +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletGenericConstraint:: +get_frame_a() const { + + return btTrans_to_TransformState(_constraint->getFrameOffsetA()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletGenericConstraint::get_frame_b +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletGenericConstraint:: +get_frame_b() const { + + return btTrans_to_TransformState(_constraint->getFrameOffsetB()); +} + diff --git a/panda/src/bullet/bulletGenericConstraint.cxx b/panda/src/bullet/bulletGenericConstraint.cxx index 6a16f6484c..04b7757202 100644 --- a/panda/src/bullet/bulletGenericConstraint.cxx +++ b/panda/src/bullet/bulletGenericConstraint.cxx @@ -24,7 +24,7 @@ TypeHandle BulletGenericConstraint::_type_handle; //////////////////////////////////////////////////////////////////// BulletGenericConstraint:: BulletGenericConstraint(const BulletRigidBodyNode *node_a, - CPT(TransformState) frame_a, + const TransformState *frame_a, bool use_frame_a) { btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object()); @@ -41,8 +41,8 @@ BulletGenericConstraint(const BulletRigidBodyNode *node_a, BulletGenericConstraint:: BulletGenericConstraint(const BulletRigidBodyNode *node_a, const BulletRigidBodyNode *node_b, - CPT(TransformState) frame_a, - CPT(TransformState) frame_b, + const TransformState *frame_a, + const TransformState *frame_b, bool use_frame_a) { btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object()); @@ -165,3 +165,17 @@ get_translational_limit_motor() { return BulletTranslationalLimitMotor(*_constraint->getTranslationalLimitMotor()); } +//////////////////////////////////////////////////////////////////// +// Function: BulletGenericConstraint::set_frames +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void BulletGenericConstraint:: +set_frames(const TransformState *ts_a, const TransformState *ts_b) { + + btTransform frame_a = TransformState_to_btTrans(ts_a); + btTransform frame_b = TransformState_to_btTrans(ts_b); + + _constraint->setFrames(frame_a, frame_b); +} + diff --git a/panda/src/bullet/bulletGenericConstraint.h b/panda/src/bullet/bulletGenericConstraint.h index 79c4213730..98bf3bce36 100644 --- a/panda/src/bullet/bulletGenericConstraint.h +++ b/panda/src/bullet/bulletGenericConstraint.h @@ -36,12 +36,12 @@ class EXPCL_PANDABULLET BulletGenericConstraint : public BulletConstraint { PUBLISHED: BulletGenericConstraint(const BulletRigidBodyNode *node_a, - CPT(TransformState) frame_a, + const TransformState *frame_a, bool use_frame_a); BulletGenericConstraint(const BulletRigidBodyNode *node_a, const BulletRigidBodyNode *node_b, - CPT(TransformState) frame_a, - CPT(TransformState) frame_b, + const TransformState *frame_a, + const TransformState *frame_b, bool use_frame_a); INLINE ~BulletGenericConstraint(); @@ -58,6 +58,11 @@ PUBLISHED: BulletRotationalLimitMotor get_rotational_limit_motor(int axis); BulletTranslationalLimitMotor get_translational_limit_motor(); + // Frames + void set_frames(const TransformState *ts_a, const TransformState *ts_b); + INLINE CPT(TransformState) get_frame_a() const; + INLINE CPT(TransformState) get_frame_b() const; + public: virtual btTypedConstraint *ptr() const; diff --git a/panda/src/bullet/bulletHingeConstraint.I b/panda/src/bullet/bulletHingeConstraint.I index 473c050963..9609f421a0 100644 --- a/panda/src/bullet/bulletHingeConstraint.I +++ b/panda/src/bullet/bulletHingeConstraint.I @@ -23,3 +23,25 @@ INLINE BulletHingeConstraint:: delete _constraint; } +//////////////////////////////////////////////////////////////////// +// Function: BulletHingeConstraint::get_frame_a +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletHingeConstraint:: +get_frame_a() const { + + return btTrans_to_TransformState(_constraint->getAFrame()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletHingeConstraint::get_frame_b +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletHingeConstraint:: +get_frame_b() const { + + return btTrans_to_TransformState(_constraint->getBFrame()); +} + diff --git a/panda/src/bullet/bulletHingeConstraint.cxx b/panda/src/bullet/bulletHingeConstraint.cxx index 7f3dbb1a46..c9a369eca7 100644 --- a/panda/src/bullet/bulletHingeConstraint.cxx +++ b/panda/src/bullet/bulletHingeConstraint.cxx @@ -267,3 +267,17 @@ set_motor_target(PN_stdfloat target_angle, PN_stdfloat dt) { _constraint->setMotorTarget(target_angle, dt); } +//////////////////////////////////////////////////////////////////// +// Function: BulletHingeConstraint::set_frames +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void BulletHingeConstraint:: +set_frames(const TransformState *ts_a, const TransformState *ts_b) { + + btTransform frame_a = TransformState_to_btTrans(ts_a); + btTransform frame_b = TransformState_to_btTrans(ts_b); + + _constraint->setFrames(frame_a, frame_b); +} + diff --git a/panda/src/bullet/bulletHingeConstraint.h b/panda/src/bullet/bulletHingeConstraint.h index c116212db9..8036e3cb14 100644 --- a/panda/src/bullet/bulletHingeConstraint.h +++ b/panda/src/bullet/bulletHingeConstraint.h @@ -72,6 +72,10 @@ PUBLISHED: void set_motor_target(const LQuaternion &quat, PN_stdfloat dt); void set_motor_target(PN_stdfloat target_angle, PN_stdfloat dt); + void set_frames(const TransformState *ts_a, const TransformState *ts_b); + INLINE CPT(TransformState) get_frame_a() const; + INLINE CPT(TransformState) get_frame_b() const; + public: virtual btTypedConstraint *ptr() const; diff --git a/panda/src/bullet/bulletRigidBodyNode.cxx b/panda/src/bullet/bulletRigidBodyNode.cxx index 37326b2cc9..c101a3b00c 100644 --- a/panda/src/bullet/bulletRigidBodyNode.cxx +++ b/panda/src/bullet/bulletRigidBodyNode.cxx @@ -606,7 +606,7 @@ sync_b2p(PandaNode *node) { // by calling MotionState::setGlobalTransform. //////////////////////////////////////////////////////////////////// void BulletRigidBodyNode::MotionState:: -set_net_transform(CPT(TransformState) &ts) { +set_net_transform(const TransformState *ts) { nassertv(ts); diff --git a/panda/src/bullet/bulletRigidBodyNode.h b/panda/src/bullet/bulletRigidBodyNode.h index 3689c5735f..05538f67cf 100644 --- a/panda/src/bullet/bulletRigidBodyNode.h +++ b/panda/src/bullet/bulletRigidBodyNode.h @@ -110,7 +110,7 @@ private: virtual void getWorldTransform(btTransform &trans) const; virtual void setWorldTransform(const btTransform &trans); - void set_net_transform(CPT(TransformState) &ts); + void set_net_transform(const TransformState *ts); void sync_b2p(PandaNode *node); bool sync_disabled() const; diff --git a/panda/src/bullet/bulletSliderConstraint.I b/panda/src/bullet/bulletSliderConstraint.I index 64eeb0ef21..9dcbfcee69 100644 --- a/panda/src/bullet/bulletSliderConstraint.I +++ b/panda/src/bullet/bulletSliderConstraint.I @@ -23,3 +23,25 @@ INLINE BulletSliderConstraint:: delete _constraint; } +//////////////////////////////////////////////////////////////////// +// Function: BulletSliderConstraint::get_frame_a +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletSliderConstraint:: +get_frame_a() const { + + return btTrans_to_TransformState(_constraint->getFrameOffsetA()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletSliderConstraint::get_frame_b +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletSliderConstraint:: +get_frame_b() const { + + return btTrans_to_TransformState(_constraint->getFrameOffsetB()); +} + diff --git a/panda/src/bullet/bulletSliderConstraint.cxx b/panda/src/bullet/bulletSliderConstraint.cxx index 0345acdb96..19cf3ab911 100644 --- a/panda/src/bullet/bulletSliderConstraint.cxx +++ b/panda/src/bullet/bulletSliderConstraint.cxx @@ -26,7 +26,7 @@ TypeHandle BulletSliderConstraint::_type_handle; //////////////////////////////////////////////////////////////////// BulletSliderConstraint:: BulletSliderConstraint(const BulletRigidBodyNode *node_a, - CPT(TransformState) frame_a, + const TransformState *frame_a, bool use_frame_a) { btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object()); @@ -43,8 +43,8 @@ BulletSliderConstraint(const BulletRigidBodyNode *node_a, BulletSliderConstraint:: BulletSliderConstraint(const BulletRigidBodyNode *node_a, const BulletRigidBodyNode *node_b, - CPT(TransformState) frame_a, - CPT(TransformState) frame_b, + const TransformState *frame_a, + const TransformState *frame_b, bool use_frame_a) { btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object()); @@ -309,3 +309,17 @@ get_max_angular_motor_force() const { return (PN_stdfloat)_constraint->getMaxAngMotorForce(); } +//////////////////////////////////////////////////////////////////// +// Function: BulletSliderConstraint::set_frames +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void BulletSliderConstraint:: +set_frames(const TransformState *ts_a, const TransformState *ts_b) { + + btTransform frame_a = TransformState_to_btTrans(ts_a); + btTransform frame_b = TransformState_to_btTrans(ts_b); + + _constraint->setFrames(frame_a, frame_b); +} + diff --git a/panda/src/bullet/bulletSliderConstraint.h b/panda/src/bullet/bulletSliderConstraint.h index 7f3c173019..395c2535e2 100644 --- a/panda/src/bullet/bulletSliderConstraint.h +++ b/panda/src/bullet/bulletSliderConstraint.h @@ -33,12 +33,12 @@ class EXPCL_PANDABULLET BulletSliderConstraint : public BulletConstraint { PUBLISHED: BulletSliderConstraint(const BulletRigidBodyNode *node_a, - CPT(TransformState) frame_a, + const TransformState *frame_a, bool useFrame_a); BulletSliderConstraint(const BulletRigidBodyNode *node_a, const BulletRigidBodyNode *node_b, - CPT(TransformState) frame_a, - CPT(TransformState) frame_b, + const TransformState *frame_a, + const TransformState *frame_b, bool use_frame_a); INLINE ~BulletSliderConstraint(); @@ -71,6 +71,11 @@ PUBLISHED: PN_stdfloat get_target_angular_motor_velocity() const; PN_stdfloat get_max_angular_motor_force() const; + // Frames + void set_frames(const TransformState *ts_a, const TransformState *ts_b); + INLINE CPT(TransformState) get_frame_a() const; + INLINE CPT(TransformState) get_frame_b() const; + public: virtual btTypedConstraint *ptr() const; diff --git a/panda/src/bullet/bulletSphericalConstraint.h b/panda/src/bullet/bulletSphericalConstraint.h index addf143644..d56735d8de 100644 --- a/panda/src/bullet/bulletSphericalConstraint.h +++ b/panda/src/bullet/bulletSphericalConstraint.h @@ -46,9 +46,9 @@ PUBLISHED: const LPoint3 &pivot_b); INLINE ~BulletSphericalConstraint(); + // Pivots void set_pivot_a(const LPoint3 &pivot_a); void set_pivot_b(const LPoint3 &pivot_b); - LPoint3 get_pivot_in_a() const; LPoint3 get_pivot_in_b() const; diff --git a/panda/src/bullet/bulletTriangleMesh.cxx b/panda/src/bullet/bulletTriangleMesh.cxx index 854d414c57..928c728677 100644 --- a/panda/src/bullet/bulletTriangleMesh.cxx +++ b/panda/src/bullet/bulletTriangleMesh.cxx @@ -101,7 +101,7 @@ get_welding_distance() const { // Description: //////////////////////////////////////////////////////////////////// void BulletTriangleMesh:: -add_geom(const Geom *geom, bool remove_duplicate_vertices, CPT(TransformState) ts) { +add_geom(const Geom *geom, bool remove_duplicate_vertices, const TransformState *ts) { nassertv(geom); nassertv(ts); diff --git a/panda/src/bullet/bulletTriangleMesh.h b/panda/src/bullet/bulletTriangleMesh.h index ca9ddc2cde..6e6caf7188 100644 --- a/panda/src/bullet/bulletTriangleMesh.h +++ b/panda/src/bullet/bulletTriangleMesh.h @@ -46,7 +46,7 @@ PUBLISHED: bool remove_duplicate_vertices=false); void add_geom(const Geom *geom, bool remove_duplicate_vertices=false, - CPT(TransformState) ts=TransformState::make_identity()); + const TransformState *ts=TransformState::make_identity()); void set_welding_distance(PN_stdfloat distance); void preallocate(int num_verts, int num_indices);