Billboard Movement

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
Aroth

Billboard Movement

Post by Aroth »

Hi. I have this code, but it keeps crashing when I run it.
Can anyone tell me whats wrong with it?

Its supposed to move a billboard up or down when you press w or s with a car texture on it.

Code: Select all

   
#include <irrlicht.h>
#include <iostream>

using namespace std;

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")
              

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

class MyEventReceiver : public IEventReceiver
{
public:


	float ypos;

	virtual bool OnEvent(SEvent event)
	{ 
		if (event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
		{
		switch(event.KeyInput.Key)
		{
		case KEY_KEY_W:
		case KEY_KEY_S:
			{
				core::vector3df v = node->getPosition();
				v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
				node->setPosition(v);
			}
			return true;
		}
}

		return false; 
	}
};


int main()
{


  MyEventReceiver receiver;

  scene::ISceneManager* smgr = device->getSceneManager();


  scene::ISceneNode* car = 0;


  device = createDevice(video::DT_OPENGL, core::dimension2d<s32>(640, 480),
             16, false, false, &receiver);

  device->setWindowCaption(L"Car Game Demo");

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

  node = device->getSceneManager()->addBillboardSceneNode(node, core::dimension2d<f32>(70,93));
  node->setMaterialFlag(video::EMF_LIGHTING, false);
  node->setMaterialTexture(0, driver->getTexture("data/car.bmp"));
  node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); 

	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	camera->setPosition(core::vector3df(-50,50,-150));



  while(device->run() && driver)
  {
	if (device->isWindowActive())
	{
		u32 time = device->getTimer()->getTime();
		driver->beginScene(true, true, video::SColor(0,0,150,0));

	smgr->drawAll();

      driver->endScene();
  }
}



   device->drop();
   return 0;
}
                  
Thanks
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Where does it crash? put some debug points into the code and find on what line it crashes.
Aroth

Post by Aroth »

The debugger points to

scene::ISceneManager* smgr = device->getSceneManager();
JoeMill
Posts: 3
Joined: Wed Jan 14, 2004 12:29 pm
Location: Dresden, Germany

Post by JoeMill »

you must create the Irrlichtdevice before you use it.

Old:

Code: Select all

  // The device IS NULL.
  // You try to use the device before you create it.
  scene::ISceneManager* smgr = device->getSceneManager(); 

  device = createDevice(video::DT_OPENGL, core::dimension2d<s32>(640, 480), 16, false, false, &receiver);
simply switch the two lines

Code: Select all

  device = createDevice(video::DT_OPENGL, core::dimension2d<s32>(640, 480), 16, false, false, &receiver);


  // Now the device is NOT NULL.
  scene::ISceneManager* smgr = device->getSceneManager(); 
Aroth

Post by Aroth »

Thanks, everything works fine now.
Post Reply