DOC PREVIEW
UCSC CMPS 20 - Introduction to 3D in XNA

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Introduction to 3D in XNAAnnouncementsAnnouncements2D to 3D3D Camera3D Coordinate SystemCameraMatrix StructureVector3 StructureCreating an XNA Camera – View MatrixCreating an XNA Camera – Projection MatrixDrawing TrianglesVertex DeclarationActually drawing the trianglesUsing Basic shaderIntroduction to 3D in XNAGame Design ExperienceProfessor Jim WhiteheadFebruary 27, 2009Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0Announcements• Partially operational game prototype► Due today• Can turn in to box by my office door by 5pm► Submit on CDROM, USB Drive, or URL to Subversion project• Project progress report► Due Monday► Take your project work breakdown and schedule (done previously)• Update this schedule based on your (now improved) understanding of what still needs to be done• Cut project scope, if necessary• Remember, you have assignments due in other classes tooAnnouncements• 3D modeling homework► Assignment text not yet on web► Will be up soon► 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 assignment2D to 3D• Many current games use 3D graphics► Much more complex than 2D graphics► This course will provide a basic overview of 3D graphics► CMPS 160, 161, 164 provide greater depthRatchet and Clank: Future3D Camera• Analogy► 2D is like putting stickers on a page• Place sticker (sprite) at x,y coordinate• If a sticker is placed at 50,50, you see it► 3D is like recording a video with a camera• What is recorded (shown on screen) is what camera sees• Can have objects in a scene that aren’t visible– Can have 3D object at 50,50,50, but if camera is pointing in the opposite direction, won’t see it!• Introduces rotation– Camera can potentially be rotated around all 3 axes– Objects can also be rotated around 3 axes– Affects what shows up on screen3D Coordinate System• 3D graphics requires use of x,y,z coordinates• So, which direction is positive z?► Is it back away from you, or towards you?► Either choice would work, need to pick one• Right handed vs left handed coordinate systems► XNA uses right handed coordinate system• Place hands, palms up► Point fingers in direction of positive X► Curl fingers in direction of positive Y► Thumb is pointing in direction of positive ZRight-handed coordinate systemCamera• Camera is comprised of two Matrix objects► View matrix holds information on• Location of camera in world• Camera direction• Camera orientation► Projection matrix holds information on• View angle• Aspect ratio• Near and far planeLocation (x,y,z)OrientationDirectionMatrix Structure• XNA provides a Matrix structure► A 4x4 matrix, in row vector layout• Row vector matrices view vectors as a row from left to right• column vector matrices view vectors as a column from top to bottom► Built-in matrix operations• +, -, *, /, ==► Also, convenience matrices• Identity, Up, Down, Left, Right► Large number of convenience methods• Rotations, views into 3D world, determinants, invertVector3 Structure• Represents either:► An X, Y, Z coordinate, or,► Distances along X, Y, Z coordinates (e.g., a vector)• Often a unit vector– all values between 0 and 1► X, Y, Z properties (floats)• Built-in operators► +, -, *, /, ==, !=• Convenience vectors► UnitX, UnitY, UnitZ, Up, Down, Left, Right• Many convenience methods► Interpolations, rotations, distance, dot product, normalization (x,y,z) coordinatexyz(x,y,z) vectorCreating an XNA Camera – View Matrix• View matrix► Use CreateLookAt method of Matrix structure► Parameters (all Vector3)• cameraPosition – location of camera (x,y,z)• cameraTarget – coordinate of point where camera is looking• cameraUpVector – vector indicating up positioncameraPosition (x,y,z)cameraUpVectorcameraTarget (x,y,z)Creating an XNA Camera – Projection Matrix• Projection Matrix► Use CreatePerspectiveFieldOfView method► Parameters (all floats)• fieldOfView – angle of camera view, in radians – Typically 45degrees – pi/2 radians• aspectRatio– Typically width of screen divided by height of screen• nearPlaneDistance– Distance from camera to near viewing plane– Objects between camera and near plane are not shown!• farPlaneDistance– Distance from camera to far viewing plane– Objects beyond far plane are not shown!cameraPosition (x,y,z)Drawing Triangles• All complex 3D shapes seen in games are composed of a series of triangles► A triangle has 3 points, one for each corner• Points are more typically known as verticies• Minimum number of points to unambiguously define a plane• VertexPositionColor object► Represents the x,y,z location of a vertex► Also has a color for the vertex► VertexPositionColor v = new VertexPositionColor(new Vector3(0,1,0), Color.Blue);► Need 3 verticies to draw a triangleVertex Declaration• XNA requires you to tell the graphics device what kind of vertex data you will be using► Unclear why XNA can’t just figure this out, or handle multiple types seamlessly► Probably due to structure of DirectX API, or capabilities of graphics hardware► For now, treat as a must-do, black box► Put following in your main, derived from Game class► GraphicsDevice.VertextDeclaration = new VertexDeclaration(GrahpicsDevice, VertexPositionColor.VertexElements);Actually drawing the triangles• In XNA, all 3D rendering is handled by a shader► Shaders defined using High Level Shader Language (HLSL)► Permits creation of wide range of visual effects► More on shaders in a few classes• XNA provides a default shader► Called BasicEffect► Will use this for now• BasicEffect is a type of effect► Effects contain a series of EffectPass► Each pass handles some aspect of putting things on screenUsing Basic shader• Three steps• Create Shader• Copy over camera information• Iterate through EffectPasses• Examine source code from example in Chapter 9 of XNA


View Full Document

UCSC CMPS 20 - Introduction to 3D in XNA

Documents in this Course
Load more
Download Introduction to 3D in XNA
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 Introduction to 3D in XNA 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 Introduction to 3D in XNA 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?