1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Pages

Showing posts with label XNA. Show all posts
Showing posts with label XNA. Show all posts

Friday, October 28, 2011

Resonance

My sophmore year I spent ~9 weeks working on a project called Resonance.  Our lead's pitch was green lit, and we quickly went to work on the project.  I was one of the two lead programmers on the game, working on low level rendering, animation, physics, and the like.  My fellow programmer also dedicated a significant amount of time helping me with these things and writing the game logic for all the game objects.  You can find more details about the game, including our design document and first playable on the lead's blog here.  Here's some footage of the first level in the game, which was mostly designed by myself (with feedback from the group and our professor).

 

Said level was built with the game editor I created.  Of course, I owe a lot of credit to the designers and artists who helped make it possible.  Here's some footage of the editor, with a voice over by yours truly explaining some details about the way it operates and the lessons I learned from creating it.
NOTE: I apologize for the audio quality.  You will likely have to turn up your volume to hear me clearly in these two videos.

 

And here's part two of the editor related videos showing the completed level used for the gameplay footage above, only this time loaded into the game editor.


A lot of the lessons learned from this project have directly influenced my XNA Game Engine (which I may introduce here sometime in the near future).

Monday, April 4, 2011

A Trip Down Memory Lane


 
 
An old project I made freshmen year in a group of 4 aspiring developers. Not bad for beginners with a mere 10 weeks of time from start to finish.

Thursday, March 31, 2011

Drawing Lines in XNA With SpriteBatch

Lines are a vital primitive that can greatly aid one's work during development. They can be used to draw the actual geometry of an object, show the distance between them, and let testers spot bugs earlier in development.

If you have a drawing interface that only relies on SpriteBatch and don't feel like messing with Vertex Buffers, you can cheat drawing lines using a single texture. By using a 1x1, white pixel, we can create a simple interface to draw lines of any size and color.

First you'll need to create the texture. Having one static copy may be preferred over creating the texture inside every instance. A current project of mine keeps a copy of this texture in a "PrimitiveManager", which oversees a number of different needs. We'll just keep a copy of this pixel in the Line class here for simplicity's sake.

public class Line {
    public static Texture2D Pixel;

    public static Initialize(GraphicsDevice graphics) {
        Pixel = new Texture2D(graphicsDevice, 1, 1, false, SurfaceFormat.Color);
    }
}

This will create our simple 1x1 pixel. By using a Color Overlay, we can have it render in any color we like. It will support transparency too.

What kind of parameters would we like to use when drawing lines? Most lines are defined by a start point, an endpoint, a color, and a line thickness.

Since we are using a 1x1 pixel, the distance between the start and endpoint will be the scale in one direction, and the line thickness in the other. The rotation passed into SpriteBatch will be the Atan2() of the x and y values from this difference.

To draw lines we are going to set our Origin to be {0.0f, 0.5f}. This is the center left of the pixel, and will thereby apply scaling in one direction.

public class Line {
    public static Texture2D Pixel;
    private static Vector2 Origin = new Vector2(0.0f, 0.5f);
    
    public Color color;
    public Vector2 start;
    public Vector2 end;
    public float lineThickness;
    // following is not needed unless you are doing front-to-back
    // or back-to-front drawing
    public float layer;
    
    public static InitializeLineDrawing(GraphicsDevice graphics) {
        Pixel = new Texture2D(graphicsDevice, 1, 1, false, SurfaceFormat.Color);
    }
    
    public void Draw(SpriteBatch spriteBatch) {
        Vector2 d = end - start;
        float angle = Math.Atan2(d.Y, d.X);
        // add 1 for single points and due to the way 
        // the origin is set up
        float distance = d.Length() + 1.0f;
        spriteBatch.Draw(Pixel, start, null, color, angle, Origin, 
            new Vector2(distance, lineThickness), SpriteEffects.None, layer);
    }
}

Why do we add 1 to our distance calculation? There are two reasons:
1) A single point, with a start and end vector in the same space, should draw one pixel on screen. If we don't add 1 to our existing result, single point lines will not be drawn at all because the distance between them will be zero.
2) The origin is offset from the center, and our single pixel texture already occupies a known distance of one. If you look carefully, without this addition, lines will always be drawn one unit short.

In general, there are a number of different ways you can go about implementing this. My code is really just a bare skeleton. The origin can just be passed in every time in the draw method with a hard coded new Vector2(0.0f, 0.5f) constructor call. You might want to write an unload method that disposes of the texture. You could precompute the distance and angle between two points and save them, perhaps as private variables. Properties could work wonderfully to this effect. When either Start or End is changed, simply compute these values and avoid running an expensive square root operation on every frame. Atan2() isn't that expensive, but if you are going to save the distance as a field you might as well do the same with the angle.

Saturday, August 28, 2010

Understanding Bounding Volumes (Paper and Code Download Included)


Over the course of the past month or so I've been working on a very detailed paper with complementary code samples on the topic of bounding volumes. I'm very happy (and relieved) to finally be able to share it with you.

Understanding Bounding Volumes thoroughly covers an integral aspect of collision detection. It explains the theory, usage, and operations required to use bounding volumes properly with explanations, graphics, and fully working code. The paper and code samples are specifically targeted at beginners, using relatively elementary language to explain what is commonly turned into an overly complicated topic. The actual samples and algorithms discussed are mostly specific to 2D volumes. Many of them (particularly the AABR and the BC) can easily be converted into their 3D equivalents.



Operations Discussed Include:
-Volume Construction
-Intersection Tests
-Closest Point Queries
-Distance Queries
-Volume Updates
-and more...

The three volumes discussed are the Axis Aligned Bounding Box (AABB), the Sphere, and the Oriented Bounding Box(OBB). Actual algorithms and code are provided for their 2D equivalents, where my personal naming conventions differ.

Accessing the main document will require a .pdf reader. In each download it is titled understanding_bounding_volumes.pdf. The paper is roughly thirty pages long, but includes numerous pictures and code samples to ease you through it. If you are familiar with bounding volumes you may find a lot of things you already know. However, you may very well find new and useful information here as well. If you are a complete beginner, (I dare say) you've come to the right place. Major operations and tests are explained assuming a great deal of ignorance by the reader. The only prerequisite is a basic understanding of vector and matrix math.


All of the code samples are written in C#/XNA and provided in a Visual Studio Project. The code gives full demos for all of the operations described in the paper. These demos are not meant to stand on their own, but rather complement the explanations seen in the full paper. Primitives, text, and sequences are used to help the user visualize the data. The actual values of the volumes and points are drawn on screen. You can browse these demos with a keyboard and/or an Xbox 360 gamepad. Specific details for using the code can be found in the code_samples_user_guide.pdf file.

The full version includes the paper and the code samples. Downloads offering only the paper or the code are also offered below.

I'm offering this free of charge, so if you appreciate my work please say so in the comments and consider subscribing.






Downloads (Paper Only Available for now)
Full Paper and Code (zip)
Paper Only (zip)
Code Only (zip)