基于时间的渲染框架

下面是一个基于时间的渲染框架

ContractedBlock.gif ExpandedBlockStart.gif 代码
 1  //  Get last time
 2  static   float  lastTime  =  ( float )timeGetTime();
 3 
 4  while  (msg.message  !=  WM_QUIT)  
 5  {
 6       if ( PeekMessage( & msg, NULL,  0U 0U , PM_REMOVE)  !=   0 )
 7      {
 8          TranslateMessage ( & msg) ;
 9          DispatchMessage ( & msg) ;
10      }
11       else   //  Render the game if there is no message to process
12      {
13           //  Get current time
14           float  currTime   =  ( float )timeGetTime();
15 
16           //  Calculate time elapsed
17           float  timeDelta  =  (currTime  -  lastTime) * 0.001f ;
18 
19           //  Render
20          Render(timeDelta) ;
21 
22           //  Update last time to current time for next loop
23          lastTime  =  currTime;
24      }
25  }
26 

这样,在Render函数中就可以调用各种对象的渲染函数了,所有这些函数都有一个时间参数,用来求速度,加速度,位移等,比如粒子系统,摄像机,地形等等渲染

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值