Example #1
0
        public void AddMaterial(Material_ material)
        {
            modified = true;
            bool zastap = false;

            for (int i = 0; i < materials.Count; i++)
            {
                if (materials[i].name == material.Name)
                {
                    zastap       = true;
                    materials[i] = new Material_(material);
                }
            }
            if (!zastap)
            {
                materials.Add(new Material_(material));
            }

            for (int i = 0; i < parts.Count; i++)
            {
                foreach (HierarchyMesh obj in selTriangles)
                {
                    if (parts[i].triangles.Contains((int)obj.triangles[0]))
                    {
                        materialAssign[i] = material.Name;
                    }
                }
            }
        }
 public Material_(Material_ copy)
 {
     this.name = copy.name;
     this.colorR = copy.colorR;
     this.colorG = copy.colorG;
     this.colorB = copy.colorB;
     this.kdcR = copy.kdcR;
     this.kdcG = copy.kdcG;
     this.kdcB = copy.kdcB;
     this.kscR = copy.kscR;
     this.kscG = copy.kscG;
     this.kscB = copy.kscB;
     this.krcR = copy.krcR;
     this.krcG = copy.krcG;
     this.krcB = copy.krcB;
     this.kacR = copy.kacR;
     this.kacG = copy.kacG;
     this.kacB = copy.kacB;
     this.g = copy.g;
     this.n = copy.n;
 }
