Jump to content

  • Log In with Google      Sign In   
  • Create Account

XNA 4.0 Workshop - Week 2 (Ch. 4)

  • You cannot reply to this topic
9 replies to this topic

#1 JWalsh   Moderators   -  Reputation: 463

Like
0Likes
Like

Posted 24 January 2011 - 12:23 PM

Welcome to Week 2 of the XNA 4.0 Winter Workshop. This week we're going to move past Part I of the textbook and into Part 2 - Understanding XNA Framework Basics.

This week's reading assignment is Chapter 4 from the textbook: "Creating 3D Objects". While there are less assigned pages for reading from the book this week (about 30), I will be providing a lot more supplemental material. Although the textbook does a great job giving an overview of the topics, and I generally like the order the information is presented in, it still only does a cursory job covering a lot of the necessary information.

When talking about "3D Graphics API's" we need to focus on all three elements at once. That is, we need to focus on the 3D Math, the Graphics Hardware, and the Programming API which exposes the other two elements.

3D Mathematics

The textbook fails in effectively covering 3D Mathematics. As with many authors of the genre, Carter chooses to emphasize the fact that the XNA Framework Library already provides classes for Vectors, Matrices, etc... and trusts the reader to either already know the fundamental mathematics or to go and learn more on their own time. As with nearly all books on Graphics API's, in this book we "do not discuss 3D math ... because there are many texts available that cover it." This is unfortunate but understandable. What Carter really means is, 3D mathematics is a difficult, time consuming topic to write about as it requires lots of visual aids (which authors generally have to make themselves) and could fill the page count of the entire book if done well.

With all that said, this is a workshop, not a textbook and understanding 3D mathematics is a pre-requisite to working effectively in 3D. When talking about "3D Mathematics" we're talking about the math required to manipulate, view, and render 3D primitives. This involves Vectors, Matrices, and potentially quaternions if you're looking for more advanced ways of storing rotations.

Ultimately, we'll use these mathematical concepts to represent an object's position in the world, it's position relative to our virtual camera, and what it looks like when projected from 3D space onto a 2D surface. While, I, like Chad do not have the time to write a textbook on 3D mathematics, there are a number of great tutorials on the web and we should take this week to provide and discuss those resources. Any and all questions on 3D mathematics is welcome. I challenge you to discover the best 3D tutorials on the web and provide links to them this week.

The Graphics Hardware

One of the reasons I chose Chad Carter's book as the textbook for this course is that it covers 3D primitives before covering 2D sprites. This may seem counter-intuitive but in reality it makes a lot of sense. While the mathematics involved in 3D rendering is more complex than 2D, most 2D API's we use today leverage the fact that our GPU's are built for 3D rendering. Gone are the days when we could simply copy byte arrays to video memory and expect them to show up on screen. Today, video cards (and drivers) have something called a 3D Graphics Pipeline, which is a series of stages data you wish to be drawn must go through before being shown on your screen.

When using the SpriteBatch class in XNA, you're really just creating a ton of pre-transformed triangles which are then being rendered as quads by the GPU hardware, using your "sprite" as the texture for the triangles. With that in mind, understanding the Graphics Pipeline makes you not only a capable 3D graphics programmer, but also a more efficient 2D programmer.

The other useful observation here is that all 2D "sprites" go through the same stages as your 3D triangles. This means that any and all effects we learn to do in 3D can also be used in 2D.

The Graphics API

XNA represents physical hardware components and data with a fairly complete set of classes, structs, and interfaces. These range from simple Color structs, to VertexBuffers which represent a collection of 3D points, all the way to the fairly complex GraphicsDevice class. The textbook takes a cursory look at the most important of these types, which are all related to 3D primitives. We'll take a closer look at some additional ones in the supplemental material, with the rest of them coming in Weeks 4, 6, 7, and 13.

