Browse Source

Fehler behoben

Kolja Strohm 5 years ago
parent
commit
790d8db98f
2 changed files with 29 additions and 28 deletions
  1. 24 24
      Bild.cpp
  2. 5 4
      Mat4.h

+ 24 - 24
Bild.cpp

@@ -77,7 +77,7 @@ inline void Bild::alphaPixelAssozP( int &fc, int f )
 {
     unsigned char *fc1 = (unsigned char*)&fc;
     unsigned char *fc2 = (unsigned char*)&f;
-    unsigned char na = ~fc2[ 3 ];
+    unsigned char na = (unsigned char)~fc2[ 3 ];
     unsigned char a = (unsigned char)( fc2[ 3 ] + ( ( na * fc1[ 3 ] ) >> 8 ) );
     if( a == 0 )
         return;
@@ -95,7 +95,7 @@ inline void Bild::alphaPixelP3D( int &fc, int colorb )
     int na = ( 0x100 - alpha );
     fc = ( ( ( ( ( na * ( fc & 0xFF00FF ) ) >> 8 ) + ( ( alpha * ( colorb & 0xFF00FF ) ) >> 8 ) ) & 0xFF00FF ) |
         ( ( ( ( na * ( fc & 0x00FF00 ) ) >> 8 ) + ( ( alpha * ( colorb & 0x00FF00 ) ) >> 8 ) ) & 0x00FF00 ) |
-        ( ( fc & 0xFF000000 ) ) ) * ( fc != 0 ) | ( fc == 0 ) * colorb;
+           ( ( fc & 0xFF000000 ) ) ) * ( fc != 0 ) | ( fc == 0 ) * colorb;
     //unsigned char *fc1 = (unsigned char*)&fc;
     //unsigned char *fc2 = (unsigned char*)&colorb;
     //unsigned char na = 255-fc2[ 3 ];
@@ -113,7 +113,7 @@ inline void Bild::alphaPixelP( int &fc, int colorb )
     int na = ( 0x100 - alpha );
     fc = ( ( ( ( ( na * ( fc & 0xFF00FF ) ) >> 8 ) + ( ( alpha * ( colorb & 0xFF00FF ) ) >> 8 ) ) & 0xFF00FF ) |
         ( ( ( ( na * ( fc & 0x00FF00 ) ) >> 8 ) + ( ( alpha * ( colorb & 0x00FF00 ) ) >> 8 ) ) & 0x00FF00 ) |
-        ( ( fc & 0xFF000000 ) ) );
+           ( ( fc & 0xFF000000 ) ) );
     //unsigned char *fc1 = (unsigned char*)&fc;
     //unsigned char *fc2 = (unsigned char*)&colorb;
     //unsigned char na = 255-fc2[ 3 ];
@@ -151,7 +151,7 @@ void Bild::drawFlatDreieck( int y1, int y2, float m1, float b1, float m2, float
 }
 
 void Bild::drawFlatDreieckTextur( int y1, int y2, double m1, double b1, double m2, double b2, double tx1, double ty1, double tx2, double ty2,
-    double tx_1o, double ty_1o, double tx_2o, double ty_2o, double txf, double tyf, Bild &textur )
+                                  double tx_1o, double ty_1o, double tx_2o, double ty_2o, double txf, double tyf, Bild &textur )
 {
     const double yStart = max( y1, dPosA[ doa ].y );
     const double yEnd = min( y2, dSizeA[ doa ].y );
@@ -191,7 +191,7 @@ void Bild::drawFlatDreieckAlpha( int y1, int y2, float m1, float b1, float m2, f
 }
 
 void Bild::drawFlatDreieckTexturAlpha( int y1, int y2, double m1, double b1, double m2, double b2, double tx1, double ty1, double tx2, double ty2,
-    double tx_1o, double ty_1o, double tx_2o, double ty_2o, double txf, double tyf, Bild &textur )
+                                       double tx_1o, double ty_1o, double tx_2o, double ty_2o, double txf, double tyf, Bild &textur )
 {
     const double yStart = max( y1, dPosA[ doa ].y );
     const double yEnd = min( y2, dSizeA[ doa ].y );
@@ -482,7 +482,7 @@ void Bild::alphaRegion( int x, int y, int b, int h, int ff )
             {
                 *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                     ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                    ( ( *pixel & 0xFF000000 ) ) ) * ( *pixel != 0 ) | ( *pixel == 0 ) * ff;
+                           ( ( *pixel & 0xFF000000 ) ) ) * ( *pixel != 0 ) | ( *pixel == 0 ) * ff;
             }
         }
     }