Example #3
0
 public Material_(Material_ copy)
 {
     this.name   = copy.name;
     this.colorR = copy.colorR;
     this.colorG = copy.colorG;
     this.colorB = copy.colorB;
     this.kdcR   = copy.kdcR;
     this.kdcG   = copy.kdcG;
     this.kdcB   = copy.kdcB;
     this.kscR   = copy.kscR;
     this.kscG   = copy.kscG;
     this.kscB   = copy.kscB;
     this.krcR   = copy.krcR;
     this.krcG   = copy.krcG;
     this.krcB   = copy.krcB;
     this.kacR   = copy.kacR;
     this.kacG   = copy.kacG;
     this.kacB   = copy.kacB;
     this.g      = copy.g;
     this.n      = copy.n;
 }
        /// <summary>
        /// Metoda odpowiadająca za przesuwanie płaszczyzn obcinających i zaznaczanie
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Views_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            ClipPlaneType planeType = ClipPlaneType.NONE;

            if (Renderer.Clipping && e.Button == MouseButtons.Left && !GetShiftPressed())
            {
                ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex);
                int x = (int)e.X;
                int y = (int)e.Y;

                ViewportOrientation viewport = GetViewportType(x, y);

                if (viewport != ViewportOrientation.None)
                {
                    ViewportType viewportType = viewport == ViewportOrientation.Perspective
                                                    ? ViewportType.Perspective
                                                    : ViewportType.Orto;
                    int rect = (int)viewport;
                    int orthoRect = rect == 3 ? 0 : rect;

                    planeType = SelectingElems.SelectClippingPlane(Renderer.clipVertices, Renderer.clipIndices, viewportType,
                                                       new System.Drawing.Point(x - views.posX[rect],
                                                                                y - views.posY[rect]),
                                                       new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]),
                                                       new Vector2(renderer.OrthoWidth[orthoRect],
                                                                   (float)views.sizeY[rect] / views.sizeX[rect] *
                                                                   renderer.OrthoWidth[orthoRect]),
                                                       renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect],
                                                       viewport);

                    //Console.WriteLine(planeType.ToString());

                    if(planeType != ClipPlaneType.NONE)
                    {
                        System.Windows.DataObject dataObject = new System.Windows.DataObject();

                        switch(viewport)
                        {
                            case ViewportOrientation.Front:
                                dataObject.SetData("Viewport", "front");
                                break;

                            case ViewportOrientation.Side:
                                dataObject.SetData("Viewport", "side");
                                break;

                            case ViewportOrientation.Top:
                                dataObject.SetData("Viewport", "top");
                                break;

                            case ViewportOrientation.Perspective:
                                dataObject.SetData("Viewport", "perspective");
                                break;

                            default:
                                break;
                        }
                        dragX = (float)e.X + xOffset;
                        dragY = (float)e.Y + yOffset;
                        dataObject.SetData("Plane", planeType.ToString());
                        DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Copy);
                    }
                }
            }

            int sumSelected = currScene.selTriangles.Count + currScene.selLights.Count + currScene.selCams.Count;

            if(e.Button == MouseButtons.Left && planeType == ClipPlaneType.NONE && contextMenu.MenuItems[0].Checked == true && sumSelected <= 1 && !GetShiftPressed())
            {
                mouseDownHandled = true;

                ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex);
                int x = (int)e.X;
                int y = (int)e.Y;

                ViewportOrientation viewport = GetViewportType(x, y);

                if(viewport != ViewportOrientation.None)
                {
                    ViewportType viewportType = viewport == ViewportOrientation.Perspective
                                                    ? ViewportType.Perspective
                                                    : ViewportType.Orto;
                    int rect = (int)viewport;
                    int orthoRect = rect == 3 ? 0 : rect;

                    SelectingElems.SelectElems(currScene, renderer.GetCamsPoints(), renderer.GetLightsPoints(), viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]),
                        new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]),
                        renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect], GetCtrlPressed());

                    rect = (int)viewport;
                    orthoRect = rect == 3 ? 0 : rect;

                    System.Windows.DataObject dataObject = new System.Windows.DataObject();

                    switch(viewport)
                    {
                        case ViewportOrientation.Front:
                            dataObject.SetData("Viewport", "front");
                            break;

                        case ViewportOrientation.Side:
                            dataObject.SetData("Viewport", "side");
                            break;

                        case ViewportOrientation.Top:
                            dataObject.SetData("Viewport", "top");
                            break;

                        case ViewportOrientation.Perspective:
                            dataObject.SetData("Viewport", "perspective");
                            break;

                        default:
                            break;
                    }

                    dataObject.SetData("Point", SelectingElems.pointFound);

                    Renderer.RecalculateData(currScene);
                    if (GetAltPressed())
                    {
                        for (int i = 0; i < currScene.parts.Count; i++)
                        {
                            foreach (HierarchyMesh obj in currScene.selTriangles)
                            {
                                if (currScene.parts[i].triangles.Contains((int) obj.triangles[0]))
                                {
                                    Material_ material = null;
                                    foreach (Material_ m in currScene.materials)
                                    {
                                        if (m.name == currScene.materialAssign[i])
                                        {
                                            material = new Material_(m);
                                            material.colorR = material.colorR*255;
                                            material.colorG = material.colorG*255;
                                            material.colorB = material.colorB*255;
                                        }
                                    }
                                    dataObject.SetData("Object", material);
                                    i = Int32.MaxValue - 1;
                                    break;
                                }
                            }
                        }
                    }

                    if(currScene.selLights.Count == 1 && GetAltPressed())
                    {
                        dataObject.SetData("Light", currScene.lights[currScene.selLights[0]]);
                        dataObject.SetData("LightPrevious", new Light_(currScene.lights[currScene.selLights[0]]));
                    }

                    if (currScene.selTriangles.Count > 0 && GetAltPressed())
                    {
                        System.Windows.DataObject do1 = new DataObject();
                        do1.SetData("Prepared", "");
                        DragDrop.DoDragDrop(this, do1, System.Windows.DragDropEffects.Copy);
                    }

                    dragX = (float)e.X + xOffset;
                    dragY = (float)e.Y + yOffset;
                    undo.Save(currScene);
                    DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Copy);

                    RenderViews();
                }
            }
        }
        // Koniec sekcji
        ////////////////////////////////////////////////////////////////////////////////////
        private void objectToScene_Drop(object sender, System.Windows.DragEventArgs e)
        {
            // Wciąganie obiektów do sceny
            if (tabWidok.SelectedIndex == 0)
            {
                if (e.Data.GetDataPresent("Object"))
                {
                    object data = e.Data.GetData("Object");
                    //Console.WriteLine(data.GetType());
                    //ViewportInfo coords = GetViewCoords(tabWidok.SelectedIndex);
                    Vector3 translation;
                    if (data is Shape_)
                    {
                        Shape_ shape = (Shape_)data;
                        undo.Save(currScene);
                        // przekształcenie współrzędnych
                        float x = (float)e.GetPosition(this).X - xOffset;
                        float y = (float)e.GetPosition(this).Y - yOffset;

                        translation = CalculateTranslation(x, y);
                        currScene.AddObject(shape.Triangulate((float)triang_Slider.Value), shape.Name, translation);
                        currScene.hierarchyChange = false;
                        initializeTreeView();

                        //sceneChange = true;
                    }
                    else if (data is PreparedElement)
                    {
                        undo.Save(currScene);
                        PreparedElement element = (PreparedElement)data;

                        // przekształcenie współrzędnych
                        float x = (float)e.GetPosition(this).X - xOffset;
                        float y = (float)e.GetPosition(this).Y - yOffset;

                        translation = CalculateTranslation(x, y);
                        //for (int i = 0; i < element.Scene.cams.Count; i++)
                        //{
                        //    cameraPan.comboBox1.Items.Add("Kamera " + (currScene.cams.Count() + 1 + i));
                        //}
                        currScene.AddPreparedElement(element, translation);
                        currScene.hierarchyChange = false;
                        initializeTreeView();

                        //sceneChange = true;
                    }
                    else if (data is Surface)
                    {
                        Surface surface = (Surface)data;
                        undo.Save(currScene);
                        bool zazn = true;

                        if (currScene.selTriangles.Count == 0)
                        {
                            zazn = false;
                            ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex);
                            int x = (int)e.GetPosition(this).X - xOffset;
                            int y = (int)e.GetPosition(this).Y - yOffset;

                            ViewportOrientation viewport = GetViewportType(x, y);

                            if (viewport != ViewportOrientation.None)
                            {
                                ViewportType viewportType = viewport == ViewportOrientation.Perspective ? ViewportType.Perspective : ViewportType.Orto;
                                int rect = (int)viewport;
                                int orthoRect = rect == 3 ? 0 : rect;

                                SelectingElems.SelectElems(currScene, renderer.GetCamsPoints(), renderer.GetLightsPoints(), viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]),
                                    new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]),
                                    renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect], false);
                            }
                        }

                        if (String.Compare(surface.Material.Name, "default", true) == 0)
                        {
                            Modeler.DialogBoxes.NameDialog newName = new NameDialog();
                            bool res = (bool)newName.Show("Podaj nową nazwę materiału", "");
                            if (!res)
                                return;
                            surface.Material.name = newName.Result;

                        }
                        bool replace = false;
                        while (currScene.ContainsMaterialName(surface.Material.Name) && !replace)
                        {
                            Modeler.DialogBoxes.NameDialog dialog = new NameDialog();
                            dialog.Owner = this;

                            bool result = (bool)dialog.Show(materialSceneMessage, surface.Material.Name);
                            string name = dialog.Result;
                            if (!result)
                                return;
                            if (surface.Material.Name == name)
                                replace = true;
                            surface.Material.name = name;
                            dialog.Close();
                        }

                        currScene.AddMaterial(surface.Material);
                        currScene.hierarchyChange = false;

                        if (!zazn) currScene.ClearSelectedTriangles();
                        //Console.WriteLine("Przypisanie atrybutów powierzchniowych");

                        //sceneChange = true;
                    }
                    else if (data is Material_)
                    {
                        Material_ material = new Material_((Material_)data);
                        material.colorR = material.colorR / 255;
                        material.colorG = material.colorG / 255;
                        material.colorB = material.colorB / 255;
                        undo.Save(currScene);
                        bool zazn = true;

                        if (currScene.selTriangles.Count == 0)
                        {
                            zazn = false;
                            ViewportInfo views = GetViewCoords(tabWidok.SelectedIndex);
                            int x = (int)e.GetPosition(this).X - xOffset;
                            int y = (int)e.GetPosition(this).Y - yOffset;

                            ViewportOrientation viewport = GetViewportType(x, y);

                            if (viewport != ViewportOrientation.None)
                            {
                                ViewportType viewportType = viewport == ViewportOrientation.Perspective ? ViewportType.Perspective : ViewportType.Orto;
                                int rect = (int)viewport;
                                int orthoRect = rect == 3 ? 0 : rect;

                                SelectingElems.SelectElems(currScene, renderer.GetCamsPoints(), renderer.GetLightsPoints(), viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]),
                                    new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]),
                                    renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect], false);
                            }
                        }

                        if (String.Compare(material.Name, "default", true) == 0)
                        {
                            Modeler.DialogBoxes.NameDialog newName = new NameDialog();
                            bool res = (bool)newName.Show("Podaj nową nazwę materiału", "");
                            if (!res)
                                return;
                            material.name = newName.Result;

                        }
                        bool replace = false;
                        while (currScene.ContainsMaterialName(material.Name) && !replace)
                        {
                            Modeler.DialogBoxes.NameDialog dialog = new NameDialog();
                            dialog.Owner = this;

                            bool result = (bool)dialog.Show(materialSceneMessage, material.Name);
                            string name = dialog.Result;
                            if (!result)
                                return;
                            if (material.Name == name)
                                replace = true;
                            material.name = name;
                            dialog.Close();
                        }

                        currScene.AddMaterial(material);

                        if (!zazn) currScene.ClearSelectedTriangles();
                        //Console.WriteLine("Przypisanie atrybutów powierzchniowych");

                        //sceneChange = true;
                    }
                    else if (data is LightObj)
                    {
                        if (currScene.selLights.Count > 0)  //objętnie ile ich jest zaznaczonych zmienia tylko 1 sprawdzająć nazwe
                        {
                            undo.Save(currScene);
                            Light_ sceneLight = currScene.lights[currScene.selLights[0]];
                            Light_ dataLight = ((LightObj)data).Light;
                            sceneLight.colorR = dataLight.colorR;
                            sceneLight.colorG = dataLight.colorG;
                            sceneLight.colorB = dataLight.colorB;
                            sceneLight.enabled = dataLight.enabled;
                            sceneLight.goniometric = dataLight.goniometric;
                            sceneLight.innerAngle = dataLight.innerAngle;
                            sceneLight.name = dataLight.name;
                            sceneLight.outerAngle = dataLight.outerAngle;
                            sceneLight.power = dataLight.power;
                            sceneLight.type = dataLight.type;

                            //sceneChange = true;
                        }
                        else
                        {
                            LightObj light = (LightObj)data;
                            undo.Save(currScene);
                            Light_ sceneLight = new Light_(light.Light);

                            // przekształcenie współrzędnych
                            float x = (float)e.GetPosition(this).X - xOffset;
                            float y = (float)e.GetPosition(this).Y - yOffset;

                            translation = CalculateTranslation(x, y);

                            currScene.AddLight(sceneLight, translation);
                            currScene.hierarchyChange = false;
                            initializeTreeView();

                            //sceneChange = true;
                        }
                    }

                    else if (data is Light_)
                    {
                        if (currScene.selLights.Count > 0)
                        {
                            undo.Save(currScene);
                            Light_ sceneLight = currScene.lights[currScene.selLights[0]];
                            Light_ dataLight = (Light_)data;
                            sceneLight.colorR = dataLight.colorR;
                            sceneLight.colorG = dataLight.colorG;
                            sceneLight.colorB = dataLight.colorB;
                            sceneLight.enabled = dataLight.enabled;
                            sceneLight.goniometric = dataLight.goniometric;
                            sceneLight.innerAngle = dataLight.innerAngle;
                            sceneLight.name = dataLight.name;
                            sceneLight.outerAngle = dataLight.outerAngle;
                            sceneLight.power = dataLight.power;
                            sceneLight.type = dataLight.type;

                            //currScene.hierarchyChange = true;
                            currScene.hierarchyChange = false;
                            initializeTreeView();

                            //sceneChange = true;
                        }
                        else
                        {
                            Light_ light = (Light_)data;
                            undo.Save(currScene);
                            Light_ sceneLight = new Light_(light);

                            // przekształcenie współrzędnych
                            float x = (float)e.GetPosition(this).X - xOffset;
                            float y = (float)e.GetPosition(this).Y - yOffset;

                            translation = CalculateTranslation(x, y);

                            currScene.AddLight(sceneLight, translation);
                            //TO DO sprawdzenie czy nazwa jest unikatowa
                            //currScene.hierarchyChange = true;
                            currScene.hierarchyChange = false;
                            initializeTreeView();

                            //sceneChange = true;
                        }

                    }
                    else if (data is Camera)
                    {
                        Camera cam = (Camera)data;
                        undo.Save(currScene);

                        float x = (float)e.GetPosition(this).X - xOffset;
                        float y = (float)e.GetPosition(this).Y - yOffset;

                        translation = CalculateTranslation(x, y);

                        currScene.AddCamera(cam, translation);
                        cameraPan.comboBox1.Items.Add("Kamera " + (currScene.cams.Count()));
                        cameraPan.comboBox1.SelectedIndex = currScene.activeCamera;

                        //sceneChange = true;
                    }
                }
            }
            // Wciąganie obiektów do edytora powierzchni beziera.
            else if (tabWidok.SelectedIndex == 1)
            {
                if (e.Data.GetDataPresent("Object"))
                {
                    object data = e.Data.GetData("Object");

                    if (data is BezierSurface)
                    {
                        bezierSurface = new BezierSurface((BezierSurface)data);
                        bezierSurface.Triangulate((float)triang_Slider.Value);
                        RenderBezier();
                    }
                }
            }

            e.Handled = true;

            trNumTBG1.Text = currScene.triangles.Count().ToString();
            trNumTBG2.Text = currScene.triangles.Count().ToString();
            trNumTBG3.Text = currScene.triangles.Count().ToString();
            trNumTBG4.Text = currScene.triangles.Count().ToString();

            Renderer.RecalculateData(currScene);

            RenderViews();
            currScene.selectedHierObj = null;
        }
        private void materialy_ListView_Drop(object sender, System.Windows.DragEventArgs e)
        {
            if (e.Data.GetDataPresent("Object"))
            {
                object data = e.Data.GetData("Object");
                //Console.WriteLine(data.GetType());
                if (data is Material_)
                {
                    Material_ material = new Material_((Material_)data);
                    Graphics.SurfaceRaytracer.Render(material);
                    material.colorR = material.colorR / 255;
                    material.colorG = material.colorG / 255;
                    material.colorB = material.colorB / 255;
                    bool replace = false;

                    if (String.Compare(material.Name, "default", true) == 0)
                    {
                        Modeler.DialogBoxes.NameDialog newName = new NameDialog();
                        bool res = (bool) newName.Show("Podaj nową nazwę materiału", "");
                        if (!res)
                            return;
                        material.name = newName.Result;

                    }
                    while (_surfaceGallery.GetNames().Contains(material.Name, StringComparer.OrdinalIgnoreCase) && !replace)
                    {
                        Modeler.DialogBoxes.NameDialog dialog = new NameDialog();
                        dialog.Owner = this;

                        bool result = (bool)dialog.Show(materialMessage, material.Name);
                        string name = dialog.Result;
                        if (!result)
                            return;
                        if (material.Name == name)
                            replace = true;
                        material.name = name;
                        dialog.Close();
                    }
                    if (replace)
                    {
                        int idx = _surfaceGallery.GetNameIndex(material.name);
                        _surfaceGallery.RemoveAt(idx);
                        Surface surface = _surfaceGallery.SaveToGallery(material);
                        _surfaceGallery.Insert(idx, surface);
                    }
                    else
                    {
                        Surface surface = _surfaceGallery.SaveToGallery(material);
                        _surfaceGallery.Add(surface);
                    }
                }
            }
        }
        public static Bitmap Render(Material_ mat)
        {
            //System.Drawing.Graphics canvas = System.Drawing.Graphics.FromImage(output);
            //canvas.FillRectangle(Brushes.Black, 0, 0, xResolution, yResolution);
            material = mat;
            Vector3D directionVector = new Vector3D();
            Color color;
            for (int i = 0; i < xResolution; i++)
            {
                for (int j = 0; j < yResolution; j++)
                {
                    directionVector = vectorU * (i / (float)(xResolution - 1)) + vectorV * (j / (float)(yResolution - 1));
                    directionVector += topLeft;
                    directionVector -= observer;
                    directionVector.Normalize();

                    color = CalculateColor(observer, directionVector, 0);
                    output.SetPixel(i, j, color);
                }
            }

            return output;
        }
 public void SetMaterial(Material_ material)
 {
     this.material = material;
     SetSliders();
 }
 private void InitializeMaterial()
 {
     material = new Material_("default", 159, 182, 205, 0.8f, 0.8f, 0.8f, 0.1f, 0.1f, 0.1f, 0, 0, 0, 0, 0, 0, 500, 0);
     SetSliders();
     RenderMaterial();
 }
 private void materialPreview_Drop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent("Object"))
     {
         object data = e.Data.GetData("Object");
         Console.WriteLine(data.GetType());
         if (data is Surface)
         {
             material = new Material_(((Surface)data).Material);
             material.colorR = material.colorR * 255;
             material.colorG = material.colorG * 255;
             material.colorB = material.colorB * 255;
             RenderMaterial();
             SetSliders();
             name_box.Text = material.name;
         }
         else if (data is Material_)
         {
             material = new Material_(((Material_)data));
             RenderMaterial();
             SetSliders();
             name_box.Text = material.name;
         }
     }
 }
