Esempio n. 1
0
        private void DrawElementsBar()
        {
            if (!IsShown)
            {
                return;
            }

            GL.LineWidth(2);
            GL.Color3(1.0, 0.0, 0.0);
            GL.Begin(PrimitiveType.Lines);
            for (int iiElem = 0; iiElem < SelectedElems.Count; iiElem++)
            {
                uint iElem0 = SelectedElems[iiElem];

                GL.ArrayElement(ElemIndexs[iElem0 * 2]);
                GL.ArrayElement(ElemIndexs[iElem0 * 2 + 1]);
            }

            GL.End();

            /*
             * if (IsSelected)
             * {
             *  GL.Color3(1.0, 1.0, 0.0);
             * }
             * else
             * {
             *  GL.Color3(0.0, 0.0, 0.0);
             * }
             */
            GL.Color3(0.0, 0.0, 0.0);
            GL.DrawElements(PrimitiveType.Lines, (int)ElemCount * 2, DrawElementsType.UnsignedInt, ElemIndexs);
        }
Esempio n. 2
0
        public void DrawFaceColorFlatShaded(NonManifoldMesh m)
        {
            GL.ShadeModel(ShadingModel.Flat);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            //GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Normalize);



            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.Begin(BeginMode.Triangles);
            for (int i = 0, j = 0; i < m.FaceCount; i++, j += 3)
            {
                GL.Normal3(ref m.FaceNormal[j]);
                GL.Color3(ref m.Color[j]);
                GL.ArrayElement(m.FaceIndex[j]);
                GL.ArrayElement(m.FaceIndex[j + 1]);
                GL.ArrayElement(m.FaceIndex[j + 2]);
            }
            GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
            //GL.Disable(EnableCap.Lighting);
        }
Esempio n. 3
0
        private void DrawElementsVertex()
        {
            if (!IsShown)
            {
                return;
            }

            GL.PointSize(5);
            GL.Color3(1.0, 0.0, 0.0);
            GL.Begin(PrimitiveType.Points);
            for (int iiElem = 0; iiElem < SelectedElems.Count; iiElem++)
            {
                uint iElem0 = SelectedElems[iiElem];

                GL.ArrayElement(ElemIndexs[iElem0]);
            }

            GL.End();

            /*
             * if (IsSelected)
             * {
             *  GL.Color3(1.0, 1.0, 0.0);
             * }
             * else
             * {
             *  GL.Color3(0.0, 0.0, 0.0);
             * }
             */
            GL.Color3(0.0, 0.0, 0.0);
            GL.DrawElements(PrimitiveType.Points, (int)ElemCount, DrawElementsType.UnsignedInt, ElemIndexs);
        }
Esempio n. 4
0
        public void DrawIsoPart(ref NonManifoldMesh m)
        {
            int N = 12;


            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.Normalize);

            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.Begin(BeginMode.Triangles);

            int n = m.FaceCount;

            for (int i = 0, j = 0; i < m.FaceCount; i++, j += 3)
            {
                GL.Normal3(ref m.FaceNormal[j]);

                if ((m.Color[m.FaceIndex[j]] + m.Color[m.FaceIndex[j]] + m.Color[m.FaceIndex[j]]) / 3 < (double)(N / 2) / (double)(N + 1))
                {
                    GL.Color3(Color.Yellow);
                }
                else
                {
                    GL.Color3(Color.CornflowerBlue);
                }
                GL.ArrayElement(m.FaceIndex[j]);

                GL.ArrayElement(m.FaceIndex[j + 1]);

                GL.ArrayElement(m.FaceIndex[j + 2]);
            }
            GL.End();


            //GL.Begin(BeginMode.Points);


            n = m.VertexCount;
            for (int i = 0; i < n; i++)
            {
                double value = (double)(N / 2) / (double)(N + 1);
                if (Math.Abs(m.Color[i] - value) < 0.01)
                {
                    GL.Color3(1.0, 0.0, 0.0);
                    GL.PushMatrix();
                    GL.Translate(m.VertexPos[i * 3], m.VertexPos[i * 3 + 1], m.VertexPos[i * 3 + 2]);
                    GL.Scale(0.002, 0.002, 0.002);
                    OpenGLManager.Instance.DrawSphere();
                    GL.PopMatrix();
                    //GL.ArrayElement(i);
                }
            }
            //GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
        }
Esempio n. 5
0
        public void Draw()
        {
            if (LineCount == 0)
            {
                return;
            }

            bool isTexture  = GL.IsEnabled(EnableCap.Texture2D);
            bool isLighting = GL.IsEnabled(EnableCap.Lighting);

            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.Lighting);

            GL.Color3(0.0, 0.0, 0.0);
            GL.LineWidth(LineWidth);

            uint drawDim = VertexArray.Dimension;

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.VertexPointer((int)drawDim, VertexPointerType.Double, 0, VertexArray.VertexCoordArray);
            if (drawDim == 2)
            {
                GL.Translate(0, 0, +0.01);
            }

            if (LinePtCount == 2) // 1次要素
            {
                GL.DrawArrays(PrimitiveType.Lines, 0, (int)(LineCount * LinePtCount));
            }
            else if (LinePtCount == 3) // 2次要素
            {
                GL.Begin(PrimitiveType.Lines);
                for (int iEdge = 0; iEdge < LineCount; iEdge++)
                {
                    GL.ArrayElement((int)(iEdge * LinePtCount + 0));
                    GL.ArrayElement((int)(iEdge * LinePtCount + 2));
                    GL.ArrayElement((int)(iEdge * LinePtCount + 2));
                    GL.ArrayElement((int)(iEdge * LinePtCount + 1));
                }
                GL.End();
            }

            if (drawDim == 2)
            {
                GL.Translate(0, 0, -0.01);
            }

            GL.DisableClientState(ArrayCap.VertexArray);
            if (isTexture)
            {
                GL.Enable(EnableCap.Texture2D);
            }
            if (isLighting)
            {
                GL.Enable(EnableCap.Lighting);
            }
        }
Esempio n. 6
0
        private void DrawElementsSelectionVertex()
        {
            if (!IsShown)
            {
                return;
            }

            GL.PushName(0);
            GL.Begin(PrimitiveType.Points);

            GL.ArrayElement(ElemIndexs[0]);
            GL.End();
            GL.PopName();
        }
Esempio n. 7
0
        public void DrawAutoTextureShaded(NonManifoldMesh m)
        {
            if (OpenGLManager.Instance.FirstTexture == 0)
            {
                return;
            }

            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            //GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Normalize);
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, OpenGLManager.Instance.FirstTexture);

            Color c = GlobalSetting.DisplaySetting.MeshColor;

            GL.Color3(c.R, c.G, c.B);

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.NormalArray);

            GL.VertexPointer <double>(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.NormalPointer <double>(NormalPointerType.Double, 0, m.VertexNormal);


            OpenGLManager.Instance.EnableAutoTexture();

            GL.Begin(BeginMode.Triangles);
            for (int i = 0, j = 0; i < m.FaceCount; i++, j += 3)
            {
                GL.ArrayElement(m.FaceIndex[j]);

                GL.ArrayElement(m.FaceIndex[j + 1]);

                GL.ArrayElement(m.FaceIndex[j + 2]);
            }
            GL.End();



            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.NormalArray);

            GL.Disable(EnableCap.Normalize);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.Disable(EnableCap.Texture2D);
        }
Esempio n. 8
0
        public void DrawGaussianCurvatureShaded(NonManifoldMesh mesh)
        {
            double max = double.MinValue;
            double min = double.MaxValue;
            int    n   = mesh.VertexCount;

            for (int i = 0; i < n; i++)
            {
                if (max < mesh.Color[i])
                {
                    max = mesh.Color[i];
                }
                if (min > mesh.Color[i])
                {
                    min = mesh.Color[i];
                }
            }

            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.Normalize);

            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer(3, VertexPointerType.Double, 0, mesh.VertexPos);
            GL.Begin(BeginMode.Triangles);

            int m = mesh.FaceCount;

            for (int i = 0, j = 0; i < m; i++, j += 3)
            {
                GL.Normal3(ref mesh.FaceNormal[j]);

                GL.Color3(mesh.Color[mesh.FaceIndex[j]] / max, 1, 0);
                GL.ArrayElement(mesh.FaceIndex[j]);
                GL.Color3(mesh.Color[mesh.FaceIndex[j + 1]] / max, 1, 0);
                GL.ArrayElement(mesh.FaceIndex[j + 1]);
                GL.Color3(mesh.Color[mesh.FaceIndex[j + 2]] / max, 1, 0);
                GL.ArrayElement(mesh.FaceIndex[j + 2]);
            }
            GL.End();


            GL.DisableClientState(ArrayCap.VertexArray);
        }
Esempio n. 9
0
        public void DrawBoundaryVertice(NonManifoldMesh m)
        {
            GL.Color3(1.0f, 0.54f, 0.0f);
            GL.PointSize(GlobalSetting.DisplaySetting.PointSize);
            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer <double>(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.Begin(BeginMode.Points);
            for (int i = 0; i < m.VertexCount; i++)
            {
                if (m.IsBoundary[i])
                {
                    GL.ArrayElement(i);
                }
            }
            GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
        }
Esempio n. 10
0
        private void DrawElementsSelectionBar()
        {
            if (!IsShown)
            {
                return;
            }

            for (int ibar = 0; ibar < ElemCount; ibar++)
            {
                GL.PushName(ibar);
                GL.Begin(PrimitiveType.Lines);

                GL.ArrayElement(ElemIndexs[ibar * 2]);
                GL.ArrayElement(ElemIndexs[ibar * 2 + 1]);

                GL.End();
                GL.PopName();
            }
        }
Esempio n. 11
0
        private void DrawElementsQuad()
        {
            if (!IsShown)
            {
                return;
            }

            // 辺を描画

            /*
             * if (IsSelected)
             * {
             *  GL.LineWidth(LineWidth + 1);
             *  GL.Color3(1.0, 1.0, 0.0);
             * }
             * else
             * {
             *  GL.LineWidth(LineWidth);
             *  GL.Color3(0.0, 0.0, 0.0);
             * }
             */
            GL.LineWidth(LineWidth);
            GL.Color3(0.0, 0.0, 0.0);
            GL.DrawElements(PrimitiveType.Lines, (int)EdgeCount * 2, DrawElementsType.UnsignedInt, EdgeIndexs);

            GL.Color3(1.0, 0.0, 0.0);
            GL.Begin(PrimitiveType.Quads);
            for (int iiElem = 0; iiElem < SelectedElems.Count; iiElem++)
            {
                uint iElem0 = SelectedElems[iiElem];

                GL.ArrayElement(ElemIndexs[iElem0 * 4]);
                GL.ArrayElement(ElemIndexs[iElem0 * 4 + 1]);
                GL.ArrayElement(ElemIndexs[iElem0 * 4 + 2]);
                GL.ArrayElement(ElemIndexs[iElem0 * 4 + 3]);
            }
            GL.End();

            // 面を描画
            GL.Color3(Color);
            GL.DrawElements(PrimitiveType.Quads, (int)ElemCount * 4, DrawElementsType.UnsignedInt, ElemIndexs);
        }
Esempio n. 12
0
        public void DrawNotFullRankVertex(NonManifoldMesh mesh, bool[] fullRank)
        {
            GL.Color3(1.0f, 0.4f, 0.4f);
            GL.PointSize(6.0f);
            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer(3, VertexPointerType.Double, 0, mesh.VertexPos);
            GL.Color3(1.0f, 0.0f, 0.0f);
            GL.Begin(BeginMode.Points);
            for (int i = 0; i < mesh.VertexCount; i++)
            {
                if (fullRank[i] == true)
                {
                    continue;
                }
                GL.ArrayElement(i);
            }
            GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
        }
Esempio n. 13
0
        private void DrawElementsSelectionTri()
        {
            if (!IsShown)
            {
                return;
            }

            // 面を描画
            for (int itri = 0; itri < ElemCount; itri++)
            {
                GL.PushName(itri);
                GL.Begin(PrimitiveType.Triangles);

                GL.ArrayElement(ElemIndexs[itri * 3]);
                GL.ArrayElement(ElemIndexs[itri * 3 + 1]);
                GL.ArrayElement(ElemIndexs[itri * 3 + 2]);

                GL.End();
                GL.PopName();
            }
        }
Esempio n. 14
0
        private void DrawElementsSelectionQuad()
        {
            if (!IsShown)
            {
                return;
            }

            // 面を描画
            for (int iquad = 0; iquad < ElemCount; iquad++)
            {
                GL.PushName(iquad);
                GL.Begin(PrimitiveType.Quads);

                GL.ArrayElement(ElemIndexs[iquad * 4]);
                GL.ArrayElement(ElemIndexs[iquad * 4 + 1]);
                GL.ArrayElement(ElemIndexs[iquad * 4 + 2]);
                GL.ArrayElement(ElemIndexs[iquad * 4 + 3]);

                GL.End();
                GL.PopName();
            }
        }
Esempio n. 15
0
        public void DrawSelectedFaceByRectangle(NonManifoldMesh m)
        {
            GL.Enable(EnableCap.PolygonOffsetFill);
            DrawSmoothShaded(m);
            //GL.Disable(EnableCap.PolygonOffsetFill);

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.Disable(EnableCap.CullFace);



            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.LineWidth(GlobalSetting.DisplaySetting.LineWidth);
            GL.EnableClientState(ArrayCap.VertexArray);



            GL.VertexPointer <double>(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.Begin(BeginMode.Triangles);

            int n = m.FaceCount;

            for (int i = 0; i < n; i++)
            {
                if (m.FaceFlag[i] == 0)
                {
                    continue;
                }

                GL.ArrayElement(m.FaceIndex[i * 3]);
                GL.ArrayElement(m.FaceIndex[i * 3 + 1]);
                GL.ArrayElement(m.FaceIndex[i * 3 + 2]);
            }
            GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
            GL.Enable(EnableCap.CullFace);
        }
Esempio n. 16
0
        public void DrawSelectedVerticeByPoint(NonManifoldMesh m)
        {
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.PointSize(GlobalSetting.DisplaySetting.PointSize);
            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer <double>(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.Begin(BeginMode.Points);
            int n = m.VertexCount;

            for (int i = 0; i < n; i++)
            {
                if (m.VertexFlag[i] == 0)
                {
                    continue;
                }
                switch (m.VertexFlag[i] % 6)
                {
                case 0: GL.Color3(0.0f, 0.0f, 1.0f); break;

                case 1: GL.Color3(1.0f, 0.0f, 0.0f); break;

                case 2: GL.Color3(0.0f, 1.0f, 0.0f); break;

                case 3: GL.Color3(1.0f, 1.0f, 0.0f); break;

                case 4: GL.Color3(0.0f, 1.0f, 1.0f); break;

                case 5: GL.Color3(1.0f, 0.0f, 1.0f); break;
                }

                GL.ArrayElement(i);
            }
            GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
        }
Esempio n. 17
0
        public void DrawStrokes(NonManifoldMesh m, List <List <int> > lines)
        {
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.PointSize(GlobalSetting.DisplaySetting.PointSize);
            GL.LineWidth(GlobalSetting.DisplaySetting.SelectionLineWidth);
            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer <double>(3, VertexPointerType.Double, 0, m.VertexPos);

            for (int i = 0; i < lines.Count; i++)
            {
                switch (i % 6)
                {
                case 0: GL.Color3(0.0f, 0.0f, 1.0f); break;

                case 1: GL.Color3(1.0f, 0.0f, 0.0f); break;

                case 2: GL.Color3(0.0f, 1.0f, 0.0f); break;

                case 3: GL.Color3(1.0f, 1.0f, 0.0f); break;

                case 4: GL.Color3(0.0f, 1.0f, 1.0f); break;

                case 5: GL.Color3(1.0f, 0.0f, 1.0f); break;
                }
                GL.Begin(BeginMode.Lines);
                if (lines[i].Count == 2)
                {
                    GL.ArrayElement(lines[i][0]);
                    GL.ArrayElement(lines[i][1]);
                }
                GL.End();
            }


            GL.DisableClientState(ArrayCap.VertexArray);
        }
Esempio n. 18
0
        public void DrawSelectedFace(NonManifoldMesh m, int face)
        {
            //GL.Enable(EnableCap.PolygonOffsetFill);
            //DrawSmoothShaded(m);

            GL.Color3(1.0f, 1.0f, 0.0f);
            GL.LineWidth(GlobalSetting.DisplaySetting.LineWidth);
            GL.EnableClientState(ArrayCap.VertexArray);



            GL.VertexPointer <double>(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.Begin(BeginMode.Triangles);

            GL.ArrayElement(m.FaceIndex[face * 3]);
            GL.ArrayElement(m.FaceIndex[face * 3 + 1]);
            GL.ArrayElement(m.FaceIndex[face * 3 + 2]);

            GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
            GL.Enable(EnableCap.CullFace);
            //GL.Disable(EnableCap.PolygonOffsetFill);
        }
Esempio n. 19
0
        public void DrawMultiTextureShaded(NonManifoldMesh m)
        {
            if (OpenGLManager.Instance.FirstTexture == 0)
            {
                return;
            }
            if (OpenGLManager.Instance.SecondTexture == 0)
            {
                return;
            }


            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            //GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Normalize);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, OpenGLManager.Instance.FirstTexture);

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, OpenGLManager.Instance.SecondTexture);

            Color c = GlobalSetting.DisplaySetting.MeshColor;

            GL.Color3(c.R, c.G, c.B);

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.NormalArray);
            //GL.EnableClientState(ArrayCap.TextureCoordArray);

            GL.VertexPointer <double>(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.NormalPointer <double>(NormalPointerType.Double, 0, m.VertexNormal);
            //GL.TexCoordPointer<double>(2, TexCoordPointerType.Double, 0, m.VertextextCoordinate);

            //int[,] face = new int[2, m.FaceCount * 3];
            //for (int i = 0; i < m.FaceCount * 3; i++)
            //{
            //    face[0, i] = m.FaceIndex[i];
            //    face[1, i] = m.FaceTexIndex[i];
            //}

            //GL.DrawElements<int>(BeginMode.Triangles, m.FaceCount * 3, DrawElementsType.UnsignedInt, face);
            //GL.DrawElements(BeginMode.Triangles, m.FaceCount * 3, DrawElementsType.UnsignedInt, m.FaceIndex);

            GL.Begin(BeginMode.Triangles);
            for (int i = 0, j = 0; i < m.FaceCount; i++, j += 3)
            {
                int s = 0;
                int t = 0;
                s = m.FaceTexIndex[j] * 2;
                t = m.FaceTexIndex[j] * 2 + 1;
                GL.MultiTexCoord2(TextureUnit.Texture0, m.TextextCoordinate[s], 1 - m.TextextCoordinate[t]);
                GL.MultiTexCoord2(TextureUnit.Texture1, m.TextextCoordinate[s], 1 - m.TextextCoordinate[t]);

                GL.ArrayElement(m.FaceIndex[j]);
                s = m.FaceTexIndex[j + 1] * 2;
                t = m.FaceTexIndex[j + 1] * 2 + 1;

                GL.MultiTexCoord2(TextureUnit.Texture0, m.TextextCoordinate[s], 1 - m.TextextCoordinate[t]);
                GL.MultiTexCoord2(TextureUnit.Texture1, m.TextextCoordinate[s], 1 - m.TextextCoordinate[t]);

                GL.ArrayElement(m.FaceIndex[j + 1]);
                s = m.FaceTexIndex[j + 2] * 2;
                t = m.FaceTexIndex[j + 2] * 2 + 1;

                GL.MultiTexCoord2(TextureUnit.Texture0, m.TextextCoordinate[s], 1 - m.TextextCoordinate[t]);
                GL.MultiTexCoord2(TextureUnit.Texture1, m.TextextCoordinate[s], 1 - m.TextextCoordinate[t]);

                GL.ArrayElement(m.FaceIndex[j + 2]);
            }
            GL.End();



            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.NormalArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            //GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.Normalize);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.Disable(EnableCap.Texture2D);
        }
Esempio n. 20
0
 public void glArrayElement(int index)
 {
     GL.ArrayElement(index);
 }
Esempio n. 21
0
        public void DrawElements()
        {
            if (Colors == null)
            {
                //GL.Color3(Color[0], Color[1], Color[2]);
                if (Type == ElementType.Line)
                {
                    if (ElemPtCount == 2) // 1次要素
                    {
                        GL.DrawElements(PrimitiveType.Lines, (int)(ElemCount * ElemPtCount), DrawElementsType.UnsignedInt, Indexs);
                    }
                    else if (ElemPtCount == 3) // 2次要素
                    {
                        GL.Begin(PrimitiveType.Lines);
                        for (int iEdge = 0; iEdge < ElemCount; iEdge++)
                        {
                            GL.ArrayElement((int)Indexs[iEdge * ElemPtCount + 0]);
                            GL.ArrayElement((int)Indexs[iEdge * ElemPtCount + 2]);
                            GL.ArrayElement((int)Indexs[iEdge * ElemPtCount + 2]);
                            GL.ArrayElement((int)Indexs[iEdge * ElemPtCount + 1]);
                        }
                        GL.End();
                    }
                }
                else if (Type == ElementType.Tri || Type == ElementType.Tet)
                {
                    if (ElemPtCount == 3) // 1次要素
                    {
                        GL.DrawElements(PrimitiveType.Triangles, (int)(ElemCount * ElemPtCount), DrawElementsType.UnsignedInt, Indexs);
                    }
                    else if (ElemPtCount == 6) // 2次要素
                    {
                        GL.Begin(PrimitiveType.Triangles);
                        for (int iTri = 0; iTri < ElemCount; iTri++)
                        {
                            // 4つの三角形
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 0]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 3]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 5]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 3]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 4]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 5]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 3]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 1]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 4]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 5]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 4]);
                            GL.ArrayElement((int)Indexs[iTri * ElemPtCount + 2]);
                        }
                        GL.End();
                    }
                }
                else if (Type == ElementType.Quad || Type == ElementType.Hex)
                {
                    throw new NotImplementedException();
                }
                return;
            }

            if (Type == ElementType.Tri || Type == ElementType.Tet)
            {
                // 要素全体を塗り潰すので要素の次数に関係なく1つの三角形を描画
                GL.Begin(PrimitiveType.Triangles);
                for (int iTri = 0; iTri < ElemCount; iTri++)
                {
                    GL.Color3(
                        Colors[iTri * 3], Colors[iTri * 3 + 1], Colors[iTri * 3 + 2]);
                    // 先頭の3点は頂点
                    for (int iPt = 0; iPt < 3; iPt++)
                    {
                        GL.ArrayElement((int)Indexs[iTri * ElemPtCount + iPt]);
                    }
                }
                GL.End();
            }
            else if (Type == ElementType.Quad || Type == ElementType.Hex)
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 22
0
        public void DrawIsoLine(ref NonManifoldMesh m)
        {
            double max = double.MinValue;
            double min = double.MaxValue;

            for (int i = 0; i < m.VertexCount; i++)
            {
                if (max < m.Color[i])
                {
                    max = m.Color[i];
                }
                if (min > m.Color[i])
                {
                    min = m.Color[i];
                }
            }

            GL.ShadeModel(ShadingModel.Smooth);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            GL.Enable(EnableCap.Normalize);

            GL.EnableClientState(ArrayCap.VertexArray);

            GL.VertexPointer(3, VertexPointerType.Double, 0, m.VertexPos);
            GL.Begin(BeginMode.Triangles);

            int n = m.FaceCount;

            for (int i = 0, j = 0; i < m.FaceCount; i++, j += 3)
            {
                GL.Normal3(ref m.FaceNormal[j]);

                GL.Color3(m.Color[m.FaceIndex[j]] / max, 1 - m.Color[m.FaceIndex[j]] / max, 0);
                GL.ArrayElement(m.FaceIndex[j]);
                GL.Color3(m.Color[m.FaceIndex[j + 1]] / max, 1 - m.Color[m.FaceIndex[j + 1]] / max, 0);
                GL.ArrayElement(m.FaceIndex[j + 1]);
                GL.Color3(m.Color[m.FaceIndex[j + 2]] / max, 1 - m.Color[m.FaceIndex[j + 2]] / max, 0);
                GL.ArrayElement(m.FaceIndex[j + 2]);
            }
            GL.End();


            //GL.Begin(BeginMode.Points);


            n = m.VertexCount;
            for (int i = 0; i < n; i++)
            {
                int N = 10;
                for (int k = 1; k < N + 1; k++)
                {
                    double value = (double)k / (double)(N + 1);
                    if (Math.Abs(m.Color[i] - value) < 0.01)
                    {
                        GL.Color3(1.0, 0.0, 0.0);
                        GL.PushMatrix();
                        GL.Translate(m.VertexPos[i * 3], m.VertexPos[i * 3 + 1], m.VertexPos[i * 3 + 2]);
                        GL.Scale(0.002, 0.002, 0.002);
                        OpenGLManager.Instance.DrawSphere();
                        GL.PopMatrix();
                        //GL.ArrayElement(i);
                    }
                }
            }
            //GL.End();

            GL.DisableClientState(ArrayCap.VertexArray);
        }
