Binding Animations to Keys
-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Binding Animations to Keys
How would you set an animation to play when you pressed a certain key? Such as pressing E the mesh would play the run animation. While standing still it would play the stand animation.
I know I have to set this up in my event receiver, but if I have it set to play the EMAT_STAND animation and then in the receiver have it set up so that when you press E, it runs EMAT_RUN...it crashes the program.
Can someone post a code snippet or in depth-advice and NOT flame me about searching because I've already tried that (I looked through 7 out of about 30 pages of irrelevance).
Thanks in advance.
I know I have to set this up in my event receiver, but if I have it set to play the EMAT_STAND animation and then in the receiver have it set up so that when you press E, it runs EMAT_RUN...it crashes the program.
Can someone post a code snippet or in depth-advice and NOT flame me about searching because I've already tried that (I looked through 7 out of about 30 pages of irrelevance).
Thanks in advance.
-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Don't have it anymore, removed it so I could work on other things while I was waiting. Here's what I think it was.
and in the event receiver
It went something like that.
Code: Select all
IAnimatedMeshSceneNode* pcam=sm->addAnimatedMeshSceneNode(sm->getMesh("media/mdls/sydney.md2"));
pcam->setMaterialFlag(EMF_LIGHTING, false);
pcam->setScale(vector3df(2,2,2));
pcam->setMD2Animation(EMAT_STAND);
pcam->setAnimationSpeed(80);
pcam->setPosition(vector3df(200,600,200));
pcam->setRotation(vector3df(0,270.0f,0));
pcam->setMaterialTexture(0, driver->getTexture("media/txts/sydney.bmp"));Code: Select all
if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_E_E&&
event.KeyInput.PressedDown == false)
{
pcam->setMD2Animation(EMAT_RUN);
pcam->setAnimationSpeed(80);
}
else -
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
hybrid
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Your IAMSN *pcam is local to the main method or wherever you defined it (the first code fragment). Although the nme in the event receiver is the same it does not use the first mentioned pointer, but maybe a global one which is initially 0 or some other wrong value. You have to set the pointer to the correct value.
-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Ok so here's what I did to try to solve that.
else
That was in my event receiver.
And that was my original drawing of Sydney, In the event receiver I restated that as you said and it drew a new sydney model and played EMAT_RUN on her at 0,0,0 (I think)....This is very confusing to me and I can't seem to figure it out. Though I'll tinker with it some more while I wait on a reply 
Code: Select all
if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_KEY_E)
{
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* sm = device->getSceneManager();
IAnimatedMeshSceneNode* pcam=sm->addAnimatedMeshSceneNode(sm->getMesh("media/mdls/sydney.md2"));
pcam->setMD2Animation(EMAT_RUN);
}That was in my event receiver.
Code: Select all
IAnimatedMeshSceneNode* pcam=sm->addAnimatedMeshSceneNode(sm->getMesh("media/mdls/sydney.md2"));
pcam->setMaterialFlag(EMF_LIGHTING, false);
pcam->setScale(vector3df(2,2,2));
pcam->setMD2Animation(EMAT_STAND);
pcam->setAnimationSpeed(80);
pcam->setPosition(vector3df(200,600,200));
pcam->setRotation(vector3df(0,270.0f,0));
pcam->setMaterialTexture(0, driver->getTexture("media/txts/sydney.bmp"));-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
This is a basic C++ problem, your pcam is going out of scope in the onevent function. I would advise you take a look at how to set up classes in C++ then have all your class members be the scene nodes etc. that you need for your 3d scene.
semi-pseudo code:
Then in main you basically create your game class:
mygame game;
And call its run function:
game.run();
semi-pseudo code:
Code: Select all
class mygame : public IEventReciever
{
public:
mygame();
~mygame();
virtual bool OnEvent(SEvent event)
void run();
private:
IrrlichtDevice device;
IAnimatedMeshSceneNode* pcam;
}
void mygame::run()
{
device = createdevice();
pcam = addmeshfunction("mesh.md2");
//irrlicht while loop and load other stuff etc.
}
bool mygame::OnEvent(SEvent event)
{
if(event is keyinput && keyinput is key_e && key isn't pressed down)
{
pcam->setMD2Animation(EMAT_RUN);
}
return false;
}
mygame game;
And call its run function:
game.run();
-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
That's how I have it set up...
I was skimming the demo code and I figured HEY, and I set it up like that. (However I didn't just copy-paste the code, I actually typed it out and the such. I have a pointer to it in my class, but I think the problem is when I'm creating the mesh. I've not got a clue how to fix it though.
I was skimming the demo code and I figured HEY, and I set it up like that. (However I didn't just copy-paste the code, I actually typed it out and the such. I have a pointer to it in my class, but I think the problem is when I'm creating the mesh. I've not got a clue how to fix it though.
-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
dhenton9000
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
I have an animation viewer that allows you to read a custom file I have that stores animation names for a .x file.
http://s-fonline.com/webhosting/dhenton9000/models.php sample models, and source for the viewer, which would have the code you might want to look at.
http://s-fonline.com/webhosting/dhenton9000/models.php sample models, and source for the viewer, which would have the code you might want to look at.
-
monkeycracks
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact: