Lorenz Cuno Klopfenstein

Posts tagged "XNA Contest"

While working on the XNA Contest I wanted to use a standard Windows Forms dialog for credits at the end of the game, instead of doing it all inside XNA (mostly because it would have been much easier and faster to do). At the moment, when the game is over, this dialog appears:

My game's credits

The problem is that, as soon as the XNA window closes and the game terminates, the XNA framework tears down the entire thread on which it was running. If you try to open a Windows Forms dialog at that point, you will see a glimpse of it for some millisecond if you're lucky.  :)

The solution is a pretty simple workaround, but since I tried a lot of different things before and wasted some time, I thought this might by interesting to share: essentially, you run the whole XNA game in a different thread than your main thread. When XNA closes its window, it will tear down the other thread you created, leaving you with the main thread still running.

static void Main(string[] args) {

	Application.EnableVisualStyles();

	//Separate thread on which the game will run
	Thread backThread = new Thread(new ThreadStart(delegate() {
		using (Main game = new Main()) {
			game.Run();
		}
	}));

	backThread.Start();

	//Wait for the game to end
	backThread.Join();

	//Credits dialog
	using (Credits c = new Credits()) {
		c.ShowDialog();
	}
}
Posted on Wednesday, February 11, 2009
949 Views
54 comments posted

One of the last steps in the production of my game for the XNA Contest was the gathering of all the needed sound clips and the implementation of a little game component that would take care of playing the different audio cues, based on what would happen during the game. (more...)

Posted on Sunday, November 23, 2008
Tagged as
1323 Views
1 comments posted

I'm finally getting back to my XNA series of posts, which will eventually lead to the release of the - cleaned up - source code of my little game (I just hope that I'll be able to do so before XNA 6.0 comes out...).

Anyway, one of the truly biggest problems I had while developing the game, was to figure out HOW exactly to point an object towards another point in space. This sounds really basic, probably is, but my math skills are so weak that I had to think about it almost an entire day before finding a solution. Perhaps this will be useful to similarly counfounded people, like me.  :D

The main problem is that you are trying to orient something along a vector, which starts in one tridimensional point and ends in another one. These two points in space are sufficient to give us a simple directional vector (the distance between the two points), but not enough for a full translation matrix (or a rotational matrix, in this case). This is because there are infinite positions in which the object we are trying to rotate could be in, while still pointing to the correct destination point. To exemplificate:

Awful scheme of the problem.

Yes, I know the drawing is extremely ugly.  :) You try doing something better with Paint.NET!

Anyway, assume the two balls are the two points I was talking about and the black thick line is the distance vector between them. Then, the disc around the red ball (or that what should look like a disc) is the plane on which all possible "up" vectors of the object could be, while still having its nose pointed straight at the blue ball.

The problem thus is that we have too much "correct" solutions: but we must decide for one (and consistently). Therefore, the simple way to do it is to simply pick a completely arbitrary vector:

//Get distance between points
Vector3 dist = ballBlue.Position - ballRed.Position;
dist.Normalize();

//Get angle to arbitrary vector and compute the rotation axis
float theta = (float)Math.Acos(Vector3.Dot(dist, Vector3.Up));
Vector3 cross = Vector3.Cross(Vector3.Up, dist);
cross.Normalize();

Quaternion rotation = Quaternion.CreateFromAxisAngle(cross, theta);

The code is pretty straightforward: first of all you compute theta, the angle between the distance vector and the arbitrary vector (in this case I chose the up vector, but you can use whichever makes more sense in your case). Then we compute the cross product between those two vector and normalize it: this will yield a nice vector (one of those on the "correct" plane I mentioned above) that can be used to generate a rotation quaternion or a matrix.

The result in my game: notice the arrow pointing towards the golden point in space.

And this is the result in my game: notice the golden "thing" above the spaceship? It's a green arrow that points exactly towards the yellow point in space on the right.

Posted on Thursday, November 13, 2008
Tagged as
346 Views
0 comments posted

Audio After a long pause, I'm finally getting back to my series of XNA posts which I started for the XNA contest @ Unive. This time it's about audio in the XNA framework, using the Microsoft Cross-Platform Audio Creation Tool (XACT).

XACT interface
The main XACT interface.

This application, which comes bundled with the XNA Game Studio (latest edition 3.0 is currently in beta), allows you to import audio files, group them together in "sounds" and "cues", editing settings like volume, frequency and doppler pitch, and finally export everything to the binary files that can then be imported into Windows or XBox 360 games.

More...

Posted on Saturday, October 18, 2008
Tagged as
1828 Views
2 comments posted

Sad pacman ghost Last friday the contest ended and the winners were announced. Unfortunately, I didn't win the Xbox...  :(

But - with just 2 points less on 192, it was a close call. That also means I won't get Grand Theft Auto IV until it's published for PC and that I'll divert my money in getting a Wii someday.  :)

I will go on writing posts about the game I created for the contest during the next days (I'm a bit busy with exams lately) and will publish the source code very soon.

Posted on Thursday, May 22, 2008
Tagged as
269 Views
0 comments posted

Since the objective of the contest is to recreate a nice-looking solar system, an effect I really wanted to implement is sun overcasting, that is the effect of the sunlight glowing inside objects appearing in front of the sun.

The same "overcasting" effect is seen in the Gothic 3 engine and looks really great.

Overcasting effect in Gothic 3

More...

Posted on Wednesday, May 14, 2008
Tagged as
296 Views
2 comments posted

An animation subsystem is an useful component of a game engine, that can be very handy when writing the game's behavior without having to hand code everything. In this article my engine will get a basic animation framework: not an extremely complex one, but enough to create some nice effects. (more...)

Posted on Thursday, May 08, 2008
Tagged as
303 Views
1 comments posted

Stopwatch Yesterday I gave the last finishing touches to the code and submitted it for the contest. The final code not only features a semi-serious rendering engine, it also includes chainable post-processing effects, particle systems and nice looking shading effects (per-pixel lighting, normal mapping and so on). And a nice game on top of it!  :)

I'll go on posting more articles about how I implemented the engine and other details in the next days, so stay tuned until May 16th for the results of the contest. I'll also publish the game after cleaning it up a bit.

Posted on Wednesday, May 07, 2008
Tagged as
326 Views
0 comments posted

As seen in the previous article about the rendering subsystem, drawing operations are incapsulated inside a "RenderOperation" class. Each instance is queued by the renderer and sorted in order to prevent graphical artifacts (and to improve performance). (more...)

Posted on Wednesday, May 07, 2008
266 Views
0 comments posted

After giving a look to the architecture of the game's renderer, now we'll see how the objects of the game will be organized. (more...)

Posted on Sunday, May 04, 2008
Tagged as
336 Views
1 comments posted
Back to Klopfenstein.net
Clemens Klopfenstein Serena Kiefer Lukas Tiberio Klopfenstein Lorenz Cuno Klopfenstein
English German