XNA 4.0 Workshop - Week 3

23. February 2011 16:43 by Jeromy Walsh in Game Developedia, User Input, Win Phone 7, Workshop, Xbox 360, XNA 4.0  //  Tags:   //   Comments (8)

Welcome to Week 3 of the XNA 4.0 Winter Workshop. As you no doubt have noticed, the workshop fell a bit behind. Due to work and real-life railroading me, I've been unable to convert code to XNA 4.0, post introductory articles, write review questions, or even respond to peoples' posts on the forums... Until NOW!

This marks the beginning of us being back on track again. As we've been sort of on chapters 4 and 5 for a couple weeks now, this will be a short week. You'll still have until the upcoming Sunday to complete the reading if you've not already done so, and then we'll move on to Week 4 on Monday.

With all that said, this week we officially move into the second sense, leaving sight behind and focusing on touch, both figuratively and literally.

This week's reading assignment is Chapter 5 from the textbook: "Handling Input to Move Our Camera". One important element of the title is that it implies we'll not only be learning how to use the User Input devices, but will also be using them to do something productive.

Creating a Game Service

The chapter begins with a discussion on creating game services. Game services, along with component oriented programming, allows us to decouple classes from one another in order to create a more pluggable architecture. By defining interactions between systems via interfaces, and then requesting services that implement those interfaces, we give ourselves the freedom to function with or without optional services, and also allow ourselves to substitute one implementation of a service for another when it benefits us to do so. 

Working with Input Devices

After the discussion on game services the chapter moves on to coverage of the different input devices in order to create our own input component and service. In specific, it addresses the Keyboard, GamePad, and Mouse input devices, highlighting that the Mouse is only available on Windows. 

At this point I feel it's important to note there's a few omissions in the book, due to changes from XNA 3.0 to XNA 4.0 as well as simple oversights. I'll go over these in supplemental tutorials I post in the coming days, but briefly...the Keyboard, through the use of a chat pad is accessible on the Xbox 360 in addition to the PC. To use the chat pad interface you must pass into the Keyboard.GetState() method an argument identifying which GamePad you'd like to access the chat pad of. Unfortunately, there's no way to determine if the GamePad actually HAS an attached chat pad.

The next big change from XNA 3.0 to 4.0 is the addition of the Windows Phone 7 as a supported device. This comes with it a slew of secondary changes. First, the Mouse API which was previously only usable on Windows is now supported on a second device. When using WinPhone7 the Mouse API can be used to get the primary touch point. Along similar lines, the brand new Input.Touch namespace and the associated classes can be used to access Gestures and multiple simultaneous touches. 

Also, while there's no classes directly within XNA to gain access to it, the Windows Phone 7 also has support for an accelerometer. However Silverlight, another library which is also accessible on the WinPhone 7, does have access to it through the Accelerometer class included in the Microsoft.Devices.Sensors assembly. You can add that as a reference to an existing WinPhone 7 XNA project and then use the Accelerometer class in order to treat the orientation of the phone as a form of input.

Another thing to note is that WinPhone7 has built in support for both hardware and virtual keypads. Unfortunately, as with the Xbox 360, there's no way to determine if the Windows Phone the user is on actually HAS a hardware keyboard or whether or not it's enabled. In general, Microsoft encourages the use of the SIP (Software Input Panel) which can be displayed via the Guide class in the GamerServices namespace.

And finally, XNA 4.0 adds support for Microphones. The Microphone can be used on all three consoles. For the PC it takes input from the primary input device. For the Windows Phone it uses the built-in microphone, and for the Xbox 360 it uses the Microphone on the headset accessory. In either case, the Microphone class, which is located in the Microsoft.Xna.Framework.Audio namespace can be used to capture voice audio for playback or other purposes directly in your games.

Creating Cameras & Split Screen

After coverage of the various XNA 3.0 supported input device, the chapter ends with an implementation of both a stationary camera as well as a first-person camera. The first-person camera is then used in the development of two demos, one called InputDemo, and one called SplitScreen.

