Revision: 29895
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29895
Author:   aligorith
Date:     2010-07-03 11:10:56 +0200 (Sat, 03 Jul 2010)

Log Message:
-----------
Bullet SoC - Exposing some more collision parameters:

* 'Bounciness' of object - this is known in Bullet terms as 'Restitution' 
(http://en.wikipedia.org/wiki/Coefficient_of_restitution). However, since I had 
to look this up to understand it, I'm guessing that choosing a more common name 
may be more suitable.

* Collision Margin - threshold for sensitivity of collision detection. This 
should be left on its default value for spheres.

Modified Paths:
--------------
    
branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
    branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
    branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
    branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
    branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h
    branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp

Modified: 
branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
===================================================================
--- 
branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
    2010-07-03 09:06:09 UTC (rev 29894)
+++ 
branches/soc-2010-aligorith-2/release/scripts/ui/properties_physics_rigidbody.py
    2010-07-03 09:10:56 UTC (rev 29895)
@@ -54,7 +54,7 @@
             split.prop(rbo, "type", text="")
 
             if wide_ui:
-                split = layout.split(percentage=0.2)
+                split = layout.split(percentage=0.3)
                 split.label(text="Collision Shape:")
             else:
                 split = layout.split()
@@ -65,6 +65,8 @@
             col = split.column()
             col.prop(rbo, "mass")
             col.prop(rbo, "friction")
+            col.prop(rbo, "bounciness")
+            col.prop(rbo, "collision_margin")
             
 
 

Modified: 
branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c  
2010-07-03 09:06:09 UTC (rev 29894)
+++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c  
2010-07-03 09:10:56 UTC (rev 29895)
@@ -352,8 +352,12 @@
        rbo->type = type;
        
        rbo->mass = 1.0f;
+       
        rbo->friction = 0.5f; // best when non-zero. 0.5 is Bullet default
+       rbo->bounciness = 0.0f; // best when zero. 0.0 is Bullet default
        
+       rbo->margin = 0.04; // 0.04 (in meters) is Bullet default
+       
        rbo->shape = get_shape_from_boundbox(ob);
        
        /* return this object */

Modified: 
branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h 
2010-07-03 09:06:09 UTC (rev 29894)
+++ branches/soc-2010-aligorith-2/source/blender/makesdna/DNA_rigidbody_types.h 
2010-07-03 09:10:56 UTC (rev 29895)
@@ -101,8 +101,12 @@
        int flag;                               /* (eRigidBodyOb_Flag) */
        
        /* Physics Parameters */
-       float mass;                             
-       float friction;
+       float mass;                             /* how much object 'weighs' 
(i.e. absolute 'amount of stuff' it holds) */
+       
+       float friction;                 /* resistance of object to movement */
+       float bounciness;               /* how 'bouncy' object is when it 
collides. also known as restitution */
+       
+       float margin;                   /* tolerance for detecting collisions 
*/ 
 } RigidBodyOb;
 
 

Modified: 
branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c
===================================================================
--- 
branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c    
    2010-07-03 09:06:09 UTC (rev 29894)
+++ 
branches/soc-2010-aligorith-2/source/blender/makesrna/intern/rna_rigidbody.c    
    2010-07-03 09:10:56 UTC (rev 29895)
@@ -119,6 +119,11 @@
        /* set new shape type */
        rbo->shape = value;
        
+       /* hack: collision margin for sphere's should not be altered from the 
default, 
+        * so reset it to Bullet's default 
+        */
+       rbo->margin = 0.04;
+       
        /* force creation of new collision shape reflecting this */
        BKE_rigidbody_validate_sim_shape(ob, 1);
        
@@ -146,9 +151,42 @@
        
        /* need to update the RigidBody's copy as well as the stored value too 
*/
        rbo->friction = value;
-       rbBodySetFriction(rbo->physics_object, value);
+       
+       if (rbo->physics_object)
+               rbBodySetFriction(rbo->physics_object, value);
 }
 
