Revision: 31156 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31156 Author: aligorith Date: 2010-08-08 06:21:58 +0200 (Sun, 08 Aug 2010)
Log Message: ----------- Bullet SoC - Fix for bug when no effectors were present in the scene Gravity (on the y-axis) was being applied to objects, on top of the normal z-axis gravity. Thus objects were moving diagonally. Now, we check for effectors, and make sure that force is initialised before tring to calculate effectors. Modified Paths: -------------- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c Modified: branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c =================================================================== --- branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-08-08 04:19:06 UTC (rev 31155) +++ branches/soc-2010-aligorith-2/source/blender/blenkernel/intern/rigidbody.c 2010-08-08 04:21:58 UTC (rev 31156) @@ -587,27 +587,31 @@ if ((ob->pd == NULL) || (ob->pd->forcefield == PFIELD_NULL)) { EffectorWeights *effector_weights = rbw->effector_weights; EffectedPoint epoint; - ListBase *effectors = pdInitEffectors(scene, ob, NULL, effector_weights); - float loc[3], vel[3]; - float force[3]; + ListBase *effectors; - /* create dummy 'point' which represents last known position of object as result of sim */ -#if 0 // XXX: this is the 'safe' version (using object info), but really should try grabbing from sim for better responses? - VECCOPY(loc, ob->obmat[3]); - vel[0]=vel[1]=vel[2]= 1.0f; -#else // XXX: this can create some inaccuracies with sim position, but is probably better than using unsimulated vals? - rbBodyGetPosition(rbo->physics_object, loc); - rbBodyGetLinearVelocity(rbo->physics_object, vel); -#endif - pd_point_from_loc(scene, loc, vel, 0, &epoint); + /* get effectors present in the group specified by effector_weights */ + effectors = pdInitEffectors(scene, ob, NULL, effector_weights); + if (effectors) { + float force[3] = {0.0f, 0.0f, 0.0f}; + float loc[3], vel[3]; + + /* create dummy 'point' which represents last known position of object as result of sim */ + // XXX: this can create some inaccuracies with sim position, but is probably better than using unsimulated vals? + rbBodyGetPosition(rbo->physics_object, loc); + rbBodyGetLinearVelocity(rbo->physics_object, vel); + + pd_point_from_loc(scene, loc, vel, 0, &epoint); + + /* calculate net force of effectors, and apply to sim object + * - we use 'central force' since apply force requires a "relative position" which we don't have... + */ + pdDoEffectors(effectors, NULL, effector_weights, &epoint, force, NULL); + printf("\tapplying force (%f,%f,%f) to '%s'\n", force[0],force[1],force[2],ob->id.name+2); + rbBodyApplyCentralForce(rbo->physics_object, force); + } + else + printf("\tno forces to apply to '%s'\n", ob->id.name+2); - /* calculate net force of effectors, and apply to sim object - * - we use 'central force' since apply force requires a "relative position" which we don't have... - */ - pdDoEffectors(effectors, NULL, effector_weights, &epoint, force, NULL); - printf("\tapplying force (%f,%f,%f) to '%s'\n", force[0],force[1],force[2],ob->id.name+2); - rbBodyApplyCentralForce(rbo->physics_object, force); - /* cleanup */ pdEndEffectors(&effectors); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs