for my first question I'll use parts of the code of the very first tutorial:
startup
Code: Select all
#include <irrLicht/irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
if (!device)
return 1;
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
Code: Select all
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
{
device->drop();
return 1;
}
But I'm not really sure that I understand what happens in the following bit of code. I've tried to explain it in my own words, is the following correct?L
So 'node' is a pointer of the class IAnimatedMeshSceneNode. And when node gets created a function is called (addAnimatedMeshSceneNode). The node itself just holds information, but the function addAnimatedMeshSceneNode() is what actually puts the sydney mesh on the scene. from that function onward the mesh exists on the scene. You can't see it just yet because there is no camera and because the drawAll() function has not been called yet by smgr.
Code: Select all
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
Code: Select all
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
- the pointer 'node' holds information
- the function addAnimatedMeshSceneNode adds the mesh to the scene, after that point the mesh exists but is not visible yet. node now points to that mesh
- letting node call functions like node->setMaterialFlag changes properties of the mesh was created on the scene
- However, if I would put the following line after the if(node){ ...} part:
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/ninja.b3d"));
then I would not be able to change the properties of the first mesh anymore (the sydney one) because node points to a different mesh now.
If I would want two meshes on the screen that I could keep changing the properties of I would need two seperate nodes.
-after the camera is created the user still doesn't see anything on the screen. Only after smgr->drawAll(); is called the user will be able to see something.
My other questions are related to tutorial 7. ( I won't put the entire code here, its very long, it is found here:http://irrlicht.sourceforge.net/docu/example007.html)
My first question is about the Triangleselector. In the comments in the code it says
"After we created the triangle selector, we attach
it to the q3node. This is not necessary, but in this way, we do not
need to care for the selector, for example dropping it after we do not
need it anymore."
This is done here:
Code: Select all
selector = smgr->createOctreeTriangleSelector(q3node->getMesh(), q3node, 128);
q3node->setTriangleSelector(selector);
But just before they said it did not matter. And later on in the code the selector gets dropped anyway. Why is this?
I'm also not quite sure what these lines of code really do. The first one creates an OcrtreeTriangleSelector and lets selector point to that TrianglSelector.
createOctreeTriangleSelector is like addAnimatedMeshSceneNode, it makes something. but they are two different things and in the case of createOctreeTriangleSelector you must not forget to drop it afterwards.
I don't understand the second line of code either. In the first line you already created a triangle selector that affects a certain mesh of node q3node. So what does the second line do?
Then a bit down there is the following code:
Code: Select all
if (selector)
{
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-10,0), core::vector3df(0,30,0));
selector->drop(); // As soon as we're done with the selector, drop it.
camera->addAnimator(anim);
anim->drop(); // And likewise, drop the animator when we're done referring to it.
}And what does the line camera->addAnimator(anim); really do? the createCollisionResponseAnimator already has 'selector' and 'camera' defined for its first 2 parameters, so what does addAnimator do that hasn't already been defined yet?
Later on in the code a md2 node gets made (called node) after that there is this bit of code:
video::SMaterial material;
material.Lighting = true;
node->getMaterial(0) = material;
would that be any different from:?
node->setMaterialFlag(EMF_LIGHTING, true);
I don't see anything change when I replace that part of the code. So is it the same or is there some other difference I can't see here?
in the game loop is the following bit of code:
Code: Select all
core::line3d<f32> ray;
ray.start = camera->getPosition();
ray.end = ray.start + (camera->getTarget() - ray.start).normalize() * 1000.0f;Then in if(selectedSceneNode) it says:
Code: Select all
// We need to reset the transform before doing our own rendering.
driver->setTransform(video::ETS_WORLD, core::matrix4());
driver->setMaterial(material);
driver->draw3DTriangle(hitTriangle, video::SColor(0,255,0,0));Phew, that took me a while to write! I hope someone is willing to help me with some of this. Any help is very much appreciated!
