コード例 #1
0
ファイル: Input.cs プロジェクト: vtserej/3d-collision-opengl
        static public void SpecialKeyDown(int key, int x, int y)
        {
            pressed    = true;
            specialKey = key;
            switch (Glut.glutGetModifiers())
            {
            case Glut.GLUT_ACTIVE_ALT:
            {
                altKey = AltKey.Alt;
                break;
            }

            case Glut.GLUT_ACTIVE_CTRL:
            {
                altKey = AltKey.Ctrol;
                break;
            }

            case Glut.GLUT_ACTIVE_SHIFT:
            {
                altKey = AltKey.Shift;
                break;
            }

            default:
            {
                altKey = AltKey.None;
                break;
            }
            }
        }
コード例 #2
0
        static void mouse(int btn, int state, int x, int y)
        {
            switch (btn)
            {
            case Glut.GLUT_RIGHT_BUTTON:
                if (state == Glut.GLUT_DOWN)
                {
                    estado.xMouse = x;
                    estado.yMouse = y;
                    if (Glut.glutGetModifiers() == 1 & Glut.GLUT_ACTIVE_CTRL == 1)
                    {
                        Glut.glutMotionFunc(motionZoom);
                    }
                    else
                    {
                        Glut.glutMotionFunc(motionRotate);
                    }
                    Console.Write("Left down\n");
                }
                else
                {
                    Glut.glutMotionFunc(null);
                    Console.Write("Left up\n");
                }
                break;

            case Glut.GLUT_LEFT_BUTTON:
                if (state == Glut.GLUT_DOWN)
                {
                    estado.eixoTranslaccao = picking(x, y);
                    if (estado.eixoTranslaccao != -4 && estado.eixoTranslaccao < 0)
                    {
                        Glut.glutMotionFunc(motionDrag);
                    }
                    else
                    {
                        Console.Write("Right down - objecto:" + estado.eixoTranslaccao + "\n");
                    }
                }
                else
                {
                    if (estado.eixoTranslaccao != -4 && estado.eixoTranslaccao < 0)
                    {
                        estado.camera.center[0] = estado.eixo[0];
                        estado.camera.center[1] = estado.eixo[1];
                        estado.camera.center[2] = estado.eixo[2];
                        Glut.glutMotionFunc(null);
                        estado.eixoTranslaccao = -4;
                        Glut.glutPostRedisplay();
                    }
                    Console.Write("Right up\n");
                    if (estado.eixoTranslaccao >= 0)
                    {
                        Console.Write("carregou num no");
                    }
                }
                break;
            }
        }
コード例 #3
0
ファイル: RenderLayerGame.cs プロジェクト: Eule01/OpenGlGame
        public override bool OnMouse(int button, int state, int x, int y)
        {
            if (button == Glut.GLUT_LEFT_BUTTON && state == Glut.GLUT_DOWN)
            {
                MouseWorld = ConvertScreenToWorldCoords(x, y, TheCamera.ViewMatrix, projectionMatrix, TheCamera.Position,
                                                        TheRenderStatus);
                Vector3 playerMouseVec =
                    (new Vector3(MouseWorld.x, 0.0, MouseWorld.z) - TheGameStatus.ThePlayer.Location).Normalize();

                TheGameStatus.ThePlayer.Orientation = playerMouseVec;
//                TheGameStatus.ThePlayer.Orientation = new Vector(playerMouseVec.x, playerMouseVec.y);

                int mod = Glut.glutGetModifiers();
                if (mod == Glut.GLUT_ACTIVE_CTRL)
                {
                    TheSceneManager.TileSelected(MouseWorld);
                }
            }
            else if (button == Glut.GLUT_RIGHT_BUTTON)
            {
                // this method gets called whenever a new mouse button event happens
                mouseDown = (state == Glut.GLUT_DOWN);

                // if the mouse has just been clicked then we hide the cursor and store the position
                if (mouseDown)
                {
                    Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);
                    prevX = downX = x;
                    prevY = downY = y;
                }
                else // unhide the cursor if the mouse has just been released
                {
                    Glut.glutSetCursor(Glut.GLUT_CURSOR_LEFT_ARROW);
                    Glut.glutWarpPointer(downX, downY);
                }
            }
            return(true);
        }
コード例 #4
0
        /**
         * kutsutaan jos hiiren nappi pohjassa liikutetaan hiirtä
         */
        private void mouseMotion(int x, int y)
        {
            if (mode == 0)
            {
                return;
            }
            if (mode != 4 && tmpObj == null)
            {
                return;
            }

            if (mode != 4)
            {
                Gl.glTranslatef(((Layer)layers[selectedLayer]).sx, ((Layer)layers[selectedLayer]).sy, 0);
                x -= (int)((Layer)layers[selectedLayer]).sx;
                y -= (int)((Layer)layers[selectedLayer]).sy;
            }

            if (tmpObj != null)
            {
                tmpObj.render(true);
            }

            int mod = Glut.glutGetModifiers();

            if (mod == Glut.GLUT_ACTIVE_CTRL)
            {
                ctrl = true;
            }
            else
            {
                ctrl = false;
            }


            switch (mode)
            {
            case 1:                             //drawLine:
                if (ctrl)                       // jos ctrl pohjassa, piirrä suora viiva, muuten lisää piste
                {
                    ((Line)tmpObj).setXY(x, y); // viivan loppukoordinaatit on hiiren koordinaatit
                }
                else
                {
                    tmpObj.add(x, y);
                    ((Line)tmpObj).setXY(-1, -1);
                }
                break;

            // x1y1 -> x2y2
            case 2:                     //drawRect:
                ((Rect)tmpObj).calcWH(x, y);

                break;

            // keskipiste ja säde
            case 3:                     //drawCircle:
                if (ctrl)               // jos ctrl pohjassa, piirrä ellipsi, muuten ympyrä
                {
                    ((Circle)tmpObj).calcXY(x, y);
                }
                else
                {
                    ((Circle)tmpObj).calcR(x, y);                     // laske säde
                }
                break;

            case 4:                     // layerin liikutus
                int xx = mx - x;
                int yy = my - y;
                ((Layer)layers[selectedLayer]).setXY(-xx, -yy);
                updateAll();
                break;
            }

            invert = !invert;
        }