Revision: 46891 http://brlcad.svn.sourceforge.net/brlcad/?rev=46891&view=rev Author: abhi2011 Date: 2011-09-25 17:54:02 +0000 (Sun, 25 Sep 2011) Log Message: ----------- stepping the physics 1 step at a time now and persisting the velocities each time and rebuilding the dynamics world at the beginning of a new step
Modified Paths: -------------- brlcad/trunk/src/libged/simulate/simphysics.cpp brlcad/trunk/src/libged/simulate/simulate.c brlcad/trunk/src/libged/simulate/simulate.h Modified: brlcad/trunk/src/libged/simulate/simphysics.cpp =================================================================== --- brlcad/trunk/src/libged/simulate/simphysics.cpp 2011-09-25 17:31:54 UTC (rev 46890) +++ brlcad/trunk/src/libged/simulate/simphysics.cpp 2011-09-25 17:54:02 UTC (rev 46891) @@ -83,6 +83,7 @@ fastf_t volume; btScalar mass; btScalar m[16]; + btVector3 v; @@ -115,6 +116,7 @@ groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0)); btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI); groundRigidBody->setUserPointer((void *)current_node); + dynamicsWorld->addRigidBody(groundRigidBody); collision_shapes.push_back(groundShape); @@ -151,6 +153,13 @@ btRigidBody* bb_RigidBody = new btRigidBody(bb_RigidBodyCI); bb_RigidBody->setUserPointer((void *)current_node); + + VMOVE(v, current_node->linear_velocity); + bb_RigidBody->setLinearVelocity(v); + + VMOVE(v, current_node->angular_velocity); + bb_RigidBody->setAngularVelocity(v); + dynamicsWorld->addRigidBody(bb_RigidBody); bu_vls_printf(sim_params->result_str, "Added new rigid body : %s to simulation with mass %f Kg\n", @@ -169,18 +178,13 @@ */ int step_physics(btDiscreteDynamicsWorld* dynamicsWorld, struct simulation_params *sim_params) { - int i; bu_vls_printf(sim_params->result_str, "Simulation will run for %d steps.\n", sim_params->duration); bu_vls_printf(sim_params->result_str, "----- Starting simulation -----\n"); - for (i=0 ; i < sim_params->duration ; i++) { + //time step of 1/60th of a second(same as internal fixedTimeStep, maxSubSteps=10 to cover 1/60th sec.) + dynamicsWorld->stepSimulation(1/60.f,10); - //time step of 1/60th of a second(same as internal fixedTimeStep, maxSubSteps=10 to cover 1/60th sec.) - dynamicsWorld->stepSimulation(1/60.f,10); - } - bu_vls_printf(sim_params->result_str, "----- Simulation Complete -----\n"); - return 0; } @@ -193,7 +197,7 @@ { int i; btScalar m[16]; - btVector3 aabbMin, aabbMax; + btVector3 aabbMin, aabbMax, v; btTransform identity; identity.setIdentity(); @@ -239,19 +243,19 @@ // Get BB length, width, height VSUB2(current_node->btbb_dims, current_node->btbb_max, current_node->btbb_min); - /* current_node->btbb_dims[0] = current_node->btbb_max[0] - current_node->btbb_min[0]; - current_node->btbb_dims[1] = current_node->btbb_max[1] - current_node->btbb_min[1]; - current_node->btbb_dims[2] = current_node->btbb_max[2] - current_node->btbb_min[2];*/ bu_vls_printf(sim_params->result_str, "get_transforms: Dimensions of this BB : %f %f %f\n", current_node->btbb_dims[0], current_node->btbb_dims[1], current_node->btbb_dims[2]); //Get BB position in 3D space VCOMB2(current_node->btbb_center, 1, current_node->btbb_min, 0.5, current_node->btbb_dims) - /* current_node->btbb_center[0] = current_node->btbb_min[0] + current_node->btbb_dims[0]/2; - current_node->btbb_center[1] = current_node->btbb_min[1] + current_node->btbb_dims[1]/2; - current_node->btbb_center[2] = current_node->btbb_min[2] + current_node->btbb_dims[2]/2;*/ + v = bb_RigidBody->getLinearVelocity(); + VMOVE(current_node->linear_velocity, v); + + v = bb_RigidBody->getAngularVelocity(); + VMOVE(current_node->angular_velocity, v); + } } @@ -301,41 +305,46 @@ extern "C" int run_simulation(struct simulation_params *sim_params) { - // Initialize the physics world - btDiscreteDynamicsWorld* dynamicsWorld; + int i; - // Keep the collision shapes, for deletion/cleanup - btAlignedObjectArray<btCollisionShape*> collision_shapes; + for (i=0 ; i < sim_params->duration ; i++) { - btBroadphaseInterface* broadphase = new btDbvtBroadphase(); - btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); - btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); - btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; + // Initialize the physics world + btDiscreteDynamicsWorld* dynamicsWorld; - dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration); + // Keep the collision shapes, for deletion/cleanup + btAlignedObjectArray<btCollisionShape*> collision_shapes; - //Set the gravity direction along -ve Z axis - dynamicsWorld->setGravity(btVector3(0, 0, -10)); + btBroadphaseInterface* broadphase = new btDbvtBroadphase(); + btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); + btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); + btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; - //Add the rigid bodies to the world, including the ground plane - add_rigid_bodies(dynamicsWorld, sim_params, collision_shapes); + dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration); - //Step the physics the required number of times - step_physics(dynamicsWorld, sim_params); + //Set the gravity direction along -ve Z axis + dynamicsWorld->setGravity(btVector3(0, 0, -10)); - //Get the world transforms back into the simulation params struct - get_transforms(dynamicsWorld, sim_params); + //Add the rigid bodies to the world, including the ground plane + add_rigid_bodies(dynamicsWorld, sim_params, collision_shapes); - //Clean and free memory used by physics objects - cleanup(dynamicsWorld, collision_shapes); + //Step the physics the required number of times + step_physics(dynamicsWorld, sim_params); - //Clean up stuff in here - delete solver; - delete dispatcher; - delete collisionConfiguration; - delete broadphase; + //Get the world transforms back into the simulation params struct + get_transforms(dynamicsWorld, sim_params); + //Clean and free memory used by physics objects + cleanup(dynamicsWorld, collision_shapes); + //Clean up stuff in here + delete solver; + delete dispatcher; + delete collisionConfiguration; + delete broadphase; + } + + return 0; } Modified: brlcad/trunk/src/libged/simulate/simulate.c =================================================================== --- brlcad/trunk/src/libged/simulate/simulate.c 2011-09-25 17:31:54 UTC (rev 46890) +++ brlcad/trunk/src/libged/simulate/simulate.c 2011-09-25 17:54:02 UTC (rev 46891) @@ -263,6 +263,9 @@ current_node->m[13] = current_node->bb_center[1]; current_node->m[14] = current_node->bb_center[2]; + VSETALL(current_node->linear_velocity, 0.0f); + VSETALL(current_node->angular_velocity, 0.0f); + /* Setup the linked list */ if(prev_node == NULL){ /* first node */ prev_node = current_node; Modified: brlcad/trunk/src/libged/simulate/simulate.h =================================================================== --- brlcad/trunk/src/libged/simulate/simulate.h 2011-09-25 17:31:54 UTC (rev 46890) +++ brlcad/trunk/src/libged/simulate/simulate.h 2011-09-25 17:54:02 UTC (rev 46891) @@ -53,6 +53,11 @@ int state; /**< @brief rigid body state from Bullet */ struct directory *dp; /**< @brief directory pointer to the related region */ struct rigid_body *next; /**< @brief link to next body */ + + /* Can be set by libged or Bullet(checked and inserted into sim) */ + vect_t linear_velocity; /**< @brief linear velocity components */ + vect_t angular_velocity; /**< @brief angular velocity components */ + }; /* Contains the simulation parameters, such as number of rigid bodies, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2dcopy2 _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits