コード例 #1
0
        public void addLine()
        {
            if (Form1.currentX0 != null && Form1.currentY0 != null && Form1.currentZ0 != null)
            {
                if (prevX != null)
                {
                    if (Form1.currentX0 != prevX || Form1.currentY0 != prevY || Form1.currentZ0 != prevZ)
                    {
                        line temp = new line(Form1.currentX0.Value, Form1.currentY0.Value, Form1.currentZ0.Value, prevX.Value, prevY.Value, prevZ.Value);
                        lineList.Add(temp);
                    }
                }

                prevX = Form1.currentX0;
                prevY = Form1.currentY0;
                prevZ = Form1.currentZ0;
            }
        }
コード例 #2
0
        public void draw()
        {
            if (Form1.currentX0 != null && Form1.currentY0 != null && Form1.currentZ0 != null)
            {
                Yoff = (float)Form1.currentY0 - 129.9f;
                Xoff = (float)Form1.currentX0 - 289.9f;
                Zoff = -(float)Form1.currentZ0 + 140f;
            }

            addLine();
            removePoint();
            checkVol();

            //GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            displayBackground();

            float far = 800, near = 50f;



            OpenTK.Matrix4 RTMat = new OpenTK.Matrix4(
                rotateArr[0], rotateArr[1], rotateArr[2], translateArr[0],
                rotateArr[3], rotateArr[4], rotateArr[5], translateArr[1],
                rotateArr[6], rotateArr[7], rotateArr[8], translateArr[2],
                0, 0, 0, 1);

            OpenTK.Matrix4 reverse = new OpenTK.Matrix4(
                1, 0, 0, 0,
                0, -1, 0, 0,
                0, 0, -1, 0,
                0, 0, 0, 1);

            //not sure if needed
            OpenTK.Matrix4 landscape = new OpenTK.Matrix4(
                0, 1, 0, 0,
                -1, 0, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1);

            OpenTK.Matrix4 projection = new OpenTK.Matrix4(
                2 * cameraPar[0] / 816f, 0, 1 - (2 * cameraPar[2] / 816f), 0,
                0, 2 * cameraPar[4] / 612f, -1 + (2 * cameraPar[5] + 2) / 612f, 0,
                0, 0, -(far + near) / (far - near), -2 * far * near / (far - near),
                0, 0, -1, 0);

            OpenTK.Matrix4 projT = new OpenTK.Matrix4(
                2 * cameraPar[0] / 816f, 0, 1 - (2 * cameraPar[2] / 816f), 0,
                0, 2 * cameraPar[4] / 612f, -1 + (2 * cameraPar[5] + 2) / 612f, 0,
                0, 0, -(far + near) / (far - near), -2 * far * near / (far - near),
                0, 0, -1, 0);

            projT.Transpose();
            OpenTK.Matrix4 mvMat    = OpenTK.Matrix4.Mult(reverse, RTMat);
            OpenTK.Matrix4 projMat2 = OpenTK.Matrix4.Mult(landscape, projection);
            OpenTK.Matrix4 mvp      = OpenTK.Matrix4.Mult(projection, mvMat);


            // render graphics

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(ref projT.Row0.X);

            mvMat.Transpose();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.LoadMatrix(ref mvMat.Row0.X);


            /*
             * GL.LineWidth(2.5f);
             * GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
             * GL.Color3(Color.Green);
             * GL.Begin(PrimitiveType.Lines);
             * GL.Vertex3(0, 0, 0);
             * GL.Vertex3(0, 0, 100);
             *
             * GL.End();
             *
             * GL.Color3(Color.Aqua);
             * GL.Begin(PrimitiveType.Lines);
             * GL.Vertex3(0, 0, 0);
             * GL.Vertex3(0, 31, 0);
             *
             *
             * GL.Color3(Color.Yellow);
             * GL.Begin(PrimitiveType.Lines);
             * GL.Vertex3(31, 0, 0);
             * GL.Vertex3(0, 0, 0);
             *
             * GL.End();
             */


            if (camInit == true)
            {
                if (Form1.axisDisplay)
                {
                    if (Form1.currentX0 != null && Form1.currentY0 != null && Form1.currentZ0 != null)
                    {
                        GL.LineWidth(5.5f);
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                        GL.Color3(.99f, 0.1f, 0.1f);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(Xoff, Yoff, Zoff);
                        GL.Vertex3(Xoff, Yoff, Zoff + 93);

                        GL.End();

                        GL.Color3(0.1f, 0.99f, 0.1f);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(Xoff, Yoff, Zoff);
                        GL.Vertex3(Xoff - 93, Yoff, Zoff);


                        GL.Color3(.1f, 0.1f, 0.99f);
                        GL.Begin(PrimitiveType.Lines);

                        GL.Vertex3(Xoff, Yoff, Zoff);
                        GL.Vertex3(Xoff, Yoff - 93, Zoff);

                        GL.End();
                    }
                }


                if (Form1.physicalToolpath)
                {
                    foreach (line ln in lineList)
                    {
                        GL.LineWidth(2.5f);
                        GL.Color3(Color.Blue);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(-ln.startX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -ln.startY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (ln.startZ - Form1.currentZ0.Value + 140 - toolZoff));
                        GL.Vertex3(-ln.endX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -ln.endY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (ln.endZ - Form1.currentZ0.Value + 140 - toolZoff));

                        GL.End();
                    }
                }

                if (Form1.tooltipDisplay)
                {
                    GL.LineWidth(20f);
                    line Drill = new line(Form1.currentX0.Value, Form1.currentY0.Value, Form1.currentZ0.Value, Form1.currentX0.Value, Form1.currentY0.Value, Form1.currentZ0.Value + 50);
                    GL.Color3(Color.Silver);
                    GL.Begin(PrimitiveType.Lines);
                    GL.Vertex3(-Drill.startX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -Drill.startY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (Drill.startZ - Form1.currentZ0.Value + 140 - toolZoff));
                    GL.Vertex3(-Drill.endX + Form1.currentX0.Value + 188 + toolXoff - 289.9, -Drill.endY + Form1.currentY0.Value + toolYoff + 50 - 129.9, (Drill.endZ - Form1.currentZ0.Value + 140 - toolZoff));

                    GL.End();
                }


                GL.Enable(EnableCap.DepthTest);
                GL.DepthFunc(DepthFunction.Lequal);

                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                GL.Enable(EnableCap.Blend);

                if (Form1.badVolDisplay)
                {
                    foreach (badVolume badVol in badVolumes)
                    {
                        Color a = Color.FromArgb(160, 255, 0, 0);
                        Color b = Color.FromArgb(160, 225, 25, 25);
                        Color c = Color.FromArgb(160, 195, 50, 50);
                        Color d = Color.FromArgb(160, 225, 25, 25);

                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.Quads);
                        GL.Color4(a);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(b);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Color4(c);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Color4(d);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        Color black = Color.FromArgb(0, 0, 0);
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                        GL.Color4(black);
                        GL.LineWidth(1.2f);


                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMax + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.Begin(PrimitiveType.LineLoop);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMin + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMax + Yoff - 50, badVol.zMax + Zoff);
                        GL.Vertex3(badVol.xMin + Xoff - 180, badVol.yMin + Yoff - 50, badVol.zMax + Zoff);
                        GL.End();

                        GL.End();
                    }
                }



                GL.LineWidth(1.8f);



                if (Form1.matRemove)
                {
                    wp.draw();
                    wp.draw2();
                }



                if (Form1.cadModel)
                {
                    Color black = Color.FromArgb(0, 0, 0);


                    Color a = Color.FromArgb(160, 119, 136, 153);
                    Color b = Color.FromArgb(160, 112, 138, 144);
                    Color c = Color.FromArgb(160, 49, 79, 79);



                    GL.LineWidth(1.0f);
                    foreach (stlObj obj in objects)
                    {
                        object[] facetArray = obj.facets.ToArray();
                        for (int i = 0; i < obj.facetNum - 1; i++)
                        {
                            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);

                            Object fcet = (facet)facetArray[i];
                            GL.Begin(PrimitiveType.Triangles);
                            facet fct = (facet)fcet;

                            if (Form1.currentX0 != null && Form1.currentY0 != null && Form1.currentZ0 != null)
                            {
                                GL.Color4(a);
                                GL.Vertex3(-fct.points[0].x + Xoff, -fct.points[0].y + Yoff, fct.points[0].z + Zoff);
                                GL.Color4(b);
                                GL.Vertex3(-fct.points[1].x + Xoff, -fct.points[1].y + Yoff, fct.points[1].z + Zoff);
                                GL.Color4(c);
                                GL.Vertex3(-fct.points[2].x + Xoff, -fct.points[2].y + Yoff, fct.points[2].z + Zoff);

                                GL.End();
                            }
                            else
                            {
                                GL.Color4(a);
                                GL.Vertex3(-fct.points[0].x, -fct.points[0].y, fct.points[0].z);
                                GL.Color4(b);
                                GL.Vertex3(-fct.points[1].x, -fct.points[1].y, fct.points[1].z);
                                GL.Color4(c);
                                GL.Vertex3(-fct.points[2].x, -fct.points[2].y, fct.points[2].z);

                                GL.End();
                            }

                            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                            GL.Color4(black);
                            GL.Begin(PrimitiveType.LineLoop);

                            GL.Vertex3(-fct.points[0].x + Xoff, -fct.points[0].y + Yoff, fct.points[0].z + Zoff);
                            GL.Vertex3(-fct.points[1].x + Xoff, -fct.points[1].y + Yoff, fct.points[1].z + Zoff);
                            GL.Vertex3(-fct.points[2].x + Xoff, -fct.points[2].y + Yoff, fct.points[2].z + Zoff);

                            GL.End();
                        }
                    }
                }



                GL.Disable(EnableCap.Blend);
            }

            glControl1.Refresh();// redraws and updates



            glControl1.SwapBuffers();
        }