Category: XNA

Weekend Advances

I have advanced quite a bit today, as I said I needed to re-factor my physics class, which I did very successfully.

I did learn something pretty cool today. How to properly create constructors for Child Classes.

something along the lines of

public class Parent
{
	public 	Parent(int age)
	{
	// do things with the stuff
	}

}

public class Child : Parent
{
	public Child(string name, age)
		: base(age)
	{
	// do things with the stuff
	}

}

Overloading Constructors is also cool.

Unsafe!

I was trying to create a constructor with an undefined number of parameters, because my PhysicsDynamicClass parameter list was looking like it was becoming unwieldy.

Well, turns out you can do something like this with C# using the params keyword. Excellent I thought and off I went to write the constructor.

I started by converting my PhysicsSimpleConstructor with just two parameters. And this is how it looked like

public CPhysicsSimple(params object[] list)
{
	Position = (Vector2)list[0];
	Rotation = (float)list[1];
}

So I build it, compiled it, and I was hoping that it would be awesome. But I ran into a stupid problem, the way I pass the paramenter when using the constructor.

CPhysicsDynamic physicsComponent = new CPhyisicsDynamic(new Vector2(10,10), 0);

looks fine right? but at runtime C# reads reads the second parameter I passed to the constructor as an integer, and when I do the Casting from object{int} to float (see line three of the first code snippet), C# just can’t do it. WTF?

Which means I need to remember to do this:

CPhysicsDynamic physicsComponent = new CPhyisicsDynamic(new Vector2(10,10), 0f);

And then everything works fine. See the difference? No? Look Harder! Yes that little “f” there After all my parameters and all of the sudden my code became unsafe.

Back to the drawing board.

[UPDATE]

I found a solution for the casting problem. I can use:

Convert.ToSingle(list[1]);

and that will work. That does not make the Constructor less dangerous though.

On the 360

I have finally managed to deploy my project to the 360 for the first time, after a bit of a battle of wits against the XNA content Pipeline.

It’s an awesome Pipeline for small games but I took sometime to get my head around it. Now Inside my solution I have 5 Projects.

Here is how it’s roughly organized.

  • A Windows Game Project containing the game code.
  • A Windows Game Library that contains readers and importers. It also contains all of my Assets, this is an awesome idea given to me by a friend, which means I don’t have to build my assets every time I change something in the game code.
  • A Windows Pipeline that Contains my Type Writers. This was the tricky part to get my head around, since the Content Pipeline will only run on Windows and only at build time, so you don’t created a version of it for Xbox because you don’t need to. You use a reference to the same pipeline project in both your windows and Xbox Game Libraries.
  • An Xbox360 Game Library that is a copy of my Windows Game Library with some reference changes.
  • A Xbox Game Project that is a copy of my windows Game project with some changes to the references.

And now I also added Source Control to my Project, using Perforce (That is free for use with up to two clients, and I’m only one).

Here is a little video of it all running. Don’t mind the quality of the video because it was made using my fairly old digital camera.

Progress II

After being able to write my Level Data from XSI and read it in XNA in a tidy XML form I decided to tackle a different problem: The fact that in a completely empty space you have absolutely no notion of where are you going to and from.

I decided for a neat Point Sprite particle system to dot some “space dust” around you.

This implementation is on it’s very early stage and it’s just an example of what is going to feel like. What you see in the video below is basically a “Box full of sprites”. Note that their size does not change with the distance, something I can probably resolve by rewriting the “.fx” file. I will need to do that anyway to have teh Particle system deasling with things like particle life, speed, duration, render distance, etc.

Then I need to write individual Particle Settings and systems for the different needs I have such as explosions, Projectiles, trails, etc.

Progress

I have to say. I am amazed at the progress I have made on my little project over the weekend. Nothing that I can post a screenshot of though because the progress was made entirely in the background.

I got my bearings with XSI, I come from years of tinkering with 3Dsmax so I still prefer it, but I am confortable with the interface now and I am actually very impressed at the level of exposure that XSI offers to the end user, so scripting for it has been rather good. Not that I needed anything too complex but with Max I never even tried dwelling into MaxScript, and XSI offers an advantage here, you can script in two languages “out of the box”, VBScript and JScript, and you can add Python and Perl if you can be bothered to install the Addons.

I decided to go for the VBScript (which I am finding a bit convoluted) mostly because of the available documentation on it. And in two days I was able to completely write my own self-installing plug-in that exports all the Data I need from XSI into an XML document that I can parse later on on XNA.

So, basically, counting the time spending googling and thinking about my pipeline I was able to create a crude, but functional, Level Editor for XNA using the XSI Mod Tool.

Right now, it comprises of the amazing ability of exporting type, name, position and rotation of every Model in the Level (Scene). Later on I’ll be adding functions to create specific entity types from the list of available entities. And Voilá, I got myself a neat Pipeline.

Now onto working on the XML Serializer to actually use the data I churn.

A little video of how the thing looked a week ago (it didn’t change a lot yet)

NOTE: I also managed to add support for the Xbox360 pad, so I can fly around the environment easily (much better than the keyboard).

Quaternion Rotations

Right.

My little XNA project is moving along. Well, tripping along is more like it. I spent the past three days trying to work out proper transformations for my camera because I they were rotating (in all axes) but the rotations were relative to the world. So they didn’t work properly for a flight camera.

Turns out that my calculations for the camera rotation and movement were only updating the position, so the rotation was aways beeing calculated from the world Axis, using values for Yaw, Pitch and Rotation that were just virtual and were not actually changing the avatar.

So I read somewhere (and by somewhere I mean Riemers XNA tutorial) that I needed to use Quaternions to do the transformations easily.

So after reading his tutorial and reading the Wikipedia page about Quaternion Rotations while lying in the bed before sleeping, I ended up dreaming the solution to my problem.

I had to create a Quaternion for the rotation of my invisible avatar, and use that to work out the rotation Matrix for the camera and updating the original Rotation Quaternion after the camera was updated.

Now. It works, but I don’t think I fully grasp what I’m doing. It’s like knowing how to read out lout a spell from a grimoire without actually knowing what the words you read mean. That can lead to unforeseen and even catastrophic consequences.

WordPress Themes