Introduction to 3D in XNA Game Design Experience Professor Jim Whitehead February 27, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

Lecture 3: Transformations and Viewing. General Idea Object in model coordinates Transform into world coordinates Represent points on object as vectors.
Defining the Viewing Coordinate System
This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Horizontal Scrolling through Tileset Levels Game Design Experience Professor Jim Whitehead March 4, 2008 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
Introduction to Shader Programming
Point Lighting Using Shaders Game Design Experience Professor Jim Whitehead March 13, 2009 Creative Commons Attribution 3.0 (Except copyrighted images.
Particle Systems Final Exam Study Guide Game Design Experience Professor Jim Whitehead March 16, 2009 Creative Commons Attribution 3.0 (Except copyrighted.
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.
Triangles, Translations Game Design Experience Professor Jim Whitehead March 2, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0.
CS 450: Computer Graphics 2D TRANSFORMATIONS
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Hierarchical Transformations Hierarchical Models Scene Graphs
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Sound in games Think about truly memorable games – They almost always have.
Mathematical Fundamentals
Introduction to 3D Computer Graphics and Virtual Reality McConnell text.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
CSE 381 – Advanced Game Programming Basic 3D Graphics
Sky Rendering The actual physics is very complicated and costly to calculate. Several cheap approaches for very distant skies: –Constant backdrop –Skybox.
225 City Avenue, Suite 106 Bala Cynwyd, PA , phone , fax presents… HTML Lists, Tables and Forms v2.0.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Week 2 - Wednesday CS361.
Geometric Transforms Changing coordinate systems.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
1 Useful Tools for Making Video Games Part V An overview of.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Announcements Prototype submissions will be directly from SVN on Gforge.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
Graphics Matrices. Today’s Lecture Brought to you by the integer 6 and letter ‘K’; 2D and 3D points Matrices Rotations Translation Putting it all together.
Games Development 1 Camera Projection / Picking CO3301 Week 8.
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.
Realtime NPR Toon and Pencil Shading Joel Jorgensen May 4, 2010.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Basic 3D Concepts. Overview 1.Coordinate systems 2.Transformations 3.Projection 4.Rasterization.
Sky Boxes and Vector Math 2 Course Information CVG: Programming 4 My Name: Mark Walsh Website:
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Computer Graphics Camera Projection / Picking CO2409 Week 8 - Optional Advanced Material Not on Exam.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
2/19/04© University of Wisconsin, CS559 Spring 2004 Last Time Painterly rendering 2D Transformations –Transformations as coordinate system changes –Transformations.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
A Photograph of two papers
Computer Graphics Matrices
Honours Graphics 2008 Session 2. Today’s focus Vectors, matrices and associated math Transformations and concatenation 3D space.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Computer Graphics CC416 Week 15 3D Graphics.
Intro to 3D Graphics.
Chapter 3 Drawing In the World.
CSCE 441 Computer Graphics 3-D Viewing
CENG 477 Introduction to Computer Graphics
Computer Graphics Lecture 20
Drawing Area Coordinate System
03 | Creating, Texturing and Moving Objects
Presentation transcript:

Introduction to 3D in XNA Game Design Experience Professor Jim Whitehead February 27, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0

Announcements 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 too

Announcements 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 assignment

2D 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 depth Ratchet and Clank: Future

3D 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 screen

3D 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 Z Right-handed coordinate system

Camera 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 plane Location (x,y,z) Orientation Direction

Matrix 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, invert

Vector3 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) coordinate x y z (x,y,z) vector

Creating 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 position cameraPosition (x,y,z) cameraUpVector cameraTarget (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 triangle

Vertex 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 screen

Using Basic shader Three steps Create Shader Copy over camera information Iterate through EffectPasses Examine source code from example in Chapter 9 of XNA 3.0