SceneNode is Random

AHelper2

21-10-2010 23:22:28

Well... I have a newton body created with a default box collision shape. I set the inertia, etc. correctly. I didn't add the default collision callback.

The fun part is... the scenenode flies around on it's own. I have a small dump done with:

// msg_printDebug prints a colored string to cout
// the scenenode is, of course, in this->bData.node
// This is executed every time after world->update(...) (which works)
msg_printDebug(string("Pos: ").append(Ogre::StringConverter::toString(this->bData.node->getPosition())));


When running this, the node flies upwards and there is no forces applied. This will continue for a long time until it stops at about 21 units upwards. When I do use setDefaultForceCallback(), it stops after a while, but the motion is the same. This is the output from the dump (no callback):
?? Pos: 0 0 0
?? Pos: 0 0 0
?? Pos: -1.61049e-08 0.084018 4.0093e-08
?? Pos: 8.08348e-07 0.168336 -2.04678e-06
?? Pos: 2.77011e-06 0.252639 -7.01065e-06
?? Pos: 5.2929e-06 0.338915 -1.33928e-05
?? Pos: 6.76003e-06 0.423492 -1.71011e-05
?? Pos: 7.23045e-06 0.508533 -1.82847e-05
?? Pos: 6.70538e-06 0.593065 -1.69468e-05
?? Pos: 5.19401e-06 0.677586 -1.31107e-05
?? Pos: 2.70013e-06 0.762113 -6.78591e-06
?? Pos: -7.73289e-07 0.846664 2.02003e-06
?? Pos: -5.22364e-06 0.931249 1.33005e-05
?? Pos: -1.06453e-05 1.01583 2.70412e-05
?? Pos: -1.70474e-05 1.10056 4.32656e-05
?? Pos: -2.4406e-05 1.18519 6.19124e-05
?? Pos: -3.27016e-05 1.26958 8.29327e-05
?? Pos: -4.19884e-05 1.35432 0.000106464
?? Pos: -5.22125e-05 1.43891 0.000132369
?? Pos: -5.97988e-05 1.5239 0.00015159
?? Pos: -6.01061e-05 1.60847 0.000152369
?? Pos: -6.13946e-05 1.6932 0.000155634
?? Pos: -5.84807e-05 1.77761 0.000148251
?? Pos: -5.84022e-05 1.86325 0.000148052
?? Pos: -5.48709e-05 1.94817 0.000139104
?? Pos: -5.77098e-05 2.03295 0.000146297
?? Pos: -5.34741e-05 2.11744 0.000135565
?? Pos: -5.27588e-05 2.20219 0.000133752
?? Pos: -5.2101e-05 2.287 0.000132086
?? Pos: -5.04982e-05 2.37161 0.000128024
?? Pos: -4.92238e-05 2.45606 0.000124795
?? Pos: -5.04633e-05 2.54085 0.000127936
?? Pos: -4.95557e-05 2.62563 0.000125636
?? Pos: -4.99008e-05 2.71012 0.000126511
?? Pos: -4.99373e-05 2.79435 0.000126603
?? Pos: -4.97667e-05 2.88152 0.000126171
?? Pos: -4.96023e-05 2.96549 0.000125754
?? Pos: -4.94366e-05 3.05016 0.000125334
?? Pos: -4.92741e-05 3.13322 0.000124923
?? Pos: -4.91121e-05 3.21597 0.000124512
?? Pos: -4.89506e-05 3.2985 0.000124103
?? Pos: -4.87894e-05 3.38085 0.000123695
?? Pos: -4.86298e-05 3.46237 0.00012329
?? Pos: -4.84709e-05 3.54357 0.000122888
?? Pos: -4.83122e-05 3.62466 0.000122486
?? Pos: -4.81545e-05 3.70526 0.000122086
...
?? Pos: -1.31577e-05 21.5865 3.34178e-05


The last entry is when it stops, but it did not come to a gradual stop (it stopped abruptly). Has anyone seen this? Could it be my inertia? My time for the world->update(...) being wrong? An AABB problem?

