|
@@ -179,9 +179,15 @@ bool Model2DData::erstelleModell( Array< Polygon2D > *polygons )
|
|
|
for( int i = 0; i < vAnz; i++ )
|
|
|
{
|
|
|
if( maxP.x < fabs( pg.vertex->get( i ).x ) )
|
|
|
+ {
|
|
|
maxP.x = abs( (int)pg.vertex->get( i ).x ) + 1;
|
|
|
+ maxP.y = abs( (int)pg.vertex->get( i ).x ) + 1;
|
|
|
+ }
|
|
|
if( maxP.y < fabs( pg.vertex->get( i ).y ) )
|
|
|
+ {
|
|
|
+ maxP.x = abs( (int)pg.vertex->get( i ).y ) + 1;
|
|
|
maxP.y = abs( (int)pg.vertex->get( i ).y ) + 1;
|
|
|
+ }
|
|
|
}
|
|
|
minP = -maxP;
|
|
|
if( !textur )
|
|
@@ -393,7 +399,7 @@ void Model2DData::removeModell() // setzt die Vertex daten zur
|
|
|
maxP = Punkt( 0, 0 );
|
|
|
}
|
|
|
|
|
|
-bool Model2DData::calcHitPoint( Vertex pos, Vertex dir, char *polygonName, Vertex &hitpoint, Vertex &moveSpeed, float &rotSpeed ) const
|
|
|
+bool Model2DData::calcHitPoint( Vertex pos, Vertex dir, const char *polygonName, Vertex &hitpoint, Vertex &moveSpeed, float &rotSpeed ) const
|
|
|
{
|
|
|
bool ret = 0;
|
|
|
for( auto *polygon = &polygons->getArray(); polygon && polygon->set; polygon = polygon->next )
|
|
@@ -653,6 +659,221 @@ Model2DData *Model2DData::release()
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+// Inhalt der Model2D Klasse aus Model2D.h
|
|
|
+// Konstruktor
|
|
|
+Model2DObject::Model2DObject()
|
|
|
+ : Object2D()
|
|
|
+{
|
|
|
+ rData = 0;
|
|
|
+ textur = new RCArray< Textur2D >;
|
|
|
+ ref = 1;
|
|
|
+}
|
|
|
+
|
|
|
+// Destruktor
|
|
|
+Model2DObject::~Model2DObject()
|
|
|
+{
|
|
|
+ if( rData )
|
|
|
+ rData->release();
|
|
|
+ textur->release();
|
|
|
+}
|
|
|
+
|
|
|
+// nicht constant
|
|
|
+void Model2DObject::setModel( Model2DData *mdl )
|
|
|
+{
|
|
|
+ if( rData )
|
|
|
+ rData->release();
|
|
|
+ rData = mdl;
|
|
|
+}
|
|
|
+
|
|
|
+void Model2DObject::setTextur( Textur2D *t )
|
|
|
+{
|
|
|
+ int index = 0;
|
|
|
+ if( rData )
|
|
|
+ {
|
|
|
+ for( auto i = rData->polygons->getArray(); i.set; i++ )
|
|
|
+ textur->set( t->getThis(), index++ );
|
|
|
+ }
|
|
|
+ t->release();
|
|
|
+}
|
|
|
+
|
|
|
+void Model2DObject::impuls( Vertex start, Vertex speed )
|
|
|
+{
|
|
|
+ if( rData )
|
|
|
+ {
|
|
|
+ Vertex hp;
|
|
|
+ Vertex mSpeed;
|
|
|
+ float rSpeed;
|
|
|
+ if( rData->calcHitPoint( start, speed, "", hp, mSpeed, rSpeed ) )
|
|
|
+ {
|
|
|
+ this->speed += mSpeed;
|
|
|
+ this->rSpeed += rSpeed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Model2DObject::setTextur( Textur2D *t, const char *polygonName )
|
|
|
+{
|
|
|
+ int index = 0;
|
|
|
+ for( auto i = rData->polygons->getArray(); i.set; i++, index++ )
|
|
|
+ {
|
|
|
+ if( i.var.name->istGleich( polygonName ) )
|
|
|
+ textur->set( t->getThis(), index );
|
|
|
+ }
|
|
|
+ t->release();
|
|
|
+}
|
|
|
+
|
|
|
+void Model2DObject::render( Mat3< float > &kamMat, Bild &zRObj )
|
|
|
+{
|
|
|
+ if( !rData || !rData->polygons || !textur )
|
|
|
+ return;
|
|
|
+ int num = 0;
|
|
|
+ for( auto *p = &rData->vListen->getArray(); p && p->set; p = p->next, num++ )
|
|
|
+ {
|
|
|
+ Mat3< float > mat = kamMat * getObjectMatrix();
|
|
|
+ if( textur->z( num ) )
|
|
|
+ {
|
|
|
+ Bild *txt = textur->z( num )->zTextur();
|
|
|
+ for( auto *i = &p->var->getArray(); i && i->set; i = i->next )
|
|
|
+ {
|
|
|
+ for( auto *j = &i->var->zListe()->getArray(); j->next->next && j->next->next->set; j = j->next )
|
|
|
+ {
|
|
|
+ Vertex a = mat * *j->var->punkt;
|
|
|
+ Vertex b = mat * *j->next->var->punkt;
|
|
|
+ Vertex c = mat * *j->next->next->var->punkt;
|
|
|
+ Punkt ta = (Punkt)Vertex( j->var->textur->x * (float)txt->getBreite(), j->var->textur->y * (float)txt->getHeight() );
|
|
|
+ Punkt tb = (Punkt)Vertex( j->next->var->textur->x * (float)txt->getBreite(), j->next->var->textur->y * (float)txt->getHeight() );
|
|
|
+ Punkt tc = (Punkt)Vertex( j->next->next->var->textur->x * (float)txt->getBreite(), j->next->next->var->textur->y * (float)txt->getHeight() );
|
|
|
+ zRObj.drawDreieckTexturAlpha( a, b, c, ta, tb, tc, *txt );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// constant
|
|
|
+bool Model2DObject::istPunktInnen( Vertex p ) const
|
|
|
+{
|
|
|
+ if( !rData )
|
|
|
+ return 0;
|
|
|
+ p -= position;
|
|
|
+ if( p < Mat3< float >::scaling( size ) * rData->minP || p > Mat3< float >::scaling( size ) * rData->maxP || !rData->polygons )
|
|
|
+ return 0;
|
|
|
+ int num = 0;
|
|
|
+ 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++ )
|
|
|
+ {
|
|
|
+ Vertex a = mat * polygon->var.vertex->get( i );
|
|
|
+ Vertex b = mat * 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;
|
|
|
+ j = i;
|
|
|
+ }
|
|
|
+ if( c )
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+bool Model2DObject::istLinieInnen( Vertex a, Vertex b ) const
|
|
|
+{
|
|
|
+ if( !rData || !rData->polygons )
|
|
|
+ return 0;
|
|
|
+ int pAnz = rData->polygons->getEintragAnzahl();
|
|
|
+ for( int p = 0; p < pAnz; p++ )
|
|
|
+ {
|
|
|
+ if( rData->polygons->get( p ).transparent )
|
|
|
+ continue;
|
|
|
+ Mat3< float > mat = Mat3< float >::rotation( rotation ) * Mat3< float >::scaling( size );
|
|
|
+ int anz = rData->polygons->get( p ).vertex->getEintragAnzahl();
|
|
|
+ int j = anz - 1;
|
|
|
+ for( int i = 0; i < anz; i++ )
|
|
|
+ {
|
|
|
+ Punkt va = mat * rData->polygons->get( p ).vertex->get( i );
|
|
|
+ Punkt vb = mat * rData->polygons->get( p ).vertex->get( j );
|
|
|
+ if( (Punkt)a == position + va && (Punkt)b == position + vb )
|
|
|
+ return 1;
|
|
|
+ if( (Punkt)a == position + vb && (Punkt)b == position + va )
|
|
|
+ return 1;
|
|
|
+ j = i;
|
|
|
+ }
|
|
|
+ Vertex len = b - a;
|
|
|
+ Vertex speed( len.x > 0 ? 1 : -1.f, len.y > 0 ? 1 : -1.f );
|
|
|
+ int mLen = 0;
|
|
|
+ if( fabs( len.x ) > fabs( len.y ) )
|
|
|
+ {
|
|
|
+ mLen = (int)fabs( len.x );
|
|
|
+ speed.y = len.y / (float)fabs( len.x );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ mLen = (int)fabs( len.y );
|
|
|
+ speed.x = len.x / (float)fabs( len.y );
|
|
|
+ }
|
|
|
+ int i = 1;
|
|
|
+ bool inside = 1;
|
|
|
+ for( Vertex vp = speed + a; (Punkt)vp != (Punkt)( b - speed ) && inside && i < mLen - 1; vp += speed, i++ )
|
|
|
+ inside &= istPunktInnen( vp );
|
|
|
+ if( inside )
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+bool Model2DObject::istModelInnen( const Model2DObject *zMdl, bool end ) const
|
|
|
+{
|
|
|
+ if( !end )
|
|
|
+ {
|
|
|
+ Vertex min = (Vertex)rData->minP * size + position;
|
|
|
+ Vertex max = (Vertex)rData->maxP * size + position;
|
|
|
+ Vertex min2 = (Vertex)zMdl->zModel()->minP * zMdl->getSize() + zMdl->getPosition();
|
|
|
+ Vertex max2 = (Vertex)zMdl->zModel()->maxP * zMdl->getSize() + zMdl->getPosition();
|
|
|
+ if( max.x < min2.x || min.x > max2.x || max.y < min2.y || min.y > max2.y )
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ Mat3< float > mat = getObjectMatrix();
|
|
|
+ for( auto *polygon = &rData->polygons->getArray(); polygon && polygon->set; polygon = polygon->next )
|
|
|
+ {
|
|
|
+ if( polygon->var.transparent )
|
|
|
+ continue;
|
|
|
+ int anz = polygon->var.vertex->getEintragAnzahl();
|
|
|
+ for( int i = 0; i < anz; i++ )
|
|
|
+ {
|
|
|
+ if( zMdl->istPunktInnen( mat * polygon->var.vertex->get( i ) ) )
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if( end )
|
|
|
+ return 0;
|
|
|
+ return zMdl->istModelInnen( this, 1 );
|
|
|
+}
|
|
|
+
|
|
|
+Rect< float > Model2DObject::getBoundingBox() const
|
|
|
+{
|
|
|
+ if( rData )
|
|
|
+ return Rect< float >{ (Vertex)rData->minP * size + position, (Vertex)rData->maxP * size + position };
|
|
|
+ return Rect< float >();
|
|
|
+}
|
|
|
+
|
|
|
+Model2DData *Model2DObject::getModel() const
|
|
|
+{
|
|
|
+ return rData ? rData->getThis() : 0;
|
|
|
+}
|
|
|
+
|
|
|
+Model2DData *Model2DObject::zModel() const
|
|
|
+{
|
|
|
+ return rData;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// Inhalt der Model2D Klasse aus Model2D.h
|
|
|
// Konstruktor
|
|
|
Model2D::Model2D()
|