| 18 | } |
| 19 | |
| 20 | void BeadSlideConsole::Execute() |
| 21 | { |
| 22 | // Set up the physics module. |
| 23 | PhysicsModule module; |
| 24 | module.gravity = 1.0f; |
| 25 | module.mass = 0.1f; |
| 26 | |
| 27 | float time = 0.0f; |
| 28 | float deltaTime = 0.001f; |
| 29 | float q = 1.0f; |
| 30 | float qDot = 0.0f; |
| 31 | module.Initialize(time, deltaTime, q, qDot); |
| 32 | |
| 33 | // Run the simulation. |
| 34 | std::ofstream outFile("simulation.txt"); |
| 35 | outFile << "time q qder position" << std::endl; |
| 36 | int32_t const imax = 2500; |
| 37 | for (int32_t i = 0; i < imax; ++i) |
| 38 | { |
| 39 | float x = q, y = q * q, z = q * y; |
| 40 | |
| 41 | std::ostringstream message; |
| 42 | message << std::fixed << std::showpoint; |
| 43 | message << std::setw(5) << std::setprecision(3) << time << ' '; |
| 44 | message << std::showpos; |
| 45 | message << std::setw(12) << std::setprecision(8) << q << ' '; |
| 46 | message << std::setw(12) << std::setprecision(8) << qDot << ' '; |
| 47 | message << std::setw(8) << std::setprecision(4) << x << ' '; |
| 48 | message << std::setw(8) << std::setprecision(4) << y << ' '; |
| 49 | message << std::setw(8) << std::setprecision(4) << z; |
| 50 | outFile << message.str() << std::endl; |
| 51 | |
| 52 | module.Update(); |
| 53 | time = module.GetTime(); |
| 54 | q = module.GetQ(); |
| 55 | qDot = module.GetQDot(); |
| 56 | } |
| 57 | outFile.close(); |
| 58 | } |
| 59 | |
| 60 | |