Does IrrlichtLime contain IEventReceiver?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Does IrrlichtLime contain IEventReceiver?

Post by Skatebone »

Hey guys,

Im using vb.net (IrrlichtLime) and I need to rotate the camera whenever the user presses the arrow keys.

My problem is that I cannot find anywhere the IEventReciever class to handle the events..

these are my declarations: (maybe I am missing something here?)

Code: Select all

Imports System
Imports IrrlichtLime
Imports IrrlichtLime.Core
Imports IrrlichtLime.Video
Imports IrrlichtLime.Scene
Imports IrrlichtLime.GUI
Also device.OnEvent = new irrlichtDevice.eventhandler(Address of....) i think should be the way to do it but OnEvent is missing? (totally mixed up here)

Thanks alot,
Dave
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Does IrrlichtLime contain IEventReceiver?

Post by greenya »

In VB.NET you can handle events next way:

Code: Select all

    Sub Main()
        Dim device ...
        ' ...
        AddHandler device.OnEvent, AddressOf device_OnEvent
        ' ...
    End Sub
 
    Function device_OnEvent(evnt As IrrlichtLime.Event) As Boolean
         ' ...event handling goes here...
         Return False
    End Function
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: Does IrrlichtLime contain IEventReceiver?

Post by Skatebone »

Thanks alot green. Keep up the great work! :))
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: Does IrrlichtLime contain IEventReceiver?

Post by Skatebone »

Sorry to disturb again but I still have a problem when pressing two or more keys at a time.

I need to store all the keys in an array like in c++ and check each key so if lets say i press the top and right arrow keys together the camera moves to the top right. But i cannot find e.key.key.count or something like that which can give me the number of keys so as to check if they are pressed or not.

My code:

Code: Select all

 
 Dim posvec As New Vector3Df(0, 50, 80)
 
    Function device_OnEvent(ByVal e As IrrlichtLime.Event) As Boolean
        If e.Type = EventType.Key Then
            If e.Key.PressedDown Then
                Select Case e.Key.Key
                    Case KeyCode.Right
                        posvec.RotateXZby(-5)
                    Case KeyCode.Left
                        posvec.RotateXZby(5)
                    Case KeyCode.Up
                        posvec.RotateYZby(-5)
                    Case KeyCode.Down
                        posvec.RotateYZby(5)
                End Select
 
            End If
 
        End If
        Return False
    End Function
 
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Does IrrlichtLime contain IEventReceiver?

Post by greenya »

If user presses more than one key at the same time, Irrlicht notifies you one by one, so if you need to check multiple key at same time, you need to store the state of each key. Please check source of \examples\04.Movement\Program.cs. You can convert C# code to VB.NET using this online converter http://www.developerfusion.com/tools/co ... arp-to-vb/
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: Does IrrlichtLime contain IEventReceiver?

Post by Skatebone »

I tried but: "Sorry, the service appears to be down at the moment. Please try again later - or contact us if the problem persists."

Although I did manage to make it alone :) It was simple and didn't think enough about it :P

For anyone who is reading this/need it:

Code: Select all

 
    Dim KeyStore(255) As Boolean
 
    Function device_OnEvent(ByVal e As IrrlichtLime.Event) As Boolean
 
        If e.Type = EventType.Key Then
 
            If e.Key.PressedDown = True Then
                KeyStore(e.Key.Key) = True
            Else
                KeyStore(e.Key.Key) = False
            End If
        End If
        Return True
    End Function
 
Then you simply add this to your loop :

Code: Select all

 
 If KeyStore(KeyCode.Left) = True Then
                    posvec.RotateXZby(5)
                End If
 
Thanks alot :)
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Does IrrlichtLime contain IEventReceiver?

Post by greenya »

Glad to hear that.
I'm not familiar with VB.NET and always use that kind of translators when i asked about VB.NET code.

P.S.: if that particular site is down, just google for "c# to vb.net translator or converter" and you will find bunch of them. Some are desktop apps, some are online ones. One more example - http://www.carlosag.net/tools/codetranslator/
Skatebone
Posts: 15
Joined: Sat Sep 01, 2012 8:23 pm

Re: Does IrrlichtLime contain IEventReceiver?

Post by Skatebone »

Awesome!

Thanks alot! :)
Post Reply