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++; }
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); }
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); } } }