Basic understanding of keyboard input

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
akku
Posts: 3
Joined: Fri Feb 27, 2004 2:43 pm

Basic understanding of keyboard input

Post by akku »

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?
Malaidas
Posts: 16
Joined: Wed Feb 25, 2004 1:15 pm

whilst I'm not an expert

Post by Malaidas »

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
Chev
Posts: 37
Joined: Wed Nov 19, 2003 6:15 am

Post by Chev »

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.
Malaidas
Posts: 16
Joined: Wed Feb 25, 2004 1:15 pm

ahh well

Post by Malaidas »

I was hop[ing I wouldn't need to do that because of the need to work out the distance between the target and the camera on each update. Hey ho if needs be then I'll have to do that.

:?

cheers Chev

Steve
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

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
Crud, how do I do this again?
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post by VeneX »

I use the code:

Code: Select all

	case KEY_KEY_W:
					{
						event.KeyInput.Key=KEY_UP;
	break;
					}
	case KEY_KEY_A:
					{
						event.KeyInput.Key=KEY_LEFT;
	break;
					}
but it doesn't work, whats wrong with event.KeyInput.Key=KEY_LEFT;???
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
Malaidas
Posts: 16
Joined: Wed Feb 25, 2004 1:15 pm

Post by Malaidas »

can't see whats wrong but you could try to deal with the 2 keys using drop through case statements i.e

swicth(e.KeyInput.Key)
{
case KEY_KEY_W: case KEY_UP:
do something
break;

}

just a thought

Steve
Post Reply