示例#1
0
        public static void Trans3D(SharpGL.OpenGL gl_object, int x, int y)
        {
            //Console.Write(_RoX + ", " + _RoY + ", " + " => ");

            //	Create an array that will be the viewport.
            //3D顯示大小
            int[] viewport = new int[4];
            //	Get the viewport, then convert the mouse point to an opengl point.
            gl_object.GetInteger(OpenGL.GL_VIEWPORT, viewport);
            double[] modelview = new double[16];
            gl_object.GetDouble(OpenGL.GL_MODELVIEW_MATRIX, modelview);
            double[] projection = new double[16];
            gl_object.GetDouble(OpenGL.GL_PROJECTION_MATRIX, projection);

            float winX, winY;
            winX = (x - viewport[2] / 2);
            winY = (y - viewport[3] / 2); //與範例不同的是 圖形原點是左上角
            //Console.Write(winX + ", " + winY + ", " + " => ");

            //(posX, posY, posZ) 轉換之前的座標
            /* double[] posX = new double[4];
             double[] posY = new double[4];
             double[] posZ = new double[4];*/
            double posX = new double();
            double posY = new double();
            double posZ = new double();
            gl_object.UnProject(x, y, 0, modelview, projection, viewport, ref posX, ref posY, ref posZ);

            isNav = 1;
            if (_RoX >= 165 && _RoX <= 200)
            {
                //if (winX * posX[0] < 0 && winY * posY[0] < 0) isNav = -1;
                if (winX * posX < 0 && winY * posY < 0) isNav = -1;
            }
            else if (_RoX >= 45 && _RoX <= 315)
            {
                //if (winX * posX[0] > 0) isNav = -1;
                if (winX * posX > 0) isNav = -1;
            }
            return;
        }