diff options
Diffstat (limited to 'intern')
-rw-r--r-- | intern/rigidbody/RBI_api.h | 6 | ||||
-rw-r--r-- | intern/rigidbody/rb_bullet_api.cpp | 45 |
2 files changed, 51 insertions, 0 deletions
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h index 9dde2cc3049..e7c88d96873 100644 --- a/intern/rigidbody/RBI_api.h +++ b/intern/rigidbody/RBI_api.h @@ -257,6 +257,7 @@ extern rbConstraint *RB_constraint_new_slider(float pivot[3], float orn[4], rbRi extern rbConstraint *RB_constraint_new_piston(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2); extern rbConstraint *RB_constraint_new_6dof(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2); extern rbConstraint *RB_constraint_new_6dof_spring(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2); +extern rbConstraint *RB_constraint_new_motor(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2); /* ............ */ @@ -292,6 +293,11 @@ extern void RB_constraint_set_damping_6dof_spring(rbConstraint *con, int axis, f extern void RB_constraint_set_spring_6dof_spring(rbConstraint *con, int axis, int enable); extern void RB_constraint_set_equilibrium_6dof_spring(rbConstraint *con); +/* motors */ +extern void RB_constraint_set_enable_motor(rbConstraint *con, int enable_lin, int enable_ang); +extern void RB_constraint_set_max_impulse_motor(rbConstraint *con, float max_impulse_lin, float max_impulse_ang); +extern void RB_constraint_set_target_velocity_motor(rbConstraint *con, float velocity_lin, float velocity_ang); + /* Set number of constraint solver iterations made per step, this overrided world setting * To use default set it to -1 */ extern void RB_constraint_set_solver_iterations(rbConstraint *con, int num_solver_iterations); 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; +} + /* ********************************** */ |