Ejemplo n.º 1
0
        public Sphere Intersection(List<Sphere> l_sphere, ref float t)
        {
            Sphere retSp = new Sphere(0, 0, 0, 1, Color.White);
            foreach (Sphere s in l_sphere)
            {
                Point dist = new Point(s.x - Position.x, s.y - Position.y, s.z - Position.z);
                float B = Direction * dist;
                float D = B * B - dist.x * dist.x - dist.y * dist.y - dist.z * dist.z + s.rayon * s.rayon;
                float t0 = B - (float)Math.Sqrt(D);
                float t1 = B + (float)Math.Sqrt(D);

                if ((t0 > 0.1f) && (t0 < t))
                {
                    t = t0;
                    retSp = s;
                }
                if ((t1 > 0.1f) && (t1 < t))
                {
                    t = t1;
                    retSp = s;
                }
                //Console.WriteLine("lol");

            }
            return retSp;
        }
Ejemplo n.º 2
0
        private void CreateEllipse(RayTracer.Sphere sphere)
        {
            DragCanvas canvas  = (DragCanvas)this.FindName("canvas");
            Ellipse    ellipse = new Ellipse();

            ellipse.Stroke = new SolidColorBrush(Colors.Black);
            int r = (int)(sphere.color.r * 256);
            int g = (int)(sphere.color.g * 256);
            int b = (int)(sphere.color.b * 256);

            ellipse.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)r, (byte)g, (byte)b));
            float diameter = (float)(sphere.diameter * CANVAS_SCALE);

            ellipse.Width  = diameter;
            ellipse.Height = diameter;
            ellipse.Name   = "Ellipse" + ellipseCount;

            objects[ellipse.Name] = sphere;

            Canvas.SetLeft(ellipse, sphere.xPos * CANVAS_SCALE);
            Canvas.SetTop(ellipse, sphere.yPos * CANVAS_SCALE);
            canvas.Children.Add(ellipse);

            list.Add(ellipse);
            AddAndSelectObject(ellipse);
            ellipseCount++;
        }
Ejemplo n.º 3
0
        private void CreateEllipse()
        {
            int   r        = rnd.Next(256);
            int   g        = rnd.Next(256);
            int   b        = rnd.Next(256);
            float diameter = 5;

            RayTracer.Sphere sphere = new RayTracer.Sphere(-1, new RayTracer.Point(2.5f, 2.5f, 2.5f), diameter);
            sphere.SetColor((float)(r / 256.0), (float)(g / 256.0), (float)(b / 256.0));
            CreateEllipse(sphere);
        }
Ejemplo n.º 4
0
        public void FillValues(Shape shape, bool dropped = false, bool first = false)
        {
            if (!first)
            {
                if (selected == shape && !dropped)
                {
                    return;
                }
            }

            TextBox positionX, positionY, positionZ;

            positionX = (TextBox)this.FindName("positionX");
            positionY = (TextBox)this.FindName("positionY");
            positionZ = (TextBox)this.FindName("positionZ");


            if (shape.GetType() == typeof(Rectangle))
            {
                Rectangle rectangle = (Rectangle)shape;
                TextBox   width, height, depth;

                width  = (TextBox)this.FindName("rectangleWidth");
                height = (TextBox)this.FindName("rectangleHeight");
                depth  = (TextBox)this.FindName("rectangleDepth");

                UpdatePositionValues(shape);
                RayTracer.Block block = (RayTracer.Block)objects[rectangle.Name];

                positionX.Text = block.a.X.ToString().Replace(',', '.');
                positionY.Text = block.a.Y.ToString().Replace(',', '.');
                positionZ.Text = block.a.Z.ToString().Replace(',', '.');
                width.Text     = block.getWidth().ToString().Replace(',', '.');
                height.Text    = block.getHeight().ToString().Replace(',', '.');
                depth.Text     = block.getDepth().ToString().Replace(',', '.');
            }
            else if (shape.GetType() == typeof(Ellipse))
            {
                Ellipse ellipse = (Ellipse)shape;
                TextBox diameter;

                diameter = (TextBox)this.FindName("diameter");

                UpdatePositionValues(shape);

                RayTracer.Sphere sphere = (RayTracer.Sphere)objects[ellipse.Name];
                positionX.Text = sphere.xPos.ToString().Replace(',', '.');
                positionY.Text = sphere.yPos.ToString().Replace(',', '.');
                positionZ.Text = sphere.zPos.ToString().Replace(',', '.');
                diameter.Text  = sphere.diameter.ToString().Replace(',', '.');
            }
            FillProperties(shape);
        }
