I have just learnt how to get keys working, which is cool. I can now rotate a model using keys.
eg
Code: Select all
while(device->run())
{
// Work out a frame delta time.
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
if(receiver.IsKeyDown(irr::KEY_KEY_A))
{
rotation+=50 * frameDeltaTime;
}
if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
rotation-=50 * frameDeltaTime;
}
node->setRotation(core::vector3df(0,rotation,0));
driver->beginScene(true,true,video::SColor(100,100,100,255));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Code: Select all
if(receiver.IsKeyDown(irr::KEY_KEY_A))
{
rotation+=50 * frameDeltaTime;
}
if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
rotation-=50 * frameDeltaTime;
}
Something like MyEventReceiver::Checkkeys();
but I know I would have to put something between the brackets so that it knows which key I am pressing eg
MyEventReceiver::Checkkeys(current key being pressed);
Yes I know I can't put that. It will probably be some pointer of the keyboard I have to pass into my method.
I hope you can understand what I am going on about heh heh.
My method will probably be something like this
Code: Select all
Checkkeys(passed keyboard device or pointer)
{
if(receiver.IsKeyDown(irr::KEY_KEY_A))
{
rotation+=50 * frameDeltaTime;
}
if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
rotation-=50 * frameDeltaTime;
}
}
I will probably need to pass a pointer to the rotation variable also.
PS just tried this
Code: Select all
void Checkkeys(MyEventReceiver *receiver,const *frameDeltaTime,float *rotation)
{
if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
rotation-=50 * frameDeltaTime;
}
}
PPS
So I have tried this
Code: Select all
void Checkkeys(MyEventReceiver *receiver,float *frameDeltaTime,float *rotation)
{
if(receiver->IsKeyDown(irr::KEY_KEY_D))
{
rotation-=50 * frameDeltaTime;
}
}
H:\Codeblock_Games\Irrlicht\MyTests\main.cpp|45|error: invalid operands of types 'int' and 'float*' to binary 'operator*'|
I don't understand the error as rotation is a float, but I think I am getting closer to working this out.