[Bf-blender-cvs] [5a6eccf] particles_refactor: Replaced the RBO_GET_MASS and RBO_GET_MARGIN macros with proper functions.

Lukas Tönne noreply at git.blender.org
Tue Apr 22 12:07:14 CEST 2014


Commit: 5a6eccfe435a26e056424f51ab304619fe6f4ee6
Author: Lukas Tönne
Date:   Tue Apr 1 18:21:52 2014 +0200
https://developer.blender.org/rB5a6eccfe435a26e056424f51ab304619fe6f4ee6

Replaced the RBO_GET_MASS and RBO_GET_MARGIN macros with proper
functions.

There is really no reason to use macros for this sort of thing.

===================================================================

M	source/blender/blenkernel/BKE_rigidbody.h
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenkernel/intern/rigidbody_objects.c
M	source/blender/makesrna/intern/rna_rigidbody.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index 7179cf6..46a835c 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -29,7 +29,6 @@
  *  \ingroup blenkernel
  *  \brief API for Blender-side Rigid Body stuff
  */
- 
 
 #ifndef __BKE_RIGIDBODY_H__
 #define __BKE_RIGIDBODY_H__
@@ -108,13 +107,11 @@ void BKE_rigidbody_free_constraint(struct Object *ob);
 struct RigidBodyCon *BKE_rigidbody_copy_constraint(struct Object *ob);
 void BKE_rigidbody_relink_constraint(struct RigidBodyCon *rbc);
 
-/* Utility Macros */
+/* Utilities */
 
 /* get mass of Rigid Body Object to supply to RigidBody simulators */
-#define RBO_GET_MASS(rbo) \
-	((rbo && ((rbo->type == RBO_TYPE_PASSIVE) || (rbo->flag & RBO_FLAG_KINEMATIC) || (rbo->flag & RBO_FLAG_DISABLED))) ? (0.0f) : (rbo->mass))
+float BKE_rigidbody_object_mass(struct RigidBodyOb *rbo);
 /* get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, convex hull always uses custom margin */
-#define RBO_GET_MARGIN(rbo) \
-	((rbo->flag & RBO_FLAG_USE_MARGIN || rbo->shape == RB_SHAPE_CONVEXH || rbo->shape == RB_SHAPE_TRIMESH || rbo->shape == RB_SHAPE_CONE) ? (rbo->margin) : (0.04f))
+float BKE_rigidbody_object_margin(struct RigidBodyOb *rbo);
 
 #endif /* __BKE_RIGIDBODY_H__ */
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 01a872f..d159f49 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -414,7 +414,7 @@ void BKE_rigidbody_validate_sim_shape(Object *ob, bool rebuild)
 		if (rbo->physics_shape)
 			RB_shape_delete(rbo->physics_shape);
 		rbo->physics_shape = new_shape;
-		RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo));
+		RB_shape_set_margin(rbo->physics_shape, BKE_rigidbody_object_margin(rbo));
 	}
 	/* use box shape if we can't fall back to old shape */
 	else if (rbo->physics_shape == NULL) {
diff --git a/source/blender/blenkernel/intern/rigidbody_objects.c b/source/blender/blenkernel/intern/rigidbody_objects.c
index b2d6773..a4c0741 100644
--- a/source/blender/blenkernel/intern/rigidbody_objects.c
+++ b/source/blender/blenkernel/intern/rigidbody_objects.c
@@ -81,7 +81,7 @@ static void rigidbody_sync_object(Scene *scene, RigidBodyWorld *rbw, Object *ob,
 	RB_body_set_scale(rbo->physics_object, scale);
 	/* compensate for embedded convex hull collision margin */
 	if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && rbo->shape == RB_SHAPE_CONVEXH)
-		RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo) * MIN3(scale[0], scale[1], scale[2]));
+		RB_shape_set_margin(rbo->physics_shape, BKE_rigidbody_object_margin(rbo) * MIN3(scale[0], scale[1], scale[2]));
 
 	/* make transformed objects temporarily kinmatic so that they can be moved by the user during simulation */
 	if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) {
@@ -185,7 +185,7 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool
 	                           (ob->protectflag & OB_LOCK_ROTY) == 0,
 	                           (ob->protectflag & OB_LOCK_ROTZ) == 0);
 	
