Irrlicht basics tutorial [Note: HUGE POST]

A forum to store posts deemed exceptionally wise and useful

How would you rate this tutorial?

Great
57
42%
Good
51
38%
Fine
21
15%
Bad
7
5%
 
Total votes: 136

dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post 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
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post 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
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post 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
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

Thanks for the help yustme :D

-dudMan
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
wizecoder
Posts: 13
Joined: Thu Jan 03, 2008 9:36 pm

Post 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 :)
dbest
Posts: 10
Joined: Wed Jan 02, 2008 4:45 pm

Post 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
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post 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
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post 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:
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

So, does anyone knows what's wrong with it?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post 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
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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)..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post 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.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post 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.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Post Reply