Browse Source

Kameraausrichtung fertig

Kolja Strohm 5 years ago
parent
commit
f9b4e9ce44
5 changed files with 31 additions and 16 deletions
  1. 5 0
      FrameworkMath.h
  2. 8 1
      Global.cpp
  3. 4 0
      Globals.h
  4. 13 14
      Kam3D.cpp
  5. 1 1
      Kam3D.h

+ 5 - 0
FrameworkMath.h

@@ -90,6 +90,11 @@ namespace Framework
         ret = ret - 2 * negate * ret;
         return negate * 3.14159265358979f + ret;
     }
+
+    inline float lowPrecisionASin( float sin )
+    {
+        return 3.14159265358979f / 2.f - lowPrecisionACos( sin );
+    }
 }
 
 #endif

+ 8 - 1
Global.cpp

@@ -137,4 +137,11 @@ void Framework::logLine( char *txt )
         logFile->close();
         logC.unlock();
     }
-}
+}
+#ifdef WIN32
+// gibt eine Referenz auf die Maus zurück
+Framework::Maus &Framework::getMaus()
+{
+    return Framework::MausZeiger;
+}
+#endif

+ 4 - 0
Globals.h

@@ -76,6 +76,10 @@ namespace Framework
     // Speichert eine Zeile in die Logdatei
     //  txt: die zu Speichernde Nachricht
     __declspec( dllexport ) void logLine( char *txt );
+#ifdef WIN32
+    // gibt eine Referenz auf die Maus zurück
+    __declspec( dllexport ) Maus &getMaus();
+#endif
 }
 
 #endif

+ 13 - 14
Kam3D.cpp

@@ -86,21 +86,20 @@ void Kam3D::scrollOut( float val )
 //  ziel: Der Punkt, auf den die Kamera zeigen soll
 void Kam3D::setAusrichtung( Vec3< float > ziel )
 {
-    rotX = 0;
-    rotY = 0;
-    rotZ = 0;
-    // TODO calculate this
     Vec3< float > target = ( ziel - pos ).normalize();
-    if( target == Vec3<float>( 0, 0, -1 ) )
-        rotY = (float)PI;
-    if( target == Vec3<float>( 0, 1, 0 ) )
-        rotX = -(float)PI / 2.f;
-    if( target == Vec3<float>( 0, -1, 0 ) )
-        rotX = (float)PI / 2.f;
-    if( target == Vec3<float>( 1, 0, 0 ) )
-        rotY = (float)PI / 2.f;
-    if( target == Vec3<float>( -1, 0, 0 ) )
-        rotY = -(float)PI / 2.f;
+    if( Vec3< float >( 0, target.y, target.z ).getLength() == 0 )
+        rotX = 0;
+    else
+        rotX = -lowPrecisionACos( abs( target.z ) / Vec3< float >( 0, target.y, target.z ).getLength() );
+    if( target.y < 0 )
+        rotX = -rotX;
+    if( Vec3< float >( target.x, 0, target.z ).getLength() == 0 )
+        rotY = 0;
+    else
+        rotY = lowPrecisionACos( abs(target.z) / Vec3< float >( target.x, 0, target.z ).getLength() );
+    if( target.x < 0 )
+        rotY = -rotY;
+    rotZ = 0;
     updateMatrix();
 }
 

+ 1 - 1
Kam3D.h

@@ -41,7 +41,7 @@ namespace Framework
 
         D3D11_VIEWPORT *viewport;
         Welt3D *welt;
-        int style;
+        __int64 style;
         int ref;
 
         // Aktualisiert die view und projektion matrizen