Collision body completely offset

Acid_Gambit

26-03-2007 18:55:20

I have a strange problem...for some reason my ogre object and collision body are not aligned.



As you can see in the picture (blue box = ogre object, red lines = ogrenewt body) the collision body is completely offset.

I can't find anything in my code either:



mMainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(mName);

mEntity = mSceneMgr->createEntity(mName, "box.mesh");
mEntity->setMaterialName("Materials/FrostedGlass");

Ogre::Vector3 size(20.0, 20.0, 20.0);
mMainNode->setScale(size);

mMainNode->attachObject(mEntity);

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box( mWorld, size );
player = new OgreNewt::Body( mWorld, col );
player->attachToNode( mMainNode );
player->setPositionOrientation(Ogre::Vector3(0, 0, 0), Ogre::Quaternion::IDENTITY);
delete col;


What makes it even more odd is when I paste the code above in Demo01_TheBasics (or any other demo related code) the bodies are aligned.

mako

27-03-2007 14:06:01

try to set the fourth parameter
example:
OgreNewt::Collision* col1 = new OgreNewt::CollisionPrimitives::Box(mWorld,BoxSize,Ogre::Quaternion::IDENTITY,Vector3(0,35,0));

the fourth parameter is a vector that u can use to adjust the position of the box in ur node.

Acid_Gambit

27-03-2007 15:05:29

Thanks, it's working :D . But can you explain to me how this is possible? Now I'll have to adjust all my objects manually since they are all offset.

(debug lines show the collision bodies)

http://img341.imageshack.us/img341/3203/debug1op5.jpg

http://img231.imageshack.us/img231/26/debug2gr9.jpg

walaber

27-03-2007 15:14:52

they shouldn't be... there must be an error somewhere in your code... are you sure all of the nodes are attached directly to yhe root scene node in your scene?

Acid_Gambit

27-03-2007 15:24:12

nvm, I've solved the problem. It was not a code issue. The mesh was some piece of junk that I modelled some time ago. It was not aligned to the origin of my scene in 3ds. That caused the weird things...

Langhole

28-03-2007 21:06:02

I almost have the same problem...

Here's a createObjects() function that just creates a box at 0,0,0. The collision is not offset if I create it there, but if I move it in any direction, the collision does not stay with the node, it offsets itself and I don't know why...


void OgreNewtonApplication::createObjects()
{
Ogre::String name = "box_test";
Ogre::Vector3 size(1, 1, 1);
Ogre::Real mass = (size.x * size.y * size.z) * 100;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( mass, size );
Ogre::Vector3 pos(0, 0, 0);
Ogre::Quaternion orient = Ogre::Quaternion::IDENTITY;

Entity* ent = mSceneMgr->createEntity(name, "box.mesh");
SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode(pos, orient);
node->attachObject(ent);

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box(m_World, size, orient, pos);
OgreNewt::Body* body = new OgreNewt::Body(m_World, col);
delete col;
body->attachToNode(node);
body->setPositionOrientation(pos, orient);
body->setMassMatrix( mass, inertia );
body->setStandardForceCallback();
}


so if i set pos to 20,0,0 then the collision is off by 20 :s even though I'm using the same variable for all positioning in this case... no idea why...

Langhole

29-03-2007 02:06:23

Ok, i've come up with a half-assed fix..

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box(m_World, size, orient, pos);

change to

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box(m_World, size, orient, Ogre::Vector3(pos.x - pos.x, pos.y - pos.y, pos.z - pos.z));

:s I'm not a fan of it but it's fixed my problem *to a degree*

I can set pos to 20, 0, 20 now and the collision will position exactly there, but If it's a larger number, such as 200, 0, -200 or something, then the body of the car becomes separated, by probably 200, the wheels all spawn on the same spot, and the collision is all where the car is, which has no physics applied. lol.

I'm pretty confused...