Problem on gravity and character move - OgreNewt

prchakal

17-11-2009 15:08:12

Hi,

I have a problem on newton gravity that i dont understand why, the objects are not on top of each other, but are left with one of its parts in other objects.

You can see here:


Im using OgreNewt, on Ogre 1.6.4.

The code of floor:

...create entity and node

node->setScale(size);

OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( world, ent, true, 0 ));
OgreNewt::Body* bod = new OgreNewt::Body( world, col );

bod->attachNode( node );
bod->setPositionOrientation( position, orientation );


The code of normal objects (barrel and others):


...create entity and node

OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box( world, size, 0 ));
OgreNewt::Body* bod = new OgreNewt::Body( world, col );

// base mass on the size of the object.
Ogre::Real mass = size.x * size.y * size.z * 2.5;

// calculate the inertia based on box formula and mass
Ogre::Vector3 inertia, offset;
col->calculateInertialMatrix(inertia, offset);

bod->attachNode( node );
bod->setMassMatrix( mass, mass*inertia );
bod->setCenterOfMass(offset);
bod->setStandardForceCallback();

bod->setPositionOrientation( position, orientation );


The code of player:

...create entity and node

OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid( world, this->tamanho, 0 ));

body = new OgreNewt::Body( world, col );
Ogre::Vector3 inertia, offset;
col->calculateInertialMatrix(inertia, offset);

body->attachNode(node);
body->setMassMatrix( 50, 50*inertia );
body->setCenterOfMass(offset);
body->setStandardForceCallback();

//body->setPositionOrientation(node->getPosition(), node->getOrientation());
body->setPositionOrientation(Ogre::Vector3(0,100,20), Ogre::Quaternion::IDENTITY);

mPlayer = new OgreNewt::PlayerController(body, 0.4);



Now the full source code of project:
http://www.prsolucoes.com/downloads/zombieIsland_alpha_4.zip

And i have other problem, on character move. When i move the player and apply the forces it not move correctly, it is walking to other direction, i rotate the player to left but he is moving to front :(

This is the code that i use to moviment:


//movimentação pela física
Ogre::Real forwardSpeed, sideSpeed;
Ogre::Radian heading;
mPlayer->getVelocity(forwardSpeed, sideSpeed, heading);
forwardSpeed = 0;
sideSpeed = 0;

if (input->isKeyDown(OIS::KC_W)) {
//node->translate(node->getOrientation () * Vector3 (0, 0, 100 * elapsedTime));
forwardSpeed -= 10.0;

mAnimationState = entidade->getAnimationState("Walk");
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
mAnimationState->addTime(elapsedTime * 2);

mWalking = true;

} else if (input->isKeyDown(OIS::KC_S)) {
//node->translate(node->getOrientation () * Vector3 (0, 0, -50 * elapsedTime));
forwardSpeed += 8.0;

mAnimationState = entidade->getAnimationState("Walk");
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
mAnimationState->addTime(elapsedTime * 2);

mWalking = true;
}

if (input->isKeyDown(OIS::KC_A)) {
//node->yaw(Radian (2 * elapsedTime));
//sideSpeed -= 5.0;
heading += Degree(45)/60.0;

mAnimationState = entidade->getAnimationState("Walk");
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
mAnimationState->addTime(elapsedTime * 2);

mWalking = true;
} else if (input->isKeyDown(OIS::KC_D)) {
//node->yaw(Radian (-2 * elapsedTime));
//sideSpeed += 5.0;
heading -= Degree(45)/60.0;

mAnimationState = entidade->getAnimationState("Walk");
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
mAnimationState->addTime(elapsedTime * 2);

mWalking = true;
}

if (mWalking == false) {
mAnimationState = entidade->getAnimationState("Walk");
mAnimationState->setEnabled( false );

mAnimationState = entidade->getAnimationState("Idle");
mAnimationState->setLoop( true );
mAnimationState->setEnabled( true );
mAnimationState->addTime(elapsedTime * 2);
}

mPlayer->setVelocity(forwardSpeed, sideSpeed, heading);


And again the full source code of project:
http://www.prsolucoes.com/downloads/zombieisland_alpha_4.zip

prchakal

17-11-2009 16:11:59

Hi,

The problem with models is solved, i have to change the Y to bottom with commando line tools:

MeshMagick.exe transform -yalign=bottom Ogre.mesh

But the problem with player orientation and walk not solved and now i see that the player stop walk when move to some places... anyone can test and see why? plz...

prchakal

18-11-2009 20:39:29

hi.

now move problem solved.

only left now 1 problem.

the character controlled (player) is freeze when walk for some place. it not move and forces no cause effect.

what im do? i dont find any information on the forum :(

prchakal

20-11-2009 05:07:05

Hi.

All problems solved.

Only we need to set the world size of our map.

mWorld->setWorldSize( Vector3(-1000, -1000, -1000), Vector3(1000, 1000, 1000) );

Thanks.