Ejemplo n.º 1
0
    public bool Render()
    {
        LightFireCS.MessageHandler.Get().ProcessEvents();

        if (InputDevice.GetKeyState(Tao.Sdl.Sdl.SDLK_ESCAPE))
        {
            GDevice.Quit();
        }

        int mouseX, mouseY;

        InputDevice.GetMousePos(out mouseX, out mouseY);

        GDevice.BeginRender();
        GDevice.SetPerspectiveView();
        Cam.UpdateCamera();

        Gl.glPushMatrix();
        Gl.glScaled(0.01, 0.01, 0.01);

        if (InputDevice.GetMouseButtonState(0))
        {
            Vector3  pos, dir;
            double[] hit;
            GDevice.RayFromPoint(mouseX, mouseY, out pos, out dir);

            foreach (Chessman cm in chessman)
            {
                BoundingBox cmbb = cm.GetBoundingBox();
                if (cmbb != null && Intersection.RayBoundingBox(pos, dir, cmbb, out hit))
                {
                    if ((cm.White && activeColor == "w") || (!cm.White && activeColor == "b"))
                    {
                        chessmanInHand = cm;
                        Console.WriteLine("Hit. x:{0} y:{1}", cm.X, cm.Y);
                    }
                    else
                    {
                        Console.WriteLine("Hit Wrong Color. x:{0} y:{1}", cm.X, cm.Y);
                    }
                }
            }
        }

        /*Gl.glColorMask(Gl.GL_FALSE, Gl.GL_FALSE, Gl.GL_FALSE, Gl.GL_FALSE);
         * Gl.glDepthMask(Gl.GL_FALSE);
         * Gl.glEnable(Gl.GL_STENCIL_TEST);
         * Gl.glStencilFunc(Gl.GL_ALWAYS, 1, 0xFFFFFFFF);
         * Gl.glStencilOp(Gl.GL_REPLACE, Gl.GL_REPLACE, Gl.GL_REPLACE);
         * RenderBoard();
         *
         * // reflektion nur im bereich
         * Gl.glColorMask(Gl.GL_TRUE, Gl.GL_TRUE, Gl.GL_TRUE, Gl.GL_TRUE);
         * Gl.glDepthMask(Gl.GL_TRUE);
         * Gl.glStencilFunc(Gl.GL_EQUAL, 1, 0xFFFFFFFF);
         * Gl.glStencilOp(Gl.GL_KEEP, Gl.GL_KEEP, Gl.GL_KEEP);
         *
         * Gl.glPushMatrix();
         * Gl.glScaled(1.0, -1.0, 1.0);
         * foreach(Chessman cm in chessman)
         *      cm.Render();
         * Gl.glPopMatrix();*/

        RenderBoard();

        foreach (Chessman cm in chessman)
        {
            if (chessmanInHand == cm)
            {
                Gl.glColor3ub(0, 255, 0);
            }
            cm.Render(Cam);
            if (!cm.Killed)
            {
                cm.GetBoundingBox().Render();
            }
            if (chessmanInHand == cm)
            {
                Gl.glColor3ub(255, 255, 255);
            }
        }

        if (chessmanInHand != null)
        {
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if (chessmanInHand != null && chessmanInHand.moveTo[x, y])
                    {
                        Gl.glColor3ub(0, 255, 0);
                        arrow.MoveTo(x + 1, y + 1);
                        arrow.Render(Cam);
                        Gl.glColor3ub(255, 255, 255);
                        if (InputDevice.GetMouseButtonState(0))
                        {
                            Vector3  pos, dir;
                            double[] hit;
                            GDevice.RayFromPoint(mouseX, mouseY, out pos, out dir);
                            if (Intersection.RayBoundingBox(pos, dir, arrow.GetBoundingBox(), out hit))
                            {
                                if (MoveFigure(chessmanInHand.X, chessmanInHand.Y, x + 1, y + 1))
                                {
                                    chessmanInHand = null;
                                }
                            }
                        }
                    }
                }
            }
        }

        Gl.glPopMatrix();
        GDevice.EndRender();

        return(GDevice.IsRunning);
    }