Fixed findOutOfRoadSector to take the height into account
(previously incorrect quads were found in FortMagma, when driving slightly off track beneath a different part of the track - and while this did not affect the kart's steering in this case, it could cause problems in other places). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11637 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
3a3d1a5a6f
commit
eaedc47ddc
@ -900,6 +900,14 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz,
|
|||||||
|
|
||||||
int min_sector = UNKNOWN_SECTOR;
|
int min_sector = UNKNOWN_SECTOR;
|
||||||
float min_dist_2 = 999999.0f*999999.0f;
|
float min_dist_2 = 999999.0f*999999.0f;
|
||||||
|
|
||||||
|
// It is (at least theoretical) possible that a kart is falling and in
|
||||||
|
// between (or too far below) a driveline point and so it doesn't fulfill
|
||||||
|
// the height condition. So we run the test twice: first with height
|
||||||
|
// condition, then again without the height condition - just to make sure
|
||||||
|
// it always comes back with some kind of quad.
|
||||||
|
for(int phase=0; phase<2; phase++)
|
||||||
|
{
|
||||||
for(int j=0; j<count; j++)
|
for(int j=0; j<count; j++)
|
||||||
{
|
{
|
||||||
int next_sector;
|
int next_sector;
|
||||||
@ -913,12 +921,29 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz,
|
|||||||
// A first simple test uses the 2d distance to the center of the quad.
|
// A first simple test uses the 2d distance to the center of the quad.
|
||||||
float dist_2 = m_all_nodes[next_sector]->getDistance2FromPoint(xyz);
|
float dist_2 = m_all_nodes[next_sector]->getDistance2FromPoint(xyz);
|
||||||
if(dist_2<min_dist_2)
|
if(dist_2<min_dist_2)
|
||||||
|
{
|
||||||
|
const Quad &q = getQuadOfNode(next_sector);
|
||||||
|
float dist = xyz.getY() - q.getMinHeight();
|
||||||
|
// While negative distances are unlikely, we allow some small
|
||||||
|
// negative numbers in case that the kart is partly in the
|
||||||
|
// track. Only do the height test in phase==0, in phase==1
|
||||||
|
// accept any point, independent of height.
|
||||||
|
if(phase==1 || (dist < 5.0f && dist>-1.0f) )
|
||||||
{
|
{
|
||||||
min_dist_2 = dist_2;
|
min_dist_2 = dist_2;
|
||||||
min_sector = next_sector;
|
min_sector = next_sector;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
current_sector = next_sector;
|
current_sector = next_sector;
|
||||||
} // for j
|
} // for j
|
||||||
|
// Leave in phase 0 if any sector was found.
|
||||||
|
if(min_sector!=UNKNOWN_SECTOR)
|
||||||
|
return min_sector;
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("findOutOfRoadSector: can't find sector with height for "
|
||||||
|
"%f %f %f\n", xyz.getX(), xyz.getY(), xyz.getZ());
|
||||||
|
#endif
|
||||||
|
} // phase
|
||||||
|
|
||||||
if(min_sector==UNKNOWN_SECTOR )
|
if(min_sector==UNKNOWN_SECTOR )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user