Fixed rotation of physical objects (like road cones).

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3824 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-08-09 05:54:33 +00:00
parent cf8e767f5c
commit f1a46e6d38
2 changed files with 29 additions and 3 deletions

View File

@ -106,7 +106,24 @@ void Moveable::reset()
void Moveable::update(float dt)
{
m_motion_state->getWorldTransform(m_transform);
m_velocityLC = getVelocity()*getTrans().getBasis();
m_velocityLC = getVelocity()*m_transform.getBasis();
// The following code would synchronise bullet to irrlicht rotations, but
// heading etc. might not be 'correct', e.g. a 180 degree heading rotation
// would be reported as 180 degree roll and pitch, and 0 degree heading.
// So to get heading, pitch etc. the way needed elsewhere (camera etc),
// we would still have to rotate unit vectors and compute heading etc.
// with atan.
//btQuaternion q = m_transform.getRotation();
//core::quaternion qirr(q.getX(), q.getZ(), q.getY(), -q.getW());
//core::vector3df r;
//qirr.toEuler(r);
// Note: toIrrHPR mixes the axis back etc., so the assignments below
// mean that getIrrHPR returns exactly (r.x,r.y,r.z)*RAD_TO_DEGREE
//m_hpr.setX(-r.Y);
//m_hpr.setY(-r.X);
//m_hpr.setZ(-r.Z);
m_hpr.setHPR(m_transform.getBasis());
// roll is not set correctly, I assume due to a different HPR order.
// So we compute the proper roll (by taking the angle between the up

View File

@ -155,7 +155,8 @@ void PhysicalObject::init()
// 2. Create the rigid object
// --------------------------
m_init_pos.setOrigin(m_init_pos.getOrigin()-offset_from_center);
// m_init_pos is the point on the track - add the offset
m_init_pos.setOrigin(m_init_pos.getOrigin()+btVector3(0,0,extend.getZ()*0.5f));
m_motion_state = new btDefaultMotionState(m_init_pos);
btVector3 inertia;
m_shape->calculateLocalInertia(m_mass, inertia);
@ -166,6 +167,7 @@ void PhysicalObject::init()
m_body = new btRigidBody(info);
m_user_pointer.set(this);
m_body->setUserPointer(&m_user_pointer);
RaceManager::getWorld()->getPhysics()->addBody(m_body);
} // init
@ -174,6 +176,7 @@ void PhysicalObject::update(float dt)
{
btTransform t;
m_motion_state->getWorldTransform(t);
Coord c(t);
if(c.getXYZ().getZ()<-100)
{
@ -181,7 +184,13 @@ void PhysicalObject::update(float dt)
c.setXYZ(m_init_pos.getOrigin());
}
m_node->setPosition(c.getXYZ().toIrrVector());
m_node->setRotation(c.getHPR().toIrrHPR());
btQuaternion q=t.getRotation();
core::quaternion qirr(q.getX(), q.getZ(), q.getY(), -q.getW());
core::vector3df r;
qirr.toEuler(r);
m_node->setRotation(r*RAD_TO_DEGREE);
return;
} // update
// -----------------------------------------------------------------------------