Beispiel #1
0
        private static void FullscreenMode()
        {
            int oldX      = 50;
            int oldY      = 50;
            int oldWidth  = 320;
            int oldHeight = 320;

            if (screensaver)
            {
                Glut.glutKeyboardFunc(new Glut.KeyboardCallback(ScreensaverKeyboard));
                Glut.glutPassiveMotionFunc(new Glut.PassiveMotionCallback(ScreensaverPassive));
                Glut.glutMouseFunc(new Glut.MouseCallback(ScreensaverMouse));
            }
            else
            {
                Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            }
            Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);

            oldX      = Glut.glutGet(Glut.GLUT_WINDOW_X);
            oldY      = Glut.glutGet(Glut.GLUT_WINDOW_Y);
            oldWidth  = Glut.glutGet(Glut.GLUT_WINDOW_WIDTH);
            oldHeight = Glut.glutGet(Glut.GLUT_WINDOW_HEIGHT);

            Glut.glutFullScreen();
        }
Beispiel #2
0
 private static void OnMouseMoves(int button, int state, int x, int y)
 {
     if (button == Glut.GLUT_RIGHT_BUTTON)
     {
         // this method gets called whenever a new mouse button event happens
         rightmouseDown = (state == Glut.GLUT_DOWN);
         // if the mouse has just been clicked then we hide the cursor and store the position
         if (rightmouseDown)
         {
             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);
         }
     }
     if (button == Glut.GLUT_LEFT_BUTTON)
     {
         leftmouseDown = (state == Glut.GLUT_DOWN);
         if (leftmouseDown)
         {
             Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);
             prevX = downX = x;
             prevY = downY = y;
         }
         else
         {
             Glut.glutSetCursor(Glut.GLUT_CURSOR_LEFT_ARROW);
         }
     }
 }
Beispiel #3
0
 private static void WindowedMode()
 {
     Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
     Glut.glutPassiveMotionFunc(null);
     Glut.glutMouseFunc(null);
     Glut.glutSetCursor(Glut.GLUT_CURSOR_INHERIT);
     Glut.glutPositionWindow(50, 50);
     Glut.glutReshapeWindow(320, 320);
 }
Beispiel #4
0
        private static void OnMouse(int button, int state, int x, int y)
        {
            // this method gets called whenever a new mouse button event happens
            if (button == Glut.GLUT_RIGHT_BUTTON) 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);
                downX = x;
                downY = y;
            }
            else // unhide the cursor if the mouse has just been released
                Glut.glutSetCursor(Glut.GLUT_CURSOR_LEFT_ARROW);
        }
