diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 12 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_rigidbody_types.h | 15 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_rigidbody.c | 128 |
3 files changed, 153 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index c2fd6a9f54a..4c6bae122cd 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -633,6 +633,13 @@ void BKE_rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, shor else RB_constraint_set_limits_6dof(rbc->physics_constraint, RB_LIMIT_ANG_Z, 0.0f, -1.0f); break; + case RBC_TYPE_MOTOR: + rbc->physics_constraint = RB_constraint_new_motor(loc, rot, rb1, rb2); + + RB_constraint_set_enable_motor(rbc->physics_constraint, rbc->flag & RBC_FLAG_USE_MOTOR_LIN, rbc->flag & RBC_FLAG_USE_MOTOR_ANG); + RB_constraint_set_max_impulse_motor(rbc->physics_constraint, rbc->motor_lin_max_impulse, rbc->motor_ang_max_impulse); + RB_constraint_set_target_velocity_motor(rbc->physics_constraint, rbc->motor_lin_target_velocity, rbc->motor_ang_target_velocity); + break; } } else { /* can't create constraint without both rigid bodies */ @@ -816,6 +823,11 @@ RigidBodyCon *BKE_rigidbody_create_constraint(Scene *scene, Object *ob, short ty rbc->spring_stiffness_y = 10.0f; rbc->spring_stiffness_z = 10.0f; + rbc->motor_lin_max_impulse = 1.0f; + rbc->motor_lin_target_velocity = 1.0f; + rbc->motor_ang_max_impulse = 1.0f; + rbc->motor_ang_target_velocity = 1.0f; + /* flag cache as outdated */ BKE_rigidbody_cache_reset(rbw); diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h index 01a680e558a..c144bc4e588 100644 --- a/source/blender/makesdna/DNA_rigidbody_types.h +++ b/source/blender/makesdna/DNA_rigidbody_types.h @@ -221,6 +221,12 @@ typedef struct RigidBodyCon { float spring_damping_y; float spring_damping_z; + /* motor settings */ + float motor_lin_target_velocity; /* linear velocity the motor tries to hold */ + float motor_ang_target_velocity; /* angular velocity the motor tries to hold */ + float motor_lin_max_impulse; /* maximum force used to reach linear target velocity */ + float motor_ang_max_impulse; /* maximum force used to reach angular target velocity */ + /* References to Physics Sim object. Exist at runtime only */ void *physics_constraint; /* Physics object representation (i.e. btTypedConstraint) */ } RigidBodyCon; @@ -249,7 +255,9 @@ typedef enum eRigidBodyCon_Type { /* similar to slider but also allows rotation around slider axis */ RBC_TYPE_PISTON, /* Simplified spring constraint with only once axis that's automatically placed between the connected bodies */ - RBC_TYPE_SPRING + RBC_TYPE_SPRING, + /* dirves bodies by applying linear and angular forces */ + RBC_TYPE_MOTOR } eRigidBodyCon_Type; /* Flags for RigidBodyCon */ @@ -274,7 +282,10 @@ typedef enum eRigidBodyCon_Flag { /* springs */ RBC_FLAG_USE_SPRING_X = (1 << 11), RBC_FLAG_USE_SPRING_Y = (1 << 12), - RBC_FLAG_USE_SPRING_Z = (1 << 13) + RBC_FLAG_USE_SPRING_Z = (1 << 13), + /* motors */ + RBC_FLAG_USE_MOTOR_LIN = (1 << 14), + RBC_FLAG_USE_MOTOR_ANG = (1 << 15) } eRigidBodyCon_Flag; /* ******************************** */ diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c index 7270ccadb81..f5cf247b5a1 100644 --- a/source/blender/makesrna/intern/rna_rigidbody.c +++ b/source/blender/makesrna/intern/rna_rigidbody.c @@ -72,6 +72,7 @@ EnumPropertyItem rigidbody_con_type_items[] = { {RBC_TYPE_6DOF, "GENERIC", ICON_NONE, "Generic", "Restrict translation and rotation to specified axes"}, {RBC_TYPE_6DOF_SPRING, "GENERIC_SPRING", ICON_NONE, "Generic Spring", "Restrict translation and rotation to specified axes with springs"}, + {RBC_TYPE_MOTOR, "MOTOR", ICON_NONE, "Motor", "Drive rigid body around or along an axis"}, {0, NULL, 0, NULL, NULL}}; @@ -501,6 +502,85 @@ static void rna_RigidBodyCon_spring_damping_z_set(PointerRNA *ptr, float value) #endif } +static void rna_RigidBodyCon_motor_lin_max_impulse_set(PointerRNA *ptr, float value) +{ + RigidBodyCon *rbc = (RigidBodyCon *)ptr->data; + + rbc->motor_lin_max_impulse = value; + +#ifdef WITH_BULLET + if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) { + RB_constraint_set_max_impulse_motor(rbc->physics_constraint, value, rbc->motor_ang_max_impulse); + } +#endif +} + +static void rna_RigidBodyCon_use_motor_lin_set(PointerRNA *ptr, int value) +{ + RigidBodyCon *rbc = (RigidBodyCon *)ptr->data; + + RB_FLAG_SET(rbc->flag, value, RBC_FLAG_USE_MOTOR_LIN); + +#ifdef WITH_BULLET + if (rbc->physics_constraint) { + RB_constraint_set_enable_motor(rbc->physics_constraint, rbc->flag & RBC_FLAG_USE_MOTOR_LIN, rbc->flag & RBC_FLAG_USE_MOTOR_ANG); + } +#endif +} + +static void rna_RigidBodyCon_use_motor_ang_set(PointerRNA *ptr, int value) +{ + RigidBodyCon *rbc = (RigidBodyCon *)ptr->data; + + RB_FLAG_SET(rbc->flag, value, RBC_FLAG_USE_MOTOR_ANG); + +#ifdef WITH_BULLET + if (rbc->physics_constraint) { + RB_constraint_set_enable_motor(rbc->physics_constraint, rbc->flag & RBC_FLAG_USE_MOTOR_LIN, rbc->flag & RBC_FLAG_USE_MOTOR_ANG); + } +#endif +} + +static void rna_RigidBodyCon_motor_lin_target_velocity_set(PointerRNA *ptr, float value) +{ + RigidBodyCon *rbc = (RigidBodyCon *)ptr->data; + + rbc->motor_lin_target_velocity = value; + +#ifdef WITH_BULLET + if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) { + RB_constraint_set_target_velocity_motor(rbc->physics_constraint, value, rbc->motor_ang_target_velocity); + } +#endif +} + +static void rna_RigidBodyCon_motor_ang_max_impulse_set(PointerRNA *ptr, float value) +{ + RigidBodyCon *rbc = (RigidBodyCon *)ptr->data; + + rbc->motor_ang_max_impulse = value; + +#ifdef WITH_BULLET + if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) { + RB_constraint_set_max_impulse_motor(rbc->physics_constraint, rbc->motor_lin_max_impulse, value); + } +#endif +} + +static void rna_RigidBodyCon_motor_ang_target_velocity_set(PointerRNA *ptr, float value) +{ + RigidBodyCon *rbc = (RigidBodyCon *)ptr->data; + + rbc->motor_ang_target_velocity = value; + +#ifdef WITH_BULLET + if (rbc->physics_constraint && rbc->type == RBC_TYPE_MOTOR) { + RB_constraint_set_target_velocity_motor(rbc->physics_constraint, rbc->motor_lin_target_velocity, value); + } +#endif +} + + #else static void rna_def_rigidbody_world(BlenderRNA *brna) @@ -866,6 +946,18 @@ static void rna_def_rigidbody_constraint(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Z Spring", "Enable spring on Z axis"); RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); + prop = RNA_def_property(srna, "use_motor_lin", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_MOTOR_LIN); + RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_use_motor_lin_set"); + RNA_def_property_ui_text(prop, "Linear Motor", "Enables linear motor"); + RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); + + prop = RNA_def_property(srna, "use_motor_ang", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", RBC_FLAG_USE_MOTOR_ANG); + RNA_def_property_boolean_funcs(prop, NULL, "rna_RigidBodyCon_use_motor_ang_set"); + RNA_def_property_ui_text(prop, "Angular Motor", "Enables angular motor"); + RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); + prop = RNA_def_property(srna, "limit_lin_x_lower", PROP_FLOAT, PROP_UNIT_LENGTH); RNA_def_property_float_sdna(prop, NULL, "limit_lin_x_lower"); RNA_def_property_float_default(prop, -1.0f); @@ -994,6 +1086,42 @@ static void rna_def_rigidbody_constraint(BlenderRNA *brna) 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, "motor_lin_target_velocity", PROP_FLOAT, PROP_UNIT_VELOCITY); + RNA_def_property_float_sdna(prop, NULL, "motor_lin_target_velocity"); + RNA_def_property_range(prop, -FLT_MAX, FLT_MAX); + RNA_def_property_ui_range(prop, -100.0f, 100.0f, 1, 3); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_lin_target_velocity_set", NULL); + RNA_def_property_ui_text(prop, "Target Velocity", "Target linear motor velocity"); + RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); + + prop = RNA_def_property(srna, "motor_lin_max_impulse", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "motor_lin_max_impulse"); + RNA_def_property_range(prop, 0.0f, FLT_MAX); + RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_lin_max_impulse_set", NULL); + RNA_def_property_ui_text(prop, "Max Impulse", "Maximum linear motor impulse"); + RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); + + prop = RNA_def_property(srna, "motor_ang_target_velocity", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "motor_ang_target_velocity"); + RNA_def_property_range(prop, -FLT_MAX, FLT_MAX); + RNA_def_property_ui_range(prop, -100.0f, 100.0f, 1, 3); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_ang_target_velocity_set", NULL); + RNA_def_property_ui_text(prop, "Target Velocity", "Target angular motor velocity"); + RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); + + prop = RNA_def_property(srna, "motor_ang_max_impulse", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "motor_ang_max_impulse"); + RNA_def_property_range(prop, 0.0f, FLT_MAX); + RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_float_funcs(prop, NULL, "rna_RigidBodyCon_motor_ang_max_impulse_set", NULL); + RNA_def_property_ui_text(prop, "Max Impulse", "Maximum angular motor impulse"); + RNA_def_property_update(prop, NC_OBJECT, "rna_RigidBodyOb_reset"); } void RNA_def_rigidbody(BlenderRNA *brna) |