playing with helloworld

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
james

playing with helloworld

Post by james »

Ok, COMPLETELY new to this.
I figured playing with and breaking the examples was probably a good way to learn, but all I seem to do is break them so far ... I added this code to the helloworld app, before int main()

Code: Select all

	IAnimatedMesh* mesh = 0;
	IAnimatedMeshSceneNode* node = 0;

class MyEventReceiver : public IEventReceiver
{

public:

	virtual bool OnEvent(SEvent event)
	{
		core::vector3df v = mesh->getPosition() + 3.0f;
		if(event.KeyInput.Key == KEY_KEY_W) { mesh->setPosition(v); }

		return true;

	}
}
And changed the bit later on in main() to:

Code: Select all

	mesh = smgr->getMesh("../../media/sydney.md2");
	node = smgr->addAnimatedMeshSceneNode( mesh );
My intention was that when W is pressed, the mesh moves 3.0f. However when compiling I get the following:

Code: Select all

--------------------Configuration: HelloWorld - Win32 Debug--------------------
Compiling...
main.cpp
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(89) : error C2628: 'MyEventReceiver' followed by 'int' is illegal (did you forget a ';'?)
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(206) : error C2664: '__thiscall MyEventReceiver::MyEventReceiver(const class MyEventReceiver &)' : cannot convert parameter 1 from 'const int' to 'const class MyEventReceiver &'
        Reason: cannot convert from 'const int' to 'const class MyEventReceiver'
        No constructor could take the source type, or constructor overload resolution was ambiguous
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(206) : error C2553: no legal conversion of return value to return type 'class MyEventReceiver *'
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(207) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

HelloWorld.exe - 3 error(s), 1 warning(s)
You might class me as lazy, but I don't really know what to do with it, even with the helpful little things that the compiler suggests. Please help me :\
Slash

LOL

Post by Slash »

LOL. Nice try but you cant just put a Key event in the middle of your code. You have to create a event receiver for input then attach it to your display driver for input when you press a key. Look at the movement exsample a little bit harder.
james

Post by james »

Ok, I'm stupid *flushes with n00bness*. I didn't create an actual instance of My EventReciever. I thought that would solve the problem, but it doesn't seem to.

In effect, I have no idea what your reply is suggesting I do.
james

Post by james »

Ok, this is annoying. I'm going to post the entire code for what I have now, with the compiler errors. All the errors seem to be related to main() being of type int, and what it returns. Though it all looks ok to me.

Code: Select all

#include <irrlicht.h>


using namespace irr;


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


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

ISceneNode* node = 0;

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		core::vector3df v = node->getPosition() + 3.0f;
		if(event.KeyInput.Key == KEY_KEY_W) { node->setPosition(v); return true;}
	return false;
	}
}

int main()
{

	MyEventReceiver receiver;


	IrrlichtDevice *device =
		createDevice(EDT_DIRECTX9, dimension2d<s32>(1024, 768), 16, false, false, 0);

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");


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


	guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!",
		rect<int>(10,10,200,30), true);

	node = smgr->addTestSceneNode();





	smgr->addCameraSceneNode(0, vector3df(0,10,-40), vector3df(0,0,0));


	while(device->run())
	{

		driver->beginScene(true, true, SColor(0,100,100,100));

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

		driver->endScene();
	}


	device->drop();

	return 0;
}
Compiler errors:

Code: Select all

Deleting intermediate files and output files for project 'HelloWorld - Win32 Debug'.
--------------------Configuration: HelloWorld - Win32 Debug--------------------
Compiling...
main.cpp
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(30) : error C2628: 'MyEventReceiver' followed by 'int' is illegal (did you forget a ';'?)
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(73) : error C2664: '__thiscall MyEventReceiver::MyEventReceiver(const class MyEventReceiver &)' : cannot convert parameter 1 from 'const int' to 'const class MyEventReceiver &'
        Reason: cannot convert from 'const int' to 'const class MyEventReceiver'
        No constructor could take the source type, or constructor overload resolution was ambiguous
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(73) : error C2553: no legal conversion of return value to return type 'class MyEventReceiver *'
c:\irrlicht-0.6\examples\1.helloworld\main.cpp(74) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

HelloWorld.exe - 3 error(s), 1 warning(s)
Sorry, but it's getting tedious here too.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, the event receiver class must end with an ";"

Code: Select all

class MyEventReceiver : public IEventReceiver { 
   public: virtual bool OnEvent(SEvent event) { 
      core::vector3df v = node->getPosition() + 3.0f; 
      if(event.KeyInput.Key == KEY_KEY_W) { 
         node->setPosition(v); 
         return true;
      } 
   return false; 
   } 
};
Then you have to setup the engine with the receiver:

Code: Select all

   MyEventReceiver receiver; 
   IrrlichtDevice *device = 
      createDevice(EDT_DIRECTX9, dimension2d<s32>(1024, 768), 16, false, false, receiver); 
CU, Acki
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

Also, don't do

Code: Select all

node->getPosition() + 3.0f;

do

v += vector3d<f32>(0.0f, 0.0f, 3.0f);
The Robomaniac
Project Head / Lead Programmer
Centaur Force
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

acki forgot the "&", you have to pass a pointer to your eventreceiver into
the createDevice-method:

Code: Select all

MyEventReceiver receiver; 
   IrrlichtDevice *device = 
      createDevice(EDT_DIRECTX9, dimension2d<s32>(1024, 768), 16, false, false, &receiver); 
james

Post by james »

MY UNDYING GRATITUDE FROM THE DEEPEST VENTRICLES OF MY HEART

...it works. thankee.

For the record, I admit most of the stuff I did was stupid.
Post Reply