Wednesday, November 29, 2006

Little Signs of Life

Things are coming along nicely with the PFD so far.

Currently, I am pulling the bank and pitch angle.

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
struct Struct1
{
public float bankangle;
public float pitchangle;
};

simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Bank Degrees", "radians", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Pitch Degrees", "radians", SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);


After that, it's all pretty simple.

I've got three layers of texture, although, technically, it could be two. The first the large brown horizon, on top of that is a "glass ball" texture (using alpha to make it partially transparent) that includes the center marks, and the top black mask layer that frames it all.

Then it's just a matter of moving and rotating the horizon based on the angles that simconnect is sending me. The program runs at 60fps, and I've got FSX at 20fps, so I send really only get an update once every 3 frames on the client side, but it still looks smooth enough.

The core of the Update function is this:

RotationAngle = 0;

KeyboardState keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
{
Exit();
}
else
{
rotpasstrans = (float)hWindow.rotpass;
RotationAngle = rotpasstrans;

float switchPitch = (float)hWindow.pitchpass * -600.0f;
horizonPos.Y = (Window.ClientBounds.Width / 2.0f)+ switchPitch;
}


It's a bit messy, but it does the work.

Here's a screenshot of the PFD in action, chirping along (2048x800)



As you can see, it can use some polish and tuning, but for the most part, it's working perfectly. The next step is going to be sizing everything down a bit to make room for more stuff, and then adding the angle of attack registration lines, bank indicator at the top of the artificial horizon, and then the fun stuff: Heading indicator, and the speed and altitude tape.

I have an idea on how to do that, but it most certainly will not be as easy as I think it will.


I want to throw out a huge show of support for ZiggyWare for their wonderfully easy to use XNAFont tutorial. Although you don't see it there, I have been using it for debug purposes.

They have some great stuff going on over there, so I suggest checking out the tutorials if you want to get started from the ground floor on XNA programming.

More to come tomorrow, when I attempt to break everything.

Labels: , ,

SimConnect Datatypes

I overcame my last issue, with not being able to have an event handler, by nesting a call to open a hidden window in the initialization section, using the handle to that form for the SimConnect constructor. All of the event handlers and setup code for SimConnect stayed within that form's extended class. I kind of like it that way, like it was it's own little transport.

If I were to draw a diagram, the form would be represented by a Mini Cooper S.

With that solved, I moved on to the question of actually displaying my instruments. First up, just the artificial horizon. Two sprites, the blue background and the brown/orange "ground" section, that will move and rotate.

The data I'll be requesting from SimConnect is rather basic so far:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
struct Struct1
{
public float bankangle;
};
And then I set up my data definition:

simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Bank Degrees", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

Except, this is wrong.

By following this up with a call to pull in my data, I discovered all sorts of crazy numbers coming through as my bank angle. It didn't make any sense to me, until I looked back and found out the issue. The data type should be SIMCONNECT_DATATYPE.FLOAT32, not FLOAT64. As soon as that happened and my nice 32-bit doubles came flowing in, the horizon was banking beautifully, smooth as silk.

Later today, I'll be adding in the pitch on the horizon and pitch guide lines.

So, that's something to keep in mind if the data you are getting back doesn't make any sense.

Labels: ,

Tuesday, November 28, 2006

Swinging For The Fences

Leave it to me, of all people, to start hard.

I was trying to decide what to do first, a SimConnect project or a XNA project. Then I was struck with most absurd bit of inspiration and decided to combine the two. My first project on this blog is a Primary Flight Display for FSX, written in XNA and connecting with SimConnect. Right away, this presents a problem.

XNA is a cross-platform framework, meant to compile for both Windows XP and XBox360. This means that certain functionality, such as WinForms, is not natively present in the framework. SimConnect, on the other hand, is assuming that you are using standard .NET to create your programs and libraries. So they pass data to you via system messages. Here is the sample override for the defwndproc:

protected override void DefWndProc(ref Message m)
{
if (m.Msg == WM_USER_SIMCONNECT)
{
if (simconnect != null)
{
simconnect.ReceiveMessage();
}
}
else
{
base.DefWndProc(ref m);
}
}

This works great if you are using System.Windows.Forms, however the XNA Framework class 'Game' doesn't have a DefWndProc to override. Right now, the only option that presents itself would be to create a dummy windows form by including a reference to WinForms, and then calling the event handlers from there. This shouldn't be as tricky as it seems. I'll just put the call to run the game in the constructor for the Form class, and roll from there.

I'll see how that goes and update back here.


Labels: , ,

In The Beginning

I've done the livejournal thingy before, and MySpace and all that nonsense, but now I am moving into different avenues of my life and I finally have some stuff to blog about.

A little introduction, my name is Brian, 26, from Northern Virginia, and among other things, I'm the moderator of the SimConnect forum at avsim.com, the leading Flight Simulator enthusiast website. I'm also a developer who will be creating add-on programs for FSX (Flight Simulator X) and I wanted to chronicle that journey.

In addition to that, because my time isn't used up enough, I've been venturing into the world of game programming with the new Microsoft XNA framework. Although I'm not completely new to the world of game logic, this is a new level for me, so I'm going to struggle along and do a lot of things wrong.

The upside? You guys get to watch.

Labels: , , ,