Page 1 of 1

Billboard Movement

Posted: Sun Mar 07, 2004 11:28 pm
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

Posted: Mon Mar 08, 2004 1:15 am
by thesmileman
Where does it crash? put some debug points into the code and find on what line it crashes.

Posted: Mon Mar 08, 2004 2:13 am
by Aroth
The debugger points to

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

Posted: Mon Mar 08, 2004 12:03 pm
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(); 

Posted: Mon Mar 08, 2004 9:02 pm
by Aroth
Thanks, everything works fine now.