Browse Source

fix in memory buffer error

Kolja Strohm 2 years ago
parent
commit
2b7fb7bd20
5 changed files with 54 additions and 29 deletions
  1. 2 0
      InMemoryBuffer.cpp
  2. 39 24
      Kam3D.cpp
  3. 5 1
      Kam3D.h
  4. 1 1
      Thread.h
  5. 7 3
      Welt3D.cpp

+ 2 - 0
InMemoryBuffer.cpp

@@ -63,6 +63,8 @@ void InMemoryBuffer::schreibe( const char *bytes, int len )
     {
         int curPos = writePos % 256;
         int tmp = MIN( len, 256 - curPos );
+        if( !buffer[ writePos / 256 ] )
+            buffer[ writePos / 256 ] = new char[ 256 ];
         memcpy( buffer[ writePos / 256 ] + curPos, bytes + writeCount, tmp );
         writeCount += tmp;
         writePos += tmp;

+ 39 - 24
Kam3D.cpp

@@ -12,7 +12,8 @@ using namespace Framework;
 // Inhalt der Kam3D Klasse
 // Konstruktor
 Kam3D::Kam3D()
-    : ReferenceCounter()
+    : ReferenceCounter(),
+    rend( 0 )
 {
     openingAngle = (float)PI / 4;
     minZ = 0.1f;
@@ -55,6 +56,7 @@ void Kam3D::updateMatrix()
 void Kam3D::setPosition( Vec3< float > pos )
 {
     this->pos = pos;
+    rend = 1;
     updateMatrix();
 }
 
@@ -66,6 +68,8 @@ void Kam3D::scrollIn( float val )
     Mat4< float > tmp = tmp.rotationY( rotY ) * tmp.rotationX( rotX ) * tmp.rotationZ( rotZ );
     n = tmp * n * val;
     pos += n;
+    rend = 1;
+    updateMatrix();
 }
 
 // zppmt heraus, indem sich die Kamera etwas von dem Blockziel entfernt
@@ -76,13 +80,15 @@ void Kam3D::scrollOut( float val )
     Mat4< float > tmp = tmp.rotationY( rotY ) * tmp.rotationX( rotX ) * tmp.rotationZ( rotZ );
     n = tmp * n * val;
     pos -= n;
+    rend = 1;
+    updateMatrix();
 }
 
 // Richtet die Kamera so aus, dass sie genau auf einen bestimmten Punkt zeigt
 //  ziel: Der Punkt, auf den die Kamera zeigen soll
 void Kam3D::setAusrichtung( Vec3< float > ziel )
 {
-    Vec3< float > target = ( ziel - pos ).normalize();
+    Vec3< float > target = (ziel - pos).normalize();
     if( Vec3< float >( 0, target.y, target.z ).getLength() == 0 )
         rotX = 0;
     else
@@ -96,6 +102,7 @@ void Kam3D::setAusrichtung( Vec3< float > ziel )
     if( target.x < 0 )
         rotY = -rotY;
     rotZ = 0;
+    rend = 1;
     updateMatrix();
 }
 
@@ -106,6 +113,7 @@ void Kam3D::setRotation( Vec3< float > rotation )
     rotX = rotation.x;
     rotY = rotation.y;
     rotZ = rotation.z;
+    rend = 1;
     updateMatrix();
 }
 
