Unformatted text preview:

Simple 3D CameraAnnouncements3D Camera Camera RefreshMake Direction ExplicitMoving Camera Forward/BackMoving Camera Side to SideRotating the CameraRotationsSource Code ExampleSimple 3D CameraGame Design ExperienceProfessor Jim WhiteheadMarch 6, 2009Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0Announcements• 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 website3D 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!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 constantLocation (x,y,z)OrientationDirectionMake 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)OrientationDirectionCamera targetCamera positionCamera directionTargetMoving 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/backwardsPosition (x,y,z)DirectionMoving 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)DirectionUpUp x DirectionRotating 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.CreateFromAxisAngleRotations• 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)DirectionUp x DirectionUpSource 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


View Full Document

UCSC CMPS 20 - Simple 3D Camera

Documents in this Course
Load more
Download Simple 3D Camera
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Simple 3D Camera and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Simple 3D Camera 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?