Fix getHeading() for ghost karts

This commit is contained in:
Benau
2016-04-22 11:32:55 +08:00
parent f6ce065cee
commit ff10bfd07a
3 changed files with 15 additions and 4 deletions

View File

@@ -112,6 +112,7 @@ void GhostKart::update(float dt)
center_shift = getTrans().getBasis() * center_shift;
Moveable::updateGraphics(dt, center_shift, btQuaternion(0, 0, 0, 1));
Moveable::updatePosition();
getKartModel()->update(dt, dt*(m_all_physic_info[idx].m_speed),
m_all_physic_info[idx].m_steer, m_all_physic_info[idx].m_speed, idx);

View File

@@ -128,7 +128,18 @@ void Moveable::update(float dt)
{
if(m_body->getInvMass()!=0)
m_motion_state->getWorldTransform(m_transform);
m_velocityLC = getVelocity()*m_transform.getBasis();
m_velocityLC = getVelocity()*m_transform.getBasis();
updatePosition();
updateGraphics(dt, Vec3(0,0,0), btQuaternion(0, 0, 0, 1));
} // update
//-----------------------------------------------------------------------------
/** Updates the current position and rotation. This function is also called
* by ghost karts for getHeading() to work.
*/
void Moveable::updatePosition()
{
Vec3 forw_vec = m_transform.getBasis().getColumn(0);
m_heading = -atan2f(forw_vec.getZ(), forw_vec.getX());
@@ -138,9 +149,7 @@ void Moveable::update(float dt)
Vec3 up = getTrans().getBasis().getColumn(1);
m_pitch = atan2(up.getZ(), fabsf(up.getY()));
m_roll = atan2(up.getX(), up.getY());
updateGraphics(dt, Vec3(0,0,0), btQuaternion(0, 0, 0, 1));
} // update
} // updatePosition
//-----------------------------------------------------------------------------
/** Creates the bullet rigid body for this moveable.

View File

@@ -110,6 +110,7 @@ public:
const btTransform
&getTrans() const {return m_transform;}
void setTrans(const btTransform& t);
void updatePosition();
}
; // class Moveable