This sample gives us some basics information about Physical Simulations. Some terminologies like Mass, Force, acceleration, velocity, time, position and the relationships among them are described here.
For the simulation part, we need to use another delta time – simulation delta time instead of application delta time. The idea is that any given application delta time will be compared with the simulation threshold (the minimum delta time that could be acceptable), if the application delta time longer than this threshold, the application delta time will be separated into a several small delta time (the total value of those delta time will equal the application delta time), the code just like the following:
// milliseconds is the application delta time float dt = milliseconds / 1000.0f; float maxPossible_dt = 0.1f; int numOfIterations = (int)(dt / maxPossible_dt) + 1; // seperate into the simulation delta time if (numOfIterations != 0) dt = dt / numOfIterations; for (int a = 0; a < numOfIterations; ++a) { constantVelocity->operate(dt); motionUnderGravitation->operate(dt); massConnectedWithSpring->operate(dt); }
Then there are 3 different simulations provided:
1) moving with constant speed, no external force applied, no acceleration;
2) moving with the certain initial speed under the gravity, constant external force applied, constant acceleration;
3) moving with the spring model, various external force applied based on the distance, the acceleration also become vary as the distance changing.
When you set up the simulation model, one thing need to take special care is the unit choose. Make sure all element choose the correct and consistent unit.
The source code could be found here.
本文介绍了物理模拟的基本概念,如质量、力、加速度、速度、时间、位置及其相互关系。详细阐述了如何使用模拟时间步长进行物理模拟,而非应用时间步长,并提供了三种不同的物理场景模拟:匀速直线运动、重力作用下的匀加速直线运动和弹簧模型下的变加速运动。强调了在建立物理模型时选择一致单位的重要性。

201

被折叠的 条评论
为什么被折叠?



