Axiom3D学习日记 5.Frame Listeners, and Input Handling

Frame Listeners

In Ogre's C++, we would register a class to receive notification before and after a frame is rendered to the screen. Such a class is known as a Frame Listener. In Axiom this behavior has been translated to .NET events. This means that using frame listeners is silghtly different in Axiom compared to Ogre. In Ogre it is necessary to register a whole class as a frame listener (observer pattern) and implement several methods for all the events described below. In Axiom on the other hand we just use events and we register single methods only to the events we are interested in.

(废话一堆,意思就是Orge用一个类监听Frame渲染,Axiom中使用C#的event委托方式监听)

Frame Events

捞干的就这些:

FrameStarted
渲染之前调用的事件
FrameRenderingQueued
在 viewport 渲染之后, 在渲染窗口交换缓冲区之前
FrameEnded
在窗口渲染之后


监听事件:

Root.Instance.FrameStarted += new EventHandler<FrameEventArgs>(Instance_FrameStarted);

Input Handling

请允许我以如此偷懒方式记录键盘监听处理方法,对于我来说,这样就很足够,看不懂朋友不要介意.

void HandleKeyboardInput(FrameEventArgs e)
        {
 input.Capture();

           if (input.IsKeyPressed(Input.KeyCodes.I))
           {
               translateVector.z -= 1;
           }
} void Instance_FrameStarted(object sender, FrameEventArgs e) { HandleKeyboardInput(e); } public override void CreateScene() { Root.Instance.FrameStarted += new EventHandler<FrameEventArgs>(Instance_FrameStarted); }

Mouse

上面是键盘,下面是鼠标:

void HandleMouseInput(FrameEventArgs e)
       {
          input.RelativeMouseX * e.TimeSinceLastFrame
       }
       void Instance_FrameStarted(object sender, FrameEventArgs e)
       {
           HandleKeyboardInput(e);
           HandleMouseInput(e);
       }
简单易懂,无需多说.

 

转载于:https://www.cnblogs.com/niconico/p/5009351.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值