public WorldChunk(Matrix worldTrans, string[] modelArray)
        {
            Transform = worldTrans;

            // build the list of ModelInfo
            for (int i = 0; i < modelArray.Length; i++)
            {
                ModelInfo mi = new ModelInfo();
                mi.ModelName = modelArray[i];
                Models.Add(mi);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            spriteFont = contentTracker.Load<SpriteFont>("Content\\SpriteFont1");

            // Load sky model.
            // If using async load, you need to make sure it is loaded
            // before using it (see the Draw method).
            // Thanks to LuckyWolf19 for finding this bug
            skyModel = new ModelInfo();
            skyModel.ModelName = "Content\\SkyDay";
            skyModel.FogEnable = false;
            skyModel.LoadContent(contentTracker, true);

            // The chunks are planes 1000 by 1000 units.
            float chunkSize = 1000.0f;
            float chunkRadius = (float)Math.Sqrt(chunkSize * chunkSize * 2.0f);

            // Calculate chunk positions
            int chunkCount = chunkCountX * chunkCountZ;
            chunks = new WorldChunk[chunkCount];
            for (int i = 0; i < chunkCountX; i++)
            {
                for (int j = 0; j < chunkCountZ; j++)
                {
                    // spread chunks in the XZ plane
                    Vector3 chunkPos = new Vector3(
                                                (i - chunkCountX / 2.0f) * chunkSize,
                                                0.0f,
                                                (j - chunkCountZ / 2.0f) * chunkSize);

                    int chunkID = i * chunkCountZ + j;

                    // Create the chunk. Currently they only have two models each - the terrain and one other
                    chunks[chunkID] = new WorldChunk(
                                        Matrix.CreateTranslation(chunkPos),
                                        new string[] { modelNameTerrain , "Content\\" + chunkModelNames[chunkID] });

                    // Create bounding sphere for entire chunk
                    chunks[chunkID].Bounds = new BoundingSphere(chunkPos, chunkRadius);
                }
            }

            // Initialise the camera
            cameraPos = Vector3.UnitY * 100.0f;

            projMatrix = Matrix.CreatePerspectiveFieldOfView(
                                            (float)MathHelper.PiOver4,
                                            graphics.GraphicsDevice.Viewport.AspectRatio,
                                            1.0f, FarClip);

            mouseRotX = 0.0f;
            mouseRotY = 0.0f;
            mouseState = Mouse.GetState(); // Ensures we are initially facing in a sensible direction
        }