/// Does the actual drawing of the skybox with our skybox effect. /// The size of the skybox can be changed with the size variable. public void Draw(Camera camera ) { // 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, but we know the cube really // 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(camera.camPosition)); part.Effect.Parameters["View"].SetValue(camera.viewMatrix); part.Effect.Parameters["Projection"].SetValue(camera.projectionMatrix); part.Effect.Parameters["SkyBoxTexture"].SetValue(skyBoxTexture); part.Effect.Parameters["CameraPosition"].SetValue(camera.camPosition); } // Draw the mesh with the skybox effect mesh.Draw(); } } }
public void Draw(Camera camera, float aspectRatio, Matrix[] transforms) { // Copy any parent transforms. playerModel.CopyAbsoluteBoneTransformsTo(transforms); // Draw the model. A model can have multiple meshes, so loop. foreach (ModelMesh mesh in playerModel.Meshes) { // This is where the mesh orientation is set, as well // as our camera and projection. foreach (BasicEffect effect in mesh.Effects) { //effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(position); effect.View = Matrix.CreateLookAt(camera.camPosition, camera.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(); } }
private void switchCamera() { //third > close third > first if (eCurrentCamState == eCamStates.firstPerson) { gameCamActive = gameCamThirdPerson; gameCamActive.setCamPosition(new Vector3(gameCamActive.getCamPosition().X, gameCamActive.getCamPosition().Y, carPlayer.getPosition().Z + gameCamThirdPerson.getCamFollowDistance())); eCurrentCamState = eCamStates.thirdPerson; } else if (eCurrentCamState == eCamStates.thirdPerson) { gameCamActive = gameCamThirdPersonClose; gameCamActive.setCamPosition(new Vector3(gameCamActive.getCamPosition().X, gameCamActive.getCamPosition().Y, carPlayer.getPosition().Z + gameCamThirdPersonClose.getCamFollowDistance())); eCurrentCamState = eCamStates.thirdPersonClose; } else if (eCurrentCamState == eCamStates.thirdPersonClose) { gameCamActive = gameCamFirstPerson; gameCamActive.setCamPosition(new Vector3(gameCamActive.getCamPosition().X, gameCamActive.getCamPosition().Y, carPlayer.getPosition().Z + gameCamFirstPerson.getCamFollowDistance())); eCurrentCamState = eCamStates.firstPerson; } }
//set up the game view public void initialiseGameView(GraphicsDeviceManager gDevice) { graphics = gDevice; //initialise all the cameras gameCamThirdPerson = new Camera(); gameCamThirdPerson.Initialise(new Vector3(0, 14, 40), graphics); gameCamThirdPerson.setCamPitch(MathHelper.ToRadians(-15)); gameCamThirdPersonClose = new Camera(); gameCamThirdPersonClose.Initialise(new Vector3(0, 10, 20), graphics); gameCamThirdPersonClose.setCamPitch(MathHelper.ToRadians(-15)); //as this camera is from the player's POV, no pitch is necessary gameCamFirstPerson = new Camera(); gameCamFirstPerson.Initialise(new Vector3(0, 3, -15), graphics); //the third person camera is the active camera by default gameCamActive = gameCamThirdPerson; //set both matrices to that of the currently active camera viewMatrix = gameCamActive.getCamViewMatrix(); projectionMatrix = gameCamActive.getProjectionMatrix(); }
/// 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. protected override void Initialize() { //Intialises the variable previously created as a new menu menu = new Menu(); //sets the gamestate at menu gamestate = GameStates.Menu; //Intialises the variable previously created as a new input input = new Input(); // Gets aspectRatio using the Graphics device aspectRatio = GraphicsDevice.Viewport.AspectRatio; //Intialises the variable previously created as a new Camera camera = new Camera(); camera.InitializeCamera(aspectRatio); //Intialises the variable previously created as a new Terrain landscape = new Terrain(GraphicsDevice); //Initialises the method that deals with the effects InitializeEffect(); //Initialises the method that resets the enemy daleks ResetDaleks(); base.Initialize(); }