Need some C++/Irrlicht syntax help (used to Java)

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
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Need some C++/Irrlicht syntax help (used to Java)

Post by Domarius »

Having some syntax problems I think. I'm new to C++ but experienced with Java, so I'm getting along for the most part, there are just a few things that are different that I don't understand.

In this next line, I'm trying to draw sydney's bounding box (from her mesh). What's wrong with this line?
IVideoDriver::draw3DBox(sydney->getBoundingBox(), SColor(255, 255, 255, 255));
This is the error I get
284 \1.HelloWorld\main.cpp
cannot call member function `virtual void irr::video::IVideoDriver::draw3DBox(irr::core::aabbox3d<f32>,


In this next line, I'm trying to test for a bounding box collision between sydney and faerie. What's wrong with this line?
if (sydney->getBoundingBox()->intersectsWithBox(faerie->getBoundingBox()))
cout<<"HEY";
joy

Post by joy »

I am quite new with C++ too, but what about that:

m_pDevice->getVideoDriver()->draw3DBox(sydney->getBoundingBox(), SColor(255, 255, 255, 255));

In the second case I have no idea, but what is cout - do you mean count? is that may be the error?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

cout is simular to printf ( I say simular because I believe you can do other things with printf depending on how you initialise it ) it just prints out text to the screen ( or console in this case ). Function calls need to be from pointers when in seperate classes, I'm fairly new to C++ so I couldn't say why, I just know it fixes the problem :)

What error does the second one give? I had problems with collision but then I worked it out, it could be the same problem, I haven't got my code in front of me.
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Re: Need some C++/Irrlicht syntax help (used to Java)

Post by warui »

Domarius wrote:What's wrong with this line?
IVideoDriver::draw3DBox(sydney->getBoundingBox(), SColor(255, 255, 255, 255));
You try to call a method of an object without specifying that object. Try that:
device->draw3DBox(sydney->getBoundingBox(), SColor(255, 255, 255, 255));
where 'device' is a pointer to an object of IVideoDriver. See tutorial 1 to learn how to get this object.
Tomasz Nowakowski
Openoko - www.openoko.pl
Guest

Re: Need some C++/Irrlicht syntax help (used to Java)

Post by Guest »

KICKASS! Thanks Warui! That was what I needed - to make it work with the HelloWorld example, I needed to say driver, instead of device though. But thanks to you I got the concept.

Yeah, sorry guys - I didn't really provide the error message or anything for the second problem. I have to re-create it again when I get home this afternoon, and I'll post with proper details then.
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

(That was me)
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Okay here's my 'collision' problem (which I still beleive to be a syntax thing, but it's possible that it isn't)

for this line;

Code: Select all

if (sydney->getBoundingBox()->intersectsWithBox(faerie->getBoundingBox())) {
printf("collision");
}
I get this error:

Code: Select all

178 \irrlicht-0.6\examples\1.HelloWorld\main.cpp
base operand of `->' has non-pointer type `const 
FYI, sydney and faerie are created here;

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
IAnimatedMeshSceneNode* sydney = smgr->addAnimatedMeshSceneNode( mesh );
mesh = smgr->getMesh("../../media/faerie.md2");
IAnimatedMeshSceneNode* faerie = smgr->addAnimatedMeshSceneNode( mesh );
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

It doesn't like it because while getBoundingBox() is a member of aabox3d, it isn't a pointer so it can't then call functions within itself. It is just a set of verts defining the bounding box. I would use this:

Code: Select all

core::aabbox3df* sydBB = sydney->getBoundingBox();

if (sydBB->intersectsWithBox(faerie->getBoundingBox())
warui
Posts: 232
Joined: Wed Apr 14, 2004 12:06 pm
Location: Lodz, Poland
Contact:

Post by warui »

Nope Tyn, you are not right. getBoundingBox() returns reference to core::aabbox3df not a pointer, that's first. The second thing is: getBoundingBox() is not a member of aabox3d, but a member of scene::SAnimatedMesh (in this example).

To Domarius:
You get error because as i said above getBoundingBox() returns reference not a pointer. So you should use "." operator instead of "->".

Code: Select all

if (sydney->getBoundingBox().intersectsWithBox(faerie->getBoundingBox()))
You should really get yourself a book about c++ and learn about pointers, references, classes and all the stuff :) Personaly I recommend "Thinking in C++" by Bruce Eckel. You can download it for free from his site here
Tomasz Nowakowski
Openoko - www.openoko.pl
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

Man, thanks again Warui. Free downloadable textbooks?? I can't beleive it!! *downloads C++ vol 2*

Well, it works (for the most part - now I have to figure out why faerie's bounding box isn't moving when her mesh does - another thread for another problem.)

Thanks for the link to the textbook Warui. I've completed a course in Java, and am finding C++ very similar, but there are a few differences which I'm learning, and that book and the net should help.
This particular difference being - I have never heard of a 'reference' before. Just pointers and primitive data types. From what I just read, I'm getting the impression that a reference is a "CONSTANT" pointer, that is dereferenced at compile time to actually specify the object it's pointing to.
Post Reply