1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <iostream> #include <ode/ode.h> #define time_step (float)0.1 int main() { dWorldID myWorld_id; dBodyID mySphere_id; dMass sphereMass; const dReal *pos; float time = 0.0; /* Create a new world */ myWorld_id = dWorldCreate(); /* Create a sphere in the world */ mySphere_id = dBodyCreate( myWorld_id ); /* Set the world's global gravity vector (Mars) -- x,y,z */ dWorldSetGravity( myWorld_id, 0, 0, -3.77 ); /* Set the Sphere's position in the world -- x,y,z */ dBodySetPosition( mySphere_id, 0, 0, 100 ); /* Set the Sphere's mass (density, radius) */ dMassSetSphere( &sphereMass, 1, 2 ); dBodySetMass( mySphere_id, &sphereMass ); /* Give the sphere a small amount of upward (z) velocity */ dBodySetLinearVel( mySphere_id, 0.0, 0.0, 5.0 ); /* Run the simulation */ while (time < 5.0) { /* Simulate the world for the defined time-step */ dWorldStep( myWorld_id, time_step ); /* Get the current position of the sphere */ pos = dBodyGetPosition( mySphere_id ); std::cout << "position (" << pos[0] << ", " << pos[1] << ", " << pos[2] << ")\n"; /* Next time step */ time += time_step; } /* Destroy the objects */ dBodyDestroy( mySphere_id ); dWorldDestroy( myWorld_id ); return 0; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |