irredit and creating collisions

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Dutch
Posts: 12
Joined: Tue Aug 22, 2006 9:45 pm
Location: UK

irredit and creating collisions

Post by Dutch »

Hi folks

I'm loading irredit files but have a problem setting up collisions. This is how far i got:

Code: Select all

smgr->loadScene("scenes/example.irr", 0);
	scene::ISceneNode* level = smgr->getSceneNodeFromId(5);
	smgr->createOctTreeTriangleSelector(??????, level ,128);

	scene::ITriangleSelector* selector = 0;
	

    scene::ICameraSceneNode* camera = 
		smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, true);
	camera->setPosition(core::vector3df(0,200,0));

	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(30,50,30),
		core::vector3df(0,-3,0), 
		core::vector3df(0,50,0));
	camera->addAnimator(anim);
	anim->drop();
How do i get a pointer to the mesh in the irredit file needed for the createOctTreeTriangleSelector

many thanks

dutch
Amt0571
Posts: 128
Joined: Mon Mar 06, 2006 6:29 pm

Post by Amt0571 »

UP! I'm also very interested on this!
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

I don't know of any way to do this because you can only search for ISceneNode (which doesn't contain an IMesh).
If I 'm right about this then it is a huge limitation. The actual mesh is needed for just about everything, after you load your scene: collision detection, physics, etc.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The scene node has a getType() method. If the type is ESNT_MESH you could cast the ISceneNode to an IMeshSceneNode. Now only if IMeshSceneNode had a getMesh() accessor...
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

vitek wrote:Now only if IMeshSceneNode had a getMesh() accessor...
Yes, that is outright strange. I don't see the reason why there isn't such a method (const even).
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

It's because an ISceneNode could be everything....a light a camera or something the user defined and as far as i know a light or a camera doesn't have a mesh and u don'T know what the user could use the scenenode for so it's good that there isn't such a method.

but i worked around that with the following trick:

Code: Select all

struct NodeCreationParams
{
      std::string name;
      std::string mesh;
      std::string type;
      vector3df position;
      vector3df rotation;
      vector3df scale;
};
NodeCreationParams* tnode;
NodeCreationParams* tempnode;

Code: Select all

IXMLReader* reader = device->getFileSystem()->createXMLReader(sceneName.c_str());

    if (reader == 0)
     return false; // file could not be opened

     // parse the file until end reached
    while(reader->read())
    {
                        // based on xml->getNodeType(), do something.
                        switch(reader->getNodeType())
                        {
                            case EXN_ELEMENT:
                                if(stringw("node") == reader->getNodeName())
                                {
                                    ///cout<<"Found NewNode"<<endl;
                                    if(tnode == NULL)
                                    {
                                        tnode = new NodeCreationParam;
                                        tnode->parent = NULL;
                                    }
                                    else
                                    {
                                        tempnode = new NodeCreationParam;
                                        tempnode->parent = tnode;
                                        tnode = tempnode;
                                        tempnode = NULL;
                                    }
                                    tnode->type = (char*)stringc(reader->getAttributeValue(L"type")).c_str();
                                    cout<<"Handeld Node"<<endl;
                                }
                                if(tnode != NULL)
                                {
                                    ///cout<<"Found NodeParameter: "<<stringc(reader->getNodeName()).c_str()<<" / "<<stringc(reader->getAttributeValue(L"name")).c_str()<<endl;
                                    if(stringw("string") == reader->getNodeName())
                                    {
                                        if(stringw("Name") == reader->getAttributeValue(L"name"))
                                        {
                                            tnode->name = (char*)stringc(reader->getAttributeValue(L"value")).c_str();
                                            cout<<"Name: "<<tnode->name;
                                        }
                                    }
                                    if(stringw("string") == reader->getNodeName())
                                    {
                                        if(stringw("Mesh") == reader->getAttributeValue(L"name"))
                                        {
                                            tnode->mesh = (char*)stringc(reader->getAttributeValue(L"value")).c_str();
                                            cout<<"Mesh: "<<tnode->mesh;
                                        }
                                    }
                                    if(stringw("vector3d") == reader->getNodeName())
                                    {
                                        if(stringw("Position") == reader->getAttributeValue(L"name"))
                                        {

                                            sscanf((char*)stringc(reader->getAttributeValue(L"value")).c_str(),"%f,%f,%f", &tnode->position.X, &tnode->position.Y, &tnode->position.Z);

                                        }
                                        if(stringw("Rotation") == reader->getAttributeValue(L"name"))
                                        {

                                            sscanf((char*)stringc(reader->getAttributeValue(L"value")).c_str(),"%f,%f,%f", &tnode->rotation.X, &tnode->rotation.Y, &tnode->rotation.Z);

                                        }
                                        if(stringw("Scale") == reader->getAttributeValue(L"name"))
                                        {

                                            sscanf((char*)stringc(reader->getAttributeValue(L"value")).c_str(),"%f,%f,%f", &tnode->scale.X, &tnode->scale.Y, &tnode->scale.Z);

                                        }
                                    }
                                    ///cout<<"Handeld NodeParameter"<<endl;
                                }
                                break;

                            case EXN_ELEMENT_END:
                                if(stringw("node") == reader->getNodeName())
                                {
                                    if(tnode != NULL)
                                    {
                                        if(!tnode->name.empty())
                                        {
                                            cout<<"Nodename: "<<tnode->name<<endl;
                                            if(tnode->type == "mesh")
                                            {
                                                //This function will build the collision
                                                buildCollisionMesh(*tnode);
                                            }
                                        }

                                        if(tnode->parent == NULL)
                                        {
                                            delete tnode;
                                            tnode = NULL;
                                        }
                                        else if(tnode->parent != NULL)
                                        {
                                            tempnode = tnode;
                                            tnode = tnode->parent;
                                            delete tempnode;
                                            tempnode = NULL;
                                        }
                                    }
                                }
                                break;
                        }
    }

    // delete the xml parser after usage
    delete reader;
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It's because an ISceneNode could be everything....a light a camera or something the user defined and as far as i know a light or a camera doesn't have a mesh
You didn't read very well. The issue is why does the IMeshSceneNode interface not provide a getMesh() accessor? All IMeshSceneNode derived classes _should_ have a mesh. You can call setMesh(), why can't you call getMesh()?

Travis
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

t's because an ISceneNode could be everything....a light a camera or something the user defined and as far as i know a light or a camera doesn't have a mesh and u don'T know what the user could use the scenenode for so it's good that there isn't such a method.
We were talking about IMeshSceneNode...
Post Reply