Supplemental Reading
Below is a list of supplemental reading that might help this week's reading make more sense to you. I am likely to add to this list over the course of the week (or even the workshop) and will make an announcement when I've added additional reading or resources.


  • Essential Math for Game Programmers - Great tutorial website on 3D math. Start with the Core Mathematics section.
  • Direct3D 9.0 Graphics Pipeline Diagram - This is the most comprehensive diagram I've seen for the DirectX 9.0 Graphics Pipeline. As XNA is largely a managed wrapper around DirectX 9.0 this is almost all relevant. Note: This is not entirely accurate for Xbox 360, but should be 99% accurate for PC
  • Microsoft.Xna.Frame.Graphics Namespace - List of all the classes, structs, and interfaces in the Graphics Library. We'll talk about almost all of them over the course of the workshop.
  • GameDevelopedia.com - My own blog. See tutorials 2-4 on the right hand side.

XNA 4.0 Source Code


Discussion


Please use the Week 2 XNA 4.0 Workshop Forums for any discussion of this week's reading.


Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints

Sponsor:

#2 NEXUSKill   Members   -  Reputation: 457

Like
0Likes
Like

Posted 24 January 2011 - 12:50 PM

Recently working on a project of my own, I realized that while I have taken Algebra and Geometric analysis, I still had a couple of concepts rather loose, there is also the issue that most formal math classes don't much care for the performance issues of complex functions like roots, sin, cosine, etc.

There is a great leap of knowledge between "Knowing math" and "Knowing 3D Games Math"

The best aproach I've found for my position is the book "3D Math Primer For Graphics And Game Development - Fletcher Dunn and Ian Parberry".
If you have the time to squeeze in another book in your schedule, it is more than worth it.



Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272



#3 Sammie22   Members   -  Reputation: 102

Like
0Likes
Like

Posted 24 January 2011 - 03:18 PM

A suggestion for more information regarding the maths is Khan Academy: http://www.khanacademy.org/

This is a free site with a TON of mathematical videos, including Geometry, Linear Algebra, etc. I found this site really useful when I was trying to learn (or relearn in some cases) some of the 3D mathematical concepts.



#4 mbalrog6   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 January 2011 - 02:29 AM

I found this site online. It is a very simple and easy to follow Vector and Matrix Math primer. With some nice apps built into the site to give you hands on manipulation and experience with the Math.

http://programmedlessons.org/VectorLessons/vectorIndex.html#15

#5 Kyle Brechin   Members   -  Reputation: 128

Like
0Likes
Like

Posted 25 January 2011 - 08:29 AM

While math has always been my favorite subject, 3D math has always seem to been my downfall. These tutorials really helped a lot to make my understanding more concrete.

#6 Puyover   Members   -  Reputation: 187

Like
0Likes
Like

Posted 25 January 2011 - 04:41 PM

I have read your Tutorial #2 and now I'm going to read these chapters in the book, because I read them once and I didn't understand some things like VertexBuffer and VertexList (I don't know very well why I have to use them); let's see if now I understand more things.

#7 b_ill   Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 January 2011 - 08:24 PM

As great as the content in this book is, I often have trouble following along with his coding. For example, the author tends to tell you to use variables before he tells you that you need to create them, too (see the paragraphs surrounding the InitializeVertices() function for a good example of this), which wreaks havoc upon anyone using an intellisense-enabled IDE -- which should be just about everyone -- and makes me think that I missed something somewhere prior to that section. This seems to be a very sloppy way of coding that can cause a lot of problems in the long run if people get used to shotgunning a bunch of code into the file and trying to go back and make sure they declared all their variables and set all their properties in the proper places.
He also does not make it very clear WHERE to put a lot of his code samples -- are they members of the Game1 class, part of a function, inside a loop?

#8 astralvoid   Members   -  Reputation: 138

Like
0Likes
Like

Posted 27 January 2011 - 05:47 AM

I tend to agree. I've just trained myself to scan down the page for the code if I come across a variable that has been undefined as of yet. Then I create that code, and return to my previous location.

#9 superkent   Members   -  Reputation: 158

Like
0Likes
Like

Posted 27 January 2011 - 06:38 AM

I dont know how much time you guys have, but I have been reading the whole chapter first, and then going back and doing the coding. It helps with situations like that and also gives me a "big picture" prespective which I think is helpful.

#10 Alpha_ProgDes   Crossbones+   -  Reputation: 4688

Like
0Likes
Like

Posted 27 January 2011 - 03:25 PM

No assignment this week?
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler





PARTNERS