EventReceiver problems

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
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

EventReceiver problems

Post by sanctus2099 »

Hi
I'm having a bit of a hard time with the eventreceiver.
Yes I do get it's concept but I'm trying to use it in a way.
I have a class named CGame that has all the things I need. I like to put it all in ojects since I'm trying to make a preety much expandable project.

So I'm trying to use it in 2 ways:

Code: Select all

CEventReceiver Receiver;
CGame::CGame()
{
	
	this->device = createDevice(video::EDT_OPENGL,dimension2d<s32>(1024,768),32,false,true,true,&Receiver);
	this->driver = device->getVideoDriver();
	this->smgr = device->getSceneManager();
	this->guienv = device->getGUIEnvironment(); 

}
and

Code: Select all


CGame::CGame()
{
	CEventReceiver Receiver;
	this->device = createDevice(video::EDT_OPENGL,dimension2d<s32>(1024,768),32,false,true,true,&Receiver);
	this->driver = device->getVideoDriver();
	this->smgr = device->getSceneManager();
	this->guienv = device->getGUIEnvironment(); 

}
in the first way I get a runtime error and in the sencond time I'm getting a can not instanciate a abstract class.

How can I solve this?
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

Hi,

Try this:

Code: Select all

CEventReceiver* Receiver = new CEventReceiver();

this->device = createDevice(video::EDT_OPENGL,dimension2d<s32>(1024,768),32,false,true,true, Receiver); 
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: EventReceiver problems

Post by rogerborg »

sanctus2099 wrote:in the first way I get a runtime error and in the sencond time I'm getting a can not instanciate a abstract class.
I find that hard to understand. It should be the latter snippet that explodes at runtime, since you're passing a pointer to an object on the stack which will be destroyed when the CGame() constructor returns.

Yustme's example fixes that issue, although (as written) it doesn't clean up the event receiver object. You can probably live with that on your conscience.

I'd suspect that something in your CEventReceiver implementation changed between those code snippets.
sanctus2099 wrote:How can I solve this?
Posting your CEventReceiver source would be a good start. If you're getting an error about an abstract class because of the OnEvent() method, then start by reading the FAQ at the top of this forum.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
sanctus2099
Posts: 18
Joined: Sat Nov 17, 2007 11:34 am

Post by sanctus2099 »

I followed what Yustme said and it works perfect.
However I have new problem:

I have character that I want to move around

Code: Select all

if(game.REC()->IsKeyDown(KEY_KEY_W))
	{
		model->Move(vector3df(cos(rot*PI/180)*0.5,0,-sin(rot*PI/180))*0.5);
	}
	if(game.REC()->IsKeyDown(KEY_KEY_S))
	{
		model->Move(vector3df(-cos(rot*PI/180)*0.2,0,sin(rot*PI/180))*0.2);
	}
in the model class I have the move function wich is something like this:

Code: Select all

void CAnimModel::Move(vector3df vec)
{
	vector3df v = node->getPosition();
	v = v + vec;
	node->setPosition(v);
	node->updateAbsolutePosition();
}
rot is the current orientation of the character (I rotate him with the mouse).
He is always facing great but when I try to move him he moves a bit weird. depending on the orientation sometimes he doesn't move exatly in front of him.
I can't see any flaw in the code. and afterall it's just some simple trigonometry
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You could try out using the matrix solution to transform the move vector by the character's rotation so he moves 'forward' based on the way the character is perceived to be facing.

If you search for transformVect you should find a few discussions on it.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

It looks like your rot is 0 at +X and positive is clockwise around the +Y axis. If your node's mesh is also facing +X then that should be OK. Personally I always use +Z as forwards, but it takes all sorts.

If you have the current SVN source (and if not, I recommend that you get it), then there's a vector3df method to create a vector from Euler rotations.

Code: Select all

// If your forwards is +X rather than +Z
vector3df directionVector = node->getRotation().rotationToDirection(vector(1, 0, 0)); 
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply