[SOLVED] Collision dont work

goldman82

23-06-2007 13:41:29

hi,

iam new here. i have read many threads here...
but nothing helps me. now i made a simple app with a plane an a camera body over it. the gravity works, my camra falls down. but dont collide with my plane.

first i set up the newton:

mWorld = new OgreNewt::World();
mWorld->setWorldSize(AxisAlignedBox(-100000,-100000,-100000,100000,100000,100000));
mOgreNewtListener = new OgreNewt::BasicFrameListener(mWindow, sceneMgr, mWorld, 120);
mRoot->addFrameListener(mOgreNewtListener);

Ogre::Vector3 size(1.0,15.0,1.0);
Ogre::SceneNode* camnode = sceneMgr->getRootSceneNode()->createChildSceneNode();
camnode->setScale(size);

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid(mWorld, size);
cambody = new OgreNewt::Body(mWorld, col);
cambody->attachToNode(camnode);
delete col;

Ogre::Real mass = 1.0;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid(mass, size);
cambody->setMassMatrix(mass, inertia);
//cambody->setStandardForceCallback();
cambody->setCustomForceAndTorqueCallback<Application>(&Application::camera_force_callback,this);
cambody->setAutoFreeze(0);

Ogre::SceneNode* camviewnode = camnode->createChildSceneNode(Vector3(0,5,0));
camviewnode->attachObject(mCamera);


and then i create the plane:

Plane plane( Vector3::UNIT_Y, 0 );
MeshManager::getSingleton().createPlane("ground",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
Ogre::Entity *ent = sceneMgr->createEntity( "GroundEntity", "ground" );
meshnode->attachObject(ent);
Ogre::Vector3 siz(5,2.5,2.5);
meshnode->setScale( siz );

//OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld, meshnode, true);
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box(mWorld,siz);
OgreNewt::Body* bod = new OgreNewt::Body(mWorld, col);
delete col;
bod->attachToNode(meshnode);
bod->setPositionOrientation( Ogre::Vector3(0.0,-10.0,0.0), Ogre::Quaternion::IDENTITY );


for moving the cambody i used setVelocity(). that is working...
whats going wrong? i tried it now for 3 days and i have no idea :(

Thanks
goldman82

pra

23-06-2007 13:55:59


Plane plane( Vector3::UNIT_Y, 0 );
MeshManager::getSingleton().createPlane("ground",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
Ogre::Entity *ent = sceneMgr->createEntity( "GroundEntity", "ground" );
meshnode->attachObject(ent);
Ogre::Vector3 siz(5,2.5,2.5);
meshnode->setScale( siz );

you make your plane 1500x1500, then scale it by 5,2.5,2.5.
If i'm correct, this will make the plane 7500x3750. but your collision body is still 5x2.5.

if you want to scale the plane, make it 1x1, if not, pass the correct width&height to the plane constructor. more info

but you can also create a treecollision from the plane's scenenode, i think this would be the best way, unless you want both-sided collision

goldman82

23-06-2007 14:19:42

thank you for your quick post :)

ok, now i changed the code a little bit. my camera is now a Box().
i am loading many meshs i a while-loop:

Ogre::SceneNode *node = meshnode->createChildSceneNode();
node->setPosition(Ogre::Vector3(0,0,0));

ent->setCastShadows(false);
ent->setNormaliseNormals(true);
node->attachObject(ent);
node->pitch(Ogre::Degree(-90));
node->scale(20,20,20);

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld, node, true);
OgreNewt::Body* bod = new OgreNewt::Body(mWorld, col);
delete col;
bod->attachToNode(node);


now my camera can hit the ground... :)
but if i moving after hitting the ground my camera begins to spinning around. that looks funny, but is not good for me. i will make a very simple first person view...

goldman82

pra

23-06-2007 16:22:37

you should search in this forum for character movement, but you'll still have to adjust the code for your needs, at least i had.
moving with setvelocity is a bad idea, too, because your character will be able to climb up walls, if they have less than 90° to the ground

goldman82

23-06-2007 18:18:47

hmmmm...
in my world there are nearly 1000 meshs. i add all with this loop above.
after loading my cambody collides with no mesh. is there a problem with scaling or so? i dont understand this... with a normal plane it works, and if i switch to my meshs nothing works :(

edit: these meshes where exported with Blender including World Coordinates. can this be a problem?

edit2: Now i seeee :) i include showLines() to debug my world. now i see that the collision lines are not pitched. my friend exported the meshs in a wrong axis system. and so i must pitch every node with -90 degree... and TreeCollision dont applied that pitch!!! is this a bug or must i change my code?

goldman82

walaber

24-06-2007 03:48:35

set the orientation and position of the body to equal the scenenode.

or

use the TreeCollisionSceneParser.

goldman82

24-06-2007 11:51:00

hi,

thank you walaber!!! :D
with bod->setPositionOrientation(node->getWorldPosition(), node->getWorldOrientation()); it works correctly!!!

goldman82