You now have to create the main functionality of the plug-in. You will want to create some global Airport objects like so:
private Airport lasVegas = new Airport(36.07639, -115.12571, 0, -14, 89.42);
private void RegisterInterfaces()
For good practice you should also create a method to unreferenced these hooks. This can be done like so:
private void UnregisterInterfaces()
In order to fly between airports you will need to create a method called FlyToAirport which will determine which airport you want to fly to and will navigate the camera to the runway at the selected airport. This method should like this:
private void FlyToAirport(string functionName, object airport)
In order to change the cockpit overlay you will need to create a method called ChangeCockpit. This method will determine which cockpit the user has selected and will call the UpdateCockpit method of the airplane. This method should like this:
private void ChangeCockpit(string functionName, object cockpit)
In the Activate method you will want to create and Airplane object and load it. You can also want to create a timer object that will call a method calls the UpdateGaage method of your airplane object. You will also want to call the RegisterInerfaces method. This method should now look like this:
public override void Activate(object activationObject)
//create the airplane cockpit overlay
//use a timer to update the gauges every 250ms
//start off at the Toronto Pearson airport
The Deactivate method should also be updated to call the UnregisterInterfaces method and setting the timer timeout to infinite. Setting a timers timeout to infinite essentially disables it. This method should now look like this:
public override void Deactivate()
//stop the timer
In order to load the cockpit images into the plug-in you will have to make them embedded resources. This can be done by right clicking on the images and going to the properties. Set the Build Action to Embedded Resource.
The final step is to strongly name the plug-in. This is required to give the plug-in partial trust to your system. To create a strongly name key for this plug-in:
- Open a Visual Studio Command Prompt.
- At the command prompt, type cd C:\Samples\Test (or the directory where you created your application) and press ENTER.
- At the command prompt, type sn -k TestPlugin.snk and press ENTER.
- At the command prompt, type exit, and press ENTER.
- In Visual Studio, right click your project and select Properties.
- Click the Signing tab and check Sign the assembly.
- In the Choose a strong name key file drop down list, select <Browse…>
- Select the SimpleFlightSimulatorPlugin.snk file and click Open. The strong name file is automatically added to your project.
- Save the properties window and then close it.
You can now build your project to compile the plug-in DLL. You can then open the HTML in a browser to view your flight simulator. To increase the sensation of flying around Virtual Earth with your own flight simulator try using an Xbox controller. The built in navigation controls of Virtual Earth recognizes the Xbox controller. The controls are similar to Halo.
The complete source code for this application can be downloaded here:
Part 1 – http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!756.entry
Part 2 – http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!752.entry
Part 3 – http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!751.entry