Problems with collision checking from mesh

Mononofu

23-05-2009 14:36:52

So I'm trying to create a little applicatin with OgreNewt, at first only doing normal collision checking.

I'm creating my dynamic objects like this:
OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(m_World, 2.5, 5));

// now we make a new rigid body based on this collision shape.
OgreNewt::Body* body = new OgreNewt::Body( m_World, col );
Ogre::Vector3 inertia, offset, dir;
col->calculateInertialMatrix(inertia, offset);

body->setMassMatrix( 10.0, 10.0*inertia );

// this is a standard callback that simply adds a gravitational force (-9.8*mass) to the body.
body->setStandardForceCallback();
body->setLinearDamping(0);

body->attachNode( node );
body->setPositionOrientation( pos, orient );
body->setContinuousCollisionMode(1);


Then I also create terrain from a .mesh:
DataContainer data = ResourceManager::Instance().loadResource(specification);
OgreNewt::CollisionPtr col = boost::shared_ptr<OgreNewt::Collision>(new OgreNewt::CollisionPrimitives::TreeCollision(m_World, boost::any_cast<Ogre::MeshPtr>(data.data), true, OgreNewt::CollisionPrimitives::FW_DEFAULT, scale));
OgreNewt::Body* body = new OgreNewt::Body(m_World, col);

body->attachNode( node );
body->setPositionOrientation( pos, orient );


Now my objects are moving as they should (falling done from gravitation) but when they hit my terrain, they just fall through it. Have I missed anything? Am I using the wrong approach?
The code for terrain loading comes from here: viewtopic.php?f=4&t=8171&p=57150

Edit: If you wonder why I pass a MeshPtr to TreeCollison(): I'm running the different parts of my engine in different threads, and since OgreNewt only uses the mesh, I pass it only the mesh to save overhead. I just overloaded the default constructor.

Edit2: Updated the overloaded constructor so it accounts for different scales. Still does not work

Zero23

24-05-2009 00:58:21

Hmm do you think that this so easy work? That you load only the whole mesh and handle this as an MeshPtr?
Does not Ogre have to parse something or so?
Do you tried the debugger to show your collisions? (May try this and take a screenhot and show it here)

Zero

Mononofu

24-05-2009 11:32:11

Well, OgreNewt _is_ parsing my mesh, that's why I pass it to the constructor of TreeCollision:
OgreNewt::CollisionPtr col = boost::shared_ptr<OgreNewt::Collision>(new OgreNewt::CollisionPrimitives::TreeCollision(m_World, boost::any_cast<Ogre::MeshPtr>(data.data), true, OgreNewt::CollisionPrimitives::FW_DEFAULT, scale));

However, I will try you idea with showing the collision - I guess in some of the demos there has to be code for that.

Zero23

24-05-2009 14:26:08

Your OgreNewt::World has the Debugger us the function getDebugger().

Zero