Browse Source

Fehler beim parsen von negativen zahlen im json parser behoben

Kolja Strohm 4 years ago
parent
commit
b0ba920f5b
2 changed files with 16 additions and 11 deletions
  1. 1 1
      JSON.cpp
  2. 15 10
      Kam3D.cpp

+ 1 - 1
JSON.cpp

@@ -420,7 +420,7 @@ JSONValue *Parser::getValue( const char *str )
     if( string.anzahlVon( '.' ) == 1 )
     {
         bool isNumber = 1;
-        for( char *c = string.getText(); *c; c++ )
+        for( char *c = (*string.getText() == '-' ) ? string.getText() + 1 : string.getText(); *c; c++ )
             isNumber &= ( *c >= '0' && *c <= '9' ) || *c == '.';
         if( isNumber )
             return new JSONNumber( string );

+ 15 - 10
Kam3D.cpp

@@ -317,23 +317,28 @@ const Vec3< float > &Kam3D::getWorldPosition() const
 //  screen: die Position auf dem Bildschirm, die übersetzt werden soll
 const Vec3< float > Kam3D::getWorldPosition( Punkt screen ) const
 {
-    Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( screen.y - viewport.y ) / ( 0.5f * viewport.height ) - 1, 0 );
-    Mat4< float > mat = proj * view;
-    mat = mat.getInverse();
-    point = mat * point;
-    return point;
+    Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( viewport.height - ( screen.y - viewport.y ) ) / ( 0.5f * viewport.height ) - 1, 0.1f );
+    Mat4< float > mat = getProjectionMatrix();
+    Mat4< float > inv = getViewMatrix().getInverse();
+    point.x = ( point.x * 0.1f ) / mat.elements[ 0 ][ 0 ];
+    point.y = ( point.y * 0.1f ) / mat.elements[ 1 ][ 1 ];
+    return inv * point;
 }
 
 // Gibt die Richtung der Kamera in der Welt zurück
 //  screen: die Position auf dem Bildschirm, die übersetzt werden soll
 const Vec3< float > Kam3D::getWorldDirection( Punkt screen ) const
 {
-    Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( screen.y - viewport.y ) / ( 0.5f * viewport.height ) - 1, 0 );
+    Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( viewport.height - ( screen.y - viewport.y ) ) / ( 0.5f * viewport.height ) - 1, 0.1f );
     Vec3< float > pointT = Vec3< float >( point.x, point.y, 1 );
-    Mat4< float > mat = proj * view;
-    mat = mat.getInverse();
-    point = mat * point;
-    pointT = mat * pointT;
+    Mat4< float > mat = getProjectionMatrix();
+    Mat4< float > inv = getViewMatrix().getInverse();
+    point.x = ( point.x * 0.1f ) / mat.elements[ 0 ][ 0 ];
+    point.y = ( point.y * 0.1f ) / mat.elements[ 1 ][ 1 ];
+    pointT.x = ( pointT.x ) / mat.elements[ 0 ][ 0 ];
+    pointT.y = ( pointT.y ) / mat.elements[ 1 ][ 1 ];
+    point = inv * point;
+    pointT = inv * pointT;
     return pointT - point;
 }