NeHe OpenGL Lesson39 – Introduction to Physical Simulations

本文介绍了物理模拟的基本概念,如质量、力、加速度、速度、时间、位置及其相互关系。详细阐述了如何使用模拟时间步长进行物理模拟,而非应用时间步长,并提供了三种不同的物理场景模拟:匀速直线运动、重力作用下的匀加速直线运动和弹簧模型下的变加速运动。强调了在建立物理模型时选择一致单位的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

转载于:https://www.cnblogs.com/open-coder/archive/2012/08/23/2651808.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值