Event

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
c_olin3404
Posts: 67
Joined: Fri Jan 23, 2004 5:04 am

Event

Post by c_olin3404 »

I'm modeling my game after the way the tech demo was coded. But my event handler does not work, I compared with the tech demo code but there is nothing different!

Code: Select all

//h18.h
#include <irrlicht.h>
#include <wchar.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

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

class h18 : public IEventReceiver
{
public:

	h18(int width, int height, int bpp, bool fullscreen, bool shadows); //Contructor

	~h18(); //Deconstructor

	void run(); //run();

	virtual bool OnEvent(SEvent event); //OnEvent();

private:
	
	/*-- Private Functions --*/
	void loadSceneData(); //loadSceneData();
	
	/* -- Variables -- */
	//Video Options
	bool shadows;
	bool fullscreen;
	int width;
	int height;
	int bpp;

	//Other Video
	IrrlichtDevice *device;

	//Scene & mesh nodes
	ISceneNode* quakeLevelNode;
	ISceneNode* skyboxNode;
	ICameraSceneNode* camera;

	//Meshes
	IAnimatedMesh* quakeLevelMesh;
};

Code: Select all

//h18.cpp
#include "h18.h"
#include <stdio.h>

h18::h18(int w, int h, int b, bool f, bool s) //Constructor
: shadows(s), width(w), height(h), bpp(b), fullscreen(f), camera(0)
{
}

h18::~h18() //Decontructor
{
	;
}

void h18::run() { //run();
	device = createDevice(DT_DIRECTX8, dimension2d<s32>(width, height), bpp, fullscreen, shadows, 0);

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

	device->setWindowCaption(L"Hanger 18 - Powered by Irrlicht");

	loadSceneData();
	camera = smgr->addCameraSceneNodeFPS();

	wchar_t tmp[255];

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

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

			driver->endScene();
		}
	}

	device->drop();
}

bool h18::OnEvent(SEvent event) //OnEvent();
{
	if (event.EventType == EET_KEY_INPUT_EVENT &&
		event.KeyInput.Key == KEY_ESCAPE &&
		event.KeyInput.PressedDown == false)
	{
		// user wants to quit.
		device->closeDevice();
	}
	else if (device->getSceneManager()->getActiveCamera())
	{
		device->getSceneManager()->getActiveCamera()->OnEvent(event);
		return true;
	}

	return false;
}

void h18::loadSceneData() { //loadSceneData();
	IVideoDriver* driver = device->getVideoDriver(); //Set up Pointer
	ISceneManager* sm = device->getSceneManager(); //Set up Pointer

	quakeLevelMesh = sm->getMesh("maps/testing.bsp"); //Load Mesh
	
	quakeLevelNode = sm->addOctTreeSceneNode(quakeLevelMesh->getMesh(0)); //Add OcTree


	/*-- SKYBOX --*/
	skyboxNode = sm->addSkyBoxSceneNode(
		driver->getTexture("skybox/greysky_up.jpg"),
		driver->getTexture("skybox/greysky_dn.jpg"),
		driver->getTexture("skybox/greysky_lf.jpg"),
		driver->getTexture("skybox/greysky_rt.jpg"),
		driver->getTexture("skybox/greysky_ft.jpg"),
		driver->getTexture("skybox/greysky_bk.jpg"));
	//
}

Code: Select all

//main.cpp
#include <windows.h>
#include "h18.h"


int main()
{
	h18 hanger18(1024, 768, 16, true, true);
	hanger18.run();		
	
	return 0;
}
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Re: Event

Post by niko »

c_olin3404 wrote:...I compared with the tech demo code but there is nothing different!

(..snip...)

Code: Select all

void h18::run() { //run();
	device = createDevice(DT_DIRECTX8, dimension2d<s32>(width, height), bpp, fullscreen, shadows, 0);
I guess this is not the same in the techdemo. :)
Try to replace the last parameter '0' with 'this'. Maybe it helps.
c_olin3404
Posts: 67
Joined: Fri Jan 23, 2004 5:04 am

Post by c_olin3404 »

thanks!

I guess I didnt completly understand the createDevice function
Post Reply