New guy needs help

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
Guest

New guy needs help

Post by Guest »

I'm using Microsoft Visual C++, I was wondering if anyone had a simple demo showing how to use keyboard control. I tried the code suggested in the forum and it works but it does not move smoothly. When you hold a key down, the object moves, then stops, then moves again smoothly. It's just like when your typing and you hold a key down, it prints one letter, stops, and if you continue holding the key down it prints the same letter many times quikly.
Before I invest months learning how to use this 3D engine, I need to know that it can handle keyboard movement properly. Below is the code I'm using to move a block up and down using the Q and A keys:


class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
//definition
bool keys[irr::KEY_KEY_CODES_COUNT] ;
//initialization
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
//onEvent
if(event.EventType == irr::EET_KEY_INPUT_EVENT){
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;

//Using it
core::vector3df v = node->getPosition();

if(keys[irr::KEY_KEY_Q]) v.Y += 1;
if(keys[irr::KEY_KEY_A]) v.Y -= 1;

node->setPosition(v);

return true;


}

return false;
}
};

I really need to know if this problem can be fixed, any help would be appreciated.
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

The problem that you are hitting isn't a problem with the engine, it's the timing for your events.

There are several posts on doing smooth movement.

It involves assigning a direction when the key is pressed and then updating the object every frame, not on the keypress event.

If you do it on the keypress event, your bound to get strange results, like.

Move
Pause
-Wait-
(typematic kicks in)
Move
Pause
Move
Pause

Due to the typematic rate you have set in your OS.


On event:
If keypress = forward_key
set direction = forward;

Each Render:
If direction = foward
move object forward
Crud, how do I do this again?
Manakel

Post by Manakel »

where move_object forward= F(T) (T time elapsed since last call...)
Your move is then time dependant and not frame dependant et even if your frame rate get low you can still have smooth behaviour (sort of)
Guest

IT WORKS!!

Post by Guest »

saigumi, Thanks, I can now control objects with the keyboard smoothly.

Manakel, I'll try that soon, right now I have one object on the screen so the frame rate never really changes.

I have another question you guys might be able to help me with; Do I have to make the environment with a level editor program or can I create the environment with a regular model editor like Milkshape 3D? I'm confortable using Milkshape and I'm sure I could build a level with it. But I need to know if it will work the same for collision detection and would there be a differance in speed?
R00mpel
Posts: 41
Joined: Sun Nov 09, 2003 10:12 am
Location: Russia, Nizhny Novgorod

Post by R00mpel »

Yes, you can use any modeler you like (if it can produce models, supported by Irrlicht). Collision will work as usually, and there shouldn't be any difference in speed...
The only thing to fear is running out of beer!
Post Reply