Exemplo n.º 1
0
        protected override void Initialize()
        {
            camera = new Camera(this, new Vector3(0, 30, 0), Vector3.Zero);
            camera.Initialize();

            ArcheryGame.Services.Initialize(this, GraphicsDevice, camera);

            terrain = new TerrainGenerator(this, "sand", "grass", "stone", "heightmap4");
            terrain.Initialize();
            terrain.GenerateWall();

            archer = new Archer(this, new Vector3(15, 30, -15), Vector3.Zero, 10, terrain);
            archer.Initialize();

            sky = new Skydome(this);
            sky.Initialize();

            target = new Target(this, new Vector3(20, 15, -20));
            target.Initialize();

            effect = new BasicEffect(graphics.GraphicsDevice);

            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), graphics.GraphicsDevice.Viewport.AspectRatio, 1f, 1000f);
            viewMatrix       = camera.View;
            worldMatrix      = Matrix.Identity;

            base.Initialize();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            m_camera = new Camera(this);
            Components.Add(m_camera);

            m_stats = new Statistics(this, Content);
            Components.Add(m_stats);

            // Load the generated skydome
            m_dome = new Skydome(this, Content);
            Components.Add(m_dome);

            m_terrain = new Terrain(this, Content);
            Components.Add(m_terrain);

            m_console = new Console(this);
            Components.Add(m_console);

            base.Initialize();
        }
Exemplo n.º 3
0
 public SkydomeController(MainForm topform, Skydome item) : base(topform, item)
 {
     Data = item;
     AddMenu("Open skydome viewer", Menu_OpenViewer);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor for the WorldViewScreen
        /// </summary>
        public WorldViewScreen(Game game, ScreenElement previousScreenElement) :
            base(previousScreenElement, game.GraphicsDevice)
        {
            this.content = game.Content;
            this.game    = game;

            // Set seed to build world with
            int mapSeed = 123;

            Noise.Simplex.Seed(mapSeed);

            // Load graphics resources/assets
            boxRenderer = new BoundingBoxRenderer(graphicsDevice);

            voxelEffect   = content.Load <Effect>("Effects/voxel");
            skydomeEffect = content.Load <Effect>("Effects/skydome");

            // Load initial data for the voxel sprite
            VoxelCache voxelCache = new VoxelCache(mapSeed, 32, 128);

            playerSprite = new VoxelSprite(graphicsDevice);
            playerSprite.Load(voxelCache, "chr_knight");

            // Attempt to load player save data
            gameData = new GameData();

            if (gameData.LoadGame(mapSeed))
            {
                player = new Player(playerSprite.Mesh, gameData.Player);
            }
            else
            {
                Player.PlayerData data = new Player.PlayerData()
                {
                    position    = new Vector3(200, 50, -20),
                    orientation = 0
                };
                player = new Player(playerSprite.Mesh, data);
            }

            // Set up voxel chunks and skydome
            chunkManager = new ChunkManager(graphicsDevice, 123);
            chunkManager.Initialize(graphicsDevice, player.playerData.position);
            skydome = new Skydome(graphicsDevice, content);

            // Set up cameras
            playerCamera  = new PlayerCamera(Vector3.Zero, Vector2.Zero);
            skydomeCamera = new PlayerCamera(Vector3.Zero, Vector2.Zero);

            InitializeGraphicsResources();

            // Set debug info
            debugStats = new DebugStats
            {
                vertexCount = this.vertexCount,
                cameraPos   = this.playerCamera.position,
                chunksAdded = this.chunkManager.ChunksAdded
            };

            // Testing console commands
            GUI.EntitySpawner spawner = new GUI.EntitySpawner();
            console.Command("test");

            // Set some non-standard effect parameters here
            Color skyColor = new Color(0.091f, 0.622f, 0.976f);

            voxelEffect.Parameters["skyColor"].SetValue(skyColor.ToVector3());
            voxelEffect.Parameters["skyTexture"].SetValue(skydome.Skymap);
            voxelEffect.Parameters["toggleColors"].SetValue(toggleColors);

            // Manage resources that need to be reset when graphics device is lost
            game.GraphicsDevice.DeviceReset += new EventHandler <EventArgs>(OnDeviceReset);

            // Add children screen with these stats
            children.Add(new ScreenElements.DebugViewScreen(this, content, graphicsDevice, debugStats, game));
        }
Exemplo n.º 5
0
        }         // GetParametersHandles

        #endregion

        #region Render

        /// <summary>
        /// Render the sky.
        /// </summary>
        internal void Render(Matrix viewMatrix, Matrix projectionMatrix, float farPlane, Vector3 sunLightDirection, Skydome skydome)
        {
            try
            {
                Matrix worldMatrix = Matrix.CreateScale(1f);
                spViewProjectionMatrix.Value = worldMatrix * Matrix.Transpose(Matrix.Invert(viewMatrix)) * projectionMatrix; // I remove the translation and scale of the view matrix.
                spTexture.Value           = skydome.Texture;
                spWorldMatrix.Value       = worldMatrix;
                spViewInverseMatrix.Value = Matrix.Invert(Matrix.Transpose(Matrix.Invert(viewMatrix)));
                spLightDirection.Value    = sunLightDirection;
                spSkyDayTexture.Value     = skyTextureDay;
                spSkyNightTexture.Value   = skyTextureNight;
                spSkySunsetTexture.Value  = skyTextureSunset;

                Resource.CurrentTechnique.Passes[0].Apply();
                skydomeModel.Render();
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Skybox shader: Unable to render the sky.", e);
            }
        } // Render