Page 2 of 5

Posted: Mon Nov 26, 2007 8:43 pm
by dudMaN
Oh, sorry about that, some users have been having problems with the code snippets because i used 1.2 for the code and not 1.3+.

To fix this error, you will need to replace:

Code: Select all

 bool OnEvent(SEvent event) {
with

Code: Select all

 virtual bool OnEvent(const SEvent& event) {
and that should fix it :)

Sorry for any inconvienence!!!

-DudMan

Posted: Thu Nov 29, 2007 5:06 pm
by dudMaN
joshcryer & fireside,

yup, it's made to be quite simple, but it also fixes the key-repeat problem where holding down a key presses key once, then waits, then presses the rest of the time.

Thanks for reading/commenting on my tutorial :)

-dudMan

Posted: Sat Dec 01, 2007 11:22 pm
by Yustme
Hi dudMaN,

First of all, very nice tutorial!

I just started a new project using your tutorial. At the end of chapter 1, I compiled the code snippet and it gave me the following error:

'driver' undeclared identifier.'

This was the code I compiled:

Code: Select all

int main() {

 IrrlichtDevice *device = createDevice(ETD_OPENGL);
 IVideoDriver* video = device->getVideoDriver();
 ISceneManager* smgr = device->getSceneManager();

 while(device->run() && device) {
  driver->beginScene(true, true, video::SColor(255,0,0,255));
  smgr->drawAll();
  driver->endScene();
 }
}

If you change "video" in "driver" in this line:

IVideoDriver* video = device->getVideoDriver();

Everything should work fine :D

You might also wanna add "int argc, char **argv" in the argument body of the main:

int main(int argc, char **argv)

And adding "return 0" at the end of main() is good programming practice :P

Keep up doing the good work dudMaN!

Yustme

Posted: Sun Dec 09, 2007 11:20 pm
by dudMaN
Thanks for the help yustme :D

-dudMan

Posted: Thu Jan 03, 2008 9:42 pm
by wizecoder
Hi I am new to irrlicht and was using your tutorial. I finished lesson 3 but when i run the program it only shows a black screen until i press A,S,W or D and after that it only shows a totally blue screen. please help me see the cube, here is my code so far copied and pasted to be sure.

#include <Irrlicht.h>

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

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

bool keys[irr::KEY_KEY_CODES_COUNT];

class MyEventReceiver : public IEventReceiver {
public:
virtual bool OnEvent(const SEvent& event) {
if(event .EventType == irr::EET_KEY_INPUT_EVENT){
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
return false;
}
};

int main()
{
IrrlichtDevice *device = createDevice(EDT_OPENGL);
IVideoDriver* video = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();

MyEventReceiver rv;
device->setEventReceiver(&rv);

for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;

ISceneNode* cube = smgr->addCubeSceneNode();
cube->setPosition(vector3df(0, 0, 5));

while(device->run() && device) {
if(keys[KEY_KEY_W]) {
cube->setPosition(cube->getPosition()+vector3df(0, 0, 5));
}
if(keys[KEY_KEY_S]) {
cube->setPosition(cube->getPosition()-vector3df(0, 0, 5));
}
if(keys[KEY_KEY_A]) {
cube->setPosition(cube->getPosition()-vector3df(5, 0, 0));
}
if(keys[KEY_KEY_D]) {
cube->setPosition(cube->getPosition()+vector3df(5, 0, 0));
}
video->beginScene(true, true, video::SColor(255,0,0,255));
smgr->drawAll();
video->endScene();
}
}


THANKS :)

Posted: Thu Jan 03, 2008 9:51 pm
by dbest
I faced the same issue yesterday, but managed to sort it out by adding a camera scene node to the code.

Code: Select all

ICameraSceneNode* cam = smgr->addCameraSceneNode(0, vector3df(0,30,-45));
add this before the while loop, and the code should work.

I suppose you are using version 1.4

Posted: Sun Feb 10, 2008 6:45 pm
by dudMaN
Hi.

Your problem is because the cube is in the camera, making it appear black, due to the fact that the cube is black.

When you move it forward, it moves too far forward, making the screen appear blue again.

Add a camera scene node and change the move increments to 0.3 or something low instead of 5.0, and it should work better