Example #11
0
 public Surface(Material_ material, String imgUri)
 {
     this.material = material;
     imageUri = imgUri;
 }
Example #12
0
        public void AddMaterial(Material_ material)
        {
            modified = true;
            bool zastap = false;
            for (int i = 0; i < materials.Count; i++) if (materials[i].name == material.Name)
                {
                    zastap = true;
                    materials[i] = new Material_(material);
                }
            if (!zastap) materials.Add(new Material_(material));

            for (int i = 0; i < parts.Count; i++)
            {
                foreach (HierarchyMesh obj in selTriangles)
                    if (parts[i].triangles.Contains((int)obj.triangles[0]))
                        materialAssign[i] = material.Name;
            }
        }
        private void Views_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (currScene.selCams.Count > 0 || currScene.selLights.Count > 0 || currScene.selTriangles.Count > 0)
                {
                    System.Windows.DataObject dataObject = new System.Windows.DataObject();
                    ViewportInfo coords = GetViewCoords();
                    undo.Save(currScene);

                    // Lewy górny panel
                    if (e.X >= coords.posX[0] && e.X < coords.posX[0] + coords.sizeX[0] && e.Y >= coords.posY[0] && e.Y < coords.posY[0] + coords.sizeY[0])
                    {
                        dataObject.SetData("Viewport", "perspective");
                    }
                    // Prawy górny panel
                    else if (e.X >= coords.posX[1] && e.X < coords.posX[1] + coords.sizeX[1] && e.Y >= coords.posY[1] && e.Y < coords.posY[1] + coords.sizeY[1])
                    {
                        dataObject.SetData("Viewport", "top");
                    }
                    // Lewy dolny panel
                    else if (e.X >= coords.posX[2] && e.X < coords.posX[2] + coords.sizeX[2] && e.Y >= coords.posY[2] && e.Y < coords.posY[2] + coords.sizeY[2])
                    {
                        dataObject.SetData("Viewport", "front");
                    }
                    // Prawy dolny panel
                    else if (e.X >= coords.posX[3] && e.X < coords.posX[3] + coords.sizeX[3] && e.Y >= coords.posY[3] && e.Y < coords.posY[3] + coords.sizeY[3])
                    {
                        dataObject.SetData("Viewport", "side");
                    }

                    dragX = (float)e.X + xOffset;
                    dragY = (float)e.Y + yOffset;
                    DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Move);

                    mousePos.X = e.X;
                    mousePos.Y = e.Y;
                }
                else
                {
                    ViewportInfo views = GetViewCoords();
                    int x = (int)e.X;
                    int y = (int)e.Y;

                    int rect = -1;

                    for (int i = 0; i < 4; ++i)
                    {
                        if (views.posX[i] <= x && x < views.posX[i] + views.sizeX[i] && views.posY[i] <= y && y < views.posY[i] + views.sizeY[i])
                        {
                            rect = i;
                        }
                    }

                    if (rect >= 0)
                    {
                        ViewportType viewportType = rect == 0 ? ViewportType.Perspective : ViewportType.Orto;
                        int orthoRect = rect == 0 ? rect : rect - 1;

                        SelectingElems.SelectElems(currScene, viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]),
                            new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]),
                            renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect]);

                    }

                    for (int i = 0; i < currScene.parts.Count; i++)
                    {
                        foreach (HierarchyMesh obj in currScene.selTriangles)
                            if (currScene.parts[i].triangles.Contains((int)obj.triangles[0]))
                            {
                                System.Windows.DataObject dataObject = new System.Windows.DataObject();
                                Material_ material = null;
                                foreach (Material_ m in currScene.materials)
                                {
                                    if (m.name == currScene.materialAssign[i])
                                    {
                                        material = new Material_(m);
                                        material.colorR = material.colorR * 255;
                                        material.colorG = material.colorG * 255;
                                        material.colorB = material.colorB * 255;
                                    }
                                }
                                dataObject.SetData("Object", material);
                                currScene.selTriangles.Clear();
                                DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Move);
                                i = Int32.MaxValue-1;
                                break;
                            }
                    }
                    currScene.selTriangles.Clear();
                }
            }
        }
        // Koniec sekcji
        ////////////////////////////////////////////////////////////////////////////////////
        private void objectToScene_Drop(object sender, System.Windows.DragEventArgs e)
        {
            if (e.Data.GetDataPresent("Object"))
            {
                object data = e.Data.GetData("Object");
                Console.WriteLine(data.GetType());
                ViewportInfo coords = GetViewCoords();
                if (data is Shape_)
                {
                    Shape_ shape = (Shape_)data;
                    undo.Save(currScene);
                    currScene.AddObject(shape.Triangulate((float)triang_Slider.Value), shape.GetType().ToString());
                    // przekształcenie współrzędnych
                    float x = (float)e.GetPosition(this).X - xOffset;
                    float y = (float)e.GetPosition(this).Y - yOffset;

                    float xtrans = 0, ytrans = 0, ztrans = 0;
                    float factor = (renderer.OrthoWidth[0] / coords.sizeX[1]);

                    // Lewy górny
                    if (x >= coords.posX[0] && x < coords.posX[0] + coords.sizeX[0] && y >= coords.posY[0] && y < coords.posY[0] + coords.sizeY[0])
                    {
                    }
                    // Prawy górny panel - gora (x, z)
                    else if (x >= coords.posX[1] && x < coords.posX[1] + coords.sizeX[1] && y >= coords.posY[1] && y < coords.posY[1] + coords.sizeY[1])
                    {
                        xtrans = (x - (coords.posX[1] + coords.sizeX[1] / 2)) / coords.sizeX[1] * renderer.OrthoWidth[0];
                        ytrans = renderer.OrthoLookAt[1].Y;
                        ztrans = (y - (coords.posY[1] + coords.sizeY[1] / 2)) / coords.sizeY[1] * (coords.sizeY[1] * renderer.OrthoWidth[0] / coords.sizeX[1]);
                    }
                    // Lewy dolny panel - przod (x, y)
                    else if (x >= coords.posX[2] && x < coords.posX[2] + coords.sizeX[2] && y >= coords.posY[2] && y < coords.posY[2] + coords.sizeY[2])
                    {
                        xtrans = (x - (coords.posX[2] + coords.sizeX[2] / 2)) / coords.sizeX[1] * renderer.OrthoWidth[1];
                        ztrans = renderer.OrthoLookAt[0].Z;
                        ytrans = - (y - (coords.posY[2] + coords.sizeY[2] / 2)) / coords.sizeY[2] * (coords.sizeY[2] * renderer.OrthoWidth[1] / coords.sizeX[2]);
                    }
                    // Prawy dolny panel - bok (z, y)
                    else if (x >= coords.posX[3] && x < coords.posX[3] + coords.sizeX[3] && y >= coords.posY[3] && y < coords.posY[3] + coords.sizeY[3])
                    {
                        ztrans = - (x - (coords.posX[3] + coords.sizeX[3] / 2)) / coords.sizeX[3] * renderer.OrthoWidth[2];
                        xtrans = renderer.OrthoLookAt[1].X;
                        ytrans = - (y - (coords.posY[3] + coords.sizeY[3] / 2)) / coords.sizeY[3] * (coords.sizeY[3] * renderer.OrthoWidth[2] / coords.sizeX[3]);
                    }

                    Transformations.Transformations.TranslateAddedObject(currScene, xtrans, ytrans, ztrans);

                    Console.WriteLine(currScene.points.Count() + " " + currScene.triangles.Count());
                }
                else if (data is PreparedElement)
                {
                    PreparedElement element = (PreparedElement)data;
                    Console.WriteLine("Dodanie do sceny");
                }
                else if (data is Surface)
                {
                    Surface surface = (Surface)data;
                    undo.Save(currScene);
                    bool zazn = true;
                    bool zastap = false;
                    for (int i = 0; i < currScene.materials.Count; i++) if (currScene.materials[i].name == surface.Material.Name)
                        {
                            zastap = true;
                            currScene.materials[i] = new Material_(surface.Material);
                        }
                    if (!zastap) currScene.materials.Add(new Material_(surface.Material));

                    if (currScene.selTriangles.Count == 0)
                    {
                        zazn = false;
                        ViewportInfo views = GetViewCoords();
                        int x = (int)e.GetPosition(this).X - xOffset;
                        int y = (int)e.GetPosition(this).Y - yOffset;

                        int rect = -1;

                        for (int i = 0; i < 4; ++i)
                        {
                            if (views.posX[i] <= x && x < views.posX[i] + views.sizeX[i] && views.posY[i] <= y && y < views.posY[i] + views.sizeY[i])
                            {
                                rect = i;
                            }
                        }

                        if (rect >= 0)
                        {
                            ViewportType viewportType = rect == 0 ? ViewportType.Perspective : ViewportType.Orto;
                            int orthoRect = rect == 0 ? rect : rect - 1;

                            SelectingElems.SelectElems(currScene, viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]),
                                new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]),
                                renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect]);

                        }
                    }

                    for (int i = 0; i < currScene.parts.Count; i++)
                    {
                        foreach (HierarchyMesh obj in currScene.selTriangles)
                            if (currScene.parts[i].triangles.Contains((int)obj.triangles[0]))
                                currScene.materialAssign[i] = surface.Material.Name;
                    }
                    if (!zazn) currScene.selTriangles.Clear();
                    Console.WriteLine("Przypisanie atrybutów powierzchniowych");
                }
                else if (data is Material_)
                {
                    Material_ material = new Material_((Material_)data);
                    material.colorR = material.colorR / 255;
                    material.colorG = material.colorG / 255;
                    material.colorB = material.colorB / 255;
                    undo.Save(currScene);
                    bool zazn = true;
                    bool zastap = false;
                    for (int i = 0; i < currScene.materials.Count; i++) if (currScene.materials[i].name == material.Name)
                        {
                            zastap = true;
                            currScene.materials[i] = new Material_(material);
                        }
                    if (!zastap) currScene.materials.Add(new Material_(material));

                    if (currScene.selTriangles.Count == 0)
                    {
                        zazn = false;
                        ViewportInfo views = GetViewCoords();
                        int x = (int)e.GetPosition(this).X - xOffset;
                        int y = (int)e.GetPosition(this).Y - yOffset;

                        int rect = -1;

                        for (int i = 0; i < 4; ++i)
                        {
                            if (views.posX[i] <= x && x < views.posX[i] + views.sizeX[i] && views.posY[i] <= y && y < views.posY[i] + views.sizeY[i])
                            {
                                rect = i;
                            }
                        }

                        if (rect >= 0)
                        {
                            ViewportType viewportType = rect == 0 ? ViewportType.Perspective : ViewportType.Orto;
                            int orthoRect = rect == 0 ? rect : rect - 1;

                            SelectingElems.SelectElems(currScene, viewportType, new System.Drawing.Point(x - views.posX[rect], y - views.posY[rect]),
                                new System.Drawing.Point(views.sizeX[rect], views.sizeY[rect]), new Vector2(renderer.OrthoWidth[orthoRect], (float)views.sizeY[rect] / views.sizeX[rect] * renderer.OrthoWidth[orthoRect]),
                                renderer.OrthoPos[orthoRect], renderer.OrthoLookAt[orthoRect]);

                        }
                    }

                    for (int i = 0; i < currScene.parts.Count; i++)
                    {
                        foreach (HierarchyMesh obj in currScene.selTriangles)
                            if (currScene.parts[i].triangles.Contains((int)obj.triangles[0]))
                                currScene.materialAssign[i] = material.Name;
                    }
                    if (!zazn) currScene.selTriangles.Clear();
                    Console.WriteLine("Przypisanie atrybutów powierzchniowych");
                }
                else if (data is LightObj)
                {
                    LightObj light = (LightObj)data;
                    undo.Save(currScene);
                    Light_ sceneLight = new Light_(light.Light);
                    currScene.lights.Add(sceneLight);
                    currScene.selLights.Add(sceneLight);
                    Console.WriteLine("Dodanie światła");
                }

                else if (data is Light_)
                {
                    Light_ light = (Light_)data;
                    undo.Save(currScene);
                    Light_ sceneLight = new Light_(light);
                    currScene.lights.Add(sceneLight);
                    currScene.selLights.Add(sceneLight);
                }

            }

            e.Handled = true;

            trNumTBG1.Text = currScene.triangles.Count().ToString();
            trNumTBG2.Text = currScene.triangles.Count().ToString();
            trNumTBG3.Text = currScene.triangles.Count().ToString();
            trNumTBG4.Text = currScene.triangles.Count().ToString();

            RenderViews();
        }
 private void materialy_ListView_Drop(object sender, System.Windows.DragEventArgs e)
 {
     if (e.Data.GetDataPresent("Object"))
     {
         object data = e.Data.GetData("Object");
         Console.WriteLine(data.GetType());
         if (data is Material_)
         {
         Material_ material=new Material_((Material_)data);
         material.colorR = material.colorR / 255;
         material.colorG = material.colorG / 255;
         material.colorB = material.colorB / 255;
         _surfaceGallery.Add(new Surface(material,"Ikony/Materialy/NiebieskieSzklo.png"));
         }
     }
 }