public World(Model model) { int a = 1; for (int i = 0; i < numDivisions + 1; i++) { int numOcts = a; OctreeReferences[i] = new List <int> [numOcts]; a *= 8; } Dictionary <string, object> tagData = (Dictionary <string, object>)model.Tag; Vector3[] vertices = (Vector3[])tagData["Vertices"]; Primatives.Triangle[] triangles = new Primatives.Triangle[vertices.Length / 3]; int n = 0; for (int i = 0; i < vertices.Length;) { Vector3 v1 = vertices[i++]; Vector3 v2 = vertices[i++]; Vector3 v3 = vertices[i++]; triangles[n++] = new Primatives.Triangle(v1, v2, v3); } octree = new Octree(new Primatives.TriangleMesh(triangles), numDivisions); this.mesh = octree.OctTaggedMesh; for (int i = 0; i < mesh.Triangles.Length; i++) { int octlet = mesh.Triangles[i].OctTag[0]; int level = mesh.Triangles[i].OctTag[1]; if (OctreeReferences[level][octlet] == null) { OctreeReferences[level][octlet] = new List <int>(); } OctreeReferences[level][octlet].Add(i); } }
public float LineTriangle(Primatives.Triangle Triangle, Primatives.Line Line) { float x = -Vector3.Dot((Line.Vertices[0] - Triangle.Vertices[0]), Triangle.Normal) / Vector3.Dot(Line.Vertices[1] - Line.Vertices[0], Triangle.Normal); if (x < 0 || x > 1) { return(-1); } else { Vector3 intersection = Line.Vertices[0] + x * Vector3.Normalize(Line.Vertices[1] - Line.Vertices[0]); if (PointInTriangle(intersection, Triangle.Vertices[0], Triangle.Vertices[1], Triangle.Vertices[2])) { return(x); } else { return(-1); } } }
public World(Model model) { int a = 1; for (int i = 0; i < numDivisions + 1; i++) { int numOcts = a; OctreeReferences[i] = new List<int>[numOcts]; a *= 8; } Dictionary<string, object> tagData = (Dictionary<string, object>)model.Tag; Vector3[] vertices = (Vector3[])tagData["Vertices"]; Primatives.Triangle[] triangles = new Primatives.Triangle[vertices.Length / 3]; int n = 0; for (int i = 0; i < vertices.Length; ) { Vector3 v1 = vertices[i++]; Vector3 v2 = vertices[i++]; Vector3 v3 = vertices[i++]; triangles[n++] = new Primatives.Triangle(v1, v2, v3); } octree = new Octree(new Primatives.TriangleMesh(triangles), numDivisions); this.mesh = octree.OctTaggedMesh; for (int i = 0; i < mesh.Triangles.Length; i++) { int octlet = mesh.Triangles[i].OctTag[0]; int level = mesh.Triangles[i].OctTag[1]; if (OctreeReferences[level][octlet] == null) { OctreeReferences[level][octlet] = new List<int>(); } OctreeReferences[level][octlet].Add(i); } }