Fix wrong angle when normal is exactly 0, -1 ,0

This commit is contained in:
Benau 2017-02-11 16:05:10 +08:00
parent 0ddada2897
commit 48f27df1c9
2 changed files with 4 additions and 16 deletions

View File

@ -644,13 +644,7 @@ btTransform LinearWorld::getRescueTransform(unsigned int index) const
// First rotate into the quad's plane (q1), then rotate so that the kart points in the
// right direction (q2).
btQuaternion q1;
if (normal.cross(Vec3(0, 1, 0)).length() > 0)
{
q1 = btQuaternion(-normal.cross(Vec3(0, 1, 0)), normal.angle(Vec3(0, 1, 0)));
}
else q1 = btQuaternion(Vec3(0,1,0),0);
btQuaternion q1 = shortestArcQuat(Vec3(0, 1, 0), normal);
// First apply the heading change, than the 'parallelisation' to the plane
btQuaternion q2(btVector3(0,1,0), Track::getCurrentTrack()->getAngle(index));
pos.setRotation(q1*q2);

View File

@ -79,15 +79,9 @@ void DriveNode::addSuccessor(unsigned int to)
Vec3 d = m_lower_center - dn_to->m_lower_center;
m_distance_to_next.push_back(d.length());
Vec3 diff = dn_to->getCenter() - getCenter();
core::CMatrix4<float> m;
m.buildRotateFromTo(getNormal().toIrrVector(),
Vec3(0, 1, 0).toIrrVector());
core::vector3df diff_rotated;
m.rotateVect(diff_rotated, diff.toIrrVector());
m_angle_to_next.push_back(atan2(diff_rotated.X, diff_rotated.Z));
Vec3 loc_pos = btTransform(shortestArcQuat(Vec3(0, 1, 0), getNormal()),
getCenter()).inverse()(dn_to->getCenter());
m_angle_to_next.push_back(atan2(loc_pos.x(), loc_pos.z()));
} // addSuccessor