예제 #1
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);
        }
예제 #2
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);
             }
         }
     }
 }
예제 #3
0
        private void CreateBlock(RayTracer.Block block)
        {
            DragCanvas canvas = (DragCanvas)this.FindName("canvas");
            Rectangle  rect   = new Rectangle();

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

            rect.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte)r, (byte)g, (byte)b));

            rect.Name = "Rectangle" + rectangleCount;

            if (currentView == View.FRONT)
            {
                rect.Width  = block.getWidth() * CANVAS_SCALE;
                rect.Height = block.getHeight() * CANVAS_SCALE;
                Canvas.SetLeft(rect, block.a.X * CANVAS_SCALE);
                Canvas.SetTop(rect, block.a.Y * CANVAS_SCALE);
            }
            else if (currentView == View.TOP)
            {
                rect.Width  = block.getWidth() * CANVAS_SCALE;
                rect.Height = block.getDepth() * CANVAS_SCALE;
                Canvas.SetLeft(rect, block.c.X * CANVAS_SCALE);
                Canvas.SetTop(rect, block.c.Z * CANVAS_SCALE);
            }
            else
            {
                rect.Width  = block.getDepth() * CANVAS_SCALE;
                rect.Height = block.getHeight() * CANVAS_SCALE;
                Canvas.SetLeft(rect, block.b.Z * CANVAS_SCALE);
                Canvas.SetTop(rect, block.b.Y * CANVAS_SCALE);
            }
            objects[rect.Name] = block;


            canvas.Children.Add(rect);
            list.Add(rect);
            AddAndSelectObject(rect);
            rectangleCount++;
        }
예제 #4
0
        private void CreateBlock()
        {
            int r = rnd.Next(256);
            int g = rnd.Next(256);
            int b = rnd.Next(256);

            RayTracer.Block block;
            if (currentView == View.FRONT)
            {
                block = new RayTracer.Block(0, 0, 0, (int)4, (int)2, 5);
            }
            else if (currentView == View.TOP)
            {
                block = new RayTracer.Block(0, 0, 0, (int)4, 5, (int)2);
            }
            else
            {
                block = new RayTracer.Block(0, 0, 0, 5, (int)4, (int)2);
            }
            block.SetColor((float)(r / 256.0), (float)(g / 256.0), (float)(b / 256.0));
            CreateBlock(block);
        }
예제 #5
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);
                }
            }
        }