private void Save_Click(object sender, RoutedEventArgs e)
        {
            this.mainWindow = (MainWindow)this.Owner;

            if (Validate())
            {
                return;
            }
            else
            {
                TextBox lightPositionX     = (TextBox)this.FindName("LightPositionX");
                TextBox lightPositionY     = (TextBox)this.FindName("LightPositionY");
                TextBox lightPositionZ     = (TextBox)this.FindName("LightPositionZ");
                TextBox CameraPositionX    = (TextBox)this.FindName("CameraPositionX");
                TextBox CameraPositionY    = (TextBox)this.FindName("CameraPositionY");
                TextBox CameraPositionZ    = (TextBox)this.FindName("CameraPositionZ");
                TextBox CameraDirectionX   = (TextBox)this.FindName("CameraDirectionX");
                TextBox CameraDirectionY   = (TextBox)this.FindName("CameraDirectionY");
                TextBox CameraDirectionZ   = (TextBox)this.FindName("CameraDirectionZ");
                TextBox CameraDirectionUpX = (TextBox)this.FindName("CameraDirectionUpX");
                TextBox CameraDirectionUpY = (TextBox)this.FindName("CameraDirectionUpY");
                TextBox CameraDirectionUpZ = (TextBox)this.FindName("CameraDirectionUpZ");
                TextBox fovy = (TextBox)this.FindName("FOVY");
                try
                {
                    RayTracer.Light light = new RayTracer.Light(-1, new RayTracer.Point(
                                                                    (float)double.Parse(lightPositionX.Text),
                                                                    (float)double.Parse(lightPositionY.Text),
                                                                    (float)double.Parse(lightPositionZ.Text)));
                    mainWindow.light = light;
                    RayTracer.Point point = new RayTracer.Point(
                        (float)double.Parse(CameraPositionX.Text),
                        (float)double.Parse(CameraPositionY.Text),
                        (float)double.Parse(CameraPositionZ.Text));

                    RayTracer.Vector direction = new RayTracer.Vector(
                        (float)double.Parse(CameraDirectionX.Text),
                        (float)double.Parse(CameraDirectionY.Text),
                        (float)double.Parse(CameraDirectionZ.Text));

                    RayTracer.Vector directionUp = new RayTracer.Vector(
                        (float)double.Parse(CameraDirectionUpX.Text),
                        (float)double.Parse(CameraDirectionUpY.Text),
                        (float)double.Parse(CameraDirectionUpZ.Text));

                    RayTracer.Camera camera = new RayTracer.Camera(-1, point, direction, directionUp, Double.Parse(fovy.Text));
                    mainWindow.camera = camera;

                    this.Close();
                }
                catch (Exception)
                {
                    Validate();
                }
            }
        }
        public Settings(MainWindow mainWindow) : this()
        {
            if (mainWindow == null)
            {
                return;
            }
            this.mainWindow = mainWindow;
            CheckBox addFloor = (CheckBox)this.FindName("addFloor");

            TextBox lightPositionX     = (TextBox)this.FindName("LightPositionX");
            TextBox lightPositionY     = (TextBox)this.FindName("LightPositionY");
            TextBox lightPositionZ     = (TextBox)this.FindName("LightPositionZ");
            TextBox CameraPositionX    = (TextBox)this.FindName("CameraPositionX");
            TextBox CameraPositionY    = (TextBox)this.FindName("CameraPositionY");
            TextBox CameraPositionZ    = (TextBox)this.FindName("CameraPositionZ");
            TextBox CameraDirectionX   = (TextBox)this.FindName("CameraDirectionX");
            TextBox CameraDirectionY   = (TextBox)this.FindName("CameraDirectionY");
            TextBox CameraDirectionZ   = (TextBox)this.FindName("CameraDirectionZ");
            TextBox CameraDirectionUpX = (TextBox)this.FindName("CameraDirectionUpX");
            TextBox CameraDirectionUpY = (TextBox)this.FindName("CameraDirectionUpY");
            TextBox CameraDirectionUpZ = (TextBox)this.FindName("CameraDirectionUpZ");
            TextBox fovy         = (TextBox)this.FindName("FOVY");
            TextBox renderWidth  = (TextBox)this.FindName("renderWidth");
            TextBox renderHeigth = (TextBox)this.FindName("renderHeight");

            addFloor.IsChecked = mainWindow.addFloor;

            if (mainWindow.light != null)
            {
                RayTracer.Light light = mainWindow.light;
                lightPositionX.Text = light.xPos.ToString();
                lightPositionY.Text = light.yPos.ToString();
                lightPositionZ.Text = light.zPos.ToString();
            }
            if (mainWindow.camera != null)
            {
                RayTracer.Camera camera = mainWindow.camera;
                CameraPositionX.Text    = camera.location.X.ToString();
                CameraPositionY.Text    = camera.location.Y.ToString();
                CameraPositionZ.Text    = camera.location.Z.ToString();
                CameraDirectionX.Text   = camera.direction.x.ToString();
                CameraDirectionY.Text   = camera.direction.y.ToString();
                CameraDirectionZ.Text   = camera.direction.z.ToString();
                CameraDirectionUpX.Text = camera.up.x.ToString();
                CameraDirectionUpY.Text = camera.up.y.ToString();
                CameraDirectionUpZ.Text = camera.up.z.ToString();
                fovy.Text = camera.fovy.ToString();
            }
            renderWidth.Text  = mainWindow.RenderWidth.ToString(CultureInfo.InvariantCulture);
            renderHeigth.Text = mainWindow.RenderHeight.ToString(CultureInfo.InvariantCulture);
        }