Need some C++/Irrlicht syntax help (used to Java)
Need some C++/Irrlicht syntax help (used to Java)
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";
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";
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.
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.
Re: Need some C++/Irrlicht syntax help (used to Java)
You try to call a method of an object without specifying that object. Try that:Domarius wrote:What's wrong with this line?
IVideoDriver::draw3DBox(sydney->getBoundingBox(), SColor(255, 255, 255, 255));
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
Openoko - www.openoko.pl
Re: Need some C++/Irrlicht syntax help (used to Java)
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.
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.
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;
I get this error:
FYI, sydney and faerie are created here;
for this line;
Code: Select all
if (sydney->getBoundingBox()->intersectsWithBox(faerie->getBoundingBox())) {
printf("collision");
}
Code: Select all
178 \irrlicht-0.6\examples\1.HelloWorld\main.cpp
base operand of `->' has non-pointer type `const
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 );
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())
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 "->".
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
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()))
Tomasz Nowakowski
Openoko - www.openoko.pl
Openoko - www.openoko.pl
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.
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.