scene node created in class MyEventReceiver not displayed!

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
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

scene node created in class MyEventReceiver not displayed!

Post by pat-rizio »

Hi everybody,
this is my problem:
I inizialize scenemanager, driver and device in main method as follow:

Code: Select all

	device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600),16, false, false, false);
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	MyEventReceiver receiver;
	
	device->setEventReceiver(&receiver);
Then I want to create (add to scenemanager) a node when I press "4" key on my keyboard. To do this I followed tutorials, and I create the class MyEventReceiver as follow:

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
		{
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_4:
				{
					miamano = new Hand(smgr,"F:/GCT/Progetto/HandModel",false);
					break;
				}
			case KEY_KEY_5:
				{
					if (miamano != NULL)
					{
					delete miamano;
					miamano = NULL;
					}
					break;
				}
			case KEY_KEY_6:
				{
					miamano->setVisibile(!miamano->isVisible());
					break;
				}
			return true;
			}
		}

		return false;
	}

};
where "miamano" is an istance of my class called "Hand". Pressing "4" class constructor is called, pressing "6" miamano should be visualized.

The Hand's costructor is:

Code: Select all

	
	{
		//Check if model directory is right terminated
		if (ModelDir.size() != 0)
		{
			c8 last = ModelDir[ModelDir.size()-1];
			if (last != SLASH) ModelDir.append(SLASH);
		}
		try
		{
		//Building Hand Model
		//ROOT
			V2Grp01 = smgr->addEmptySceneNode();
			V2Grp01->setName(L"V2Grp01");
			V2Grp01->setVisible(this->startVisible);
			scene::ISceneNode* dad_GROUND01 = smgr->addEmptySceneNode();
			dad_GROUND01->setName(L"dad_GROUND01");
			scene::ISceneNode* GROUND01 = smgr->addEmptySceneNode();
			GROUND01->setName(L"GROUND01");
			dad_Palm01 = smgr->addEmptySceneNode();
			dad_Palm01->setName(L"dad_Palm01");
			scene::ISceneNode* Palm01 = smgr->addEmptySceneNode();
			Palm01->setName(L"Palm01");
		//PALM
			scene::ISceneNode* dad_Palm02 = smgr->addEmptySceneNode();
			dad_Palm02->setName(L"dad_Palm02");
			scene::ISceneNode* VIFS16 = smgr->addOctTreeSceneNode( smgr->getMesh((ModelDir + "VIFS16.3ds").c_str())->getMesh(0,255));
			VIFS16->setName(L"VIFS16");
..........
now the problem is that my object "miamano" has been displayed ONLY if in main method I create a useless TestSceneNode or EmptySceneNode as follow:

Code: Select all

	
node = smgr->addTestSceneNode();
or

Code: Select all

	
node = smgr->addEmptySceneNode();
can anyone explain me why it happens?
hybrid

Post by hybrid »

How does your event receiver know which Scene Manager to use? You did not set it anywhere inside the event receiver, nor in any other code. And how does your main loop look like?
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

sorry, I forgot to write that smgr is a global variable, so myEventReceiver can access to it and pass it to Hand's constructor as shown in my code:

Code: Select all

miamano = new Hand(smgr,"F:/GCT/Progetto/HandModel",false);
My complete main is:

Code: Select all

int main(int argc, int argv[])
{
	device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800, 600),16, false, false, false);
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	MyEventReceiver receiver;
	
	device->setEventReceiver(&receiver);

	//LUCE
	smgr->addLightSceneNode(0, core::vector3df(1,1,11), video::SColorf(1.0f,0.6f,0.6f,1.0f),	1.0f);
    
	node = smgr->addEmptySceneNode();
	//node = smgr->addTestSceneNode();

	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 30.0f, 10.0f);
	camera->setPosition(core::vector3df(0,5,0));
	device->getCursorControl()->setVisible(false);

	int lastFPS = -1;

	while(device->run())
	{
		driver->beginScene(true, true, video::SColor(255,113,113,133));
		smgr->drawAll();
		driver->endScene();


	}

device->drop();
	
	return 0;
}
hybrid

Post by hybrid »

Sorry, no clues. But your grouping and visibility won't work this way. You only set visibility for one empty node, but this node does not become the parent of the others. Anyway, this won't help with your problem.
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

well, parent relationships are managed in another part of my code, and it works if I ignore the problem I post here...

My problem should be a bug problem?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It sounds like you are not setting a world transform in your Hand::render method. You are not the only one... http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11582

One more thing. You should never delete a scene node directly. It can, and will, cause crashes in your program. Use this instead...

Code: Select all

  miamano->remove(); // remove from parent
  miamano->drop(); // remove our reference, will delete object
  miamano = NULL;
Travis
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

first of all sorry for my late reply.

@vitek: on this topic, what is

Code: Select all

matrix()
as the second argument of setTransform method you suggest to use? At what i have to set it?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

driver->setTransform(ETS_WORLD, matrix()); 
The call matrix() should have been matrix4(). It is an explicit call to the matrix4 constructor. The default constructor for matrix4 creates an identity matrix. We then pass the identity matrix to setTransform. It is equivalent to doing this...

Code: Select all

matrix4 mat;
mat.makeIdentity();

driver->setTransform(ETS_WORLD, mat);
You probably don't want to use an identity matrix, I just used it as an example.
Last edited by vitek on Thu Mar 02, 2006 5:00 pm, edited 1 time in total.
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

ok thanks for your explanation, but nothing change :(
which matrix should "mat" be?
it doesn't matter which matrix is, I have only to call it and set to identity or is it a particular transformation matrix of my virtual word?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'd be willing to bet that the test scene node works just fine, but your scene node does not. Right? Well if this is true, why not just have a look at the code in CTestSceneNode.cpp.

Travis
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

you win your bet... :wink:
If nobody has any idea to solve my problem then I will have a look at the code in CTestSceneNode.cpp... :?
r3i
Posts: 147
Joined: Wed Jun 29, 2005 10:15 am
Location: Sorrento
Contact:

Hi

Post by r3i »

Maybe your problem is similar to me. I've a collision test in my event receiver and if some elements are pointed some nodes must change their texture: my code works correctly only WITH ONE NODE in the smgr.

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11881

Take the Hello World example and put the code for create Sidney after smgr->drawAll() recompile and you know the problem: sometimes you have nothing...

maybe womething goes wrong
"We work in the dark, we do what we can, we give what we have, Our doubt is our passion and our passion is our task. The rest: is art of Madness" (H.James)
pat-rizio
Posts: 20
Joined: Thu Jan 05, 2006 10:59 am

Post by pat-rizio »

Yes I think we have the same problem.

Maybe is it a bug inside IEventReceiver class?
r3i
Posts: 147
Joined: Wed Jun 29, 2005 10:15 am
Location: Sorrento
Contact:

Post by r3i »

It can be also a logic problem in programming: I'm trying to make some tests: if I discover something i'll tell you.
"We work in the dark, we do what we can, we give what we have, Our doubt is our passion and our passion is our task. The rest: is art of Madness" (H.James)
Post Reply