Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple 3D Camera Game Design Experience Professor Jim Whitehead March 6, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0.

Similar presentations


Presentation on theme: "Simple 3D Camera Game Design Experience Professor Jim Whitehead March 6, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0."— Presentation transcript:

1 Simple 3D Camera Game Design Experience Professor Jim Whitehead March 6, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0

2 Announcements Days until Final Project Due: 10 ► Due Monday, March 16 ► Few students have been attending help sessions ► We will not be able to help you as well at the last minute 3D modeling homework ► Assignment text now on web ► Due Monday, March 9 ► Assignment will involve: Create a simple 3D model (e.g., in Blender) –Something slightly (but not by much) more complex than a cube will be fine Make this model show up in XNA Extra credit for making model rotate, applying bitmap textures Goal is to exercise a model import pathway ► Intended to be a straightforward assignment ► Submit code via Homework submission website

3 3D Camera In many 3D games, when the player moves, this results in the camera being moved The camera is the player’s view into the game world Existing 3D code shown in class has not moved the camera ► Now we will!

4 Camera Refresh Camera is comprised of two Matrix objects ► View matrix holds information on Location of camera in world Camera direction Camera orientation Modify view to move camera ► Projection matrix holds information on View angle Aspect ratio Near and far plane Typically stays constant Location (x,y,z) Orientation Direction

5 Make Direction Explicit In past, have created view matrix as follows: ► View = Matrix.CreateLookAt(pos, target, up) ► Creates view from camera position, and explicit point target of the camera For camera manipulations, is more convenient to compute Direction vector (vector math) ► Direction = target – pos Typically then normalize ► Make all values between 0 and 1 To create view using Direction ► View = Matrix.CreateLookAt(pos, pos+Direction, up) Position (x,y,z) Orientation Direction Camera target Camera position Camera direction Target

6 Moving Camera Forward/Back Moving a camera involves changing its position ► Typically add a fixed increment (speed) to position each clock tick ► But, want to move the way the camera is facing ► That is, want to move in the direction of the Direction vector cameraPosition += cameraDirection * speed; ► Moves forward/backwards Position (x,y,z) Direction

7 Moving Camera Side to Side To move side-to-side, need vector that is simultaneously perpendicular to Direction and Up vectors ► A Matrix cross product computes this ► Once this sideways vector is computed, add a small amount each clock tick to position to move that way ► cameraPosition += Vector3.Cross( cameraUp, cameraDirection) * speed; Position (x,y,z) Direction Up Up x Direction

8 Rotating the Camera To rotate the camera, need to rotate around the three axial vectors of the camera ► Yaw – rotate around Up ► Roll – rotate around Direction ► Pitch – rotate around Up x Direction General approach ► Use Vector3.Transform method ► First parameter is axis to rotate around ► Second parameter is call to Matrix.CreateFromAxisAngle

9 Rotations Yaw ► Change Direction vector by rotating around Up ► cameraDirection = Vector3.Transform (cameraDirection, Matrix. CreateFromAxisAngle(cameraUp, angle) Roll ► Change Up vector by rotating around Direction ► cameraUp = Vector3.Transform(cameraUp, Matrix.CreateFromAxisAngle(cameraDirection, angle) Pitch ► Change Up and Direction vectors by rotating around Up x Direction ► cameraDirection = Vector3.Transform(cameraDirection, Matrix.CreateFromAxisAngle( Vector3.Cross(cameraUp, cameraDirection), angle)); ► cameraUp = Vector3.Transform(cameraUp, Matrix.CreateFromAxisAngle( Vector3.Cross(cameraUp, cameraDirection), angle)); Position (x,y,z) Direction Up x Direction Up

10 Source Code Example Examine source code from Chapter 11 of Learning XNA 3.0 ► Note: code was modified to use I-K and J-L for rotations, instead of mouse


Download ppt "Simple 3D Camera Game Design Experience Professor Jim Whitehead March 6, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0."

Similar presentations


Ads by Google