Exemplo n.º 1
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();          
        }