The only difference between these two demos is SplitScreen has multiple viewports and thus allows the scene to be shown from two different viewpoints. On the Xbox 360 these two viewports are tied to gamepad 1 and gamepad 2 respectively and so simulates a split screen race car game, etc... With the transition from XNA 3.1 to XNA 4.0 Microsoft more closely aligned the XNA API with that of DirectX 11. As a result, it is no longer possible to clear regions of the current display buffer. As a result, migrating the code from XNA 3.0 to 4.0 required a few rendering changes.

I'll discuss those changes in a later tutorial.

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.

[none]

XNA 4.0 Source Code

In this week's reading I again migrated the code from XNA 3.0 to 4.0. Feel free to compare the code I've provided below with that which was originally on the companion disk to see the differences. I will also be providing a more in-depth explanation in a future tutorial. One other thing I wanted to note, per Chad's request over twitter, I've excluded the art assets from the downloads. In order to get the below source code to work, you'll need to copy the required textures into the Content folders.

Discussion

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

XNA 4.0 Workshop - Week 2 (Part 2)

31. January 2011 08:34 by Jeromy Walsh in Workshop, XNA 4.0  //  Tags:   //   Comments (13)

Heya All, Last week was supposed to be Week 2 of the workshop, which was to focus on 3D Mathematics and the Graphics Pipeline, however I saw very few questions until the end of the week, with just a few people posting links to recommended math tutorials. I took this to mean everyone understood the material until I started seeing people posting "I'm totally lost, I don't understand anything."

This was more the reaction I expected at the beginning of the week, and was hoping that as people encountered things they didn't understand they'd ask questions about it. For example, one person said they didn't understand a laundry list of acronyms but then googled the terms for hours trying to figure out what they all mean. If you're brand new to game programming the best thing you can do is bring your questions to the community. We can answer them in minutes where it might take you hours.

Also, I had end of the semester grades I had to submit last week, plus lesson planning for this upcoming semester, so I was unable to post the tutorials I wanted to. So I'm going to allow this week to act as "Part 2" of Week 2. Please use this opportunity to ask specific questions and discuss the areas you are unfamiliar with, and I'll make it a point to post more tutorials this week. See you on the forums!

XNA 4.0 Workshop - Week 2

24. January 2011 10:10 by Jeromy Walsh in 3D Graphics, Mathematics, Workshop, Xbox 360, XNA 4.0  //  Tags:   //   Comments (0)

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 - See my own blog, tutorials 2 - 4.

XNA 4.0 Source Code

 

Discussion

 

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

XNA 4.0 Workshop - Week 1

17. January 2011 10:24 by Jeromy Walsh in Workshop, XNA 4.0  //  Tags:   //   Comments (1)

Hey All,

Welcome to Week 1 of the XNA 4.0 Winter Workshop. Each week there will be 30-50 pages of reading to be done, plus some supplemental materials which may be provided by myself or one of the other students or mentors. I know it's a lot of reading, but it's necessary if we're going to get through the entire XNA Framework and Library in 16 weeks.

Reading Assignment


Chapter 1
Week 1 starts off the workshop slowly with a guide on getting XNA 3.0 (now 4.0) installed on your computer. This is an essential first step as you're not going to progress very far in the workshop if you don't have XNA Game Studio 4.0 installed on your machine. With that said, the instructions are a bit out-dated. As of XNA 4.0, XNA Game Studio is now integrated into the "Windows Phone Developer Tools" and is installed along side The Windows Phone Emulator and The Express Edition of Visual Studio 2010. You can get the required download from the AppHub Download Resources page.

This was confusing to many people at first as it seems to suggest XNA is now only for developing Windows Phone games. While XNA is the only way to develop hardware accelerated games for Windows Phone 7, it is NOT just for developing Windows Phone games. Once you've installed the Windows Phone Developer tools you can launch it or Visual C# 2010 (Express or Studio) and make games for both PC, Xbox 360, AND Windows Phone. 

Note: The Windows Phone Developer Tools only works on Windows Vista or Windows 7. If you happen to have Windows XP still (upgrade to Win7), there is a separate installer that just includes the XNA Game Studio 4 extension to Visual Studio 2010. In this case, you will not be able to develop WinPhone7 games and you'll need to have a separate version of Visual Studio 2010 pre-installed on your machine. As with previous versions of XNA, the extensions work for both the full Visual Studio 2010, as well as the express edition.

