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.

Slides:



Advertisements
Similar presentations
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Advertisements

Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
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.
CGDD 4003 THE MASSIVE FIELD OF COMPUTER GRAPHICS.
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.
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.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
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.
3D Concepts Coordinate Systems Coordinates specify points in space 3D coords commonly use X, Y, & Z A vertex is a 'corner' of an object Different coordinate.
Introduction to 3D Computer Graphics and Virtual Reality McConnell text.
C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.
COMP 175: Computer Graphics March 24, 2015
CSE 381 – Advanced Game Programming Basic 3D Graphics
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
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.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
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.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Jinxiang Chai Composite Transformations and Forward Kinematics 0.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.
Realtime NPR Toon and Pencil Shading Joel Jorgensen May 4, 2010.
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.
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
Jens Krüger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization 3D Rendering Praktikum: Shader Gallery The.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
3D Transformation A 3D point (x,y,z) – x,y, and z coordinates
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
Computer Graphics Matrices
Honours Graphics 2008 Session 2. Today’s focus Vectors, matrices and associated math Transformations and concatenation 3D space.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
 Advancing from moving premade primitives to making our own models  Two different approaches: ◦ Direct mesh editing: A more traditional approach commonly.
Honors Geometry.  We learned how to set up a polygon / vertex matrix  We learned how to add matrices  We learned how to multiply matrices.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.
Computer Graphics Imaging Lecture 13 and 14 UV Mapping.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Computer Science – Game DesignUC Santa Cruz Tile Engine.
How to use a Pixel Shader CMT3317. Pixel shaders There is NO requirement to use a pixel shader for the coursework though you can if you want to You should.
Week 3 - Monday CS361.
Computer Graphics CC416 Week 15 3D Graphics.
Computer Graphics Index Buffers
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
GIF's by POV-Ray and GIAM a tiny crash course
CENG 477 Introduction to Computer Graphics
ICG 2018 Fall Homework1 Guidance
03 | Creating, Texturing and Moving Objects
Presentation transcript:

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

Announcements Project progress report ► Due Today In class, or in my box by 5pm ► 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 Days until Final Project Due: 14 ► Due Monday, March 16

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

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

Vertex Structures in XNA XNA has 4 different structures for representing verticies ► VertexPositionColor Useful for basic shapes, basic colors x,y,z plus a color for each vertex ► VertexPositionTexture Overlay a bitmap texture onto a shape x,y,z plus a u,v coordinate into a bitmap texture ► VertexPositionNormalTexture Normal permits lighting effects x,y,z plus a u,v, coordinate, plus a normal vector ► VertexPositionColorTexture Color information changes color of bitmap texture Reuse same texture in different contexts x,y,z plus u,v plus color

VertexPositionColor 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 ► Vertex data is written directly to the GPU ► Need to tell the GPU how to interpret the data it receives ► GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements); For different types of verticies, would change the vertex structure ► VertexPositionTexture example: ► GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionTexture.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 Five steps: 1.Create Shader ► BasicEffect effect = new BasicEffect(GraphicsDevice, null); 2.Copy over camera information ► effect.View = camera.view; ► effect.Projection = camera.projection; 3.Set world matrix ► effect.World = … (more on this in a few slides) 4.Enable vertex capabilities (varies by Vertex type) ► Effect.VertexColorEnabled = true; // for VertexPositionColor ► Effect.Texture = myTexture; // for VertexPositionTexture Effect.TextureEnabled = true; 5.Iterate through EffectPasses ► Call to DrawUserPrimitives inside EffectPass puts triangles on screen

Iterating Through Effect Passes Each Effect has calls to begin()/end() Effects are comprised of passes ► Each pass requires a call to begin()/end() effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserPrimitives (PrimitiveType.TriangleStrip, verts, 0, 1); pass.End(); } effect.End(); Draws verticies Passes # of triangles (the “primitive shape” in this context) to draw Index into verts array

Triangle Drawing Examine this line of code ► GraphicsDevice.DrawUserPrimitives (PrimitiveType.TriangleStrip, verts, 0, 1); ► What is a TriangleStrip? Three ways to draw triangles ► Triangle List Each set of three verticies defines a triangle Memory inefficient, since triangles often share edges in complex 3D meshes ► Triangle Strip Builds triangle out of first three verticies Each additional vertex creates new triangle using that vertex, plus previous two verticies ► Triangle Fan Each additional vertex creates new triable using that vertex, the previous vertex, plus the first vertex surfaceModeling015.png

World Matrix Each triangle has 3 verticies, and each vertex has an x,y,z position ► This position is given with respect to an origin location ► That is, location is with respect to a local coordinate system World matrix ► Translates from the local coordinate system to the world (i.e., visible on screen) coordinate system Local coordinate system offset, no rotation (Note: example uses left handed coordinate system, XNA uses right-handed coordinates) Source: MSDN DirectX documentation Local coordinate system offset and rotated www1.adept.com/main/KE/DATA/V%20Plus/V%20Language%20 User/images/World+yaw.gif local world

Translation A translation shifts the local coordinate system relative to the world coordinate system XNA provides a method for this ► Matrix.CreateTranslation 3 parameters are x,y,z movements Matrix.CreateTranslation(0.01f, 0, 0); // Shift right (positive) along x axis Matrix.CreateTranslation(-0.01f, 0, 0); // Shift left (negative) along x axis Multiply world matrix by translation matrix to cause shift ► All translations and rotations in 3D graphics accomplished via matrix multiplication

Rotation A rotation shifts the local coordinate system by an angle relative to the world coordinate system XNA helper methods ► Matrix.CreateRotationX, Matrix.CreateRotationY, Matrix.CreateRotationZ Rotations around single axes Matrix.CreateRotationY(angle in radians); ► Matrix.CreateFromYawPitchRoll Rotate around multiple axes Matrix.CreateFromYawPitchRoll(yaw rad., pitch rad., roll rad.) Demonstration of example triangle drawing code