diff options
author | Sergej Reich <sergej.reich@googlemail.com> | 2013-02-24 03:04:07 +0400 |
---|---|---|
committer | Sergej Reich <sergej.reich@googlemail.com> | 2013-02-24 03:04:07 +0400 |
commit | c82213359aa8bc2a762dc0a76c813d46c159a291 (patch) | |
tree | 312fc8aa5a246025d8d6d519b83c266d3a2b861a /intern/rigidbody/rb_bullet_api.cpp | |
parent | 47bd908e014412b4339ca4bca0a3556d9bd7fcd2 (diff) |
rigidbody: Add motor constraint
It's implemented as a separate constraint instead of adding properties
to the existing constraints.
Motors only apply linear and angular impulses and don't limit the
movement of rigid bodies, so it's best to use them in conjunction with
other constraints to limit the degrees of freedom.
Thanks to Markus Kasten (markus111) for the initial patch.
Diffstat (limited to 'intern/rigidbody/rb_bullet_api.cpp')
-rw-r--r-- | intern/rigidbody/rb_bullet_api.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp index 58345d4e08c..a628c35218c 100644 --- a/intern/rigidbody/rb_bullet_api.cpp +++ b/intern/rigidbody/rb_bullet_api.cpp @@ -850,6 +850,27 @@ rbConstraint *RB_constraint_new_6dof_spring(float pivot[3], float orn[4], rbRigi return (rbConstraint *)con; } +rbConstraint *RB_constraint_new_motor(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2) +{ + btRigidBody *body1 = rb1->body; + btRigidBody *body2 = rb2->body; + btTransform transform1; + btTransform transform2; + + make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn); + + btGeneric6DofConstraint *con = new btGeneric6DofConstraint(*body1, *body2, transform1, transform2, true); + + /* unlock constraint axes */ + for (int i = 0; i < 6; i++) { + con->setLimit(i, 0.0f, -1.0f); + } + /* unlock motor axes */ + con->getTranslationalLimitMotor()->m_upperLimit.setValue(-1.0f, -1.0f, -1.0f); + + return (rbConstraint*)con; +} + /* Cleanup ----------------------------- */ void RB_constraint_delete(rbConstraint *con) @@ -947,4 +968,28 @@ void RB_constraint_set_breaking_threshold(rbConstraint *con, float threshold) constraint->setBreakingImpulseThreshold(threshold); } +void RB_constraint_set_enable_motor(rbConstraint *con, int enable_lin, int enable_ang) +{ + btGeneric6DofConstraint *constraint = reinterpret_cast<btGeneric6DofConstraint*>(con); + + constraint->getTranslationalLimitMotor()->m_enableMotor[0] = enable_lin; + constraint->getRotationalLimitMotor(0)->m_enableMotor = enable_ang; +} + +void RB_constraint_set_max_impulse_motor(rbConstraint *con, float max_impulse_lin, float max_impulse_ang) +{ + btGeneric6DofConstraint *constraint = reinterpret_cast<btGeneric6DofConstraint*>(con); + + constraint->getTranslationalLimitMotor()->m_maxMotorForce.setX(max_impulse_lin); + constraint->getRotationalLimitMotor(0)->m_maxMotorForce = max_impulse_ang; +} + +void RB_constraint_set_target_velocity_motor(rbConstraint *con, float velocity_lin, float velocity_ang) +{ + btGeneric6DofConstraint *constraint = reinterpret_cast<btGeneric6DofConstraint*>(con); + + constraint->getTranslationalLimitMotor()->m_targetVelocity.setX(velocity_lin); + constraint->getRotationalLimitMotor(0)->m_targetVelocity = velocity_ang; +} + /* ********************************** */ |