IPhysic problem part 2

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
Requiem
Posts: 20
Joined: Fri Mar 02, 2007 10:01 am

IPhysic problem part 2

Post by Requiem »

Hi,
I was having problem in introducing iphysics in my program but now that ok. thank to the forum. But now im getting another problem. My program compile well no errors... but when it initialised it stuck on this line

Code: Select all

IPhysicsEntity* levelEntity = physics.addEntity(&level);
my mesh is a static mesh created with 3DS max 8 export to ".obj" with some texture the i use irredit for a better lookin of theenvironment .THe name I've give to the mesh in irrEdit is "city" . then the code continues for some collision stuff. The code are as follows:

Code: Select all


smgr->loadScene("media/town.irr");
   
    scene_node = smgr->getSceneNodeFromName("city");
  
    if(scene_node->getType()==ESNT_MESH)
    {
                                       
         IAttributes* attribs = device->getFileSystem()->createEmptyAttributes(); 
         if (attribs) 
         {
                      
               scene_node->serializeAttributes(attribs);
               // get the mesh name out 
               core::stringc mesh_name = attribs->getAttributeAsString("Mesh");
               const c8 *meshName = mesh_name.c_str(); 
               
               attribs->drop();
              
               // get a mesh from the name 
               IAnimatedMesh* town_mesh = smgr->getMesh(meshName);
               IAnimatedMeshSceneNode* levelnode = smgr->addAnimatedMeshSceneNode(town_mesh);  
   
               	SPhysicsStaticMesh level;
	            level.mesh = town_mesh;
	            level.meshnode = levelnode;
                
	            level.meshScale = vector3df(0.1f, 0.1f, 0.10f);    
	            level.meshnode->setScale(level.meshScale);  

	            IPhysicsEntity* levelEntity = physics.addEntity(&level);   
	             
           }    
    }

Someone with any solution??
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You load the scene, find a node named 'city', get the animated mesh used for the node named 'city', then create a new animated mesh scene node using that mesh? Are you absolutely sure this is what you want to be doing, creating a duplicate of the 'city'?
Requiem
Posts: 20
Joined: Fri Mar 02, 2007 10:01 am

Post by Requiem »

Even if i remove the line

Code: Select all

IAnimatedMeshSceneNode* levelnode = smgr->addAnimatedMeshSceneNode(town_mesh);
and change the line

Code: Select all

level.meshnode = levelnode;
to

Code: Select all

level.meshnode=scene_node;
i get the same problem
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Oh, sorry, I didn't mean to imply that I was providing a solution to your problem. I was just commenting that you are creating a new scene node when it didn't appear that you would want to be doing that. I don't use IPhysics, so I don't really know what the problem could be.

I'll take a guess though. I'm assuming that the addEntity code builds up some sort of bounding heirarchy for collisions. This may take some time to do if your mesh is really big.
Ethan
Posts: 9
Joined: Sun Oct 12, 2008 9:00 pm

Post by Ethan »

I had problems with casting to IAnimatedMesh from IMesh too.
But i solved the problem by importing my levelmesh as animated mesh and not as normal mesh in the irrEdit.
So i didn't get a casting error, but i don't collide anyway with this mesh?!
I tried collision with boxes before and everything works, except of collision with this mesh.

anyone can tell why?

(notice: m_node is an ISceneNode, i imported as .obj animated mesh file in the irrEdit)

Code: Select all

SPhysicsStaticMesh meshColObj;

	if(m_node->getType() == ESNT_ANIMATED_MESH)
	{
		meshColObj.mesh = (IAnimatedMesh*)(((IAnimatedMeshSceneNode*)m_node)->getMesh());
		meshColObj.meshnode = m_node;

		m_physics->addEntity(&meshColObj);
	}
	else
	{
		printf("Assigned MeshCollider NodeCode without having IAnimatedMesh");
	} 
Ethan
Posts: 9
Joined: Sun Oct 12, 2008 9:00 pm

Post by Ethan »

Solved the problem, by syncing the SCALE and the POSITION of the physics and the irrlicht object.

Code: Select all

if(m_node->getType() == ESNT_ANIMATED_MESH)
	{
		meshColObj.mesh = (IAnimatedMesh*)(((IAnimatedMeshSceneNode*)m_node)->getMesh());
		meshColObj.meshnode = m_node;

		meshColObj.meshScale = m_node->getScale();

		IPhysicsEntity* myPhyObj = m_physics->addEntity(&meshColObj);
		myPhyObj->setPosition(m_node->getAbsolutePosition());
	}
Post Reply