Пример #1
0
        // Draws Skybox, no world matrix since it won't move
        // Passes in camera instance so to use current view and projection matrices
        public void Draw(Camera cam)
        {
            // Go through each pass in the effect, but we know there is only one...
            foreach (EffectPass pass in skyBoxEffect.CurrentTechnique.Passes)
            {
                // Draw all of the components of the mesh, even though the cube only has one mesh
                foreach (ModelMesh mesh in skyBox.Meshes)
                {
                    // Assign the appropriate values to each of the parameters
                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        part.Effect = skyBoxEffect;
                        part.Effect.Parameters["World"].SetValue(
                            Matrix.CreateScale(size) * Matrix.CreateTranslation(cam.camPosition));
                        part.Effect.Parameters["View"].SetValue(cam.viewMatrix);
                        part.Effect.Parameters["Projection"].SetValue(cam.projectionMatrix);
                        part.Effect.Parameters["SkyBoxTexture"].SetValue(skyBoxTexture);
                        part.Effect.Parameters["CameraPosition"].SetValue(cam.camPosition);
                    }

                    // Draw the mesh with the skybox effect
                    mesh.Draw();
                }
            }
        }
Пример #2
0
        // Method to draw model
        public void Draw(Camera cam, float aspectRatio, Matrix [] transforms)
        {
            // Copy any parent transforms.
            myModel.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                // Mesh orientation is set, and camera and projection
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(rotation) * Matrix.CreateTranslation(position);
                    effect.View = Matrix.CreateLookAt(cam.camPosition, cam.camLookat, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 50000.0f);
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }
Пример #3
0
        // Method to setup scene
        protected override void Initialize()
        {
            // Gives window a title
            Window.Title = "Space Conquerors";
            // Gets aspectRatio using the Graphics device
            aspectRatio = GraphicsDevice.Viewport.AspectRatio;
            // Creates instances of classes
            menu = new Menu();
            gamestate = GameStates.Menu;
            cam = new Camera();

            // Sets default values for the camera
            cam.InitializeCamera(aspectRatio);
            // Sets dafault values for effect
            InitializeEffect();
            // Creates instance of terrain
            landscape2 = new Terrain(GraphicsDevice);
            // Spawns baddies
            ResetDaleks();
            base.Initialize();
        }