-DudMan

Posted: Thu Mar 27, 2008 8:14 pm
by MasterGod
or, another more "accurate" collision function:
Code:

bool collision(ISceneNode* one, ISceneNode* two) {
if(one->getBoundingBox().intersectsWithBox(two->getBoundingBox())) {
return true;
return false;
}


havent tested this one but it should work.
It doesn't seem to work.
Add those lines to example 4:

Code: Select all

	int lastFPS = -1;

	anms->setDebugDataVisible(scene::EDS_FULL);
	node->setDebugDataVisible(scene::EDS_FULL);
	n->setDebugDataVisible(scene::EDS_FULL);

	while(device->run())
	{

		if(n->getBoundingBox().intersectsWithBox(node->getBoundingBox()))
			printf("Collision Detected");
You'll see what I mean by doing it..

Posted: Thu Apr 03, 2008 10:53 pm
by MasterGod
MasterGod wrote:
or, another more "accurate" collision function:
Code:

bool collision(ISceneNode* one, ISceneNode* two) {
if(one->getBoundingBox().intersectsWithBox(two->getBoundingBox())) {
return true;
return false;
}


havent tested this one but it should work.
It doesn't seem to work.
Add those lines to example 4:

Code: Select all

	int lastFPS = -1;

	anms->setDebugDataVisible(scene::EDS_FULL);
	node->setDebugDataVisible(scene::EDS_FULL);
	n->setDebugDataVisible(scene::EDS_FULL);

	while(device->run())
	{

		if(n->getBoundingBox().intersectsWithBox(node->getBoundingBox()))
			printf("Collision Detected");
You'll see what I mean by doing it..
dudMaN, (or anyone else), you know why it doesn't work?

Posted: Fri Apr 04, 2008 7:30 pm
by shadowslair
This is a really nice tutorial. Still can be improved though. Adding fixed and working versions of the codes will be really nice. I don`t think that there are much guys so fallen in love with the old versions to use it. :lol:
or, another more "accurate" collision function:
Code:

bool collision(ISceneNode* one, ISceneNode* two) {
if(one->getBoundingBox().intersectsWithBox(two->getBoundingBox())) {
return true;
return false;
}

havent tested this one but it should work.
Yeah, actually this always returns "true". I would like to know what`s wrong with it too (if possible).

Anyway, this tut is really useful, since it helped me understand some basic stuff. "Working and learning" seems to be a good startegy :wink:

Posted: Wed Apr 09, 2008 6:29 am
by MasterGod
So, does anyone knows what's wrong with it?

Posted: Sat Apr 19, 2008 7:35 pm
by dudMaN
shadowslair wrote:This is a really nice tutorial. Still can be improved though. Adding fixed and working versions of the codes will be really nice. I don`t think that there are much guys so fallen in love with the old versions to use it. :lol:
or, another more "accurate" collision function:
Code:

bool collision(ISceneNode* one, ISceneNode* two) {
if(one->getBoundingBox().intersectsWithBox(two->getBoundingBox())) {
return true;
return false;
}

havent tested this one but it should work.
Yeah, actually this always returns "true". I would like to know what`s wrong with it too (if possible).

Anyway, this tut is really useful, since it helped me understand some basic stuff. "Working and learning" seems to be a good startegy :wink:
Yeah, tested that out on something(dont remember what) and it always returns true. I'm ganna remove that sometime :shock: .

-DudMan

Posted: Sun Apr 20, 2008 3:30 pm
by MasterGod
But it Should work, doesn't it?
We need to find why it is almost always true (I somehow had few falses in some cases)..

Posted: Sun Apr 20, 2008 3:48 pm
by BlindSide
You should use ->getTransformedBoundingBox()

Infact, I went over this months ago on IRC with you dudMaN, didn't I?
But it Should work, doesn't it?
No, no it shouldn't, if you dont return the Transformed bounding box, it just gives you one thats always placed at 0,0.

Posted: Sun Apr 20, 2008 4:06 pm
by MasterGod
"Transformed":?:
Could you explain please what do you mean. I guess you're right and I'll try that tomorrow when I get home but I'm not familiar with the term 'Transformed' in relation to graphics.

Thanks.