예제 #1
0
        private void Subdivide(Vector3 mins, Vector3 maxes)
        {
            float avgX = (mins.x + maxes.x) / 2;
            float avgY = (mins.y + maxes.y) / 2;
            float avgZ = (mins.z + maxes.z) / 2;

            var subnodes = new List<Triangle>[8];
            for (int i = 0; i < 8; i++)
            {
                subnodes[i] = new List<Triangle>();
            }
            _directTriangleChildren = new List<Triangle>();

            foreach (Triangle triangle in _triangles)
            {
                int subnodeIndex = AssignSubnode(triangle, avgX, avgY, avgZ);
                if (subnodeIndex == -1)
                {
                    _directTriangleChildren.Add(triangle);
                }
                else
                {
                    subnodes[subnodeIndex].Add(triangle);
                }
            }

            for (int i = 0; i < 8; i++)
            {
                if (subnodes[i].Count == 0) continue;
                _children[i] = new Octree(subnodes[i].ToArray(), _parentMesh);
            }
        }
예제 #2
0
 private void FindEdges(out Vector3 mins, out Vector3 maxes)
 {
     Vector3 firstVertex = _triangles[0].V1;
     float minX = firstVertex.x;
     float maxX = firstVertex.x;
     float minY = firstVertex.y;
     float maxY = firstVertex.y;
     float minZ = firstVertex.z;
     float maxZ = firstVertex.z;
     foreach (Triangle triangle in _triangles)
     {
         for (int i = 0; i < 3; i++)
         {
             Vector3 v = triangle[i];
             if (v.x < minX) minX = v.x;
             if (v.x > maxX) maxX = v.x;
             if (v.y < minY) minY = v.y;
             if (v.y > maxY) maxY = v.y;
             if (v.z < minZ) minZ = v.z;
             if (v.z > maxZ) maxZ = v.z;
         }
     }
     mins = new Vector3(minX, minY, minZ);
     maxes = new Vector3(maxX, maxY, maxZ);
 }
예제 #3
0
 public Scene(List<Mesh> meshes, List<LightSource> lightSources, Camera camera, Color skyColor)
 {
     _meshes = meshes;
     LightSources = lightSources;
     _camera = camera;
     _skyColor = Vector3.FromColor(skyColor);
 }
예제 #4
0
 public bool IsVisible(Vector3 from, Vector3 to)
 {
     Vector3 direction = to - from;
     float distance = direction.Length();
     var ray = new Ray(from, direction);
     return IsVisible(ray, distance);
 }
예제 #5
0
 public Mesh(Vector3[] vertices, Triangle[] triangles, Vector3 position, Quaternion rotation, Shader shader, ISampler normalSampler)
 {
     Vertices = vertices;
     _triangles = triangles;
     Shader = shader;
     Position = position;
     Rotation = rotation;
     _normalSampler = normalSampler;
     Init();
 }