For centuries I have terrorised this land, and now I am stuck on the most trivial of hurdles.
I am a beginner in irrlicht and do not understand the logic behind and how to use keyboard inputs.
I have read the tutorials and am still no closer to understanding.
Whats all this event stuff? and how do I simply get a ball to move?
Basic understanding of keyboard input
whilst I'm not an expert
I'd like to say that I'm pretty knew to irrlicht myself, so this is simply my understanding so far based upon limit experimentation and similar systems
Irrlicht like many modern systems deals with events, which may be mouse clicks, key presses etc. These are passed to you in a common fashion via messages, in the case of irrlicht this is an SEvent.
To get an SEvent you need to construct your message handling class which extends IEventReciever.
This contains a single method OnEvent which recieves an SEvent as its sole paremeter.
To use this class you have to assign it to an element of the irrlicht system, this can be done by calling the setEventReciever method of the irrlicht device.
Having done so you can now use the event how you like.
There are 3 types of event GUI, Mouse and Keyboard, the nature of a specific event can be got from the EventType entry. You can then use the correct struct to get the message information. For example
to detect the keypress A
onEvent (SEvent e)
{
switch(e.EventType)
{
case EET_KEY_INPUT_EVENT:
switch(e.KeyInput.Key)
{
case KEY_KEY_A:
--- do something ---
return true;
break
}
}
return false;
}
if you don't use the namespaces you'll need to look up which namespace these are in, most are simply part or irr I believe
To move your ball, you'll need to get a reference to its screen node and then move its position using the setPosition method I believe. But as I'm currently having problems with setRotation on cameras this may or may not be the case.
Hope this helps
Steve
Irrlicht like many modern systems deals with events, which may be mouse clicks, key presses etc. These are passed to you in a common fashion via messages, in the case of irrlicht this is an SEvent.
To get an SEvent you need to construct your message handling class which extends IEventReciever.
This contains a single method OnEvent which recieves an SEvent as its sole paremeter.
To use this class you have to assign it to an element of the irrlicht system, this can be done by calling the setEventReciever method of the irrlicht device.
Having done so you can now use the event how you like.
There are 3 types of event GUI, Mouse and Keyboard, the nature of a specific event can be got from the EventType entry. You can then use the correct struct to get the message information. For example
to detect the keypress A
onEvent (SEvent e)
{
switch(e.EventType)
{
case EET_KEY_INPUT_EVENT:
switch(e.KeyInput.Key)
{
case KEY_KEY_A:
--- do something ---
return true;
break
}
}
return false;
}
if you don't use the namespaces you'll need to look up which namespace these are in, most are simply part or irr I believe
To move your ball, you'll need to get a reference to its screen node and then move its position using the setPosition method I believe. But as I'm currently having problems with setRotation on cameras this may or may not be the case.
Hope this helps
Steve
This is for steve. As far as I know, standard cameras are rotated by camera->setTarget(). They do not respond to node rotation changes because they have to point at their assigned target. Currently I have to update this target every frame to make the camera behave. Perhaps one of the guru's can give a more detailed explanation or workaround.
Yeah, I was hoping that you could assign permanent targets and let the engine handle it every frame update. But for now, you need to perform the action.
There is a really good example from Keless here. http://irrlicht.sourceforge.net/phpBB2/ ... amera#7991
There is a really good example from Keless here. http://irrlicht.sourceforge.net/phpBB2/ ... amera#7991
Crud, how do I do this again?
I use the code:
but it doesn't work, whats wrong with event.KeyInput.Key=KEY_LEFT;???
Code: Select all
case KEY_KEY_W:
{
event.KeyInput.Key=KEY_UP;
break;
}
case KEY_KEY_A:
{
event.KeyInput.Key=KEY_LEFT;
break;
}
Visit my website @ www.venex.be
Plethora project will be added to the site
AMD AthlonXP 2600+, 512MB DDR, Radeon M10 (mobile 9600) PRO 64MB, WinXP
Plethora project will be added to the site
AMD AthlonXP 2600+, 512MB DDR, Radeon M10 (mobile 9600) PRO 64MB, WinXP