Presentation is loading. Please wait.

Presentation is loading. Please wait.

3D Cameras and Enemies COSC 315 Fall 2014 Bridget M. Blodgett.

Similar presentations


Presentation on theme: "3D Cameras and Enemies COSC 315 Fall 2014 Bridget M. Blodgett."— Presentation transcript:

1 3D Cameras and Enemies COSC 315 Fall 2014 Bridget M. Blodgett

2 Rotations in a 3D Camera Up to this point we have rotated relative to the XYZ axes But you can rotate relative to the object within the game – These rotations are called Yaw, Pitch, and Roll Yaw is around the up vector Roll is around the direction vector Pitch is perpendicular to yaw and roll

3 Apply YPR In most 3D games the mouse is used to control the main camera You will need to determine the mouse input before you start applying camera YPR transformations First you want to center the mouse in the camera class: MouseState prevMouseState; (initialize method) Mouse.SetPosition(Game.Window.ClientBounds.Width/2, Game.Window.ClientBounds.Height/2); prevMouseState = Mouse.GetState();

4 Applying Transformation In the update method above CreateLookAt cameraDirection.Vector3.Transform(cameraDirection, Matrix.CreateFromAxisAngle(cameraUp, (- MathHelp.PiOver4/150) * (Mouse.GetState().X – previousMouseState.X))); prevMouseState = Mouse.GetState(); How would these transformations work for the other two types of transformations? Is there anything extra we need to take into account?

5 Moving Enemies Load the 3D game code from the book chapter 11 code This code incorporates a model and more realistic yaw and pitch controls (it removes the roll altogether) To add enemies that are a little more difficult we are going to make them roll randomly

6 Spinning Enemy You should now have a SpinningEnemy class available Create four class level variables: float yawAngle = 0; float pitchAngle = 0; float rollAngle = 0; Vector3 direction; Alter the constructor to make use of these new variables calling them yaw, pitch, and roll In the method definition assign the angle variables you made to the ones defined in the constructor (and direction to Direction)

7 Spinning Enemy Update will also need to be changed to apply the new variables rotation *= Matrix.CreateFromYawPitchRoll(yawAngle, pitchAngle,rollAngle); world *= Matrix.CreateTranslation(direction); GetWorld() should be changed as well public override Matrix GetWorld(){ return rotation * world; }

8 Adding Randomness Create a new random number in Game1 and initialize it in the constructor Also change the background color to black In ModelManager remove the spinning ship that is currently generated Make a new class called LevelInfo and make it match the following code:

9 namespace _3D_Game { class LevelInfo { public int minSpawnTime { get; set;} public int maxSpawnTime { get; set;} public int numberEnemies { get; set;} public int minSpeed { get; set;} public int maxSpeed { get; set;} public int missesAllowed { get; set;} public LevelInfo(int minSpawnTime, int maxSpawnTime, int numberEnemies, int minSpeed, int maxSpeed, int missesAllowed) { this.minSpawnTime = minSpawnTime; this.maxSpawnTime = maxSpawnTime; this.numberEnemies = numberEnemies; this.minSpeed = minSpeed; this.maxSpeed = maxSpeed; this.missesAllowed = missesAllowed; }

10 Making Use of Level Info In ModelManager add the following class level variables Vector3 maxSpawnLocation = new Vector3(100, 100, -3000); int nextSpawnTime = 0; int timeSinceLastSpawn = 0; float maxRollAngle = MathHelper.Pi / 40; int enemiesThisLevel = 0; int currentLevel = 0; List levelInfoList = new List ();

11 Making Use of Level Info In the ModelManager constructor add: levelInfoList.Add(new LevelInfo(1000, 3000, 20, 2, 6, 10)); levelInfoList.Add(new LevelInfo(900, 2800, 22, 2, 6, 9)); levelInfoList.Add(new LevelInfo(800, 2600, 24, 2, 6, 8)); levelInfoList.Add(new LevelInfo(700, 2400, 26, 3, 7, 7)); levelInfoList.Add(new LevelInfo(600, 2200, 28, 3, 7, 6)); levelInfoList.Add(new LevelInfo(500, 2000, 30, 3, 7, 5)); levelInfoList.Add(new LevelInfo(400, 1800, 32, 4, 7, 4)); levelInfoList.Add(new LevelInfo(300, 1600, 34, 4, 8, 3)); levelInfoList.Add(new LevelInfo(200, 1400, 36, 5, 8, 2)); levelInfoList.Add(new LevelInfo(100, 1200, 38, 5, 9, 1)); levelInfoList.Add(new LevelInfo(50, 1000, 40, 6, 9, 0)); levelInfoList.Add(new LevelInfo(50, 800, 42, 6, 9, 0)); levelInfoList.Add(new LevelInfo(50, 600, 44, 8, 10, 0)); levelInfoList.Add(new LevelInfo(25, 400, 46, 8, 10, 0)); levelInfoList.Add(new LevelInfo(0, 200, 48, 18, 20, 0));


Download ppt "3D Cameras and Enemies COSC 315 Fall 2014 Bridget M. Blodgett."

Similar presentations


Ads by Google