@@ -147,7 +155,7 @@ void Kam3D::setBildschirmSize( int br, int h
 
 // Setzt die Welt, die gezeichnet werden soll
 //  w: Die Welt
-void Kam3D::setWelt( Welt3D *w )
+void Kam3D::setWelt( Welt3D* w )
 {
     if( welt )
         welt->release();
@@ -191,7 +199,8 @@ void Kam3D::removeStyle( __int64 style )
 //  return: true, wenn sich das Bild neu gezeichnet werden muss, false sonnst.
 bool Kam3D::tick( double tv )
 {
-    bool ret = 0;
+    bool ret = rend;
+    rend = 0;
     if( hatStyle( Style::Rotatable ) )
     {
         if( getTastenStand( T_Oben ) )
@@ -266,7 +275,7 @@ bool Kam3D::tick( double tv )
 
 // Verarbeitet ein Mausereignis
 //  me: Das Mausereignis, das verarbeitet werden soll
-void Kam3D::doMausEreignis( MausEreignis &me )
+void Kam3D::doMausEreignis( MausEreignis& me )
 {
     if( me.verarbeitet )
         return;
@@ -275,7 +284,7 @@ void Kam3D::doMausEreignis( MausEreignis &me )
         MausEreignis3D me3d;
         me3d.id = me.id;
         me3d.verarbeitet = me.verarbeitet;
-        Vec3< float > mausP = Vec3< float >( ( me.mx - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( me.my - viewport.y ) / ( 0.5f * viewport.height ) - 1, 0 );
+        Vec3< float > mausP = Vec3< float >( (me.mx - viewport.x) / (0.5f * viewport.width) - 1, (me.my - viewport.y) / (0.5f * viewport.height) - 1, 0 );
         Vec3< float > mausT = Vec3< float >( mausP.x, mausP.y, 1 );
         Mat4< float > mat = proj * view;
         mat = mat.getInverse();
@@ -289,7 +298,7 @@ void Kam3D::doMausEreignis( MausEreignis &me )
 
 // Verarbeitet ein Tastaturereignis
 //  te: das Tastaturereignis, das verarbeitet werden soll
-void Kam3D::doTastaturEreignis( TastaturEreignis &te )
+void Kam3D::doTastaturEreignis( TastaturEreignis& te )
 {
 
 }
@@ -299,7 +308,7 @@ void Kam3D::doTastaturEreignis( TastaturEreignis &te )
 //  return: 1, falls alle Styles in style gesetzt wurden
 bool Kam3D::hatStyle( __int64 style ) const
 {
-    return ( this->style | style ) == this->style;
+    return (this->style | style) == this->style;
 }
 
 // Gibt zurück, ob bestimmte Styles nicht gesetzt wurden
@@ -307,17 +316,17 @@ bool Kam3D::hatStyle( __int64 style ) const
 //  return: 1, falls alle Styles in style nicht gesetzt wurden
 bool Kam3D::hatStyleNicht( __int64 style ) const
 {
-    return ( this->style | style ) != this->style;
+    return (this->style | style) != this->style;
 }
 
 // Gibt einen Zeiger auf den Viewport zurück
-const ViewPort *Kam3D::zViewPort() const
+const ViewPort* Kam3D::zViewPort() const
 {
     return &viewport;
 }
 
 // Gibt die Position der Kamera in der Welt zurück
-const Vec3< float > &Kam3D::getWorldPosition() const
+const Vec3< float >& Kam3D::getWorldPosition() const
 {
     return pos;
 }
@@ -326,11 +335,11 @@ 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, ( viewport.height - ( screen.y - viewport.y ) ) / ( 0.5f * viewport.height ) - 1, 0.1f );
+    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 ];
+    point.x = (point.x * 0.1f) / mat.elements[ 0 ][ 0 ];
+    point.y = (point.y * 0.1f) / mat.elements[ 1 ][ 1 ];
     return inv * point;
 }
 
@@ -338,39 +347,45 @@ const Vec3< float > Kam3D::getWorldPosition( Punkt screen ) const
 //  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, ( viewport.height - ( screen.y - viewport.y ) ) / ( 0.5f * viewport.height ) - 1, 0.1f );
+    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 = 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.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;
 }
 
 // Gibt die Projektionsmatrix der Kamera zurück
-const Mat4< float > &Kam3D::getProjectionMatrix() const
+const Mat4< float >& Kam3D::getProjectionMatrix() const
 {
     return proj;
 }
 
 // Gibt die Ansichtsmatrix der Kamera zurück
-const Mat4< float > &Kam3D::getViewMatrix() const
+const Mat4< float >& Kam3D::getViewMatrix() const
 {
     return view;
 }
 
+//! Gibt die Rotation um die einzelnen axen zurück
+const Vec3< float > Kam3D::getRotation() const
+{
+    return { rotX, rotY, rotZ };
+}
+
 // Gibt die Welt zurück
-Welt3D *Kam3D::getWelt() const
+Welt3D* Kam3D::getWelt() const
 {
-    return welt ? dynamic_cast<Welt3D *>( welt->getThis() ) : 0;
+    return welt ? dynamic_cast<Welt3D*>(welt->getThis()) : 0;
 }
 
 // Gibt die Welt zurück
-Welt3D *Kam3D::zWelt() const
+Welt3D* Kam3D::zWelt() const
 {
     return welt;
 }

+ 5 - 1
Kam3D.h

@@ -25,7 +25,7 @@ namespace Framework
     };
 
     //! Eine 3d Kamera, die einen Ausschnitt einer 3D Welt in einen bestimmten Teil des Bildschirms zeichnet
-    class Kam3D : public virtual ReferenceCounter
+    class Kam3D : public virtual Framework::ReferenceCounter
     {
     public:
         class Style
@@ -36,6 +36,8 @@ namespace Framework
             const static __int64 Zoomable = 0x4;
             const static __int64 Tick = 0x8;
         };
+    protected:
+        bool rend;
 
     private:
         Mat4< float > view;
@@ -137,6 +139,8 @@ namespace Framework
         DLLEXPORT const Mat4< float > &getProjectionMatrix() const;
         //! Gibt die Ansichtsmatrix der Kamera zurück
         DLLEXPORT const Mat4< float > &getViewMatrix() const;
+        //! Gibt die Rotation um die einzelnen axen zurück
+        DLLEXPORT const Vec3< float > getRotation() const;
         //! Gibt die Welt zurück
         DLLEXPORT Welt3D *getWelt() const;
         //! Gibt die Welt zurück

+ 1 - 1
Thread.h

@@ -72,7 +72,7 @@ namespace Framework
     class ThreadRegister
     {
     private:
-        Array< Thread* > threads;
+        Array< Framework::Thread* > threads;
         CRITICAL_SECTION cs;
         Array< pthread_t > closedThreads;
 

+ 7 - 3
Welt3D.cpp

@@ -4,6 +4,7 @@
 #include "Model3D.h"
 #include "GraphicsApi.h"
 #include "DXBuffer.h"
+#include "Globals.h"
 
 using namespace Framework;
 
@@ -45,10 +46,13 @@ void Welt3D::unlock()
 void Welt3D::addZeichnung( Model3D *obj )
 {
     cs.lock();
-    for( auto i : *members )
+    if( debugDX )
     {
-        if( i == obj )
-            throw std::exception();
+        for( auto i : *members )
+        {
+            if( i == obj )
+                throw std::exception();
+        }
     }
     members->add( obj );
     rend = 1;