maybe a bug...or maybe not

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.
bappy
Posts: 63
Joined: Fri Dec 12, 2003 10:49 am
Location: france
Contact:

maybe a bug...or maybe not

Post by bappy »

hi, maybe it s a bug or maybe i ve make something wrong...
here is my code, it s just a md2 animation handling receiver.

so i just want this thing:
when i press 8, sydney, run.
but when i press nothing , sydney stand.

the problem is that when i press 8, it run and if i dont touch anything, it continu running, i always receive the EET_KEY_INPUT_EVENT even if i don t press anything :?
but if i move the mouse , it goes to the else code and sydney is standing as i want.

class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_X:
go=0;
break;

case KEY_NUMPAD8:
if(Sydney->getFrameNr()<=312)
{
Sydney->setMD2Animation("run");
Running=1;
}
break;
return true;
}
}
else
{
if(go==true && Running==1)
{
Running=0;
Sydney->setMD2Animation("stand");
}
}
return false;
}
};

another thing...
it should be cool if we could have a getActiveAnimationName function in IAnimatedMeshSceneNode...because testing which frame is playing is not very confortable.
-----------------------------
Sans danger, pas de gloire...
http;//bappy.free.fr
-----------------------------
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Yep, it's a bug in your code.

If there is no event (KeyPress, Mouse, GUI) being sent, OnEvent() won't get called.

You'd be better off with something like:

Code: Select all

class MyEventReceiver : public IEventReceiver 
{ 
	public: 

		virtual bool OnEvent(SEvent event) { 
			if (event.EventType == EET_KEY_INPUT_EVENT) { 
				switch(event.KeyInput.Key) { 
					case KEY_NUMPAD8: 
						if (event.KeyInput.PressedDown) { 
							Sydney->setMD2Animation("run"); 
						} else {
							Sydney->setMD2Animation("stand");
						}
						break; 
					return true; 
				} 
			} 
			return false; 
		} 
}; 
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 »

Please saigumi can you add something to your code?
It would be nice to finish the animation when using the 8 key.
And what is the code for a mouse click in stead of the 8 key?
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
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

to check for a mouse click just replace

Code: Select all

 if (event.EventType == EET_KEY_INPUT_EVENT) 
with

Code: Select all

 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
and then don't worry about the switch in there.

ex.

Code: Select all

 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN && gameState == GAME_STATE_RUNNING) // just add in a check to the gameState 
      { 
         shootPlasma();
      }
--The Robomaniac
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post by VeneX »

gameState == GAME_STATE_RUNNING are two variables, I don't know how to assign one of the variable with true or false of a movement: what is the code to check if he is playing an animation or not.

btw thanks for your help
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
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

gameState and GAME_STATE_RUNNING were 2 var's that i added to check whether the game was running, idk how to check whether an anim is playing though.
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post by VeneX »

But... If you added the variables but you don't know how to see if the anim is playing, how could you assign the variables with playing or not playing (as known as true/false)?
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
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

Oh, gameState and GAME_STATE_RUNNING are vars that i set to see whether the game was in the menu or running the main loop

--The Robomaniac
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post by VeneX »

Does anybody know if it is possible to check the animation? I mean when you use the mouse button he finishes the animation. And when the animation is playing and you click again he won't start the animation over but plays further.
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
bappy
Posts: 63
Joined: Fri Dec 12, 2003 10:49 am
Location: france
Contact:

Post by bappy »

that s why i do this:
Sydney->getFrameNr()<=312)

before 312, it's the stand animation. you can know it with your mesh->getAnimationName() function(!!be carefull it's not with your meshnode!!)

that s why i have post this request:

it should be cool if we could have a getActiveAnimationName function in IAnimatedMeshSceneNode...because testing which frame is playing is not very confortable.
-----------------------------
Sans danger, pas de gloire...
http;//bappy.free.fr
-----------------------------
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post by VeneX »

thank you very much! that's usefull, but what's wrong with this code?

Code: Select all

#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")

int main()
{
	IrrlichtDevice *device =
		createDevice(DT_SOFTWARE, dimension2d<s32>(512, 384), 16, false, false, 0);

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!",
		true, rect<int>(10,10,200,30));

	IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setFrameLoop(0, 310);	
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
	}

	smgr->addCameraSceneNode(0, vector3df(0,10,-40), vector3df(0,0,0));


	class MyEventReceiver : public IEventReceiver 
{ 
   public: 

      virtual bool OnEvent(SEvent event) { 
         if (event.EventType == EET_KEY_INPUT_EVENT) { 
            switch(event.KeyInput.Key) { 
               case KEY_NUMPAD8: 
                  if (event.KeyInput.PressedDown) { 
                     node->setMD2Animation("run"); 
                  } else { 
                     node->setMD2Animation("stand"); 
                  } 
                  break; 
               return true; 
            } 
         } 
         return false; 
      } 
}; 


	while(device->run())
	{
		driver->beginScene(true, true, SColor(0,100,100,100));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
E:\Irrlicht\examples\Kopie van 1.HelloWorld\main.cpp(46) : error C2065: 'node' : undeclared identifier
E:\Irrlicht\examples\Kopie van 1.HelloWorld\main.cpp(46) : error C2227: left of '->setMD2Animation' must point to class/struct/union
E:\Irrlicht\examples\Kopie van 1.HelloWorld\main.cpp(48) : error C2227: left of '->setMD2Animation' must point to class/struct/union
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
VeneX
Posts: 228
Joined: Sun Nov 30, 2003 3:32 pm
Location: The Netherlands
Contact:

Post by VeneX »

I don't know what it could be. Can someone help me please?
I know the MyEventReceiver should be above MAIN but, node isn't created than.
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
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

The problem is that node isn't a member of the MyEventReciever Class, it's a member of your main.

So, what you need to do is have your main call a class extended from MyEventReceiver as in the Movement tutorial.

You can find out about how classes work at:
http://www.cprogramming.com/tutorial/lesson12.html
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 »

Thanks for your help. But, when I set the "class MyEventReceiver : public IEventReceiver" above main and set "MyEventReceiver receiver;" in then main. It is still not working.
"'setMD2Animation' : cannot convert parameter 1 from 'char [4]' to 'enum irr::scene::EMD2_ANIMATION_TYPE'"
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
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

That is because 'setMD2Animation' takes either a irr::c8* or an EMD2_ANIMATION_TYPE.

Try:

Code: Select all

 node->setMD2Animation(irr::scene::EMAT_STAND);

and

 node->setMD2Animation(irr::scene::EMAT_RUN);
Crud, how do I do this again?
Post Reply