Correct the landing after rescue for non-horizontal tracks.

This commit is contained in:
nixt
2014-07-03 11:13:49 +05:30
parent 64c2292051
commit 184e45bb6d
6 changed files with 37 additions and 10 deletions

View File

@@ -1187,10 +1187,16 @@ void Kart::update(float dt)
// But only do this if auto-rescue is enabled (i.e. it will be disabled in
// battle mode), and the material the kart is driving on does not have
// gravity (which can
unsigned int sector = ((LinearWorld*)World::getWorld())->getTrackSector(getWorldKartId()).getCurrentGraphNode();
const Vec3 quadNormal = QuadGraph::get()->getQuadOfNode(sector).getNormal();
btQuaternion q = getTrans().getRotation();
float roll = quadNormal.angle((Vec3(0, 1, 0).rotate(q.getAxis(), q.getAngle())));
if(World::getWorld()->getTrack()->isAutoRescueEnabled() &&
(!m_terrain_info->getMaterial() ||
!m_terrain_info->getMaterial()->hasGravity()) &&
!getKartAnimation() && fabs(getRoll())>60*DEGREE_TO_RAD &&
!getKartAnimation() && fabs(roll)>60*DEGREE_TO_RAD &&
fabs(getSpeed())<3.0f )
{
new RescueAnimation(this, /*is_auto_rescue*/true);
@@ -1214,8 +1220,8 @@ void Kart::update(float dt)
m_body->getBroadphaseHandle()->m_collisionFilterGroup = 0;
}
unsigned int sector = ((LinearWorld*)World::getWorld())->getTrackSector(getWorldKartId()).getCurrentGraphNode();
const Vec3 quadNormal = QuadGraph::get()->getQuadOfNode(sector).getNormal();
m_terrain_info->update(getXYZ() + epsilon*(quadNormal), -quadNormal);

View File

@@ -97,7 +97,9 @@ RescueAnimation::~RescueAnimation()
void RescueAnimation::update(float dt)
{
m_xyz.setY(m_xyz.getY() + dt*m_velocity);
//m_xyz.setY(m_xyz.getY() + dt*m_velocity);
btQuaternion q1 = m_kart->getTrans().getRotation();
m_xyz = m_xyz + dt*m_velocity*(Vec3(0, 1, 0).rotate(q1.getAxis(), q1.getAngle()));
m_kart->setXYZ(m_xyz);
m_curr_rotation += dt*m_add_rotation;
btQuaternion q(m_curr_rotation.getHeading(), m_curr_rotation.getPitch(),

View File

@@ -634,10 +634,21 @@ unsigned int LinearWorld::getRescuePositionIndex(AbstractKart *kart)
btTransform LinearWorld::getRescueTransform(unsigned int index) const
{
const Vec3 &xyz = QuadGraph::get()->getQuadOfNode(index).getCenter();
const Vec3 &normal = QuadGraph::get()->getQuadOfNode(index).getNormal();
btTransform pos;
// 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 q2(btVector3(normal), m_track->getAngle(index));
pos.setOrigin(xyz);
pos.setRotation(btQuaternion(btVector3(0.0f, 1.0f, 0.0f),
m_track->getAngle(index)));
pos.setRotation(q2*q1);
return pos;
} // getRescueTransform

View File

@@ -712,8 +712,11 @@ void World::moveKartTo(AbstractKart* kart, const btTransform &transform)
{
btTransform pos(transform);
btQuaternion rot = pos.getRotation();
// Move the kart
Vec3 xyz = pos.getOrigin() + btVector3(0, 0.5f*kart->getKartHeight(),0.0f);
Vec3 xyz = pos.getOrigin() + btVector3(0, 0.55f*kart->getKartHeight(),0.0f).
rotate(rot.getAxis(),rot.getAngle());
pos.setOrigin(xyz);
kart->setXYZ(xyz);

View File

@@ -2388,7 +2388,12 @@ const core::vector3df& Track::getSunRotation()
bool Track::findGround(AbstractKart *kart)
{
btVector3 to(kart->getXYZ());
to.setY(-100000.f);
unsigned int sector = ((LinearWorld*)World::getWorld())->getTrackSector(kart->getWorldKartId()).getCurrentGraphNode();
Vec3 quadNormal;
if (sector != QuadGraph::UNKNOWN_SECTOR)
quadNormal = QuadGraph::get()->getQuadOfNode(sector).getNormal();
else quadNormal = Vec3(0, 1, 0);
to = to + -1000.0f*quadNormal;
// Material and hit point are not needed;
const Material *m;

View File

@@ -65,8 +65,8 @@ void TrackSector::update(const Vec3 &xyz)
{
// keep the current quad as the latest valid one IF the player has one
// of the required checklines
const std::vector<int>& checkline_requirements =
QuadGraph::get()->getNode(m_current_graph_node).getChecklineRequirements();
GraphNode gn = QuadGraph::get()->getNode(m_current_graph_node);
const std::vector<int>& checkline_requirements = gn.getChecklineRequirements();
if (checkline_requirements.size() == 0)
{