keyboard input -> showing 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
spearfire
Posts: 11
Joined: Sat Apr 12, 2008 10:26 am

keyboard input -> showing animation

Post by spearfire »

hello all
i am having problems with keyboard input

i like to have when i press the R button that a animation shows 1 time not looping
i have searched for it but realy can't find it

here is my (error giving) code(i know its wrong but this is the closest that i can come to let you know what i want)

Code: Select all

main code

#include <irrlicht.h>
#include <iostream>
#include <irrKlang.h>
#include <ILightSceneNode.h>
#include <ISceneNode.h>
#include <stdio.h>
#include <wchar.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace irrklang;
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "irrKlang.lib")

scene::ISceneNode* g = 0;
IrrlichtDevice* device = 0; 

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
            if (g != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT &&
				!event.KeyInput.PressedDown)
	{
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_R:
				{
	                          gun->setFrameLoop(0,100);
				}
				return true;
			}
	}


	return false;
	}
};

int main(int argc, const char** argv)
{
  MyEventReceiver receiver;

   device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480),

       32, false, true, false, &receiver);

   video::IVideoDriver* driver = device->getVideoDriver();

   scene::ISceneManager* smgr = device->getSceneManager();
   
   // start the sound engine
   ISoundEngine* engine = createIrrKlangDevice();

   if (!engine)
      return 0; // error starting up the engine
    IrrlichtDevice *device =
		createDevice(EDT_OPENGL, dimension2d<s32>(1024,768), 32,
			false, true, false, &receiver);

MY GUN
//test: object added to camera
IAnimatedMesh* gun = smgr->getMesh("assault.X");
IAnimatedMeshSceneNode* g = smgr->addAnimatedMeshSceneNode( gun );

if(g)
{
     g->setMaterialFlag(EMF_LIGHTING, true);
     g->setPosition(core::vector3df(1.0,-1.6,3.35));
     //g->setPosition(core::vector3df(0.7,-1.4,3.35));
     g->setRotation(core::vector3df(90,0,180));
     g->setScale(core::vector3df(3,3,3));
     //g->setScale(core::vector3df(2,2,2));
     g->setParent(camera);
     
}

i hope someone can help me
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Do we have to guess what's wrong with it? It would be quicker if you told us :P
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

probably the error is "gun was not declared in this scope" !!! :roll:
don't use "gun" in the event receiver (use "g" instead) !!!
and don't declare "g" as local in function main !!!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
spearfire
Posts: 11
Joined: Sat Apr 12, 2008 10:26 am

Post by spearfire »

ok i have got everything where it needs to be like in the tutorial of moving a node
(and the gun part of the code is not directly under the key event its almost at the end of the file)
(and i dont realy understand what you mean with
and don't declare "g" as local in function main !!!!
but then it gives a error

Image

i hope you can help me with this new info
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: keyboard input -> showing animation

Post by Acki »

you don't know what a local variable is !?!?! :shock:
then you should learn more about declaring variables... :lol:
well, you have declared "g" twice, one global and one local...
OK, here some explanations:

Code: Select all

.
.
.
scene::ISceneNode* g = 0; // global, but must be IAnimatedMeshSceneNode !!!
IrrlichtDevice* device = 0; 
.
.
.

Code: Select all

.
.
.
MY GUN
//test: object added to camera
IAnimatedMesh* gun = smgr->getMesh("assault.X");
IAnimatedMeshSceneNode* g = smgr->addAnimatedMeshSceneNode( gun ); // this is local, so you have no access inside the event receiver
.
.
.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
spearfire
Posts: 11
Joined: Sat Apr 12, 2008 10:26 am

Re: keyboard input -> showing animation

Post by spearfire »

Acki wrote:you don't know what a local variable is !?!?! :shock:
then you should learn more about declaring variables... :lol:
well, you have declared "g" twice, one global and one local...
OK, here some explanations:

Code: Select all

.
.
.
scene::ISceneNode* g = 0; // global, but must be IAnimatedMeshSceneNode !!!
IrrlichtDevice* device = 0; 
.
.
.

Code: Select all

.
.
.
MY GUN
//test: object added to camera
IAnimatedMesh* gun = smgr->getMesh("assault.X");
IAnimatedMeshSceneNode* g = smgr->addAnimatedMeshSceneNode( gun ); // this is local, so you have no access inside the event receiver
.
.
.
whell.....
ques i need to study more :roll: :P
before i go any further

well i still cant get it to work but thanks for the info about the variables
i will continue my study in c++
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

well... aside from the c++ errors... im guessing that what u want is to display an animation just once....

i hope someone with more experience corrects me if im giving wrong info...

a IanimatedMeshSceneNode(wich is what u have to use if u are using an animated mesh) has this 2 methods:

Code: Select all

getEndFrame () 
and

Code: Select all

getFrameNr () 
if i understand well enough the API doc... the first one gives u the end Frame of the current frame loop of your animated scene node.... the second one... gives u the current displayed frame... so if u want to see when it ends... just compare this 2 values and when they match means thats the last frame and u have to do... whatever u want to do when that animation ends... of course u have to do this from within the main loop.

Hope this helps u[/code]
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

for this you could use the setAnimationEndCallback() function of the IAnimatedMeshSceneNode...
I think that would be better than comparing current and last frame of the animation... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply