Browse Source

Weiterentwickelt

kolja 5 years ago
parent
commit
07af48e96d
6 changed files with 43 additions and 41 deletions
  1. 1 1
      Array.h
  2. 1 2
      Framework.vcxproj
  3. 5 0
      Kamera2D.cpp
  4. 1 0
      Kamera2D.h
  5. 18 15
      Model2D.cpp
  6. 17 23
      Welt2D.cpp

+ 1 - 1
Array.h

@@ -609,7 +609,7 @@ namespace Framework
 
         // Gibt das Erste Element der Liste zurück.
         // Mit ++ kann durch die Liste iteriert werden
-        ArrayEintrag< TYP* > &getArray()
+        ArrayEintrag< TYP* > &getArray() const
         {
             return *entries;
         }

+ 1 - 2
Framework.vcxproj

@@ -128,8 +128,7 @@
       <AdditionalDependencies>d3dcompiler.lib;d3d9.lib;d3d11.lib;DXGI.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <CustomBuildStep>
-      <Command>copy "x64\Debug\Framework.dll" "..\Test\Test\framework.dll"
-copy "x64\Debug\Framework.dll" "..\..\Spiele Platform\Klient\Start\Start\framework.dll"
+      <Command>copy "x64\Debug\Framework.dll" "..\..\Spiele Platform\Klient\Start\Start\framework.dll"
 copy "x64\Debug\Framework.dll" "..\..\Spiele Platform\Klient\patcher\patcher\framework.dll"
 copy "x64\Debug\Framework.dll" "..\..\Spiele Platform\Klient\Icon\Icon\framework.dll"
 copy "x64\Debug\Framework.dll" "..\..\Spiele Platform\SMP\SMP\framework.dll"

+ 5 - 0
Kamera2D.cpp

@@ -22,6 +22,11 @@ Kamera2D::~Kamera2D()
         welt->release();
 }
 
+void Kamera2D::setZoom( float zoom )
+{
+    this->zoom = zoom;
+}
+
 void Kamera2D::setWelt( Welt2D *welt )
 {
     if( this->welt )

+ 1 - 0
Kamera2D.h

@@ -22,6 +22,7 @@ namespace Framework
     public:
         __declspec( dllexport ) Kamera2D();
         virtual __declspec( dllexport ) ~Kamera2D();
+        __declspec( dllexport ) void setZoom( float zoom );
         __declspec( dllexport ) void setWelt( Welt2D *welt );
         __declspec( dllexport ) bool tick( double time );
         __declspec( dllexport ) void render( Bild &zRObj );

+ 18 - 15
Model2D.cpp

@@ -47,28 +47,29 @@ bool Model2DData::istPunktInnen( Vertex p, int polygonId ) const
     if( p < minP || p > maxP || !polygons )
         return 0;
     int num = 0;
-    for( auto *polygon = &polygons->getArray(); polygon && polygon->set; polygon = polygon->next, num++ )
+    auto outListP = outList.getArray();
+    for( auto *polygon = &polygons->getArray(); polygon && polygon->set; polygon = polygon->next, num++, outListP++ )
     {
         if( polygonId >= 0 && num != polygonId )
             continue;
         int anz = polygon->var.vertex->getEintragAnzahl();
-        int ola = outList.z( num )->getEintragAnzahl();
         bool c = 0;
         int j = anz - 1;
-        for( int k = 0; k < ola; k++ )
+        for( auto outListPP = outListP.var->getArray(); outListPP.set; outListPP++ )
         {
-            Punkt out = outList.z( num )->get( k );
+            Punkt out = outListPP.var;
             if( out.x < out.y && j > out.x && j < out.y )
                 j = out.x;
             if( out.x > out.y && ( j > out.x || j < out.y ) )
                 j = out.x;
         }
-        for( int i = 0; i < anz; i++ )
+        auto point = polygon->var.vertex->getArray();
+        for( int i = 0; i < anz; i++, point++ )
         {
             bool cont = 0;
-            for( int k = 0; k < ola; k++ )
+            for( auto outListPP = outListP.var->getArray(); outListPP.set; outListPP++ )
             {
-                Punkt out = outList.z( num )->get( k );
+                Punkt out = outListPP.var;
                 if( out.x < out.y && i > out.x && i < out.y )
                     cont = 1;
                 if( out.x > out.y && ( i > out.x || i < out.y ) )
@@ -76,7 +77,7 @@ bool Model2DData::istPunktInnen( Vertex p, int polygonId ) const
             }
             if( cont )
                 continue;
-            Vertex a = polygon->var.vertex->get( i );
+            Vertex a = point.var;
             Vertex b = polygon->var.vertex->get( j );
             if( ( ( a.y >= p.y ) != ( b.y >= p.y ) ) && ( p.x <= ( b.x - a.x ) * ( p.y - a.y ) / (float)( b.y - a.y ) + a.x ) )
                 c = !c;
@@ -794,21 +795,23 @@ bool Model2DObject::istPunktInnen( Vertex p ) const
     if( p < Mat3< float >::scaling( size ) * rData->minP || p > Mat3< float >::scaling( size ) * rData->maxP || !rData->polygons )
         return 0;
     int num = 0;
+    Mat3< float > mat = Mat3< float >::rotation( -rotation ) * Mat3< float >::scaling( -size );
+    p = mat * p;
     for( auto *polygon = &rData->polygons->getArray(); polygon && polygon->set; polygon = polygon->next, num++ )
     {
         if( polygon->var.transparent )
             continue;
-        Mat3< float > mat = Mat3< float >::rotation( rotation ) * Mat3< float >::scaling( size );
-        int anz = polygon->var.vertex->getEintragAnzahl();
         bool c = 0;
-        int j = anz - 1;
-        for( int i = 0; i < anz; i++ )
+        for( auto point = polygon->var.vertex->getArray(); point.set; point++ )
         {
-            Vertex a = mat * polygon->var.vertex->get( i );
-            Vertex b = mat * polygon->var.vertex->get( j );
+            Vertex a;
+            if( point.next )
+                a = point.next->var;
+            else
+                a = polygon->var.vertex->get( 0 );
+            Vertex b = point.var;
             if( ( ( a.y >= p.y ) != ( b.y >= p.y ) ) && ( p.x <= ( b.x - a.x ) * ( p.y - a.y ) / (float)( b.y - a.y ) + a.x ) )
                 c = !c;
-            j = i;
         }
         if( c )
             return 1;

+ 17 - 23
Welt2D.cpp

@@ -83,19 +83,22 @@ bool Object2D::handleCollision( Object2D *obj )
     {
         Vertex v1 = getSpeed() + getWorldDir( getObjectPos( hp ).rotation( rSpeed ) - getObjectPos( hp ) );
         Vertex v2 = obj->getSpeed() + getWorldDir( obj->getObjectPos( hp ).rotation( obj->getDrehungSpeed() ) - obj->getObjectPos( hp ) );
-        float m1 = getMasse();
-        float m2 = obj->getMasse();
-        if( m1 == 0 || m2 == 0 )
-            return 0;
-        rSpeed = 0;
-        speed = Vertex( 0, 0 );
-        obj->setDrehungSpeed( 0 );
-        obj->setSpeed( 0, 0 );
-        if( v2.x || v2.y )
-            impuls( hp - v2, v2 * ( m2 / ( m1 + m2 ) ) );
-        if( v1.x || v1.y )
-            obj->impuls( hp - v1, v1 * ( m1 / ( m1 + m2 ) ) );
-        return 1;
+        if( ( position - obj->getPosition() ).getLengthSq() > ( position + v1 * 0.03f - obj->getPosition() - v2 * 0.03f ).getLengthSq() )
+        {
+            float m1 = getMasse();
+            float m2 = obj->getMasse();
+            if( m1 == 0 || m2 == 0 )
+                return 0;
+            rSpeed = 0;
+            speed = Vertex( 0, 0 );
+            obj->setDrehungSpeed( 0 );
+            obj->setSpeed( 0, 0 );
+            if( v2.x || v2.y )
+                impuls( hp - v2, v2 * ( m2 / ( m1 + m2 ) ) );
+            if( v1.x || v1.y )
+                obj->impuls( hp - v1, v1 * ( m1 / ( m1 + m2 ) ) );
+            return 1;
+        }
     }
     return 0;
 }
@@ -278,16 +281,7 @@ bool Welt2D::tick( double zeit )
         if( obj.next )
         {
             for( auto obj2 = *obj.next; obj2.set; obj2++ )
-            {
-                if( obj.var->handleCollision( obj2 ) )
-                {
-                    while( obj.var->istModelInnen( obj2 ) )
-                    {
-                        ret |= obj.var->tick( info, 0.03 );
-                        ret |= obj2.var->tick( info, 0.03 );
-                    }
-                }
-            }
+                obj.var->handleCollision( obj2 );
         }
         ret |= obj.var->tick( info, zeit );
     }