Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jul 15, 2025 14:46

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Autor Nachricht
 Betreff des Beitrags: Oriented Bounding Box für Dreieck
BeitragVerfasst: Fr Aug 01, 2003 23:21 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Mai 27, 2002 16:29
Beiträge: 77
Wohnort: Düsseldorf
Hallo
Wie berechne ich für ein einziges Dreieck eine Oriented Bounding Box?
Bisher habe ich es so versucht:
Code:
  1.  
  2.   TOOBoundingBox=record
  3.     SizeX,SizeY,SizeZ:single;
  4.     vX,vY,vZ:TVector3f;
  5.     mitte:TVector3f;
  6.   end;
  7.  
  8.   function CalculateLeaveOBB(const daten:TList):TOOBoundingBox;
  9.   var objekt:TTriangle;
  10.       temp:THomogeneousFltVector;
  11.       tempMat:TMatrix4f;
  12.       v1, v2, v3:TVector4f;
  13.       tempMinMax:TMinMax;
  14.   begin
  15.   //Objekt bestimmen
  16.   objekt:=PTriangle(daten[0])^;
  17.  
  18.   //OBB bestimmen
  19.   temp:=NullVector4;
  20.  
  21.   result.vZ:=VectorAffineSubtract(objekt.normale,objekt.mitte); //Z Achse ist der Normalen Vektor
  22.  
  23.   //Y Achse ist der um 90° um die X Achse gedrehte Normalenvektor
  24.   move(result.vZ,temp,sizeof(result.vZ));
  25.   VectorRotate(temp,XVector,pi/2);
  26.   move(temp,Result.vY,sizeof(Result.vY));
  27.  
  28.   //X Achse ist der um 90° um die Y Achse gedrehte Normalenvektor
  29.   move(result.vZ,temp,sizeof(result.vZ));
  30.   VectorRotate(temp,YVector,pi/2);
  31.   move(temp,Result.vX,sizeof(Result.vX));
  32.  
  33.   //Jetzt muss das Dreieck so gedreht werden, dass seine Achsen Weltachsen sind:
  34.  
  35.    //Erstmal Matrix berechnen, um ein Dreieck, das AA ist, zu einem O zu machen
  36.     move(IdentityMatrix4f[3],tempMat[3],sizeof(IdentityMatrix4f)); //Letzte Spalte, Identiy
  37.     tempMat[0][3]:=0; //Letzte Zeile: Identity
  38.     tempMat[1][3]:=0; //Letzte Zeile: Identity
  39.     tempMat[2][3]:=0; //Letzte Zeile: Identity
  40.     move(result.vX,tempMat[0],sizeof(result.vX));
  41.     move(result.vY,tempMat[1],sizeof(result.vY));
  42.     move(result.vZ,tempMat[2],sizeof(result.vZ));
  43.  
  44.    MatrixInvert(tempMat); //Jetzt erfüllte sie den gegenteiligen Zweck
  45.  
  46.    //Die Matrix auf alle Punkte anwenden
  47.    v1[3]:=0;
  48.    move(objekt.v1,v1,sizeof(objekt.v1));
  49.    VectorTransform(v1,tempMat);
  50.  
  51.    v2[3]:=0;
  52.    move(objekt.v2,v2,sizeof(objekt.v2));
  53.    VectorTransform(v2,tempMat);
  54.  
  55.    v3[3]:=0;
  56.    move(objekt.v3,v3,sizeof(objekt.v3));
  57.    VectorTransform(v3,tempMat);
  58.  
  59.    //Min und Max für X berechnen
  60.    if v1[0]<v2[0] then begin
  61.      if v2[0]<v3[0] then begin
  62.        tempMinMax.MinX:= v1[0];
  63.        tempMinMax.MaxX:= v3[0];
  64.      end else begin
  65.        if v1[0]<v3[0] then tempMinMax.MinX:= v1[0]
  66.        else tempMinMax.MinX:= v3[0];
  67.        tempMinMax.MaxX:= v2[0];
  68.      end;
  69.    end else begin //v2<v1
  70.      if v1[0]<v3[0] then begin //v2<v1<v3
  71.        tempMinMax.MinX:= v2[0];
  72.        tempMinMax.MaxX:= v3[0];
  73.      end else begin //v3<v2<v1 oder v2<v3<v1
  74.        if v2[0]<v1[0] then tempMinMax.MinX:= v3[0] //v3<v2<v1
  75.        else tempMinMax.MinX:= v2[0]; //v2<v3<v1
  76.        tempMinMax.MaxX:= v1[0];
  77.      end;
  78.    end;
  79.  
  80.    //Min und Max für Y berechnen
  81.    if v1[1]<v2[1] then begin
  82.      if v2[1]<v3[1] then begin
  83.        tempMinMax.MinY:= v1[1];
  84.        tempMinMax.MaxY:= v3[1];
  85.      end else begin
  86.        if v1[1]<v3[1] then tempMinMax.MinY:= v1[1]
  87.        else tempMinMax.MinY:= v3[1];
  88.        tempMinMax.MaxY:= v2[1];
  89.      end;
  90.    end else begin //v2<v1
  91.      if v1[1]<v3[1] then begin //v2<v1<v3
  92.        tempMinMax.MinY:= v2[1];
  93.        tempMinMax.MaxY:= v3[1];
  94.      end else begin //v3<v2<v1 oder v2<v3<v1
  95.        if v2[1]<v1[1] then tempMinMax.MinY:= v3[1] //v3<v2<v1
  96.        else tempMinMax.MinY:= v2[1]; //v2<v3<v1
  97.        tempMinMax.MaxY:= v1[1];
  98.      end;
  99.    end;
  100.  
  101.    //Min und Max für Z berechnen
  102.    if v1[2]<v2[2] then begin
  103.      if v2[2]<v3[2] then begin
  104.        tempMinMax.MinZ:= v1[2];
  105.        tempMinMax.MaxZ:= v3[2];
  106.      end else begin
  107.        if v1[2]<v3[2] then tempMinMax.MinZ:= v1[2]
  108.        else tempMinMax.MinZ:= v3[2];
  109.        tempMinMax.MaxZ:= v2[2];
  110.      end;
  111.    end else begin //v2<v1
  112.      if v1[2]<v3[2] then begin //v2<v1<v3
  113.        tempMinMax.MinZ:= v2[2];
  114.        tempMinMax.MaxZ:= v3[2];
  115.      end else begin //v3<v2<v1 oder v2<v3<v1
  116.        if v2[2]<v1[2] then tempMinMax.MinZ:= v3[2] //v3<v2<v1
  117.        else tempMinMax.MinZ:= v2[2]; //v2<v3<v1
  118.        tempMinMax.MaxZ:= v1[2];
  119.      end;
  120.    end;
  121.  
  122.  
  123.    Result.SizeX:=(tempminMax.MaxX-tempminMax.MinX)/2;
  124.    Result.SizeY:=(tempminMax.MaxY-tempminMax.MinY)/2;
  125.    Result.SizeZ:=(tempminMax.MaxZ-tempminMax.MinZ)/2;
  126.  
  127.    result.mitte:=objekt.mitte;
  128. end;
  129.  

