Beispiel #1
0
        public void Draw()
        {
            if (VertexArray.Dimension == 2)
            {
                // cannot see the opposite side
                GL.Enable(EnableCap.CullFace);
                GL.CullFace(CullFaceMode.Back);
            }
            else
            {
                GL.Disable(EnableCap.CullFace);
            }

            int minLayer;
            int maxLayer;
            {
                if (DrawParts.Count > 0)
                {
                    minLayer = DrawParts[0].Layer;
                    maxLayer = minLayer;
                }
                else
                {
                    minLayer = 0; maxLayer = 0;
                }
                for (int idp = 1; idp < DrawParts.Count; idp++)
                {
                    int layer = DrawParts[idp].Layer;
                    minLayer = (layer < minLayer) ? layer : minLayer;
                    maxLayer = (layer > maxLayer) ? layer : maxLayer;
                }
            }
            double layerHeight = 1.0 / (maxLayer - minLayer + 1);

            if (ColorArray == null)
            {
                // color is assigned to face
                GL.LineWidth(3);
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.VertexPointer((int)VertexArray.Dimension, VertexPointerType.Double,
                                 0, VertexArray.VertexCoordArray);
                if (NormalArray != null && GL.IsEnabled(EnableCap.Lighting))
                {
                    GL.EnableClientState(ArrayCap.NormalArray);
                    GL.NormalPointer(NormalPointerType.Double, 0, NormalArray);
                    float[] shine = { 0, 0, 0, 0 };
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, shine);
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Shininess, 20.0f);
                }
                if (UVArray != null && GL.IsEnabled(EnableCap.Texture2D))
                {
                    GL.EnableClientState(ArrayCap.TextureCoordArray);
                    GL.TexCoordPointer(2, TexCoordPointerType.Double, 0, UVArray);
                    GL.MatrixMode(MatrixMode.Texture);
                    GL.LoadIdentity();
                    GL.Translate(-TexCentX, -TexCentY, 0.0);
                    GL.MatrixMode(MatrixMode.Modelview);
                }
                for (int idp = 0; idp < DrawParts.Count; idp++)
                {
                    FaceFieldDrawPart dp = DrawParts[idp];
                    if (dp.Dimension == 1)
                    {
                        // draw line
                        GL.Color3(0.0, 0.0, 0.0);
                        GL.LineWidth(3);
                    }
                    if (dp.Dimension == 2 || dp.Dimension == 3)
                    {
                        // draw face
                        GL.Color3(dp.Color);
                    }
                    float[] color1 = { (float)dp.Color[0], (float)dp.Color[1], (float)dp.Color[2] };
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, color1);
                    //GL.Color3(0.8, 0.8, 0.8);
                    dp.DrawElements();
                }

                GL.DisableClientState(ArrayCap.VertexArray);
                GL.DisableClientState(ArrayCap.NormalArray);
                GL.DisableClientState(ArrayCap.TextureCoordArray);
            }
            else
            {
                // color is assigned to vertex
                GL.ShadeModel(ShadingModel.Smooth);
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.VertexPointer((int)VertexArray.Dimension, VertexPointerType.Double,
                                 0, VertexArray.VertexCoordArray);
                if (NormalArray != null && GL.IsEnabled(EnableCap.Lighting))
                {
                    GL.EnableClientState(ArrayCap.NormalArray);
                    GL.NormalPointer(NormalPointerType.Double, 0, NormalArray);
                    GL.Enable(EnableCap.ColorMaterial);
                    GL.ColorMaterial(MaterialFace.FrontAndBack, ColorMaterialParameter.AmbientAndDiffuse);
                    float[] shine = { 1, 1, 1, 1 };
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, shine);
                    GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Shininess, 100.0f);
                }
                if (UVArray != null && GL.IsEnabled(EnableCap.Texture2D))
                {
                    GL.EnableClientState(ArrayCap.TextureCoordArray);
                    GL.TexCoordPointer(2, TexCoordPointerType.Double, 0, UVArray);
                }
                GL.EnableClientState(ArrayCap.ColorArray);
                GL.ColorPointer(4, ColorPointerType.Float, 0, ColorArray);

                for (int idp = 0; idp < DrawParts.Count; idp++)
                {
                    FaceFieldDrawPart dp = DrawParts[idp];
                    int    layer         = dp.Layer;
                    double height        = (layer - minLayer) * layerHeight;
                    GL.Translate(0, 0, +height);
                    dp.DrawElements();
                    GL.Translate(0, 0, -height);
                }

                GL.DisableClientState(ArrayCap.ColorArray);
                GL.DisableClientState(ArrayCap.VertexArray);
                GL.DisableClientState(ArrayCap.NormalArray);
                GL.DisableClientState(ArrayCap.TextureCoordArray);
            }

            if (IsColorLegendDraw)
            {
                // draw legend
                var legend = new ColorLegend(ColorMap);
                legend.Draw();
            }
        }