Any help is welcome :o

AHelper2

22-10-2010 01:45:17

Oops, solved m own problem... partly...

This is my code for creating a Box-type body:
OgreNewt::Body* physics::createObject_Box (Ogre::SceneNode *n, int id, float mass, string mesh)
{
stringstream s;
Ogre::Entity *e;
OgreNewt::Body *bod;
OgreNewt::CollisionPrimitives::Box *col;
Ogre::AxisAlignedBox aabb;
Ogre::Vector3 inertia, offset;

// CREATE NODE/ENTITY
s << id;
e = mSceneMgr->createEntity (s.str(), mesh);
msg_printDebug("FOO");
//n = mSceneMgr->getRootSceneNode()->createChildSceneNode(s.str());
msg_printDebug("FOO");
n->attachObject (e);

// CREATE BOX
col = new OgreNewt::CollisionPrimitives::Box(this->mWorld, e->getBoundingBox().getSize(), id);
OgreNewt::CollisionPtr col2(col);
col->calculateInertialMatrix(inertia, offset);
bod = new OgreNewt::Body(mWorld, col2, id);
bod->attachNode(n);
bod->setPositionOrientation(Ogre::Vector3(0,2,0), Ogre::Quaternion::IDENTITY);

// INPUT FORCE
bod->setMassMatrix(mass, inertia);
bod->setStandardForceCallback();

return bod;
}


This caused the problem because I didn't use a collisionPtr, as in this fixed one:
OgreNewt::Body* physics::createObject_Convex (Ogre::SceneNode *n, int id, float mass, string mesh)
{
stringstream s;
Ogre::Entity *e;
OgreNewt::Body *bod;
Ogre::Vector3 inertia, offset;
OgreNewt::CollisionPrimitives::ConvexHull *col;

// CREATE NODE/ENTITY
s << id;
e = mSceneMgr->createEntity (s.str(), mesh);
//n = mSceneMgr->getRootSceneNode()->createChildSceneNode();
n->attachObject (e);

// CREATE COLLISION
col = new OgreNewt::CollisionPrimitives::ConvexHull(this->mWorld, e, id);
OgreNewt::CollisionPtr col2(col);
col->calculateInertialMatrix(inertia, offset);
bod = new OgreNewt::Body(mWorld, col2, id);
bod->attachNode(n);

// INPUT FORCE
bod->setMassMatrix(mass, inertia);
bod->setStandardForceCallback();

return bod;
}


Now, the new problem is that the bounding boxes too big. For example, if I drop a cube on a plane, the box hovers. I know that in Bullet, the collision shape size for bullet is bigger than the actual shape's size. But why is the convex hull hovering? Is there a difference of sizes in collision shapes? Or am I getting the scenenode locations incorrectly (Body->getVisualPosition(), etc.)?

SFCBias

22-10-2010 16:47:07

Just as a test, try dividing the size of the object in half.

AHelper2

23-10-2010 00:51:37

I would, but I can't get the BB size factored into the collision shape :-X
Something like...
col = new OgreNewt::CollisionPrimitives::ConvexHull(this->mWorld, e, id);
Can't take a manual size.

I noticed that the sizes of the bboxes vary by about 0.5 in all directions (for some). Why aren't they the same? Do the entities have to be scaled first, have the collision shpae created, then set back?

Clueless here... I know that Bullet have a margin in the sizes of the BBoxes, but I didn't see anything for Newton :oops:

AHelper2

24-10-2010 01:10:32

Ok. I have gone back to making a box shape. I am getting the size manually by subtracting the max bbox corner by the min (bbox is from the entity). The boxes hover above each other even more than just using entity->getBoundingBox->getSize() (Why?!?) This method came from Newton's wiki. Could this be a problem with no offset matrix being supplied? (My meshes are not centered around the origin, they can be 100's of units away)

Also, am I right to assume that there is no dynamic trimesh collision shape? A convex Hull is not a trimesh, but the treecollision is more like a trimesh but can't be moved...