Beispiel #5
0
        private static void OnMouse(int button, int state, int x, int y)
        {
            if (button != Glut.GLUT_RIGHT_BUTTON)
            {
                return;                            //Nic sie nie dzieje jak przycisk nie jest nacisniety
            }
            mouseDown = (state == Glut.GLUT_DOWN); //pobieranie stanu czy przycisk jest wcisniety

            if (mouseDown)
            {
                Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE); //Ukrywanie kursora podczas gdy mouseDown == true
                prevX = downX = x;                         //Nadanie wartosci prevX i downX
                prevY = downY = y;                         //Nadanie wartosci prevY i downY
            }
            else
            {
                Glut.glutSetCursor(Glut.GLUT_CURSOR_LEFT_ARROW); //Przywrocenie przycisku
                Glut.glutWarpPointer(downX, downY);              //zamiana lokalizacji kursora
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("Input the number of levels to recurse. Must be greater than or equal to zero.\r\n" +
                                      "Mouse to look and WASD to move. Hold R to run. F to toggle fullscreen.\r\n" +
                                      "O to toggle between walking and flying. When flying, use E/Q to ascend/descend.");
                    if ((levelNum = Convert.ToInt32(Console.ReadLine())) >= 0)
                    {
                        break;
                    }
                }
                catch
                {
                    Console.WriteLine("Please input an integer greater than or equal to zero.");
                }
            }

            // init GLUT and create window
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);   // multisampling purportedly "makes things beautiful!"
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("Fractal");

            // register main loop callbacks
            Glut.glutDisplayFunc(renderScene);
            Glut.glutIdleFunc(idle);
            Glut.glutCloseFunc(onClose);

            //register resize callback
            Glut.glutReshapeFunc(OnReshape);

            // register keyboard callbacks
            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            // register mouse callbacks
            Glut.glutMotionFunc(OnMove);
            Glut.glutPassiveMotionFunc(OnMove);

            //hide mouse
            Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);

            //enable depth testing
            Gl.Enable(EnableCap.DepthTest);

            //enable alpha blending
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //compile shader
            program = new ShaderProgram(VertexShader, FragmentShader);

            //make a camera
            camera = new Camera(new Vector3(0, 0, 0), Quaternion.Identity); //set the camera starting location here
            camera.SetDirection(new Vector3(0, 0, -1));

            // set the view and projection matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.90f, (float)width / height, 0.01f, 1000f));

            program["light_direction"].SetValue(new Vector3(-0.3f, -0.8f, -0.7f));  //pink
            program["light2_direction"].SetValue(new Vector3(0.7f, -0.8f, 0.3f));   //cyan
            program["light3_direction"].SetValue(new Vector3(0.3f, -0.8f, 0.7f));   //celadon
            program["light4_direction"].SetValue(new Vector3(-0.7f, -0.8f, -0.3f)); //yellow
            program["enable_lighting"].SetValue(lighting);

            //set background color
            Gl.ClearColor(0.99f, 0.93f, 0.85f, 1f);

            // load each block's model and decomposition rule from files and add to blockRef
            int fCount = Directory.GetFiles("assets", "*", SearchOption.TopDirectoryOnly).Length;

            for (int n = 0; n < fCount / 2; ++n)
            {
                List <Vector3> indexVertices = new List <Vector3>();
                List <Vector3> indexNormals  = new List <Vector3>();
                List <Vector3> vertices      = new List <Vector3>();
                List <Vector3> normals       = new List <Vector3>();
                List <Vector3> edgeVertices  = new List <Vector3>();

                StreamReader sr = new StreamReader("assets/" + n.ToString() + ".txt");
                while (!sr.EndOfStream)
                {
                    string[] fields = sr.ReadLine().Split();
                    if (fields[0] == "v") //a vertex
                    {
                        Vector3 vertex = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                        indexVertices.Add(vertex);
                    }
                    else if (fields[0] == "vn") //a vertex normal
                    {
                        Vector3 normal = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                        indexNormals.Add(normal);
                    }
                    else if (fields[0] == "f") //a face
                    {
                        for (int i = 1; i < fields.Length; ++i)
                        {
                            string[] indices = fields[i].Split('/');
                            vertices.Add(indexVertices[Convert.ToInt32(indices[0]) - 1]);
                            normals.Add(indexNormals[Convert.ToInt32(indices[2]) - 1]);
                        }
                    }
                    else if (fields[0] == "l") //an edge
                    {
                        edgeVertices.Add(indexVertices[Convert.ToInt32(fields[1]) - 1]);
                        edgeVertices.Add(indexVertices[Convert.ToInt32(fields[2]) - 1]);
                    }
                }
                sr.Close();

                //create the block object
                Block newBlock = new Block();
                newBlock.position     = new Vector3(0, 0, 0);
                newBlock.yOrientation = 0;
                newBlock.scale        = new Vector3(1, 1, 1);
                newBlock.ID           = n;

                //fill the block object with data loaded from .obj above
                newBlock.verticeData = vertices.ToArray();
                newBlock.normalData  = normals.ToArray();

                newBlock.edgeVerticeData = edgeVertices.ToArray();

                blockRef.Add(newBlock);

                //load the decomposition rule for this block
                List <DecompBlock> newDRule = new List <DecompBlock>();
                float scaleConst            = 1;
                float unitConst             = 1;

                sr = new StreamReader("assets/" + n.ToString() + "rule.txt");
                while (!sr.EndOfStream)
                {
                    string[] fields = sr.ReadLine().Split();
                    if (fields[0] != "#") //check its not a comment
                    {
                        if (fields[0] == "!")
                        {
                            //setting scale down values. e.g. if set to 1/3 and 2/3, each new block would be scaled down
                            //by 1/3, and each 1 unit offset written in the rule file would be scaled to move the block 2/3 units instead.
                            //default 1 and 1: no scaling applied.
                            scaleConst = Convert.ToSingle(fields[1]);
                            unitConst  = Convert.ToSingle(fields[2]);
                        }
                        else
                        {
                            //load in fields
                            DecompBlock newDBlock = new DecompBlock();
                            newDBlock.ID             = Convert.ToInt32(fields[0]);
                            newDBlock.posOffset      = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                            newDBlock.xAngleOffset   = Convert.ToSingle(fields[4]);
                            newDBlock.extraScale     = new Vector3(1, 1, 1);
                            newDBlock.unitScaleConst = unitConst;
                            newDBlock.scaleDownConst = scaleConst;
                            if (fields.Length > 5)
                            {
                                newDBlock.extraScale = new Vector3(Convert.ToInt32(fields[5]), Convert.ToInt32(fields[6]), Convert.ToInt32(fields[7]));
                            }

                            //add block to rule
                            newDRule.Add(newDBlock);
                        }
                    }
                }
                sr.Close();

                decompRules.Add(newDRule);
            }

            Block seedBlock = blockRef[0];

            blocks = Decompose(seedBlock, levelNum);

            //merge all vertices and normals into a an interleaved vbo
            List <Vector3> preVertices = new List <Vector3>();
            List <Vector3> preNormals  = new List <Vector3>();
            List <Vector3> preEdges    = new List <Vector3>();

            foreach (Block block in blocks)
            {
                foreach (Vector3 point in block.verticeData)
                {
                    Vector4 preVertex = (new Vector4(point, 1)
                                         * Matrix4.CreateScaling(block.scale)
                                         * Matrix4.CreateRotationY(block.yOrientation)
                                         + new Vector4(block.position, 1));
                    preVertices.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2)));
                }

                foreach (Vector3 normal in block.normalData)
                {
                    Vector4 preNormal = (new Vector4(normal, 1)
                                         * Matrix4.CreateScaling(new Vector3(Math.Sign(block.scale[0]),
                                                                             Math.Sign(block.scale[1]),
                                                                             Math.Sign(block.scale[2])))
                                         * Matrix4.CreateRotationY(block.yOrientation));

                    preNormals.Add(new Vector3(Convert.ToSingle(Math.Round(preNormal.Get(0))),
                                               Convert.ToSingle(Math.Round(preNormal.Get(1))),
                                               Convert.ToSingle(Math.Round(preNormal.Get(2)))));
                }

                foreach (Vector3 point in block.edgeVerticeData)
                {
                    Vector4 preVertex = (new Vector4(point, 1)
                                         * Matrix4.CreateScaling(block.scale)
                                         * Matrix4.CreateRotationY(block.yOrientation)
                                         + new Vector4(block.position, 1));
                    preEdges.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2)));
                }
            }

            //exportOBJ(preVertices, preNormals); //exports fractal if left uncommented

            drawVertices = new VBO <Vector3>(preVertices.ToArray());
            drawNormals  = new VBO <Vector3>(preNormals.ToArray());
            drawEdges    = new VBO <Vector3>(preEdges.ToArray());

            List <uint> drawOrder = new List <uint>();

            for (int x = 0; x < preVertices.Count; ++x)
            {
                drawOrder.Add(Convert.ToUInt32(x));
            }
            drawElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer);

            drawOrder.Clear();
            for (int x = 0; x < preEdges.Count; ++x)
            {
                drawOrder.Add(Convert.ToUInt32(x));
            }
            drawEdgeElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer);

            watch = System.Diagnostics.Stopwatch.StartNew();

            // enter GLUT event processing cycle
            Glut.glutMainLoop();
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fullscreen"></param>
        public void executar()
        {
            AppState.Instance.setLanguage(AppState.Instance.Language);

            #region Inicializações Glut
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGBA | Glut.GLUT_DEPTH);

            if (AppState.Instance.Fullscreen)
            {
                Glut.glutGameModeString(AppState.Instance.Width + "x" + AppState.Instance.Height + ":32");

                if (Glut.glutGameModeGet(Glut.GLUT_GAME_MODE_POSSIBLE) == 1)
                {
                    Glut.glutEnterGameMode();
                    Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);
                }
                else
                {
                    System.Environment.Exit(0);
                }
            }
            else
            {
                Glut.glutInitWindowSize(AppState.Instance.Width, AppState.Instance.Height);
                Glut.glutCreateWindow(Settings.Default.ApplicationName + "-" + Settings.Default.VersionNumber);
            }
            #endregion

            #region Inicializações OpenGL
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glShadeModel(Gl.GL_SMOOTH);

            Gl.glEnable(Gl.GL_POINT_SMOOTH);
            Gl.glEnable(Gl.GL_LINE_SMOOTH);

            Gl.glEnable(Gl.GL_POLYGON_SMOOTH);
            Gl.glEnable(Gl.GL_TEXTURE_2D);

            Gl.glEnable(Gl.GL_NORMALIZE);

            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glEnable(Gl.GL_AUTO_NORMAL);
            //Gl.glEnable(Gl.GL_CULL_FACE);

            Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            #endregion

            Camera cam = new Camera();
            cam.IsActive  = true;
            cam.Following = (ThreeDObject)this.ActiveTourist;
            Camera.CameraList.Add(cam);

            this.Renderer.Atmosphere = this.AtmosphericConditions;

            #region Inicialização do DevIL, Alut e bibliotecas associadas
            Il.ilInit();
            Ilut.ilutInit();
            Ilut.ilutRenderer(Ilut.ILUT_OPENGL);

            Alut.alutInit();
            #endregion

            #region Carregar os Recursos

            Console.WriteLine(AppState.Instance.ResourceManager.GetString("LoadingTextures"));
            Assets.Instance.loadTextures();

            Console.WriteLine(AppState.Instance.ResourceManager.GetString("Loading3DS"));
            Assets.Instance.loadModels();

            Console.WriteLine(AppState.Instance.ResourceManager.GetString("LoadingSounds"));
            Assets.Instance.loadSounds();

            #endregion

            #region Skybox
            Skybox skybox = new Skybox();
            skybox.createDisplayList();
            this.Renderer.ObjectosCena.Add(skybox);
            #endregion

            #region Terreno
            Terrain terreno = new Terrain();
            terreno.createDisplayList();
            this.Renderer.ObjectosCena.Add(terreno);
            #endregion

            #region Sol
            Sun sol = new Sun();
            this.Renderer.IluminacaoCena.Add(sol);
            #endregion

            #region Carregamento dos Dados obtidos atrávés do WebService
            this.Ws.loadTour(ref this.tour);
            this.Ws.loadCartography(ref this.cartography, this.tour.cityID);
            AppState.Instance.CurrentDate = this.tour.begin;
            #endregion

            #region Adicionar Elementos "Colidíveis"
            foreach (PointOfInterest p in this.Cartography.pointsOfInterest)
            {
                this.collidible.Add(p);
            }

            foreach (GenericObject go in this.Cartography.genericObjects)
            {
                if (go is RandomBuilding)
                {
                    this.collidible.Add(go);
                }
            }
            #endregion

            #region Adicionar Elementos Visitáveis
            PointOfInterest poi;
            foreach (ToVisit t in this.CurrentTour.toVisit)
            {
                poi = this.Cartography.getPointOfInterestWithID(t.attractionID);

                poi.ToVisit = true;
                poi.Visited = t.visited;
            }
            #endregion

            #region Ajustes à Área de Colisão dos Modelos
            String[] adjustment;
            String[] dimensions;
            foreach (PointOfInterest col in this.Cartography.pointsOfInterest)
            {
                adjustment = ModelSettings.Default[col.ModelName + "Adjustment"].ToString().Split('|');
                col.ColisionArea.Adjustment.set(Double.Parse(adjustment[0]), Double.Parse(adjustment[1]), Double.Parse(adjustment[2]));

                dimensions = ModelSettings.Default[col.ModelName + "Dimensions"].ToString().Split('|');
                col.ColisionArea.Dimensions.set(Double.Parse(dimensions[0]), Double.Parse(dimensions[1]), Double.Parse(dimensions[2]));

                col.SoundName            = ModelSettings.Default[col.ModelName + "SoundName"].ToString();
                col.ColisionArea.Visible = true;
            }
            #endregion

            #region Turista
            this.ActiveTourist.ModelName = "Turista";
            this.ActiveTourist.setPosicao(20.0, -0.9, 0.0);

            this.ActiveTourist.SoundName = "HeroStep3";
            this.ActiveTourist.setSoundPosition();
            this.Renderer.ObjectosCena.Add(this.ActiveTourist);
            #endregion

            //  TODO: Cria uma propriedade para isto
            new Ambiente().definirProperiedades();

            Glut.glutDisplayFunc(new Glut.DisplayCallback(this.Renderer.render));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(this.Input.tecladoNormal));
            Glut.glutKeyboardUpFunc(new Glut.KeyboardUpCallback(this.Input.tecladoNormalUp));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(this.Renderer.redimensionar));
            Glut.glutSpecialFunc(new Glut.SpecialCallback(this.Input.tecladoEspecial));

            Glut.glutTimerFunc(30, new Glut.TimerCallback(this.timer), 0);

            this.createPopupMenus();

            if (this.CurrentTour.toVisit.Count > 0)
            {
                Messaging.Instance.Permanent.Add(AppState.Instance.ResourceManager.GetString("ToVisitLabel") + ":");

                foreach (ToVisit tv in this.CurrentTour.toVisit)
                {
                    poi = this.Cartography.getPointOfInterestWithID(tv.attractionID);

                    if (poi.ToVisit && !poi.Visited)
                    {
                        Messaging.Instance.Permanent.Add("- " + poi.Nome);
                    }
                    else
                    {
                        Messaging.Instance.Permanent.Add("- " + poi.Nome + " (" + AppState.Instance.ResourceManager.GetString("VisitedLabel") + ")");
                    }
                }
            }
            else
            {
                Messaging.Instance.Permanent.Add(AppState.Instance.ResourceManager.GetString("NoPOIsToVisit"));
            }


            #region Inicializar Música Ambiente
            this.SoundManager.switchAmbientMusicTo("MusicaAmbiente1");
            #endregion

            this.Renderer.Map = this.Cartography;

            Glut.glutMainLoop();
        }