Chapter 2
Chapter 2 of the book assumes you have an interest in developing XNA games for the Xbox 360 and shows you how to create an Xbox 360 game, how to purchase the required Creators Club Subscription (if you're interested in deploying to the Xbox 360 - not required for the workshop), how to connect your Xbox 360 to your PC via a LAN connection, and finally, how to deploy and debug your game on the Xbox 360. After that, it goes into basic information on how to manage games for multiple platforms, including how to copy your project from one platform to another. With XNA 4.0, Microsoft has added the Windows Phone platform as well. So any project you make for either PC, Xbox 360, or WinPhone 7 can easily be exported to another platform with a few clicks. Note also that XNA Game Studio 4.0 comes along with a Windows Phone Emulator. So even if you do not own a WinPhone (Like me), it's still possible for you to "test" your games on that platform.

As a side note, deploying to the Xbox 360 or WinPhone emulator is a time-consuming process, and debugging is also more tedious. In general, I like to develop a game for the PC first, work out all the bugs/kinks, and then port the game to the chosen console. This means I have faster iterations while developing the game, and only really need to spend time deploying to the consoles when I test the games on those platforms. Does this sometimes mean I'll have unexpected surprises when I change platforms? - Yes. But the time I save in development more than makes up for the time I spend trying to figure out what's different on the new platform.

Note: As the workshop progresses I'll point out key differences between the consoles so there's fewer surprises for readers. The first, which isn't entirely relevant yet, is that the x86 architecture is a little-endian architecture, while the Xbox 360 is big-endian. This means if you're serializing data between PC and Xbox 360 (such as with networking or shared files), then the order of your bytes within a word or dword will be wrong. The Windows Phone 7 is bi-endian, so it's up to the OS to determine. Fortunately, the .NET Compact Framework has a static field that allows you to test whether your application is running in big or little endian: BitConverter.IsLittleEndian. 

Chapter 3
Chapter 3 is on "Performance Considerations" and is designed to help readers realize that XNA is a managed framework, and as such has some performance and memory caveats which you need to be aware of. Many of the suggestions in here will be intuitive for experienced C# or Java developers. If you're new to the Managed scene, make notes and then move on. I have a phrase I often repeat to my junior developers which I heard many years ago when I was learning about eXtreme Programming: "Optimize Last." While it is important to develop with memory and performance limitations in mind, it's far too easy to get caught up in the "optimization" phase of development and forget to actually finish the project. This is a form of procrastination for many people. So while you do need to "Measure, Measure, Measure...." don't start measuring and optimizing until you've finished the project or until you reach a point where performance is so poor it makes development difficult.

The second part of Chapter 3 is source code for a benchmarking framework. Please note that it will not compile for XNA 4.0 as XNA 4.0 had many breaking changes in the Graphics API as well as the GameTime class. I'll provide functional XNA 4.0 Source Code a little later (my laptop is out of juice and it has my projects on it), as well as supplemental material indicating why the source code doesn't work.

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.

GameDevelopedia.net Tutorial #1 - This tutorial shows how to create your first "application" with XNA 4.0.
*RealTime Revisited - A blog post I did about the changes to GameTime class in XNA 4.0

XNA 4.0 Source Code

Discussion

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

XNA 4.0 Winter Workshop Introductions

16. January 2011 21:45 by Jeromy Walsh in Workshop, XNA 4.0  //  Tags:   //   Comments (8)

Heya All,

Student Zack T. posted an Introduction Thread over on the GameDev.net Workshop Forums. Take advantage of it and introduce yourselves.

XNA 4.0 Winter Workshop Reaches 250!

16. January 2011 13:19 by Jeromy Walsh in Workshop, XNA 4.0  //  Tags:   //   Comments (13)

Hi All,

For those that are interested, more than 250 people have signed up to participate in the XNA 4.0 Winter Workshop, and no doubt more will be following our discussions in the GameDev.net XNA 4.0 Workshop forums.

Thanks for spreading the word! The more people who participate, the better the questions and answers will be - and the better games we can look forward to seeing in the coming year(s).

XNA 4.0 Winter Workshop Final Notes

16. January 2011 11:33 by Jeromy Walsh in Workshop, XNA 4.0  //  Tags:   //   Comments (0)

Hi All!

Here we are down to the wire. The XNA 4.0 Winter Workshop 2011 officially begins tomorrow. This means that starting tomorrow there will be 16 (more or less) consecutive weeks of intense XNA 4.0 study taking place here on my blog, on the GameDev.net XNA 4.0 Workshop Forums, and wherever you feel like sitting down with your compiler or the assigned text book.

Each week on Monday I will, at some point during the day, post here to my blog the reading assignments for the week, as well as any additional supplemental tutorials or information I want to throw out. I will also provide the XNA 4.0 version of the source code provided in our textbook (because it's XNA 3.0 and doesn't compile on its own).

Then, you'll have approximately 50 pages of reading to do, as well as source code to implement. As you encounter problems, have questions, or think of additional information you want to provide, head over to the Official Forums of the XNA 4.0 Winter Workshop. There you can post your thoughts, questions, observations, tips, etc... for the benefit of all.

Myself, and the other mentors will do our best to answer questions in a timely fashion, but remember most of us have full-time jobs or school, so it could be up to 24 hours before we answer your question (unlikely).

Around Friday I will post review questions here in the guise of a web form. Answer the multiple choice, true/false, and matching questions to the best of your ability and hit submit. The answers will be provided to you as well as your score, so you can get a general idea of how well you're progressing. Remember, this isn't a graded class. Answering the review questions, completing projects, etc... is all up to you and depends on how much you want to master the material we cover.

The Week 1 forums will be opened at some point tomorrow. In the mean-time, feel free to post questions in the General forum, or post comments here.

Cheers!

XNA 4.0 Winter Workshop 2011 Signup is Live!

29. December 2010 18:51 by Jeromy Walsh in Workshop, XNA 4.0  //  Tags:   //   Comments (6)

After a bit of coaxing the BlogEngine.net AJAX system I finally got the sign-up form done. Hey, I said it would be up on the 29th - I didn't say it would be up by mid-day. :)

You can sign up to participate in the XNA 4.0 Winter Workshop by visiting the XNA 4.0 Winter Workshop Signup page.

XNA 4.0 Winter Workshop Signup Coming Dec. 29th

23. December 2010 11:13 by Jeromy Walsh in Workshop, XNA 4.0  //  Tags:   //   Comments (4)

I'm out of town on vacation and was unable (due to work) to get the sign-up sheet posted before I left. So the signup will be available here on my website when I return on December 29th.

XNA 4.0 Winter Workshop Schedule and Topics

3. December 2010 13:35 by Jeromy Walsh in Win Phone 7, Windows Installer, Xbox 360, XNA 4.0, Workshop  //  Tags:   //   Comments (14)

After reading the feedback everyone has provided, in addition to looking through the Microsoft XNA Game Studio 3.0 Unleashed "Textbook", I've decided on the following rough topics and schedule.

I'll go into the schedule in more detail in the coming weeks; including disclosure of the sub-topics, assigned chapters from the text, and additional resources & links. As I mentioned before, I'll be providing updated source code and additional tutorials each week to make the leap from the textbook's coverage of XNA 3.0, to include the relevant topics of XNA 4.0, such as coverage of Input.Touch during Week 3.

As usual, feel free to provide comments. This is just the first draft.

  • Week 1:  Game API/Introduction
  • Week 2:  3D Graphics
  • Week 3:  User Input
  • Week 4:  2D Graphics & Effects
  • Week 5:  Audio/Video
  • Week 6:  High Level Shader Language (HLSL)
  • Week 7:  Scene Management, Resource/Entity Management, & Streaming
  • Week 8:  State Management & FSM's
  • Week 9:  Extending the Content Pipeline
  • Week 10: 3D Animation (Hardware Skinning & Skeletal Animation)
  • Week 11: Rigid-Body Physics & Constraints
  • Week 12: Advanced Texturing Techniques
  • Week 13: Particles & Other Effects
  • Week 14: Networking/Gamer Services
  • Week 15: XNA Development with Web Services    
  • Week 16: Install Projects and Deployment

About the author

Jeromy Walsh is a professional game programmer with multiple credited and uncredited AAA game titles. Jeromy's primary area of expertise is in Tools/Engine development, though he likes to fiddle with other areas as well.

Month List