Ejemplo n.º 1
0
        public void InitAxis(SceneElement parent)
        {
            var folder = new SharpGL.SceneGraph.Primitives.Folder()
            {
                Name = "Axis"
            };

            parent.AddChild(folder);
            folder.AddChild(new Figures.Axies());
        }
Ejemplo n.º 2
0
        private void InitFrameElement(int width, int length, int height, SceneElement parent)
        {
            var folder = new SharpGL.SceneGraph.Primitives.Folder()
            {
                Name = "Frame"
            };

            parent.AddChild(folder);

            var frame = new FrameElement(width, length, height);

            folder.AddChild(frame);
        }
Ejemplo n.º 3
0
        private void InitGridElement(float x, float y, float z, float width, float length, SceneElement parent)
        {
            var folder = new SharpGL.SceneGraph.Primitives.Folder()
            {
                Name = "Grid"
            };

            parent.AddChild(folder);

            var grid = new GridElement(x, y, z, width, length);

            folder.AddChild(grid);
        }
Ejemplo n.º 4
0
        private void InitElements(Scene scene)
        {
            var objectRoot = new SharpGL.SceneGraph.Primitives.Folder()
            {
                Name = "Root"
            };

            scene.SceneContainer.AddChild(objectRoot);
            // This implements free rotation(with translation and rotation).
            var camera = GetCamera();

            objectArcBallEffect = new ArcBallEffect(
                camera.Position.X, camera.Position.Y, camera.Position.Z,
                camera.Target.X, camera.Target.Y, camera.Target.Z,
                camera.UpVector.X, camera.UpVector.Y, camera.UpVector.Z);
            objectRoot.AddEffect(objectArcBallEffect);
            var axisRoot = new SharpGL.SceneGraph.Primitives.Folder()
            {
                Name = "axis root"
            };

            scene.SceneContainer.AddChild(axisRoot);

            axisArcBallEffect = new Figures.ArcBallEffect(
                camera.Position.X, camera.Position.Y, camera.Position.Z,
                camera.Target.X, camera.Target.Y, camera.Target.Z,
                camera.UpVector.X, camera.UpVector.Y, camera.UpVector.Z);
            axisRoot.AddEffect(axisArcBallEffect);



            InitAxis(objectRoot);
            InitAxis(axisRoot);
            InitFrameElement(1, 1, 1, objectRoot);
            InitGridElement(-5, -5, 0, 10, 10, objectRoot);
        }
Ejemplo n.º 5
0
        private void sceneControl_Load(object sender, EventArgs e)
        {
            SharpGL.SceneGraph.Quadrics.Cylinder cylinder = new SharpGL.SceneGraph.Quadrics.Cylinder
            {
                BaseRadius = 0.0,
                Height     = 5.0,
                TopRadius  = 2.0,
            };

            SharpGL.SceneGraph.Quadrics.Cylinder cylinderTop = new SharpGL.SceneGraph.Quadrics.Cylinder
            {
                BaseRadius = 2.0,
                Height     = 20.0,
                TopRadius  = 2.0
            };

            SharpGL.SceneGraph.Transformations.LinearTransformation linearTransformation = new SharpGL.SceneGraph.Transformations.LinearTransformation
            {
                TranslateZ = 5
            };
            SharpGL.SceneGraph.Effects.LinearTransformationEffect effect = new SharpGL.SceneGraph.Effects.LinearTransformationEffect
            {
                LinearTransformation = linearTransformation
            };
            cylinderTop.Effects.Add(effect);

            SharpGL.SceneGraph.Primitives.Folder extruder = new SharpGL.SceneGraph.Primitives.Folder
            {
                Name = constExtruder
            };

            sceneControl.Scene.SceneContainer.AddChild(extruder);

            extruder.AddChild(cylinder);
            extruder.AddChild(cylinderTop);
        }