-	RB_body_set_mass(body, RBO_GET_MASS(rbo));
+	RB_body_set_mass(body, BKE_rigidbody_object_mass(rbo));
 	RB_body_set_kinematic_state(body, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
 
 	if (rbw && rbw->physics_world)
@@ -472,7 +472,7 @@ static void rigidbody_world_apply_object(Scene *UNUSED(scene), Object *ob)
 	/* reset kinematic state for transformed objects */
 	if (rbo && (ob->flag & SELECT) && (G.moving & G_TRANSFORM_OBJ)) {
 		RB_body_set_kinematic_state(rbo->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
-		RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
+		RB_body_set_mass(rbo->physics_object, BKE_rigidbody_object_mass(rbo));
 		/* deactivate passive objects so they don't interfere with deactivation of active objects */
 		if (rbo->type == RBO_TYPE_PASSIVE)
 			RB_body_deactivate(rbo->physics_object);
@@ -837,3 +837,25 @@ void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc)
 	ID_NEW(rbc->ob1);
 	ID_NEW(rbc->ob2);
 }
+
+/* ------------------------ */
+/* Utilities */
+
+float BKE_rigidbody_object_mass(RigidBodyOb *rbo)
+{
+	if (!rbo)
+		return 0.0f;
+	if (rbo->type == RBO_TYPE_PASSIVE || rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED)
+		return 0.0f;
+	return rbo->mass;
+}
+
+float BKE_rigidbody_object_margin(RigidBodyOb *rbo)
+{
+	if (!rbo)
+		return 0.0f;
+	if (rbo->flag & RBO_FLAG_USE_MARGIN || ELEM3(rbo->shape, RB_SHAPE_CONVEXH, RB_SHAPE_TRIMESH, RB_SHAPE_CONE))
+		return rbo->margin;
+	else
+		return 0.04f;
+}
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index 78cd8d4..b517c83 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -192,7 +192,7 @@ static void rna_RigidBodyOb_disabled_set(PointerRNA *ptr, int value)
 #ifdef WITH_BULLET
 	/* update kinematic state if necessary - only needed for active bodies */
 	if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
-		RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
+		RB_body_set_mass(rbo->physics_object, BKE_rigidbody_object_mass(rbo));
 		RB_body_set_kinematic_state(rbo->physics_object, !value);
 		rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
 	}
@@ -208,7 +208,7 @@ static void rna_RigidBodyOb_mass_set(PointerRNA *ptr, float value)
 #ifdef WITH_BULLET
 	/* only active bodies need mass update */
 	if ((rbo->physics_object) && (rbo->type == RBO_TYPE_ACTIVE)) {
-		RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
+		RB_body_set_mass(rbo->physics_object, BKE_rigidbody_object_mass(rbo));
 	}
 #endif
 }
@@ -246,7 +246,7 @@ static void rna_RigidBodyOb_collision_margin_set(PointerRNA *ptr, float value)
 
 #ifdef WITH_BULLET
 	if (rbo->physics_shape) {
-		RB_shape_set_margin(rbo->physics_shape, RBO_GET_MARGIN(rbo));
+		RB_shape_set_margin(rbo->physics_shape, BKE_rigidbody_object_margin(rbo));
 	}
 #endif
 }
@@ -274,7 +274,7 @@ static void rna_RigidBodyOb_kinematic_state_set(PointerRNA *ptr, int value)
 #ifdef WITH_BULLET
 	/* update kinematic state if necessary */
 	if (rbo->physics_object) {
-		RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
+		RB_body_set_mass(rbo->physics_object, BKE_rigidbody_object_mass(rbo));
 		RB_body_set_kinematic_state(rbo->physics_object, value);
 		rbo->flag |= RBO_FLAG_NEEDS_VALIDATE;
 	}




More information about the Bf-blender-cvs mailing list