240 likes | 551 Views
Direct3D Workshop. November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals. Workshop Breakdown. Part 1: 3D Graphics Pipeline Part 2: Projective Space Part 3: Windows Programming Intermission Part 4: Setting Up Direct3D Part 5: Using Direct3D.
E N D
Direct3DWorkshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals
Workshop Breakdown • Part 1: 3D Graphics Pipeline • Part 2: Projective Space • Part 3: Windows Programming • Intermission • Part 4: Setting Up Direct3D • Part 5: Using Direct3D
Notes and Code Samples • You can download these notes and all the code samples from http://p2pclub.eng.usf.edu/direct3d/
Motivation • How should space be represented in computer graphics? • Using linear algebra seems like a fairly natural way to represent space, but eventually you will find it has its limits. • A better solution is called projective space, and it’s the math being used behind all graphics cards today. • Let’s start with the linear algebra and develop projective spaces from there.
Vectors • Remember vectors? • They have direction and magnitude. • We usually break down vectors into x, y, and z components. • Vectors can represent coordinates (displacement from an origin).
Matrices • Remember matrices? • Matrices can represent transformations • From a vector to a vector. • From another matrix to another matrix. • Matrices can also represent tensors, orientations, or coordinate systems.
Matrix-Vector Multiplication • Each columns of the matrix can be interpreted as transforming a component of the vector.
Linear Transformations • A transformation T is linear iff • Linear transformations include Scaling, Shearing, and Rotations. • Translation is not linear:
Linear Transformations (Cont’d) • A transformation is linear iff it can be written in matrix-vector form: • You can find the columns of A by transforming the standard basis: • Multiplying matrices together results in a composition of transforms.
Affine Spaces • Extending vector spaces, affine spaces add another set of objects called points. • A point has a position, but not a direction or magnitude. • Points have only a couple operations: • P – Q = v • Q + v = P • Where P and Q are points and v is a vector. • You cannot add two points together or multiply a point by a scaler.
Affine Frame • Let e1, e2, e3 form a basis for the vectors in an affine space, A. • Let O be a point in A. We will call this point the origin. • Then e1, e2, e3, O forms a frame for A. • Any vector in A can be written as: • Any point can be written as:
Affine Coordinates • Using frames we can write vectors like this: • And points like this:
Affine Coordinates • The appended 0 or 1 is called the w-component. • In affine space this is either • 0 for a vector • 1 for a point • And anything else is undefined. • Note that if you add vectors together or scale them, the result is a vector, but if you try the same with points, the result is undefined.
Affine Transform • An affine transform adds translation to a linear transform. • In regular vector space it has the form: • In affine space it is written as: • If you run a point through this transform it is translated, while vectors are not.
Perspective • Projective space is an extension to affine space. • Using transformations in this space we will be able to calculate perspective.
Projective Space • In projective space, the w-component is either 0 for a vector or any nonzero real number for a point. • However, coordinates in projective space are homogeneous. • Two points in projection space are said to be equivalent if the coordinates of one are a multiple of the other. • That is, if:
Projective Space (Cont’d) • Points in projective space actually represent lines through the origin. • We can standardize the points, by dividing by w so that its w component is 1.
Projective Space (Cont’d) • In the case of the projective plane (the 2D projective space). • 3D coordinates are used. • The intersection points of the lines through the origin and the plane w=1 make a perspective image of the space.
Projective Transform • The projective transform generalizes the affine transform. • With homogeneous coordinates it looks like: • With linear algebra it would look like this:
Perspective Transform • When perspective is actually calculated in computer graphics, it doesn’t usually flatten the space. • Instead coordinates are transformed so that the viewing frustum is transformed into a unit square • This is done through a composite of a scaling and a projective transform.
Direct3D Matrices and Vectors • Direct3D includes a matrices and vectors (as well as planes and quaternions). • D3DVECTOR and D3DMATRIX • D3DXVECTOR# and D3DMATRIX# • D3DXMATRIXA# • Where # is an integer. • List of functions for D3DX* structures http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/d3dx/functions/math/mathfunctions.asp
Direct3D Math Quirks • Be aware of Direct3D’s left handed coordinate system • X is positive to the left • Y is positive to the top • Z is position going into the monitor • Matrices are multiplied on the right side of a vector:
References • Computer-Aided Geometric Design by F. Yamaguchi • Computer Animation Slides by JeHee Lee http://mrl.snu.ac.kr/CourseAnimation/ • Computer Graphics Notes by Ken Joy http://graphics.idav.ucdavis.edu/education/GraphicsNotes/Graphics-Notes.html