+static void rna_RigidBodyOb_bounciness_set(PointerRNA *ptr, float value)
+{
+       RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+       
+       /* need to update the RigidBody's copy as well as the stored value too 
*/
+       rbo->bounciness = value;
+       
+       if (rbo->physics_object)
+               rbBodySetRestitution(rbo->physics_object, value);
+}
+
+static int rna_RigidBodyOb_collision_margin_editable(PointerRNA *ptr)
+{
+       RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+       
+       /* collision margin is useless for spheres, so shouldn't be editable 
there */
+       // TODO: should we reset it too?
+       return (rbo->shape != RB_SHAPE_SPHERE);
+}
+
+static void rna_RigidBodyOb_collision_margin_set(PointerRNA *ptr, float value)
+{
+       RigidBodyOb *rbo = (RigidBodyOb *)ptr->data;
+       
+       /* need to update the RigidBody's copy as well as the stored value too 
*/
+       rbo->margin = value;
+       
+       if (rbo->physics_shape)
+               rbShapeSetMargin(rbo->physics_shape, value);
+}
+
 #else
 
 static void rna_def_rigidbody_world(BlenderRNA *brna)
@@ -244,6 +282,21 @@
        RNA_def_property_ui_text(prop, "Friction", "Resistance of object to 
movement");
        // TODO: setup necessary updates for this setting
        
+       prop= RNA_def_property(srna, "bounciness", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "bounciness");
+       RNA_def_property_range(prop, 0.0, 1.0); // XXX: this needs checking
+       RNA_def_property_float_funcs(prop, NULL, 
"rna_RigidBodyOb_bounciness_set", NULL);
+       RNA_def_property_ui_text(prop, "Bounciness", "How likely object is to 
bounce after colliding with another (0 = stays still, 1 = perfectly elastic)");
+       // TODO: setup necessary updates for this setting
+       
+       prop= RNA_def_property(srna, "collision_margin", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "margin");
+       //RNA_def_property_range(prop, FLT_MIN, FLT_MAX); // XXX: this needs 
checking
+       RNA_def_property_editable_func(prop, 
"rna_RigidBodyOb_collision_margin_editable");
+       RNA_def_property_float_funcs(prop, NULL, 
"rna_RigidBodyOb_collision_margin_set", NULL);
+       RNA_def_property_ui_text(prop, "Collision Margin", "Threshold of 
distance near surface where collisions are still considered (best results when 
non-zero)");
+       // TODO: setup necessary updates for this setting
+       
        // TODO:
        //      - expose rest of settings relevant to sim ob
 }

Modified: branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h    
2010-07-03 09:06:09 UTC (rev 29894)
+++ branches/soc-2010-aligorith-2/source/blender/rigidbody/RBI_api.h    
2010-07-03 09:10:56 UTC (rev 29895)
@@ -107,6 +107,12 @@
 
 /* Settings ------------------------- */
 
+/* 'Type' */
+// XXX: experimental call - sets mass and other flags correctly
+extern void rbBodySetType(rbRigidBody *body, int type, float mass);
+
+/* ............ */
+
 /* Collision Shape */
 extern rbCollisionShape *rbBodyGetCollisionShape(rbRigidBody *body);
 extern void rbBodySetCollisionShape(rbRigidBody *body, rbCollisionShape 
*cshape);
@@ -121,8 +127,7 @@
 extern float rbBodyGetFriction(rbRigidBody *body);
 extern void rbBodySetFriction(rbRigidBody *body, float value);
 
-/* Restitution */
-// XXX: what the hell is this?!
+/* Restitution (aka 'Bounciness') */
 extern float rbBodyGetRestitution(rbRigidBody *body);
 extern void rbBodySetRestitution(rbRigidBody *body, float value);
 
@@ -189,8 +194,8 @@
 
 /* Settings --------------------------- */
 
-// TODO:
-//     - collision margin?
+extern float rbShapeGetMargin(rbCollisionShape *cshape);
+extern void rbShapeSetMargin(rbCollisionShape *cshape, float value);
 
 /* ********************************** */
 

Modified: 
branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp
===================================================================
--- branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp    
2010-07-03 09:06:09 UTC (rev 29894)
+++ branches/soc-2010-aligorith-2/source/blender/rigidbody/rb_bullet_api.cpp    
2010-07-03 09:10:56 UTC (rev 29895)
@@ -469,4 +469,18 @@
        btAlignedFree(shape);
 }
 
+/* Settings --------------------------- */
+
+float rbShapeGetMargin(rbCollisionShape *cshape)
+{
+       btCollisionShape *shape = reinterpret_cast<btCollisionShape*>(cshape);
+       return shape->getMargin();
+}
+
+void rbShapeSetMargin(rbCollisionShape *cshape, float value)
+{
+       btCollisionShape *shape = reinterpret_cast<btCollisionShape*>(cshape);
+       shape->setMargin(value);
+}
+
 /* ********************************** */


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to