@@ -494,7 +494,7 @@ void Bild::alphaRegion( int x, int y, int b, int h, int ff )
             {
                 *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                     ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                    ( ( *pixel & 0xFF000000 ) ) );
+                           ( ( *pixel & 0xFF000000 ) ) );
             }
         }
     }
@@ -757,7 +757,7 @@ void Bild::drawLinieHAlpha( int x, int y, int len, int f ) // zeichnet eine hori
     {
         fc[ i ] = ( ( ( ( ( na * ( fc[ i ] & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
             ( ( ( ( na * ( fc[ i ] & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-            ( ( fc[ i ] & 0xFF000000 ) ) ) * ( fc[ i ] != 0 || !alpha3D ) | ( fc[ i ] == 0 && alpha3D ) * f;
+                    ( ( fc[ i ] & 0xFF000000 ) ) ) * ( fc[ i ] != 0 || !alpha3D ) | ( fc[ i ] == 0 && alpha3D ) * f;
     }
     rend = 1;
 }
@@ -804,7 +804,7 @@ void Bild::drawLinieVAlpha( int x, int y, int len, int f ) // zeichnet eine vert
     {
         fc[ i ] = ( ( ( ( ( na * ( fc[ i ] & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
             ( ( ( ( na * ( fc[ i ] & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-            ( fc[ i ] & 0xFF000000 ) ) * ( fc[ i ] != 0 || !alpha3D ) | ( fc[ i ] == 0 && alpha3D ) * f;
+                    ( fc[ i ] & 0xFF000000 ) ) * ( fc[ i ] != 0 || !alpha3D ) | ( fc[ i ] == 0 && alpha3D ) * f;
     }
     rend = 1;
 }
@@ -1001,28 +1001,28 @@ void Bild::drawLinieBorderedAlpha( Punkt a, Punkt b, int bc, int fc )
                 int &pixel = this->fc[ (int)( x - 0.5 ) + (int)( y + 0.5 ) * size.x ];
                 pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
                     ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
-                    ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
             }
             if( (int)( (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ) < maxPixel )
             {
                 int &pixel = this->fc[ (int)( x + 1.5 ) + (int)( y + 0.5 ) * size.x ];
                 pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
                     ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
-                    ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
             }
             if( (int)( (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ) < maxPixel )
             {
                 int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y - 0.5 ) * size.x ];
                 pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
                     ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
-                    ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
             }
             if( (int)( (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ) < maxPixel )
             {
                 int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 1.5 ) * size.x ];
                 pixel = ( ( ( ( ( na2 * ( pixel & 0xFF00FF ) ) >> 8 ) + j1 ) & 0xFF00FF ) |
                     ( ( ( ( na2 * ( pixel & 0x00FF00 ) ) >> 8 ) + j2 ) & 0x00FF00 ) |
-                    ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
+                          ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * bc;
             }
             x += xf, y += yf;
         }
@@ -1033,7 +1033,7 @@ void Bild::drawLinieBorderedAlpha( Punkt a, Punkt b, int bc, int fc )
             int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ];
             pixel = ( ( ( ( ( na * ( pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * fc;
+                      ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * fc;
             x += xf, y += yf;
         }
         rend = 1;
@@ -1212,7 +1212,7 @@ void Bild::drawLinieAlpha( Punkt a, Punkt b, int fc )
             int &pixel = this->fc[ (int)( x + 0.5 ) + (int)( y + 0.5 ) * size.x ];
             pixel = ( ( ( ( ( na * ( pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * fc;
+                      ( pixel & 0xFF000000 ) ) * ( pixel != 0 || !alpha3D ) | ( pixel == 0 && alpha3D ) * fc;
             x += xf, y += yf;
         }
         rend = 1;
@@ -1297,56 +1297,56 @@ void Bild::drawKreisAlpha( int xOff, int yOff, int r, int fc )
             pixel = &this->fc[ xOff + a + ( yOff + b ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
         if( xOff - a < dgx && xOff - a > dpx && yOff + b < dgy && yOff + b > dpy )
         {
             pixel = &this->fc[ xOff - a + ( yOff + b ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
         if( xOff + a < dgx && xOff + a > dpx && yOff - b < dgy && yOff - b > dpy )
         {
             pixel = &this->fc[ xOff + a + ( yOff - b ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
         if( xOff - a < dgx && xOff - a > dpx && yOff - b < dgy && yOff - b > dpy )
         {
             pixel = &this->fc[ xOff - a + ( yOff - b ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
         if( xOff + b < dgx && xOff + b > dpx && yOff + a < dgy && yOff + a > dpy )
         {
             pixel = &this->fc[ xOff + b + ( yOff + a ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
         if( xOff - b < dgx && xOff - b > dpx && yOff + a < dgy && yOff + a > dpy )
         {
             pixel = &this->fc[ xOff - b + ( yOff + a ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
         if( xOff + b < dgx && xOff + b > dpx && yOff - a < dgy && yOff - a > dpy )
         {
             pixel = &this->fc[ xOff + b + ( yOff - a ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
         if( xOff - b < dgx && xOff - b > dpx && yOff - a < dgy && yOff - a > dpy )
         {
             pixel = &this->fc[ xOff - b + ( yOff - a ) * size.x ];
             *pixel = ( ( ( ( ( na * ( *pixel & 0xFF00FF ) ) >> 8 ) + i1 ) & 0xFF00FF ) |
                 ( ( ( ( na * ( *pixel & 0x00FF00 ) ) >> 8 ) + i2 ) & 0x00FF00 ) |
-                ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
+                       ( *pixel & 0xFF000000 ) ) * ( *pixel != 0 || !alpha3D ) | ( *pixel == 0 && alpha3D ) * fc;
         }
     }
     rend = 1;
@@ -1434,7 +1434,7 @@ void Bild::alphaBildAssoz( int x, int y, int br, int hi, Bild &zBild )
             {
                 int fc = ff[ ( xx - xst2 + xst ) + ygr2 ];
                 unsigned char *cf = (unsigned char*)&fc;
-                //cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
+                cf[ 3 ] = (unsigned char)( ( cf[ 3 ] > alpha[ alphaAnzahl ] ) * ( cf[ 3 ] - alpha[ alphaAnzahl ] ) );
                 alphaPixelAssozP( this->fc[ xx + ygr ], fc );
             }
         }

+ 5 - 4
Mat4.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include "Vec3.h"
+#include "Mat3.h"
 #include <iostream>
 
 namespace Framework
@@ -287,9 +288,9 @@ namespace Framework
         //  b: der vector zu dem gedreht werden soll
         static Mat4 rotationTo( Vec3<T> &a, Vec3<T> &b )
         {
-            Vec3 aNorm = Vec3( a ).normalize();
-            Vec3 bNorm = Vec3( b ).normalize();
-            Vec3 v = aNotm.crossProduct( bNorm );
+            Vec3<T> aNorm = Vec3<T>( a ).normalize();
+            Vec3<T> bNorm = Vec3<T>( b ).normalize();
+            Vec3<T> v = aNorm.crossProduct( bNorm );
             T s = v.getLengthSq();
             T c = aNorm * bNorm;
             T m = ( 1 - c ) / s;
@@ -299,7 +300,7 @@ namespace Framework
             return Mat4( { res.elements[ 0 ][ 0 ], res.elements[ 0 ][ 1 ], res.elements[ 0 ][ 2 ], 0,
                            res.elements[ 1 ][ 0 ], res.elements[ 1 ][ 1 ], res.elements[ 1 ][ 2 ], 0,
                            res.elements[ 2 ][ 0 ], res.elements[ 2 ][ 1 ], res.elements[ 2 ][ 2 ], 0,
-                           0, 0, 0, 1 } )
+                           0, 0, 0, 1 } );
         }
     };
 }