Zuerst wird die Normale als Z-Achse genommen, danach wird sie um die Y-Achse gedreht, und als X Achse genommen, und für Y-Achse wird nochmal dasselbe um (Welt) Y gemacht.
Danach wird das Dreieck zu einem an den Achsen ausgerichteten gedreht, und der Mittelpunkt, auf den Dreiecksmittelpunkt gesetzt.

Angezeigt wird sie dann so:
Code:
  1.  
  2. procedure TSubObjectTreeLeaf.RenderTo{(const renderer:TOGLRenderer)};
  3. var tempMat:TMatrix4f;
  4. begin
  5.   glPushMatrix;
  6.   move(local.vX,tempMat[0],sizeof(local.vX));
  7.   move(local.vY,tempMat[1],sizeof(local.vY));
  8.   move(local.vZ,tempMat[2],sizeof(local.vZ));
  9.   move(local.mitte,tempMat[3],sizeof(local.mitte));
  10.   tempMat[0][3]:=0;
  11.   tempMat[1][3]:=0;
  12.   tempMat[2][3]:=0;
  13.   tempMat[3][3]:=1;
  14.   glMultMatrixf(@tempMat[0][0]);
  15.   glBegin(GL_LINES);      //local.c
  16.     glVertex3f(+local.SizeX,+local.SizeY,-local.SizeZ);
  17.     glVertex3f(+local.SizeX,+local.SizeY,+local.SizeZ);
  18.  
  19.     glVertex3f(+local.SizeX,-local.SizeY,-local.SizeZ);
  20.     glVertex3f(+local.SizeX,-local.SizeY,+local.SizeZ);
  21.  
  22.     glVertex3f(-local.SizeX,+local.SizeY,-local.SizeZ);
  23.     glVertex3f(-local.SizeX,+local.SizeY,+local.SizeZ);
  24.  
  25.     glVertex3f(-local.SizeX,-local.SizeY,-local.SizeZ);
  26.     glVertex3f(-local.SizeX,-local.SizeY,+local.SizeZ);
  27.  
  28.  
  29.     glVertex3f(-local.SizeX,-local.SizeY,+local.SizeZ);
  30.     glVertex3f(+local.SizeX,-local.SizeY,+local.SizeZ);
  31.  
  32.     glVertex3f(-local.SizeX,+local.SizeY,+local.SizeZ);
  33.     glVertex3f(+local.SizeX,+local.SizeY,+local.SizeZ);
  34.  
  35.     glVertex3f(-local.SizeX,-local.SizeY,-local.SizeZ);
  36.     glVertex3f(+local.SizeX,-local.SizeY,-local.SizeZ);
  37.  
  38.     glVertex3f(-local.SizeX,+local.SizeY,-local.SizeZ);
  39.     glVertex3f(+local.SizeX,+local.SizeY,-local.SizeZ);
  40.  
  41.  
  42.     glVertex3f(+local.SizeX,-local.SizeY,+local.SizeZ);
  43.     glVertex3f(+local.SizeX,+local.SizeY,+local.SizeZ);
  44.  
  45.     glVertex3f(-local.SizeX,-local.SizeY,+local.SizeZ);
  46.     glVertex3f(-local.SizeX,+local.SizeY,+local.SizeZ);
  47.  
  48.     glVertex3f(+local.SizeX,-local.SizeY,-local.SizeZ);
  49.     glVertex3f(+local.SizeX,+local.SizeY,-local.SizeZ);
  50.  
  51.     glVertex3f(-local.SizeX,-local.SizeY,-local.SizeZ);
  52.     glVertex3f(-local.SizeX,+local.SizeY,-local.SizeZ);
  53.   glEnd;
  54.  
  55. end;
  56.  