Esempio n. 23
0
        public virtual void GL_DrawAliasFrameLerp(qfiles.dmdl_t paliashdr, Single backlerp)
        {
            Single l;

            qfiles.daliasframe_t frame, oldframe;
            Int32[] v, ov;
            Int32[] order;
            var     orderIndex = 0;
            Int32   count;
            Single  frontlerp;
            Single  alpha;

            Single[]   move    = new Single[] { 0, 0, 0 };
            Single[][] vectors = new Single[][] { new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 }, new Single[] { 0, 0, 0 } };
            Single[]   frontv  = new Single[] { 0, 0, 0 };
            Single[]   backv   = new Single[] { 0, 0, 0 };
            Int32      i;
            Int32      index_xyz;

            frame    = paliashdr.aliasFrames[currententity.frame];
            v        = frame.verts;
            oldframe = paliashdr.aliasFrames[currententity.oldframe];
            ov       = oldframe.verts;
            order    = paliashdr.glCmds;
            if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0)
            {
                alpha = currententity.alpha;
            }
            else
            {
                alpha = 1F;
            }
            if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)
            {
                GL.Disable(EnableCap.Texture2D);
            }
            frontlerp = 1F - backlerp;
            Math3D.VectorSubtract(currententity.oldorigin, currententity.origin, frontv);
            Math3D.AngleVectors(currententity.angles, vectors[0], vectors[1], vectors[2]);
            move[0] = Math3D.DotProduct(frontv, vectors[0]);
            move[1] = -Math3D.DotProduct(frontv, vectors[1]);
            move[2] = Math3D.DotProduct(frontv, vectors[2]);
            Math3D.VectorAdd(move, oldframe.translate, move);
            for (i = 0; i < 3; i++)
            {
                move[i]   = backlerp * move[i] + frontlerp * frame.translate[i];
                frontv[i] = frontlerp * frame.scale[i];
                backv[i]  = backlerp * oldframe.scale[i];
            }

            if (gl_vertex_arrays.value != 0F)
            {
                GL_LerpVerts(paliashdr.num_xyz, ov, v, move, frontv, backv);
                GL.EnableClientState(ArrayCap.VertexArray);
                new Pinnable(vertexArrayBuf.Array, (ptr) =>
                {
                    GL.VertexPointer(3, VertexPointerType.Float, 0, ptr);
                });
                if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)
                {
                    GL.DisableClientState(ArrayCap.ColorArray);
                    GL.Color4(shadelight[0], shadelight[1], shadelight[2], alpha);
                }
                else
                {
                    GL.EnableClientState(ArrayCap.ColorArray);
                    new Pinnable(colorArrayBuf.Array, (ptr) =>
                    {
                        GL.ColorPointer(4, ColorPointerType.Float, 0, ptr);
                    });
                    SingleBuffer color = colorArrayBuf;
                    var          j     = 0;
                    for (i = 0; i < paliashdr.num_xyz; i++)
                    {
                        l = shadedots[(v[i] >> 24) & 0xFF];
                        color.Put(j++, l * shadelight[0]);
                        color.Put(j++, l * shadelight[1]);
                        color.Put(j++, l * shadelight[2]);
                        color.Put(j++, alpha);
                    }
                }

                //if (qglLockArraysEXT)
                //    gl.GlLockArraysEXT(0, paliashdr.num_xyz);
                while (true)
                {
                    count = order[orderIndex++];
                    if (count == 0)
                    {
                        break;
                    }
                    if (count < 0)
                    {
                        count = -count;
                        GL.Begin(PrimitiveType.TriangleFan);
                    }
                    else
                    {
                        GL.Begin(PrimitiveType.TriangleStrip);
                    }

                    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)
                    {
                        do
                        {
                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;
                            GL.ArrayElement(index_xyz);
                        }while (--count != 0);
                    }
                    else
                    {
                        do
                        {
                            GL.TexCoord2(BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 0])), BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 1])));
                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;
                            GL.ArrayElement(index_xyz);
                        }while (--count != 0);
                    }

                    GL.End();
                }

                // if (qglLockArraysEXT)
                //     gl.GlUnlockArraysEXT();
            }
            else
            {
                GL_LerpVerts(paliashdr.num_xyz, ov, v, s_lerped, move, frontv, backv);
                Single[] tmp;
                while (true)
                {
                    count = order[orderIndex++];
                    if (count == 0)
                    {
                        break;
                    }
                    if (count < 0)
                    {
                        count = -count;
                        GL.Begin(PrimitiveType.TriangleFan);
                    }
                    else
                    {
                        GL.Begin(PrimitiveType.TriangleStrip);
                    }

                    if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE)) != 0)
                    {
                        do
                        {
                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;
                            GL.Color4(shadelight[0], shadelight[1], shadelight[2], alpha);
                            tmp = s_lerped[index_xyz];
                            GL.Vertex3(tmp[0], tmp[1], tmp[2]);
                        }while (--count != 0);
                    }
                    else
                    {
                        do
                        {
                            GL.TexCoord2(BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 0])), BitConverter.ToSingle(BitConverter.GetBytes(order[orderIndex + 1])));
                            index_xyz   = order[orderIndex + 2];
                            orderIndex += 3;
                            l           = shadedots[(v[index_xyz] >> 24) & 0xFF];
                            GL.Color4(l * shadelight[0], l * shadelight[1], l * shadelight[2], alpha);
                            tmp = s_lerped[index_xyz];
                            GL.Vertex3(tmp[0], tmp[1], tmp[2]);
                        }while (--count != 0);
                    }

                    GL.End();
                }
            }

            if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0)
            {
                GL.Enable(EnableCap.Texture2D);
            }
        }
Esempio n. 24
0
 public virtual void GlArrayElement(int index)
 {
     GL.ArrayElement(index);
 }