Ejemplo n.º 1
0
        private void OnChangeXYZ(double X, double Y, double Z)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.TxtX.InvokeRequired)
            {
                try
                {
                    SetXYZCallback d = new SetXYZCallback(OnChangeXYZ);
                    this.Invoke(d, new object[] { X, Y, Z });
                }
                catch (Exception) { }
            }
            else
            {
                this.TxtX.Text = X.ToString("0.000");
                this.TxtY.Text = Y.ToString("0.000");
                this.TxtZ.Text = Z.ToString("0.000");

                foreach (SharpGL.SceneGraph.Core.SceneElement item in sceneControl.Scene.SceneContainer.Children)
                {
                    if (item.Name == constExtruder && item is SharpGL.SceneGraph.Primitives.Folder)
                    {
                        if (item.Effects.Count != 0)
                        {
                            for (int i = 0; i < item.Effects.Count; i++)
                            {
                                if (item.Effects[i] is SharpGL.SceneGraph.Effects.LinearTransformationEffect)
                                {
                                    item.RemoveEffect(item.Effects[i]);
                                }
                            }
                        }

                        SharpGL.SceneGraph.Effects.LinearTransformationEffect linearTransformationEffect = new SharpGL.SceneGraph.Effects.LinearTransformationEffect();
                        linearTransformationEffect.LinearTransformation.TranslateX = Convert.ToSingle(X);
                        linearTransformationEffect.LinearTransformation.TranslateY = Convert.ToSingle(Y);
                        linearTransformationEffect.LinearTransformation.TranslateZ = Convert.ToSingle(Z);

                        item.AddEffect(linearTransformationEffect);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draw color indicator on viewport as an UI.
        /// </summary>
        /// <param name="anchor">the edges of the viewport to which a SimpleUIColorIndicator is bound and determines how it is resized with its parent.</param>
        /// <param name="margin">the space between viewport and SimpleUIColorIndicator.</param>
        /// <param name="size">Stores width when <see cref="OpenGLUIRect.Anchor"/>.Left & <see cref="OpenGLUIRect.Anchor"/>.Right is <see cref="OpenGLUIRect.Anchor"/>.None.
        /// <para> and height when <see cref="OpenGLUIRect.Anchor"/>.Top & <see cref="OpenGLUIRect.Anchor"/>.Bottom is <see cref="OpenGLUIRect.Anchor"/>.None.</para></param>
        /// <param name="zNear"></param>
        /// <param name="zFar"></param>
        /// <param name="rectColor"></param>
        public SimpleUIColorIndicator(AnchorStyles anchor, Padding margin, System.Drawing.Size size, int zNear = -1000, int zFar = 1000, GLColor rectColor = null)
            : base(anchor, margin, size, zNear, zFar)
        {
            {
                this.colorBar = new ColorIndicatorBar()
                {
                    Name = "color indicator's bar"
                };
                var colorBarTransform = new SharpGL.SceneGraph.Effects.LinearTransformationEffect();
                colorBar.AddEffect(colorBarTransform);
                base.AddChild(colorBar);
                this.colorBarTransform = colorBarTransform.LinearTransformation;
            }

            {
                this.colorNumber = new ColorIndicatorNumber()
                {
                    Name = "color indicator's number"
                };
                base.AddChild(colorNumber);
            }
        }
Ejemplo n.º 3
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.º 4
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);
        }