Ejemplo n.º 5
0
 private void RepositionShapes()
 {
     foreach (Shape shape in list)
     {
         if (shape.GetType() == typeof(Rectangle))
         {
             Rectangle       rectangle = (Rectangle)shape;
             RayTracer.Block block     = (RayTracer.Block)objects[rectangle.Name];
             if (currentView == View.FRONT)
             {
                 Canvas.SetLeft(rectangle, block.a.X * CANVAS_SCALE);
                 Canvas.SetTop(rectangle, block.a.Y * CANVAS_SCALE);
             }
             else if (currentView == View.TOP)
             {
                 Canvas.SetLeft(rectangle, block.a.X * CANVAS_SCALE);
                 Canvas.SetTop(rectangle, block.a.Z * CANVAS_SCALE);
             }
             else
             {
                 Canvas.SetLeft(rectangle, block.a.Z * CANVAS_SCALE);
                 Canvas.SetTop(rectangle, block.a.Y * CANVAS_SCALE);
             }
         }
         else if (shape.GetType() == typeof(Ellipse))
         {
             Ellipse          ellipse = (Ellipse)shape;
             RayTracer.Sphere sphere  = (RayTracer.Sphere)objects[ellipse.Name];
             if (currentView == View.FRONT)
             {
                 Canvas.SetLeft(ellipse, sphere.xPos);
                 Canvas.SetTop(ellipse, sphere.yPos);
             }
             else if (currentView == View.TOP)
             {
                 Canvas.SetLeft(ellipse, sphere.xPos);
                 Canvas.SetTop(ellipse, sphere.zPos);
             }
             else
             {
                 Canvas.SetLeft(ellipse, sphere.zPos);
                 Canvas.SetTop(ellipse, sphere.yPos);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public void AddObject(Sphere s)
 {
     Objects.Add(s);
 }
Ejemplo n.º 7
0
        private void UpdatePositionValues(Shape shape)
        {
            if (currentView == View.FRONT)
            {
                if (shape.GetType() == typeof(Rectangle))
                {
                    Rectangle       rectangle = (Rectangle)shape;
                    RayTracer.Block block     = (RayTracer.Block)objects[rectangle.Name];
                    double          x         = GetX(rectangle);
                    double          y         = GetY(rectangle);
                    block.SetPosition((float)x, (float)y, block.a.Z, (float)(rectangle.Width / CANVAS_SCALE), (float)(rectangle.Height / CANVAS_SCALE), block.getDepth());
                }
                else if (shape.GetType() == typeof(Ellipse))
                {
                    Ellipse          ellipse = (Ellipse)shape;
                    RayTracer.Sphere sphere  = (RayTracer.Sphere)objects[ellipse.Name];
                    double           x       = (Canvas.GetLeft(ellipse) + (ellipse.Width / 2)) / CANVAS_SCALE;
                    double           y       = (Canvas.GetTop(ellipse) + (ellipse.Height / 2)) / CANVAS_SCALE;
                    sphere.xPos     = (float)x;
                    sphere.yPos     = (float)y;
                    sphere.diameter = (float)(ellipse.Width / CANVAS_SCALE);
                }
            }
            else if (currentView == View.TOP)
            {
                if (shape.GetType() == typeof(Rectangle))
                {
                    Rectangle       rectangle = (Rectangle)shape;
                    RayTracer.Block block     = (RayTracer.Block)objects[rectangle.Name];
                    double          x         = GetX(rectangle);
                    double          z         = GetY(rectangle);
                    block.SetPosition((float)x, block.a.Y, (float)z, (float)(rectangle.Width / CANVAS_SCALE), block.getHeight(), (float)(rectangle.Height / CANVAS_SCALE));
                }
                else if (shape.GetType() == typeof(Ellipse))
                {
                    Ellipse          ellipse = (Ellipse)shape;
                    RayTracer.Sphere sphere  = (RayTracer.Sphere)objects[ellipse.Name];
                    double           x       = (Canvas.GetLeft(ellipse) + (ellipse.Width / 2)) / CANVAS_SCALE;
                    double           z       = (Canvas.GetTop(ellipse) + (ellipse.Height / 2)) / CANVAS_SCALE;

                    sphere.xPos     = (float)x;
                    sphere.zPos     = (float)z;
                    sphere.diameter = (float)(ellipse.Width / CANVAS_SCALE);
                }
            }
            else if (currentView == View.RIGHT)
            {
                if (shape.GetType() == typeof(Rectangle))
                {
                    Rectangle       rectangle = (Rectangle)shape;
                    RayTracer.Block block     = (RayTracer.Block)objects[rectangle.Name];
                    double          z         = GetX(rectangle);
                    double          y         = GetY(rectangle);
                    block.SetPosition(block.a.X, (float)y, (float)z, block.getWidth(), (float)(rectangle.Height / CANVAS_SCALE), (float)(rectangle.Width / CANVAS_SCALE));
                }
                else if (shape.GetType() == typeof(Ellipse))
                {
                    Ellipse          ellipse = (Ellipse)shape;
                    RayTracer.Sphere sphere  = (RayTracer.Sphere)objects[ellipse.Name];
                    double           z       = (Canvas.GetLeft(ellipse) + (ellipse.Width / 2)) / CANVAS_SCALE;
                    double           y       = (Canvas.GetTop(ellipse) + (ellipse.Height / 2)) / CANVAS_SCALE;
                    sphere.zPos     = (float)z;
                    sphere.yPos     = (float)y;
                    sphere.diameter = (float)(ellipse.Width / CANVAS_SCALE);
                }
            }
        }