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:
The code of normal objects (barrel and others):
The code of player:
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:
And again the full source code of project:
http://www.prsolucoes.com/downloads/zombieisland_alpha_4.zip
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