From 00f2d43ec14dbf87232285772efca2efc71952d2 Mon Sep 17 00:00:00 2001 From: enn0x Date: Sat, 20 Aug 2011 21:22:03 +0000 Subject: [PATCH] More detailed limits for generic constraints. --- panda/src/bullet/bulletGenericConstraint.cxx | 94 +++++++++++++------- panda/src/bullet/bulletGenericConstraint.h | 10 ++- 2 files changed, 68 insertions(+), 36 deletions(-) diff --git a/panda/src/bullet/bulletGenericConstraint.cxx b/panda/src/bullet/bulletGenericConstraint.cxx index 01c6a4b5c9..46ca2fa72d 100644 --- a/panda/src/bullet/bulletGenericConstraint.cxx +++ b/panda/src/bullet/bulletGenericConstraint.cxx @@ -66,50 +66,80 @@ ptr() const { } //////////////////////////////////////////////////////////////////// -// Function: BulletGenericConstraint::set_lower_linear_limit +// Function: BulletGenericConstraint::get_axis +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +LVector3f BulletGenericConstraint:: +get_axis(int axis) const { + + nassertr(axis >= 0, LVector3f::zero()); + nassertr(axis <= 3, LVector3f::zero()); + + _constraint->buildJacobian(); + return btVector3_to_LVector3f(_constraint->getAxis(axis)); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletGenericConstraint::get_pivot +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float BulletGenericConstraint:: +get_pivot(int axis) const { + + nassertr(axis >= 0, 0.0f); + nassertr(axis <= 3, 0.0f); + + _constraint->buildJacobian(); + return _constraint->getRelativePivotPosition(axis); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletGenericConstraint::get_angle +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +float BulletGenericConstraint:: +get_angle(int axis) const { + + nassertr(axis >= 0, 0.0f); + nassertr(axis <= 3, 0.0f); + + _constraint->buildJacobian(); + return _constraint->getAngle(axis); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletGenericConstraint::set_linear_limit // Access: Published // Description: //////////////////////////////////////////////////////////////////// void BulletGenericConstraint:: -set_lower_linear_limit(const LPoint3f &limit) { +set_linear_limit(int axis, float low, float high) { - nassertv(!limit.is_nan()); - _constraint->setLinearLowerLimit(LVecBase3f_to_btVector3(limit)); + nassertv(axis >= 0); + nassertv(axis <= 3); + + _constraint->buildJacobian(); + _constraint->setLimit(axis, low, high); } //////////////////////////////////////////////////////////////////// -// Function: BulletGenericConstraint::set_upper_linear_limit +// Function: BulletGenericConstraint::set_angular_limit // Access: Published // Description: //////////////////////////////////////////////////////////////////// void BulletGenericConstraint:: -set_upper_linear_limit(const LPoint3f &limit) { +set_angular_limit(int axis, float low, float high) { - nassertv(!limit.is_nan()); - _constraint->setLinearUpperLimit(LVecBase3f_to_btVector3(limit)); -} - -//////////////////////////////////////////////////////////////////// -// Function: BulletGenericConstraint::set_lower_angular_limit -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -void BulletGenericConstraint:: -set_lower_angular_limit(const LVector3f &limit) { - - nassertv(!limit.is_nan()); - _constraint->setAngularLowerLimit(LVecBase3f_to_btVector3(limit)); -} - -//////////////////////////////////////////////////////////////////// -// Function: BulletGenericConstraint::set_upper_angular_limit -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -void BulletGenericConstraint:: -set_upper_angular_limit(const LVector3f &limit) { - - nassertv(!limit.is_nan()); - _constraint->setAngularUpperLimit(LVecBase3f_to_btVector3(limit)); + nassertv(axis >= 0); + nassertv(axis <= 3); + + low = deg_2_rad(low); + high = deg_2_rad(high); + + _constraint->buildJacobian(); + _constraint->setLimit(axis + 3, low, high); } diff --git a/panda/src/bullet/bulletGenericConstraint.h b/panda/src/bullet/bulletGenericConstraint.h index 6d72f42cca..3483791191 100644 --- a/panda/src/bullet/bulletGenericConstraint.h +++ b/panda/src/bullet/bulletGenericConstraint.h @@ -44,10 +44,12 @@ PUBLISHED: bool use_frame_a); INLINE ~BulletGenericConstraint(); - void set_lower_linear_limit(const LPoint3f &limit); - void set_upper_linear_limit(const LPoint3f &limit); - void set_lower_angular_limit(const LVector3f &limit); - void set_upper_angular_limit(const LVector3f &limit); + void set_linear_limit(int axis, float low, float high); + void set_angular_limit(int axis, float low, float high); + + LVector3f get_axis(int axis) const; + float get_pivot(int axis) const; + float get_angle(int axis) const; public: virtual btTypedConstraint *ptr() const;