Collsion with a irredit scene
Collsion with a irredit scene
Hello Folks,
how can I create a pointer (node) to a irredit scene?
I'm trying to add a collisionanimator to the scene and I guess a node is necessary to accomplish.
The function LoadIrrScene returns only TRUE if successfull but no pointer.
Thanx for helping.
Andi
how can I create a pointer (node) to a irredit scene?
I'm trying to add a collisionanimator to the scene and I guess a node is necessary to accomplish.
The function LoadIrrScene returns only TRUE if successfull but no pointer.
Thanx for helping.
Andi
I've got the same question to.
My irrScene contain only one mesh (a simply room) and i've got to made the collision between it and the camera.
In IrrEdit i notice that it's possible to add an OctTree (Edit->Insert->OctTree) and to add a CollisionResponse (from the Property menu click on '+' then 'collisionResponse').
Some ideas?
My irrScene contain only one mesh (a simply room) and i've got to made the collision between it and the camera.
In IrrEdit i notice that it's possible to add an OctTree (Edit->Insert->OctTree) and to add a CollisionResponse (from the Property menu click on '+' then 'collisionResponse').
Some ideas?
Bye bye,
Wally
Wally
You want to apply an animator to the entire scene? smgr->getRootSceneNode() will return a pointer to the root of the scene graph. You should be able to put an animator on that. If you want to apply an animator to some node within the scene, you have two options. You can search the scene graph for the node you want [using name, type and/or id]. You could use irrEdit to apply the animator to the object before writing out the .irr file.
The one issue with the second solution is that you can't apply user-created animators from within irrEdit. You could edit the xml with a text editor and add the necessary information directly.
I'm trying to talk with Niko about making it possible to do scene node and scene node animator factories to irrEdit dynamically.
If you are trying to add collision to a specific node in the tree, the best thing to do is search the scene graph for the right node, make sure it is the right type, cast it to the right type, and use that to access the type specific member variables.
Travis
The one issue with the second solution is that you can't apply user-created animators from within irrEdit. You could edit the xml with a text editor and add the necessary information directly.
I'm trying to talk with Niko about making it possible to do scene node and scene node animator factories to irrEdit dynamically.
If you are trying to add collision to a specific node in the tree, the best thing to do is search the scene graph for the right node, make sure it is the right type, cast it to the right type, and use that to access the type specific member variables.
Travis
Thanks for your answer. I understand.
Unfortunatly i'm new at Irrlicht.. can you help me a little more?
Look, suppose that i've got a scene called "Scene1.irr" and, in it, a single mesh called "Mesh1" (nothing more, no camera, no light).
First I use the loadScene and the getRootSceneNode to retrieve the node
Ok, this should be right..
Now... i've got my collision routine..
... but to use it i need to have the "mesh" in the rootnode (to make the substitution of the "getMesh" in the CreateOctTreeTriangleSelector
How can i retrieve this mesh from the root node?
I'm sorry, too new to irrlicht
Thanks!
Unfortunatly i'm new at Irrlicht.. can you help me a little more?
Look, suppose that i've got a scene called "Scene1.irr" and, in it, a single mesh called "Mesh1" (nothing more, no camera, no light).
First I use the loadScene and the getRootSceneNode to retrieve the node
Code: Select all
smgr->loadScene("Scene1.irr")
// add a user controlled camera
smgr->addCameraSceneNodeFPS();
scene::ISceneNode* node = smgr->getRootSceneNode();
Now... i've got my collision routine..
Code: Select all
if (node)
{
selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
node->setTriangleSelector(selector);
selector->drop();
}
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f, -1, 0, 0, true);
//camera->setPosition(core::vector3df(0,1000,0));
camera->setPosition(core::vector3df(0,0,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);
Code: Select all
smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
I'm sorry, too new to irrlicht
Thanks!
Bye bye,
Wally
Wally
Collsion with a irredit scene
Hi,
Have you resolved this problem? I am also looking to do collision detection with a .irr scene file. Any help Greatly appreciated!
Cheers.
Have you resolved this problem? I am also looking to do collision detection with a .irr scene file. Any help Greatly appreciated!
Cheers.
You don't want the root node. The root node doesn't have a mesh. The node that you want is somewhere under the root. You have to find it by searching the scene node graph.
The scene manager provides functions for finding nodes given their id or name. You just have to use them.
The other way is to add collision information as the object is read back from the xml file using a data serializer. You would create a class derived from ISceneUserDataSerializer and in the derived class createUserData you would create an attribute, and set a flag indicating whether or not to add collision, and return it. In OnReadUserData you would check the scene node type and the flag. If they both indicate you should do so, you would create collision data for the scene node.
Travis
The scene manager provides functions for finding nodes given their id or name. You just have to use them.
Code: Select all
ISceneNode* scene_node = smgr->getSceneNodeFromName("ball1");
if (scene_node && scene_node->getType() == ESNT_MESH)
{
IMeshSceneNode* node = (IMeshSceneNode*)scene_node;
// add collision stuff...
}
Travis
-
- Posts: 13
- Joined: Wed Feb 14, 2007 3:32 pm
- Location: HH | Germany
- Contact:
ok umm, im having troubles with this..
i have an .irr file named ship which holds all the objects ect. in my level. inside the Irr is a model named Ship which is a .obj.
so i load up te irr file, get the node from searching then typecast it to IAnimatedMesh*:
i then setup a new scene node and triangle selector:
is this how i do it? it compiles fine but crahes while it loads up the models
i have an .irr file named ship which holds all the objects ect. in my level. inside the Irr is a model named Ship which is a .obj.
so i load up te irr file, get the node from searching then typecast it to IAnimatedMesh*:
Code: Select all
smgr->loadScene("media/levels/Ship.irr");
ISceneNode* scene_node = smgr->getSceneNodeFromName("Ship");
scene::IAnimatedMesh* levelMesh;
if (scene_node)
{
levelMesh = (IAnimatedMesh*)scene_node;
}
Code: Select all
scene::ISceneNode* levelNode = 0;
if (levelMesh)
levelNode = smgr->addOctTreeSceneNode(levelMesh->getMesh(0));
scene::ITriangleSelector* selector = 0;
if (levelNode)
{
levelNode->setPosition(core::vector3df(0,0,0));
selector = smgr->createOctTreeTriangleSelector(levelMesh->getMesh(0), levelNode, 128);
levelNode->setTriangleSelector(selector);
selector->drop();
}
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, 25.0f, -1, 0, 0, true);
camera->setPosition(core::vector3df(-30,15,4));
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(3,1,3),
core::vector3df(0,-2,0),
core::vector3df(0,7,0));
camera->addAnimator(anim);
anim->drop();
Code: Select all
ISceneNode* scene_node = smgr->getSceneNodeFromName("Ship");
scene::IAnimatedMesh* levelMesh;
if (scene_node)
{
levelMesh = (IAnimatedMesh*)scene_node;
}
Code: Select all
ISceneNode* scene_node = smgr->getSceneNodeFromName("Ship");
scene::IAnimatedMesh* levelMesh;
if (scene_node)
{
IAnimatedMeshSceneNode* msn = (IAnimatedMeshSceneNode*)scene_node;
levelMesh = scene_node->getAnimatedMesh();
}
yah but i forgot that the ISceneNode wasn't an IAnimatedMesh... thats an irrlicht thing.
and im hoping that
was suposed to be
also my program crashes on the
line.
in the debugger it shows that msn connected to the right node that i searched for, but an error comes up and says:
and im hoping that
Code: Select all
levelMesh = scene_node->getAnimatedMesh();
Code: Select all
levelMesh = msn->getMesh();
Code: Select all
levelMesh = msn->getMesh();
in the debugger it shows that msn connected to the right node that i searched for, but an error comes up and says:
Unhandled exception at 0x20642528 in collision test.exe: 0xC0000005: Access violation reading location 0x20642528.
There are some differences between the code I originally wrote and the code you are using.
Notice in the first block of code I explicitly check the type of the scene node before I go and cast it. This is the only way that you can tell if it is safe to cast the scene node to a derived scene node type [kinda like dynamic_cast]. The code you provided later doesn't do that. Looking at your code, I see that the actual node is an oct-tree scene node. The oct-tree scene node type is not related to IAnimatedMeshSceneNode, so the cast isn't something that you can legally do.
For oct-tree nodes, you'll want to do something like this.
Travis
Code: Select all
ISceneNode* scene_node = smgr->getSceneNodeFromName("ball1");
if (scene_node && scene_node->getType() == ESNT_MESH)
{
IMeshSceneNode* node = (IMeshSceneNode*)scene_node;
// add collision stuff...
}
Code: Select all
ISceneNode* scene_node = smgr->getSceneNodeFromName("Ship");
scene::IAnimatedMesh* levelMesh;
if (scene_node)
{
IAnimatedMeshSceneNode* msn = (IAnimatedMeshSceneNode*)scene_node;
levelMesh = scene_node->getAnimatedMesh();
}
For oct-tree nodes, you'll want to do something like this.
Code: Select all
ISceneNode* scene_node = smgr->getSceneNodeFromName("Ship");
if (scene_node && scene_node->getType() == ESNT_OCT_TREE)
{
core::IAttributes* attribs = fileSystem->createEmptyAttributes();
if (attribs)
{
scene_node->serializeAttributes(attribs);
// get the mesh name out
core::stringc mesh_name = attribs->getAttributeAsString("Mesh");
attribs->drop();
// get a mesh from the name
IMesh* mesh = smgr->getMesh(mesh_name)->getMesh(0);
ITriangleSelector* selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), scene_node, 128);
scene_node->setTriangleSelector(selector);
selector->drop();
}
}
Last edited by vitek on Tue Feb 20, 2007 3:37 am, edited 1 time in total.