DOC PREVIEW
GT ECE 4893 - XNA 3-D API Basics
School name Georgia Tech
Pages 48

This preview shows page 1-2-3-23-24-25-26-46-47-48 out of 48 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 48 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 48 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 48 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 48 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 48 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 48 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 48 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 48 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 48 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 48 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 48 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

XNA 3-D API Basics Prof. Aaron Lanterman (Based on slides by Prof. Hsien-Hsin Sean Lee) School of Electrical and Computer Engineering Georgia Institute of Technology2 XNA: The Big Picture Initialize() LoadContent() Camera setup Update() Game Logic Draw() Initialization phase Texture load Model load Graphics Device Content Pipeline Vertex data, commands3 Careful when googling • XNA Math is different from old D3DX… It's your decision whether you start to use it or not, because it's completely separate library that can be used with DirectX 11, 10, 9 or without anyone of them. On the other hand, you can still link with old D3DX while coding in new DirectX 11, so it's all your choice. • By the way, I don't know why is this library called "XNA Math.” It looks like it has nothing to do with the XNA technology. XNA is a .NET library with its own vector and matrix classes while XNA Math is pure native C++ library distributed with DirectX SDK. It looks like a misnomer.4 Vectors in XNA • Various types – Vector2 vec2 = new Vector2(100, 100); – Vector3 vec3 = new Vector3(10, 10, 10); – Vector4 vec4 = new Vector4(1, 1, 10, 2); – Vector4 vec4 = new Vector4( new Vector2(1,1),10,2);5 Standard vector types • Vector4 vec4 = Vector4.One; vec4 = (1,1,1,1) • Vector4 vec4 = Vector4.UnitX; vec4 = (1,0,0,0) • Vector4 vec4 = Vector4.Zero vec4 = (0,0,0,0)6 Vector member functions • Vector4 vec4 = new Vector4(1, 1, 10, 2); • vec4.X = vec4.Y + vec4.Z; • Result: vec4 = (11,1,10,2)7 Adding and subtracting vectors • Vector3.Add(a,b,c); // a=b+c • a = Vector3.Add(b,c); // a=b+c • a = b + c; (look up “op_Addition” method) • Vector3.Subtract(a,b,c); // a=b-c • a = Vector3.Subtract(b,c); // a=b-c • a = b – c; (look up “op_Subtraction” method) • In general, there may be performance reasons to choose one over another or to “DIY”8 Multiplying & dividing vectors • c = a*b; c=a/b; • Works elementwise for vectors • Work as you’d expect for a scalar and a vector • Various corresponding explicit method calls9 Common vector functions • float len = v3.Length() • float len = Vector3.Length(v) • float dp = Vector3.Dot(va,vb) • Vector3 cp = Vector3.Cross(va,vb) • Vector3.Cross(cp,va,vb) • Vector3 lerpv = Vector3.Lerp(va,vb,float) • Vector3 dist = Vector3.Distance(va,vb) • Check out http://msdn.microsoft.com for more 2nd vector’s weight• Vector3 nv = Vector3.Normalize(va) • Vector3.Normalize(nv,va) • va.Normalize(); // “destructive” call • Can normalize other vector types too, but note you’ll most likely want to normalize 3-D vectors (usually for lighting calculations) and not 4-D vectors 10 Normalizing vectors11 VECTOR Example Vectors (See Demo in Visual Studio)12 Matrices (4x4) in XNA • Matrix Rmat44 = new Matrix(M11,M12,M13,M14, M21,M22,M23,M24, M31,M32,M33,M34, M41,M42,M43,M44); • Most often use one of the special matrix initialization routines – See if what you need is already there first • Rmat44.M13 = Rmat44.M43 + 3;13 Common matrix functions • Vector4 Rmat41= Vector4.Transform(vec4, mat); // [4x1]*[4x4] • Matrix Rmat44 = Matrix.Multiply(mat1, mat2); // [4x4]*[4x4] • Overloaded with operator *, thus Rmat44=M1*M2; • Matrix inv = Matrix.Invert(mat); // find its inverse • Matrix tr = Matrix.Transpose(mat); // transpose • Matrix im = Matrix.Identity; // return an identity matrix14 MATRIX Example SimpleMatrix (See Demo in Visual Studio)15 Planes • Plane plane1 = new Plane(vec3, d) vec3 describes a normal vector d = plane’s distance from the origin • A useful plane function – Plane.Intersects(boundingbox) – Many others, check msdn16 Shaders in XNA • You always need an “effect file” (.fx) • An effect file is a shader code consisting of – Vertex Shader – Pixel Shader • Need to communicate variables between your C# code and the shader code, e.g., matrices • Even rendering a simple triangle requires an effect file – Use XNA’s BasicEffect to “fake” a classic DirectX9 style fixed-function pipeline17 Specifying an effect (1) • Either use a BasicEffect or specify a provided .fx file18 Specifying an effect (2) • Either use a BasicEffect or specify a provided .fx file An effect file called effects.fx has been dropped into the Content folder19 Specifying an effect (3) • Either use a BasicEffect or specify a provided .fx file Passes specified in the shader will be processed20 BasicEffect: Just a shader • Internally set via the “ShaderIndex” parameter: – 0: Flat color – 1: Vertex colors – 2: Textured – 3: Textured + Vertex colors – 4: Lit – 5: Lit + Vertex colors – 6: Lit + Textured – 7: Lit + Textured + Vertex colors – 8: Per-pixel lit – 9: Per-pixel lit + Vertex colors – 10: Per-pixel lit + Textured – 11: Per-pixel lit + Textured + Vertex colors21 BasicEffect handles 3 directional lights • Parameters – AmbientLightColor – DirLight0Direction – DirLight0DiffuseColor – DirLight0SpecularColor – DirLight1Direction – DirLight1DiffuseColor – DirLight1SpecularColor – DirLight2Direction – DirLight2DiffuseColor – DirLight2SpecularColor22 BasicEffect material properties • Colors range 0 to 1: – DiffuseColor – EmissiveColor – SpecularColor – SpecularPower – Alpha23 BasicEffect fog properties • FogEnabled – 0 to disable, 1 to enable • FogStart • FogEnd • FogColor24 Set up BasicEffect (1)25 Set up BasicEffect (2)26 BasicEffect.fx (the end of the file)27 VertexBuffer • Contains a list of vertices – 4-D colors – 3-D positions – 2-D texture coordinates – 3-D normals28 VertexBuffer structures • VertexPositionColor • VertexPositionColorTexture • VertexPositionNormalTexture • VertexPositionTexture • Can make your own with VertexElement; See “How to: Create and Use a Custom Vertex” http://msdn.microsoft.com/en-us/library/bb976065.aspx29 PrimitiveType enumeration30 DrawUserPrimitives (1) Declare the type of vertices31 DrawUserPrimitives (2) Give vertex list Inform the gfx device the type of vertices # of Triangles Offset32 Use Vertex Buffer – DrawPrimitives (1)


View Full Document

GT ECE 4893 - XNA 3-D API Basics

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