Ejemplo n.º 6
0
        public bool Renderiza(ref SharpGL.SceneControl scene_GLControl, bool Grid = false, bool Modelo = false, double CotaZ = double.NaN, bool BBox = false)
        {
            bool Res = true;

            scene_GLControl.Scene.RenderBoundingVolumes = BBox;

            for (int i = 0; i < scene_GLControl.Scene.SceneContainer.Children.Count(); i++)
            {
                switch (scene_GLControl.Scene.SceneContainer.Children[i].Name)
                {
                case constPlanoSLT:
                    if (CotaZ != double.NaN)
                    {
                        scene_GLControl.Scene.SceneContainer.RemoveChild(scene_GLControl.Scene.SceneContainer.Children[i]);
                        i--;
                    }
                    break;

                case constModeloSLT:
                    if (Modelo)
                    {
                        scene_GLControl.Scene.SceneContainer.RemoveChild(scene_GLControl.Scene.SceneContainer.Children[i]);
                        i--;
                    }
                    break;

                case constDesignPrimitives:
                    if (Grid)
                    {
                        if (scene_GLControl.Scene.SceneContainer.Children[i] is SharpGL.SceneGraph.Primitives.Folder)
                        {
                            SharpGL.SceneGraph.Primitives.Folder Foldr = scene_GLControl.Scene.SceneContainer.Children[i] as SharpGL.SceneGraph.Primitives.Folder;
                            for (int j = 0; j < Foldr.Children.Count(); j++)
                            {
                                if (Foldr.Children[j] is SharpGL.SceneGraph.Primitives.Grid)
                                {
                                    SharpGL.SceneGraph.Primitives.Grid Grd = Foldr.Children[j] as SharpGL.SceneGraph.Primitives.Grid;

                                    if (Grd.Name == constDesignGrid)
                                    {
                                        Foldr.RemoveChild(Grd);
                                        j--;
                                    }
                                }
                                else if (Foldr.Children[j] is SharpGL.SceneGraph.Primitives.Axies)
                                {
                                    SharpGL.SceneGraph.Primitives.Axies Ax = Foldr.Children[j] as SharpGL.SceneGraph.Primitives.Axies;

                                    if (Ax.Name == constDesignAxie)
                                    {
                                        Foldr.RemoveChild(Ax);
                                        j--;
                                    }
                                }
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            if (Grid)
            {
                SharpGL.SceneGraph.Primitives.Folder Foldr = null;

                for (int i = 0; i < scene_GLControl.Scene.SceneContainer.Children.Count(); i++)
                {
                    if (scene_GLControl.Scene.SceneContainer.Children[i].Name == constDesignPrimitives)
                    {
                        if (scene_GLControl.Scene.SceneContainer.Children[i] is SharpGL.SceneGraph.Primitives.Folder)
                        {
                            Foldr = scene_GLControl.Scene.SceneContainer.Children[i] as SharpGL.SceneGraph.Primitives.Folder;
                            break;
                        }
                    }
                }

                if (Foldr != null)
                {
                    SharpGL.SceneGraph.Primitives.Grid grid = new SharpGL.SceneGraph.Primitives.Grid();
                    grid.Name = constDesignGrid;

                    SharpGL.SceneGraph.Primitives.Axies axie = new SharpGL.SceneGraph.Primitives.Axies();
                    axie.Name = constDesignAxie;

                    if (_Facets.Count > 0)
                    {
                        //printer Axies
                        SharpGL.SceneGraph.Transformations.LinearTransformation linearAxiesTransformation = new SharpGL.SceneGraph.Transformations.LinearTransformation();

                        linearAxiesTransformation.ScaleX = 10;
                        linearAxiesTransformation.ScaleY = 10;
                        linearAxiesTransformation.ScaleZ = 10;

                        SharpGL.SceneGraph.Effects.LinearTransformationEffect linearAxiesTransformationEffect = new SharpGL.SceneGraph.Effects.LinearTransformationEffect();
                        linearAxiesTransformationEffect.LinearTransformation = linearAxiesTransformation;

                        axie.AddEffect(linearAxiesTransformationEffect);

                        //Printer Grid
                        SharpGL.SceneGraph.Transformations.LinearTransformation linearGridTransformation = new SharpGL.SceneGraph.Transformations.LinearTransformation();

                        linearGridTransformation.TranslateX = 200;
                        linearGridTransformation.TranslateY = 200;
                        linearGridTransformation.ScaleX     = 20;
                        linearGridTransformation.ScaleY     = 20;

                        SharpGL.SceneGraph.Effects.LinearTransformationEffect linearGridTransformationEffect = new SharpGL.SceneGraph.Effects.LinearTransformationEffect();
                        linearGridTransformationEffect.LinearTransformation = linearGridTransformation;

                        grid.AddEffect(linearGridTransformationEffect);
                    }

                    Foldr.AddChild(axie);
                    Foldr.AddChild(grid);
                }
            }

            if (!double.IsNaN(CotaZ))
            {
                //Dibuja el plano Z.
                SharpGL.SceneGraph.Primitives.Polygon Polig = new SharpGL.SceneGraph.Primitives.Polygon();
                Polig.Name        = constPlanoSLT;
                Polig.DrawNormals = false;

                SharpGL.SceneGraph.Vertex[] Vertices = new SharpGL.SceneGraph.Vertex[4];

                float MargenX = (float)this.Ancho * 0.1f;
                float MargenY = (float)this.Alto * 0.1f;

                Vertices[0] = new SharpGL.SceneGraph.Vertex(_IzqFrontInf.Xf - MargenX, _IzqFrontInf.Yf - MargenY, (float)CotaZ);
                Vertices[1] = new SharpGL.SceneGraph.Vertex(_IzqFrontInf.Xf - MargenX, _DerPostSup.Yf + MargenY, (float)CotaZ);
                Vertices[2] = new SharpGL.SceneGraph.Vertex(_DerPostSup.Xf + MargenX, _DerPostSup.Yf + MargenY, (float)CotaZ);
                Vertices[3] = new SharpGL.SceneGraph.Vertex(_DerPostSup.Xf + MargenX, _IzqFrontInf.Yf - MargenY, (float)CotaZ);

                Polig.AddFaceFromVertexData(Vertices);

                Polig.Validate(true);

                scene_GLControl.Scene.SceneContainer.AddChild(Polig);
            }

            if (Modelo && _Facets.Count > 0)
            {
                SharpGL.SceneGraph.Primitives.Polygon Polig = new SharpGL.SceneGraph.Primitives.Polygon();
                Polig.Name        = constModeloSLT;
                Polig.DrawNormals = false;

                foreach (FacetSLT F in _Facets)
                {
                    foreach (LoopSLT L in F._Loops)
                    {
                        bool Representar = true;

                        if (!double.IsNaN(CotaZ))
                        {
                            //Evalua si se tiene que mostrar o no por encontrarse bajo el plano
                            foreach (VertexSLT V in L.Vertices)
                            {
                                if (V.Z <= CotaZ)
                                {
                                    Representar = true;
                                    break;
                                }
                                else
                                {
                                    Representar = false;
                                }
                            }
                        }

                        if (Representar)
                        {
                            SharpGL.SceneGraph.Vertex[] Vertices = new SharpGL.SceneGraph.Vertex[L.Vertices.Count()];
                            for (int i = 0; i < L.Vertices.Count(); i++)
                            {
                                //Polig.Vertices.Add(new SharpGL.SceneGraph.Vertex(V._X, V._Y, V._Z));
                                Vertices[i] = new SharpGL.SceneGraph.Vertex(L.Vertices[i].Xf + (float)_Tx, L.Vertices[i].Yf + (float)_Ty, L.Vertices[i].Zf + (float)_Tz);
                            }

                            Polig.AddFaceFromVertexData(Vertices);
                        }
                    }
                }

                Polig.Validate(true);

                scene_GLControl.Scene.SceneContainer.AddChild(Polig);
            }

            return(Res);
        }