# コピペ: TD2 ISIR.txt

Plain text

2021-03-18 21:06

` class Cell {   Cell[] children;   Triangles[] triangles;   AABB box;    Cell(Triangles[] t, AABB b){       triangles = t;        if(triangles.length > 10){         box = b;         createChildren();       }   }    void createChildren(){     AABB bbox1 = new AABB(box.min, box.max/2);     AABB bbox2 = new AABB(Vec3(box.min.x, box.min.y, box.max.z/2), Vec3(box.max.x, box.max.y/2, box.max.z));     AABB bbox3 = new AABB(Vec3(box.max.x/2, box.min.y, box.min.z), Vec3(box.max.x, box.max.y/2, box.max.z));     AABB bbox4 = new AABB(Vec3(box.max.x/2, box.min.y, box.max.z/2), Vec3(box.max.x, box.max.y/2, box.max.z));     AABB bbox5 = new AABB(Vec3(box.min.x, box.max.y/2, box.min.z), Vec3(box.max.x/2, box.max.y, box.max.z/2));     AABB bbox6 = new AABB(Vec3(box.min.x, box.max.y/2, box.max.z/2), Vec3(box.max.x/2, box.max.y, box.max.z/2));     AABB bbox7 = new AABB(Vec3(box.max.x/2, box.max.y/2, box.min.z), Vec3(box.max.x, box.max.y, box.max.z/2));     AABB bbox8 = new AABB(Vec3(box.max.x/2, box.max.y/2, box.max.z/2), box.max);      //Array that contains the 8 boxes     AABB[] arrayBox;      for(int i = 0; i < 8; i++){       Triangles[] t;       for(int j = 0; j < triangles.length; j++){         if(arrayBox[i].isIn(triangles[i])){           t.add(triangles[i]);         }       }       children.add(new Cell(t, arrayBox[i]));     }   }  }  bool AABB::isIn(Triangle t){   Vec3 taille = max - min;    Vec3 pos = min;   Segment s1 = new Segment(pos, pos + Vec3(taille.x, 0, 0);   Segment s2 = new Segment(pos, pos + Vec3(0, taille.y, 0);   Segment s3 = new Segment(pos, pos + Vec3(0, 0, taille.z);    pos = min + Vec3(taille.x, 0, taille.z);   Segment s4 = new Segment(pos, pos + Vec3(-taille.x, 0, 0);   Segment s5 = new Segment(pos, pos + Vec3(0, taille.y, 0);   Segment s6 = new Segment(pos, pos + Vec3(0, 0, -taille.z);      pos = min + Vec3(taille.x, taille.y, 0);   Segment s7 = new Segment(pos, pos + Vec3(-taille.x, 0, 0);   Segment s8 = new Segment(pos, pos + Vec3(0, -taille.y, 0);   Segment s9 = new Segment(pos, pos + Vec3(0, 0, taille.z);      pos = min + Vec3(0, taille.y, taille.z);   Segment s10 = new Segment(pos, pos + Vec3(taille.x, 0, 0);   Segment s11 = new Segment(pos, pos + Vec3(0, -taille.y, 0);   Segment s12 = new Segment(pos, pos + Vec3(0, 0, -taille.z);      Pour chaque Segment s de la AABB faire :     if (intersection(s, t)){         retourner vrai     }    Carre c1 = new Carre(s1, s3 ,s4, s6);   Carre c2 = new Carre(s3, s2, s11, s12);   Carre c3 = new Carre(s10, s7, s9, s12);   Carre c4 = new Carre(s8, s9, s5, s6);   Carre c5 = ///   Carre c6 = ///   Pour chaque Carre c de la AABB faire {     si(intersection(c, st1) ou intersection(c, st2) ou intersection(c, t3)){         retourner vrai ;     }   }   // Déterminer les triangles de la AABB   // Déterminer les segments du triangles st1 st2 st3   Pour chaque Triangle t de la AABB faire {     si (intersection(t, st1) ou intersection(t, st2) ou intersection(t, st3)){         retourner vrai   }  bool intersection(Segment s, Triangle t){      }  // Main program Triangles triangles....; AABB aabb = new AABB(); aabb = calculeBoite(triangles); aabb = aabb.adjustBox(); Cell cell = new Cell(triangles, aabb);`