CollisionPrimitives and CalcBoxSolid

deshan

10-05-2009 18:11:25

Hi all
I have a problem with using
  1. OgreNewt::CollisionPrimitives::Box[/list:u]
    1. OgreNewt::MomentOfInertia::CalcBoxSolid[/list:u]

      In my program I am load a tree model and apply physics on tree node. But the problem is selecting the correct parameters for CollisionPrimitives::Box and MomentOfInertia::CalcBoxSolid. I have tried it with several different values but still didn't manage to find the correct one. Tree is loaded but actual collision bounding box is not correct. The issue is collision works only for part of the tree. For some part(top part of the tree) it doesn't.
      Now I am wondering whether these two methods get affected by tree model properties. please help me to get a clear idea about those two methods. I am a beginner please help me.

      This is my code

      void GameApplication::createEnemy(Ogre::SceneNode* node)
      {
      //--------
      Vector3 size(100.0f,100.0f,100.0f);
      SceneNode* node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
      Entity* ent = mSceneMgr->createEntity("Ninja", myTree3.mesh" );
      node1->attachObject( ent );
      node1->setScale( size );

      // rigid body.
      OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box( mWorld, Vector3(40.0f,1000.0f,40.0f));
      OgreNewt::Body* bod = new OgreNewt::Body( mWorld, col );
      bod->attachToNode( node1 );

      // initial position
      bod->setPositionOrientation( Ogre::Vector3(0,100,-2),Ogre::Quaternion::IDENTITY );
      delete col;

      Ogre::Real mass = 10.0;
      Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( mass, Vector3(40.0f,1000.0f,40.0f));
      bod->setMassMatrix( mass, inertia );
      bod->setStandardForceCallback();
      }

Virginie

11-05-2009 08:42:45

Hello,

Me I don't use calcBoxSolid, I use calculateInertialMatrix :

For you :

Ogre::Vector3 inertia,offset;
col->->calculateInertialMatrix(inertia,offset);
delete col;
bod->setMassMatrix( mass, mass*inertia );

deshan

11-05-2009 18:16:12

Hi Virginie
First thank you very much for answering.
Your solution works great. Now it's quite clear. :D

But I have a small issue. Initially I set the Body position (body->setPositionOrientation(...)) at some higher place from ground. So it's fall because of gravity. But now I sees the the place where it stops is affected by the size parameter of CollisionPrimitives::Box( ,size ).
For a example when I set it like CollisionPrimitives::Box( mWorld, Vector3(1.0f,1.0f,1.0f) It continuously fall until it reach the floor. But when It is CollisionPrimitives::Box( mWorld, Vector3(40.0f,100.0f,40.0f) it stops some higher place from ground. But collision works great here as I expected.

This is my code.

SceneNode *treeNode = node->createChildSceneNode("TreeNode");
Vector3 size(100.0f,100.0f,100.0f);
Entity* pPlaneEnt = mSceneMgr->createEntity( "TreeEntity1", "myTree3.mesh");
treeNode->attachObject( pPlaneEnt );
treeNode->setScale( size );

Ogre::Vector3 inertia,offset;
OgreNewt::ConvexCollision* col= new OgreNewt::CollisionPrimitives::Box( mWorld, Vector3(40.0f,1.0f,40.0f) );
col->calculateInertialMatrix(inertia,offset);

OgreNewt::Body* treebody= new OgreNewt::Body( mWorld, col );
treebody->attachToNode( treeNode );
treebody->setPositionOrientation( *iterator, Ogre::Quaternion::IDENTITY );
delete col;

Ogre::Real mass = 10000000.0;
treebody->setMassMatrix( mass, mass*inertia );
treebody->setStandardForceCallback();


Could you please suggest a solution to make it fall until it reach the floor while maintaining the collision box size.

Virginie

12-05-2009 08:45:55

That I see seems correct (I don't know what is your iterator I think but I's just a pointor in vector3).

So maybe your problem don't become of this node. So :
- Have you correctly define your floor? It's possible that is your floor wich don't have a good collision.
- I don't know if you move object by physics but if not maybe your contactCallback is wrong.

Me I use only collision in OgreNewt, I don't moved my objects by physics, so I don't know very well some problem of masse...

Excuse me for my english ;)

deshan

12-05-2009 10:04:32

Hi Virginie
Thank you again for answering.

I don't know what is your iterator I think but I's just a pointor in vector3
Yeah it is a pointer in vector3(There I create many trees that's why I did use a iterator).

Have you correctly define your floor? It's possible that is your floor wich don't have a good collision.
This is the way which I create my floor.
void GameApplication::createFloor()
{
//-- Create floor object
Vector3 size(10000.0f,10.0f,10000.0f);
Ogre::SceneNode* floorNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Entity* pPlaneEnt= mSceneMgr->createEntity( "floorobj", "box.mesh" );
pPlaneEnt->setMaterialName("Examples/GrassFloor");

floorNode->attachObject( pPlaneEnt );
floorNode->setScale( size );

//-- create collision object represents the shape
OgreNewt::ConvexCollision* floorCol = new OgreNewt::CollisionPrimitives::Box( mWorld, size );
//OgreNewt::ConvexCollision* floorCol = new OgreNewt::CollisionPrimitives::TreeCollision( mWorld, floorNode, true );

// create rigid body object from collision object
OgreNewt::Body* floorbody = new OgreNewt::Body( mWorld, floorCol );

floorbody->attachToNode( floorNode );

floorbody->setPositionOrientation( Ogre::Vector3(0.0f,0.0f,0.0f), Ogre::Quaternion::IDENTITY );

delete floorCol;
}


I don't know if you move object by physics but if not maybe your contactCallback is wrong.

I dnot move objects. But place them some high place from the ground to just see the gravity effect.
treebody->setPositionOrientation(Vector3(0,500,0), Ogre::Quaternion::IDENTITY );

As I mention earlier object falls until it touch the floor when the collision primitive set to
CollisionPrimitives::Box( mWorld, Vector3(1.0f,1.0f,1.0f)

When it is
CollisionPrimitives::Box( mWorld, Vector3(40.0f,100.0f,40.0f)
It falls but stops some place above the floor. Which means not touch the ground. The place where it stops, affected by the y axis parameter in CollisionPrimitives::Box.

Please help me

Virginie

12-05-2009 11:03:09

So, I resay in my bad english :
Your objects fall and stop when they touch the floor?

So, for effects as bounce... you must define material and materialPair and affect some physics properties (setDefaultElasticity, setDefaultFriction...)

And I don't know why when you set the collision box the object don't do as same. But be careful, you are a big collision box with 100.0 in y coodinate : has your object the same size? if no, it's possible that your collision box touch the floor but not your object in your scene(because it's much little).

deshan

13-05-2009 20:13:51

Ok I think I have found the solution.
The problem was my collison primitive position alignment. With using the forth parameter I can set alignment or adjust the position of the box.

For users
Real boxHeight = pPlaneEnt-> getBoundingBox().getSize().y * size.y; // now we can get actual collison bounding hight
col = new OgreNewt::CollisionPrimitives::Box( mWorld, Vector3(40.0f, boxHeight ,40.0f),Ogre::Quaternion::IDENTITY,Vector3(0, boxHeight/2 ,0) );


Now the collision bounding is aligned.

Related discussion
https://www.ogre3d.org/addonforums/view ... f=4&t=3900

Virginie

14-05-2009 08:33:44

ok