private void CreateRandomScene() //TODO: Refactor this (colors should go, separate into several methods)
        {
            List <PotatoSphere>     spheres = new List <PotatoSphere>();
            List <PotatoMesh>       meshs   = new List <PotatoMesh>();
            List <PotatoPointLight> lights  = new List <PotatoPointLight>();

            List <Color> colors = new List <Color>()
            {
                Color.Red,
                Color.Purple,
                Color.Plum,
                Color.RosyBrown,
                Color.Green,
                Color.White,
                Color.Yellow,
                Color.BlueViolet,
                Color.CadetBlue,
                Color.OrangeRed,
                Color.Orange
            };

            Random r = new Random();

            for (int i = 0; i < 10; i++)
            {
                Vector3 pos = new Vector3(r.Next(-250, 250), r.Next(-100, 100), r.Next(-100, 100));
                float   rad = (float)r.NextDouble() * 20;
                spheres.Add(new PotatoSphere(pos, rad, @"Resources\\Textures\\default.bmp"));
                spheres[i].Color = colors[(int)(r.NextDouble() * colors.Count)];
            }

            //Vector3 pos = new Vector3(50, 0, 0);
            //float rad = 20f;//(float)r.NextDouble() * 20;
            //spheres.Add(new PotatoSphere(pos, rad, @"Resources\\Textures\\default.bmp"));
            //spheres[0].Color = colors[(int)(r.NextDouble() * colors.Count)];

            //lights.Add(new PotatoPointLight(new Vector3(0, -100, 0), 500, 1, Color.Green));
            //lights.Add(new PotatoPointLight(new Vector3(0, 0, 0), 500, 1, Color.Blue));
            //lights.Add(new PotatoPointLight(new Vector3(0, 100, 0), 500, 1, Color.Red));
            lights.Add(new PotatoPointLight(new Vector3(0, 0, 100000), 500, 1, Color.White));

            const int randomMeshCount = 0;

            for (int i = 0; i < randomMeshCount; i++)
            {
                PotatoMesh mesh = new PotatoMesh
                {
                    Position   = new Vector3(r.Next(1, 20), r.Next(-20, 20), r.Next(-20, 20)),
                    ObjectPath = @"Resources\\Objects\\cube.obj", //TODO: Implement ressource path.
                    Color      = colors[(int)(r.NextDouble() * colors.Count)]
                };

                meshs.Add(mesh);
            }

            meshsBuilder.Build(ref meshs);

            Cubemap.LoadCubemap(option.Cubemap);
            PotatoSceneData = new PotatoSceneData(spheres, meshs, lights, RetreiveAllTextureInScene(spheres), option, Cubemap, Camera);
        }
Example #2
0
        private ClosestTriangle GetClosestTriangleIntersectionInList(Ray ray, List <PotatoMesh> meshs)
        {
            Triangle   triangleInt      = null;
            PotatoMesh meshInt          = null;
            Vector3    hitPosition      = new Vector3();
            Vector3    hitNormal        = new Vector3();
            Vector3    localHitPosition = new Vector3();
            Vector3    localHitNormal   = new Vector3();
            double     distance         = double.PositiveInfinity;
            double     t = 0;

            LoopMeshListToGetTheClosets(ray, meshs, ref triangleInt, ref meshInt, ref hitPosition, ref hitNormal, ref localHitPosition, ref localHitNormal, ref distance, ref t);

            return(new ClosestTriangle(meshInt, triangleInt, hitPosition, hitNormal, distance));
        }
Example #3
0
        private void LoopMeshListToGetTheClosets(Ray ray, List <PotatoMesh> meshs, ref Triangle triangleInt, ref PotatoMesh meshInt, ref Vector3 hitPosition, ref Vector3 hitNormal, ref Vector3 localHitPosition, ref Vector3 localHitNormal, ref double distance, ref double t)
        {
            for (int i = 0; i < meshs.Count; i++)
            {
                PotatoMesh mesh = meshs[i];

                for (int j = 0; j < mesh.GetTrianglesCount; j++)
                {
                    if (TriangleIntersection.RayIntersectsTriangle(ray.Origin, ray.Direction, mesh.GetTriangle(j), ref localHitPosition, ref localHitNormal, ref t))
                    {
                        if (t < distance)
                        {
                            distance    = t;
                            triangleInt = mesh.GetTriangle(j);
                            meshInt     = mesh;

                            hitPosition = localHitPosition;
                            hitNormal   = localHitNormal;
                        }
                    }
                }
            }
        }
Example #4
0
 public ClosestTriangle(PotatoMesh mesh, Triangle triangle, Vector3 hitPosition, Vector3 hitNormal, double distance) : base(hitPosition, hitNormal, distance, true)
 {
     Mesh     = mesh;
     Triangle = triangle;
 }