NeHe OpenGL Lesson39 – Introduction to Physical Simulations

lesson39_screen_shot-300x246

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.

posted @   opencoder  阅读(161)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示