Das "Modell", für den sie generiert werden ist dieses:
Code:
  1.  
  2.  
  3.   glBegin(GL_TRIANGLES);
  4.     glTexCoord2f(0.0,0.0); glVertex3d( 0.0, 2.0,0.0);
  5.     glTexCoord2f(1.0,0.0); glVertex3d(-1.5, 0.1,1.0);
  6.     glTexCoord2f(1.0,1.0); glVertex3d(-1.5, 0.1,-1.0);
  7.  
  8.     glTexCoord2f(1.0,1.0); glVertex3d( 1.5, 0.1,-1.0);
  9.     glTexCoord2f(1.0,0.0); glVertex3d( 1.5, 0.1,1.0);
  10.     glTexCoord2f(0.0,0.0); glVertex3d( 0.0, 2.0,0.0);
  11.  
  12.     glTexCoord2f(1.0,1.0); glVertex3d( 0.75, 0.8,  0.5);
  13.     glTexCoord2f(1.0,0.0); glVertex3d(-0.75, 0.8,  0.5);
  14.     glTexCoord2f(0.0,0.0); glVertex3d( 0.00, 0.15, -2.2);
  15.   glEnd();
  16.  
  17.  


Leider passt die erzeugte Box nicht zum Modell :-(, woran kann das liegen?
(Im Anhang ist Bild, das das Aussehen zeigen)

BeniBela


Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 1 Beitrag ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: Google [Bot] und 9 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.007s | 15 Queries | GZIP : On ]