|
namespace Flash
{
using System;
using System.IO;
using System.Windows.Forms;
using MWudka;
/// <summary>
/// A fairly lame demo of the Lenovo APS. Wiggle the computer and the bar wiggles. I can get the ball to stay on the bar for about 8 seconds.
/// </summary>
public partial class Form1 : Form
{
/// <summary>
/// An APS instance for talking to the APS
/// </summary>
private APS aps;
/// <summary>
/// Initializes a new instance of the Form1 class
/// </summary>
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Called when the form loads. It sets up the APS, calibrates it, and loads the sample SWF
/// </summary>
/// <param name="sender">The sender</param>
/// <param name="e">Event args</param>
private void Form1_Load(object sender, EventArgs e)
{
// Try loading the demo swf
var demoPath = Path.GetFullPath("AS3.swf");
if (!File.Exists(demoPath))
{
MessageBox.Show(
this,
"Can't load the demo. There should be a file called AS3.swf in this directory",
"Demo Missing",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
this.Close();
return;
}
// Setup and calibrate the APS
this.aps = new APS();
this.aps.Calibrate();
// Load the flash file
var url = demoPath;
axShockwaveFlash1.ScaleMode = 0;
axShockwaveFlash1.LoadMovie(0, url);
}
/// <summary>
/// Called when the flash file uses the external interface. It returns the current attitude.
/// </summary>
/// <param name="sender">The sender</param>
/// <param name="e">Event args</param>
private void AxShockwaveFlash1_FlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)
{
var att = this.aps.ReadAttitude();
// Convert the attitude structure into a flash object and pass it to the flash file
var ret = "<object><property id=\"x\"><number>{0}</number></property><property id=\"y\"><number>{1}</number></property></object>";
ret = string.Format(ret, att.Roll, att.Pitch);
axShockwaveFlash1.SetReturnValue(ret);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.