shanefarris
24-02-2010 19:26:21
I am running through the tutorial, and when I try and move the character, the sphere (feet) stay in place even though the sphere rolls. The capsule moves as if it is falling back as the sphere rolls, so that's weird. Here is my code to initialize the physics:
Here is the code I am using to just move the model (in this case the robot) forward:
So again, the sphere rolls, but stays in place, any ideas?
// Getting AABB
AxisAlignedBox aab = mEntity->getBoundingBox();
reVector3Df min = aab.getMinimum() * m_PlayerNode->getScale();
reVector3Df max = aab.getMaximum() * m_PlayerNode->getScale();
reVector3Df center = aab.getCenter() * m_PlayerNode->getScale();
reVector3Df size(fabs(max.x - min.x), fabs(max.y - min.y), fabs(max.z - min.z));
float radius = (size.x > size.z) ? size.z / 2.0f : size.x / 2.0f;
// Create a new space
OgreOde::SimpleSpace* dollSpace = new OgreOde::SimpleSpace(world, world->getDefaultSpace());
dollSpace->setInternalCollisions(false);
// create sphere
dollFeetBody = new OgreOde::Body(world, "feet");
dollFeetBody->setMass(OgreOde::SphereMass(70 * 2.5, radius));
OgreOde::SphereGeometry* feetGeom = new OgreOde::SphereGeometry(radius, world, 0);
OgreOde::TransformGeometry* feetTrans = new OgreOde::TransformGeometry(world, dollSpace);
modelNode->translate(reVector3Df(0,-radius / m_PlayerNode->getScale().y, 0));
feetTrans->setBody(dollFeetBody);
feetTrans->setEncapsulatedGeometry(feetGeom);
m_PlayerNode->attachObject(dollFeetBody);
// Create the Capsule (torso)
dollTorsoBody = new OgreOde::Body(world, "torso");
dollTorsoBody->setMass(OgreOde::CapsuleMass(70 * 2.5, radius, reVector3Df::UNIT_Y, radius));
dollTorsoBody->setAffectedByGravity(false);
dollTorsoBody->setDamping(0, 50000);
OgreOde::TransformGeometry* torsoTrans = new OgreOde::TransformGeometry(world, dollSpace);
OgreOde::CapsuleGeometry* torsoGeom = new OgreOde::CapsuleGeometry(
radius, size.y - 4 * radius, world, dollSpace);
torsoGeom->setPosition(reVector3Df(0, size.y - ((size.y - 4 * radius) / 2 + 2 * radius), 0));
torsoGeom->setOrientation(Quaternion(Degree(90), reVector3Df::UNIT_X));
torsoTrans->setBody(dollTorsoBody);
torsoTrans->setEncapsulatedGeometry(torsoGeom);
m_PlayerNode->attachObject(dollTorsoBody);
// Create the Joint
OgreOde::HingeJoint* joint = new OgreOde::HingeJoint(world);
joint->attach(dollTorsoBody, dollFeetBody);
joint->setAxis(reVector3Df::UNIT_X); //set the rotation axis
Here is the code I am using to just move the model (in this case the robot) forward:
if(Keyboard->isKeyDown(OIS::KC_W))
{
Quaternion q = dollTorsoBody->getOrientation();
dollFeetBody->wake();
dollFeetBody->setAngularVelocity(q * reVector3Df(10 * cos(1.0f), 0, 10 * sin(1.0f)));
}
else if(Keyboard->isKeyDown(OIS::KC_A))
{
Quaternion q1 = dollTorsoBody->getOrientation();
Quaternion q2(Degree(-4), reVector3Df::UNIT_Y);
dollTorsoBody->setOrientation(q1 * q2);
}
else
{
dollFeetBody->setAngularVelocity(reVector3Df(0, 0, 0));
dollFeetBody->setLinearVelocity(Vector3(0, dollFeetBody->getLinearVelocity().y, 0));
}
Quaternion q = dollTorsoBody->getOrientation();
Vector3 x = q.xAxis();
Vector3 y = q.yAxis();
Vector3 z = q.zAxis();
dollTorsoBody->wake();
dollTorsoBody->setOrientation(Quaternion(x, reVector3Df::UNIT_Y, z));
So again, the sphere rolls, but stays in place, any ideas?