Wednesday, December 08, 2010

vs2010 Resx Error Not Valid Win32 Application Workaround

I had a problem today compiling an app on Windows 7 64-Bit that compiled fine on XP 32 bit. It turns out that it is a bug in vs2010. This is the workaround that I used just in case you run into it.

Two things were happening. Both of them were related to the resx file of my main form.
1. Images that were used in ImageList or Toolbars were causing a problem.
2. A Matrix from a class property was being cached in the resources now and causing an error.

I reloaded the GUI images for the toolbar buttons to use images imported into the Properties Resources instead of the Form Resource. This seemed to clear up that issue.

Next, I deleted the offending Matrix data out of resx. I also removed where it was setting the class property in the InitializeComponents function. Next, I fixed the class so that the Matrix property was not serializable by the designer. So, I wouldn't have to do this again. This took a piece of metadata above the property to tell it not to set a default value:
Everything seems to be working after that. I'll try to post the exact error next time I see it.

Happy Coding!

Tuesday, December 07, 2010

BSP Trees in Modern Game Engines

I first came across BSP when working with the Unreal Engine. We were working in UnrealEd and a level designer was demonstrating how they were using BSP Brushes to make rooms. I thought they looked like plain boxes. And, that’s really all they were until the compile button was pressed and the magic began. Then, those boxes were sliced, diced, lit, packaged, and ready to run.

Now, as I start planning out my level editor, I find myself thinking about those BSP trees. It has been a few years now, and I begin to wonder if they are the right structure to use in my level editor.

A Binary Space Partitioning (BSP) Tree is a structure that subdivides space into smaller sections or sets. It has been used in First Person Shooter (FPS) games to solve a problem with rendering polygons in the correct order. It would provide a method to traverse the structure and draw the polygons from back to front quickly.

But, the need to manually order triangles became less of an issue with the advent of the hardware accelerated Z-buffer. The polygons get pushed onto the GPU to be quickly sorted and processed for rendering.

That doesn't mean that BSP is obsolete. Spatial partitions, such as BSP, quad-tree, and octrees, are essential tools in modern rendering engines. They are used in visibility testing, network optimization, collision, and lighting. They can also be computed during compile time.

There are many discussions on which spatial partition is best. The truth is that they've all got their strengths and weaknesses. Once you've identified the characteristics of your engine, you'll be ready to identify which structure is best for you. But don't rule out the BSP Tree. They are well documented and still used today in modern engines. Especially for First Person Shooters.

Happy Coding!

Related Links:

Saturday, December 04, 2010

XNA Multiplayer Programming

In a previous post I put together a simple multiplayer tank game with GDI+. But, I decided to change to XNA when I hit a limitation with the game sound. What a perfect opportunity to make it 3D!

There are many advantages to using XNA 4.0, especially if you want to play your game on the xbox 360 or Zune. But, keep in mind that if you want to play it on the XBox 360 you will need to purchase a Developers Membership at App Hub

Content Creation
The first task is to create the tank model and turret using Artismo 3D. If you want a copy just let me know by commenting on this page. Or send me your e-mail by using my contact page here.

The tank in Artismo:

In Artismo I can create the models and the artwork in one application. It even does animation for characters. And, supports plug-in architecture to incorporate project-specific processes. For example, a level editor plug-in could be incorporated into the tool to produce the levels for your game.

Tank Movement
Moving around a 3D object is a lot easier than in GDI+. In GDI+ you're only drawing a square bitmap and everything is centered on the upper left corner so you have to move the image up there, rotate it, and put it back. In 3D you have a matrix and XNA provides really simple functions to rotate or translate the object around. If you ever used Managed DirectX for Windows it is very similar code.

User Interface
In the first version I had regular windows textbox controls and buttons. Not in XNA! You'll have to code them or get a GUI library on the internet. They're not that hard to code though. But, the textbox control does take a little work. If you do a few searches on the internet you can find some examples of doing it. The font support was really easy as well.

Client/Server Protocol
On the server side, there were a few changes because I had to send more data now. Instead of just a position point in 2D and a rotation amount, I changed it to send the tank matrix or transform. It is possible to do it with the original data but it was much easier to pass back and forth the exact data I needed instead of trying to derive the matrix from pieces of information.

Sound was a lot easier! I can play multiple sounds at the same time and XNA even supports stereo functionality so if a tank blasts off a round to your right you can hear it in the right speaker. I didn't take it that far but atleast it is good to know that it supports it.

I used a small 3D ball for the bullet. To do the collision I created a Bounding Box roughly the same size of the tank. Then, I move the position of the bullet into the model's space and create a Bounding Sphere for it and do collision against the two. All of the collision code is built into XNA. It looks like this:
BoundingSphere sphere = new BoundingSphere(bulletpoint, 0.2f);
// create a bounding box for each object.
BoundingBox bbox = new BoundingBox(new Vector3(-3, 0, -3), new Vector3(3, 3, 3));
bbox.Intersects(ref sphere, out result);
if (result)
od.Health -= 1;
return true;

The end result is a 3D version of my original tank game that can be played on multiple computers. Some extra features that could be tossed in there is chatting, explosions, etc. That's as far as I'm going with this game.

Tank Wars Single Player with 20 NPC Tanks:

Next time we'll discuss level design and make some plug-ins for Artismo to produce the levels.

Happy Coding!


Sunday, November 14, 2010

XNA 3D Models

Creating a character from start to finish requires a game plan. I used to work with a content artist that would spend about 8 hours working on a single plant. So, when you're talking about a fully rigged and textured character with multiple animation sequences you start measuring the task in days. And, if it's a main character it may be a few weeks.

This model above is of John Crighton from the Sci-fi Show FarScape. By the way, if you haven't already, I highly recommend it. Give it a few episodes to get over the puppet factor and it's a really good storyline (Thanks Matt!). Anyway, this character is fully rigged and textured (1900 polys). It took around 8 hours to complete.

I used a simple mirror tool (In my editor, Artismo) to keep the character symmetrical. And, used extrude and line-flip and line-split functions to shape the character. After finishing the basic shape you want to save a copy for future models to add to your 3D tool box. Note: If you want a copy of my basic model let me know.

Once you are finished with the shape of the character, you should begin building a basic skeleton. While you're making the skeleton, add some extra bones for the lungs and for the neck as shown here:

You now have a base skeleton and character for any of your characters. You just need to customize them. Note that I didn't attach the model to the skeleton at this time. Since this is a generic character you may end up changing the shape before you're ready to rig it to the bones.

After doing the rigging, then it is time to paint the character. One mistake I've been guilty of is painting too many of the shadows especially around the neck and face. These fake shadows turned out looking really bad. It is better to use the model geometry and a light shading to augment the character shape. It's not like 2D drawing. This model started looking a lot better after I removed those shadows.

One tip to keep in mind when texturing is to lay out your geometry on the texture so you can line things up. You don't want to have the backs of the legs pointing upside down if you have to wrap some detailed clothing around it. By the way, next time you're walking around take a look at the patterns on people's clothes and how they wrap. You may notice that none of the patterns line up correctly on the seams. But, they're good at hiding the seams where you won't notice! Keep that in mind when you do your textures.

That's about it for now. I've got work to do on my 3D tank game and my next character is Dargo from Farscape. If you want a copy of Artismo let me know.


Monday, November 08, 2010

C# .NET Asynchronous Sockets Tank Game

First, let me say that this project was not about the graphics and game play. I wanted to try out some Asynchronous Client Sockets in C#. Getting sick last week was a good opportunity to try it out since I wasn't going anywhere. I came up with this little Tank Wars game.

I kept the client really simple by using GDI+ to draw the bitmaps on the screen. It just communicates the key events to the server. All of the game logic and scoring is handled by the server. Add some basic scoring and sound effects and we have Tank Wars!

I did hit a roadblock when I decided to add some sound. I used a simple class called SoundPlayer in C#. This was great for the Tank shot but was unable to play multiple sounds at the same time. So, I think it is time to call this exercise finished and move on to the next version.

Overall, it was a fun little couple hour project that got me exposed to what happens behind the scenes.

For the next version:
- DirectX Client.
- Really good sound support.
- Polish up the full GUI.
- Make the Server Public so Client can be downloaded.
- Support a SinglePlayer mode.

Feel free to leave any questions or comments. I can even post some code up here if anyone is interested.

Happy Coding!

Related Links:
Asynchronous Socket Programming in C#
PlaneShift Video on MMORPG Design.

Sunday, July 11, 2010

DirectX 2D Sprite Animation

I've been working on my first plug-in for Artismo 0.11.5 (dev). The Sprite Capture Plug-in will take the current animation sequence and export the animation to a bitmap as a 2D sprite map for import into any 3D Isometric engine.

The benefit of this plug-in is to quickly generate realistic 3D animations and run them in 2D. Several games use this technique. For example Diablo, WarCraft III, StarCraft, and other 2D sprite engines.

I had written a program in the past to allow me to create these animations by hand, but I had to draw every frame. So, a walk sequence which had 10 frames had to be drawn in 8 directions which was 80 frames for one animation sequence. So, if you wanted to have the character swing the sword while walking, that was an additional 80 frames.

With this tool, I create the 3D model with animation, and export any sequence I want. The penguin above is the test model. There are a few minor tweaks but this plug-in is almost ready.

Happy Coding!

Sunday, June 27, 2010

DirectX 3D Modeling in Beta Testing

I released the beta of my editor this weekend. This evening I began working on the car shown above. I'll post a finished shot when I'm done.

I'm looking for a few 3D projects that I can supply my software to for feedback. It exports animated .X files and I have working examples of how to animate the meshes in XNA and DirectX. If you have a 2D or 3D project, this may be the tool for you. I'm working on a tool right now that will export all the animations in a 2D format for sprite engines. If you're interested in beta testing please let me know.

Happy coding.

Friday, June 11, 2010

Think out of the Box

Just a short thought on solving hard coding problems. We all know that when it comes to writing code, there are usually several ways you can do something. If the way you're doing something seems really difficult, try stepping back and attacking it from a different angle.

We're not talking about code snippets here. If you're searching for specific code, you can probably find a sample out there. But, as Dex from Starwars would tell you, there's a difference between knowledge and wisdom. Applying the knowledge is where the money is! Do some research and see how people are solving similar problems. And, carry some paper with you so you can doodle designs on the go.

Most importantly, don't be afraid of failure. Just because you think it will work doesn't mean that it will, but it brings you one step closer to fully understanding the problem. Prototyping is your friend.

Happy Coding!

Friday, May 14, 2010

Bevel Algorithm

I've been working on this bevel algorithm for about a month now. Actually, this is the second bevel algorithm I've written for this. The above box was beveled three times in a row. I added some colors just to show off the geometry.

So, with this algorithm there were two challenges. First, was writing an algorithm that worked on all primitives multiple times. The other was support for the bevel gizmo that allows the user to bevel the object in realtime.

This is also the first modifier I have that displays text next to the gizmo so no panels with controls are required to perform the task. Slightly off subject, I tried using blender the other day and my editor is SO much more user friendly! If you use blender, you'll love mine.

I still have a lot of work on it but it's nice to be heading in the right direction.

Happy Coding!