diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2018-03-31 12:08:16 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2018-04-09 19:14:35 +0300 |
commit | 26a283deae7a3b78a197d4bcf4bfd288c598aedc (patch) | |
tree | e6c38423101f5c63b8476a96e26b3be391fedd58 /source/blender | |
parent | 7e39d151d850590fbabc9870bc5134d9421c5c2c (diff) |
Use the newer version of the bullet 6dof spring constraint for rigidbody.
The new constraint is slower and not backward compatible, but should
be better, especially in the damping side. The new constraint also
has a different valid range of the damping coefficient, and a limit
implementation that bounces instead of making the object stationary.
Reviewers: sergof
Differential Revision: https://developer.blender.org/D3125
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 70 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_rigidbody.c | 24 |
2 files changed, 50 insertions, 44 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index c10f54a99eb..b8873cca0fb 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -700,6 +700,39 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool /* --------------------- */ +static void rigidbody_constraint_set_limits(RigidBodyCon *rbc, void (*set_limits)(rbConstraint*,int,float,float)) +{ + if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_X) + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->limit_lin_x_lower, rbc->limit_lin_x_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_X, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Y) + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Y, rbc->limit_lin_y_lower, rbc->limit_lin_y_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Y, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Z) + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->limit_lin_z_lower, rbc->limit_lin_z_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_LIN_Z, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_X) + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_X, rbc->limit_ang_x_lower, rbc->limit_ang_x_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_X, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Y) + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Y, rbc->limit_ang_y_lower, rbc->limit_ang_y_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Y, 0.0f, -1.0f); + + if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Z) + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Z, rbc->limit_ang_z_lower, rbc->limit_ang_z_upper); + else + set_limits(rbc->physics_constraint, RB_LIMIT_ANG_Z, 0.0f, -1.0f); +} + /** * Create physics sim representation of constraint given rigid body constraint settings * @@ -818,40 +851,13 @@ static void rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, b RB_constraint_set_damping_6dof_spring(rbc->physics_constraint, RB_LIMIT_ANG_Z, rbc->spring_damping_ang_z); RB_constraint_set_equilibrium_6dof_spring(rbc->physics_constraint); - ATTR_FALLTHROUGH; - case RBC_TYPE_6DOF: - if (rbc->type == RBC_TYPE_6DOF) /* a litte awkward but avoids duplicate code for limits */ - rbc->physics_constraint = RB_constraint_new_6dof(loc, rot, rb1, rb2); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_X) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_X, rbc->limit_lin_x_lower, rbc->limit_lin_x_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_X, 0.0f, -1.0f); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Y) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Y, rbc->limit_lin_y_lower, rbc->limit_lin_y_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Y, 0.0f, -1.0f); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_LIN_Z) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Z, rbc->limit_lin_z_lower, rbc->limit_lin_z_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_LIN_Z, 0.0f, -1.0f); - - if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_X) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_X, rbc->limit_ang_x_lower, rbc->limit_ang_x_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_X, 0.0f, -1.0f); - if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Y) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Y, rbc->limit_ang_y_lower, rbc->limit_ang_y_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Y, 0.0f, -1.0f); + rigidbody_constraint_set_limits(rbc, RB_constraint_set_limits_6dof_spring); + break; + case RBC_TYPE_6DOF: + rbc->physics_constraint = RB_constraint_new_6dof(loc, rot, rb1, rb2); - if (rbc->flag & RBC_FLAG_USE_LIMIT_ANG_Z) - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Z, rbc->limit_ang_z_lower, rbc->limit_ang_z_upper); - else - RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Z, 0.0f, -1.0f); + rigidbody_constraint_set_limits(rbc, RB_constraint_set_limits_6dof); break; case RBC_TYPE_MOTOR: rbc->physics_constraint = RB_constraint_new_motor(loc, rot, rb1, rb2); diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c index 188200eaff9..4c3301d5f9e 100644 --- a/source/blender/makesrna/intern/rna_rigidbody.c +++ b/source/blender/makesrna/intern/rna_rigidbody.c @@ -1293,49 +1293,49 @@ static void rna_def_rigidbody_constraint(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Z Angle Stiffness", "Stiffness on the Z rotational axis"); RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); - prop = RNA_def_property(srna, "spring_damping_x", PROP_FLOAT, PROP_FACTOR); + prop = RNA_def_property(srna, "spring_damping_x", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "spring_damping_x"); - RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_float_default(prop, 0.5f); RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_x_set", NULL); RNA_def_property_ui_text(prop, "Damping X", "Damping on the X axis"); RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); - prop = RNA_def_property(srna, "spring_damping_y", PROP_FLOAT, PROP_FACTOR); + prop = RNA_def_property(srna, "spring_damping_y", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "spring_damping_y"); - RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_float_default(prop, 0.5f); RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_y_set", NULL); RNA_def_property_ui_text(prop, "Damping Y", "Damping on the Y axis"); RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); - prop = RNA_def_property(srna, "spring_damping_z", PROP_FLOAT, PROP_FACTOR); + prop = RNA_def_property(srna, "spring_damping_z", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "spring_damping_z"); - RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_float_default(prop, 0.5f); RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_z_set", NULL); RNA_def_property_ui_text(prop, "Damping Z", "Damping on the Z axis"); RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); - prop = RNA_def_property(srna, "spring_damping_ang_x", PROP_FLOAT, PROP_FACTOR); + prop = RNA_def_property(srna, "spring_damping_ang_x", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "spring_damping_ang_x"); - RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_float_default(prop, 0.5f); RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_ang_x_set", NULL); RNA_def_property_ui_text(prop, "Damping X Angle", "Damping on the X rotational axis"); RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); - prop = RNA_def_property(srna, "spring_damping_ang_y", PROP_FLOAT, PROP_FACTOR); + prop = RNA_def_property(srna, "spring_damping_ang_y", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "spring_damping_ang_y"); - RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_float_default(prop, 0.5f); RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_ang_y_set", NULL); RNA_def_property_ui_text(prop, "Damping Y Angle", "Damping on the Y rotational axis"); RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); - prop = RNA_def_property(srna, "spring_damping_ang_z", PROP_FLOAT, PROP_FACTOR); + prop = RNA_def_property(srna, "spring_damping_ang_z", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "spring_damping_ang_z"); - RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_float_default(prop, 0.5f); RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_spring_damping_ang_z_set", NULL); RNA_def_property_ui_text(prop, "Damping Z Angle", "Damping on the Z rotational axis"); |