Set MD2 Animation

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
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Set MD2 Animation

Post by AshmenGlue »

Hello I'm a new user to Irrlicht. I'm trying out simple movements for a character.

I've loaded a model:
scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/faerie.md2"));

I did all the rest of the necessary stuff, including an Event Receiver. The updating of the model's position is done in the while loop for smooth movement. Now I want to update the model's animation when the Move Forward key is being held down.

switch(event.KeyInput.Key){
case KEY_KEY_W:
{
node->setMD2Animation(scene::EMAT_RUN);
}


So I added the above code in my event receiver. Thing is, when I compiled, I get an error saying setMD2Animation is not a member of irr::scene::ISceneNode.

I thought I've already declared 'node' as an IAnimatedMeshSceneNode. What is the problem here?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I'm using a java binding for Irrlicht and when i want to set the MD2 animation i need to use EMD2_ANIMATION_TYPE.EMAT_RUN as the param, although that may just be because it's a java binding that it's different, as it doesn't sound as if that would solve your problem...

And the strange thing is that i've just decided that today i'm going to have a bash at animating my MD2s when they move, so i may have to ask you for some help if i get a bit stuck!
Image Image Image
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

The 'node' in the switch statement probably isn't the same as the one youv'e defined in the code above, maybe called the same thing, but different variables.

Double check your code, and change the name to make sure your'e referencing the correct variable.
________
Maryjane
Last edited by area51 on Tue Feb 22, 2011 1:15 pm, edited 1 time in total.
Guest

Post by Guest »

I'm still not too sure how the event receiver works.

There is only one 'node' in main(). How can I check what varialbe the 'node' in the switch statement is referencing?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Don't suppose i could get a description of how to make the MD2 move forward smoothly whilst executing the EMAT_RUN? I've had a go at it but it doesn't work and i couldn't find any other threads which deal with this so i'm a bit stuck!
Image Image Image
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

are51: You're right. There was a pointer stored to a node that I missed. It was an ISceneNode. I've made the necessary changes. There is no problem with that now.

The problem is that my logic for implementing moving forward smoothly whilst executing the run animation is flawed. It doesn't work, even though the thing compiles fine. Heh so I'm sorry JP, at this stage I'm still figuring it out.
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

JP, I figured it out. The model updates fine now.

Go to this Wiki link : http://irrforge.org/index.php/Simple_wa ... ard_Events

Copy the class and paste it in your main.cpp. Make sure you include the necessary header files or DWORD won't be recognized. Also, set the functions in the class to public.

After that call it in the main loop as such:

Code: Select all

while(device->run()) {
TTinyEvent* Inp = new TTinyEvent;

if (Inp->KeyDown(irr::Key_UP) && run == false) {
//movement code here blahblahblah
playernode->setMD2Animation(scene::EMAT_RUN);
run = true;
}

if (Inp->KeyUp(irr::Key_UP) && run == true) {
playernode->setMD2Animation(scene::EMAT_STAND);
run=false;
}
Oh, don't forget to declare a boolean run. That's it, the animation should play fine. I hope this helps you.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Nice one, i'll give that a look, might be tricky to convert it into java though!

I'm trying out some threading stuff to see if i can get my code working currently but my brain isnt working at the moment so it'll have to wait til later!
Image Image Image
Guest

Post by Guest »

It should be almost exactly the same in Java. Perhaps instead of Inp->KeyDown you might have Inp.KeyDown

I'm not really too sure I haven't coded Java in a while but it should be something like that.
Post Reply