Browse Source

Fehler in der schnittpunktberechnung von 2D Modellen behoben

kolja 5 years ago
parent
commit
96c31bece3
1 changed files with 12 additions and 0 deletions
  1. 12 0
      Model2D.cpp

+ 12 - 0
Model2D.cpp

@@ -402,6 +402,8 @@ void Model2DData::removeModell() // setzt die Vertex daten zur
 
 bool Model2DData::calcHitPoint( Vertex pos, Vertex dir, const char *polygonName, Vertex &hitpoint, Vertex &moveSpeed, float &rotSpeed ) const
 {
+    if( dir.x == 0 && dir.y == 0 )
+        return 0;
     bool ret = 0;
     for( auto polygon = polygons->getIterator(); polygon; polygon++ )
     {
@@ -417,9 +419,17 @@ bool Model2DData::calcHitPoint( Vertex pos, Vertex dir, const char *polygonName,
                 if( dir.y != 0 && dir.x != 0 )
                     offset = ( ( a.y - pos.y ) / dir.y - ( a.x - pos.x ) / dir.x ) / ( b.x / dir.x - b.y / dir.y ); // solve hitpoint equasion
                 else if( dir.y == 0 )
+                {
+                    if( b.y == 0 )
+                        continue;
                     offset = ( pos.y - a.y ) / b.y;
+                }
                 else if( dir.x == 0 )
+                {
+                    if( b.x == 0 )
+                        continue;
                     offset = ( pos.x - a.x ) / b.x;
+                }
                 Vertex point = a + ( b * offset );
                 if( offset >= 0 && offset <= 1 )
                 {
@@ -435,6 +445,8 @@ bool Model2DData::calcHitPoint( Vertex pos, Vertex dir, const char *polygonName,
                         Vertex rotKraft = normal * ( normal * kNorm ) * dir.getLength();
                         rotSpeed = ( (float)sqrt( rotKraft.getLength() * ( point - *polygon._.schwerpunkt ).getLength() ) / 180.f ) * 3.14f * ( normal * kNorm );
                         hitpoint = point;
+                        if( isnan( moveSpeed.x ) || isnan( moveSpeed.y ) || isnan( rotSpeed ) )
+                            return 0;
                         ret = 1;
                     }
                 }