Problems with collisions

russianStalker

14-08-2010 09:54:30

Hello everyone. Sorry for my english.
I have some problem with OgreNewt.
I created my level with the tree collision:

World::World()
{
physWorld = new OgreNewt::World();
mNewtonListener = new OgreNewt::BasicFrameListener( engine->window, physWorld );
engine->root->addFrameListener(mNewtonListener);

map = engine->sceneMgr->createEntity("World", "castle.mesh");
mapNode = engine->sceneMgr->getRootSceneNode()->createChildSceneNode("WorldNode", Vector3(0,0,0));
mapNode->attachObject(map);
mapNode->setScale(100,100,100);
createCollision();
}

void World::createCollision()
{
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* tree_col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser(physWorld);
tree_col->parseScene(mapNode, true, 0);
body = new OgreNewt::Body(physWorld, OgreNewt::CollisionPtr(tree_col));
body->attachNode(mapNode);
body->setPositionOrientation( Ogre::Vector3(0.0,0.0,0.0), Ogre::Quaternion::IDENTITY );
delete tree_col;
}


I created a player like Ellipsoid:

Actor::Actor(std::string name, std::string path, Vector3 position)
{
mainNode = engine->sceneMgr->getRootSceneNode()->createChildSceneNode(name);
entity = engine->sceneMgr->createEntity(name, path);
mainNode->attachObject(entity);
cameraNode = mainNode->createChildSceneNode (name + "_camera", Vector3(0, 200, 200));
velocity = strafe = 0;
Vector3 actorSize(1,1,1);
OgreNewt::CollisionPrimitives::Ellipsoid* col = new OgreNewt::CollisionPrimitives::Ellipsoid(engine->world->physWorld, actorSize, 0);
body = new OgreNewt::Body(engine->world->physWorld, OgreNewt::CollisionPtr(col));
body->attachNode(mainNode);
float mass = 500;
Vector3 cam_inertia;
Vector3 inertia, offset;
col->calculateInertialMatrix (inertia, offset);
body->setMassMatrix(mass, inertia*mass);
body->setCustomForceAndTorqueCallback<Actor>(&Actor::forceCallback,this);
delete col;
}

void Actor::forceCallback(OgreNewt::Body* mBody, float timeStep, int threadIndex)
{
Quaternion orient;
Vector3 pos;

mBody->getPositionOrientation(pos, orient);
Vector3 force(0,9.8,0);
Vector3 force2(0,9.8,0);
Ogre::Real mass;
Ogre::Vector3 inertia;
mBody->getMassMatrix(mass, inertia);

Ogre::Quaternion q;
Ogre::Vector3 qq,s;
Vector3 direction = (orient * Vector3::NEGATIVE_UNIT_Z);
Vector3 poo2=(orient * Vector3::NEGATIVE_UNIT_X);
qq = direction;
s = poo2;
Ogre::Vector3 V0 = mBody->getVelocity();
Ogre::Vector3 V1(qq * velocity);
Ogre::Vector3 V2 (s * strafe);
Ogre::Vector3 acel = (V1 - V0);
Ogre::Vector3 acel2 = (V2 - V0);
acel = acel * 0.5f;
acel2 = acel2 * 0.5f;

force.x = acel.x;
force.z = acel.z;

force2.x = acel2.x;
force2.z = acel2.z;

mBody->setOmega(Vector3(0, engine->frameListener->mRotateX.valueRadians()*500,0));
force *= mass;
force2 *= mass;
mBody->setForce(force);
mBody->addForce( force2 );
}

But when the player moves, he stops the invisible wall. Please help me create a 3rd-person character.

russianStalker

15-08-2010 19:58:27

I found a solution to this problem. I just didn't set the size of the world.