Skip to content

Playing with Tilt (in Flash CS4)

March 28, 2010

I know, with CS5 so close, why would I try out programming for tilt before I could try out the Accelerometer class and the related AccelerometerEvent class which are both currently in their beta stages? The short answer is “school”. Anyways, this post will cover emulating tilt with external API’s and also mention trying out tilt with a Wiimote.

The possible applications of data related to Tilt are numerous. You could use it to actually mick gravitational forces (ex. rolling a ball around on your screen by tilting it), it could be used in place of standard controls (ex. tilting to turn a car in a game instead of pressing buttons) or in more unique ways (ex. tilting a iPod to simulate a 3d view).

Defining Roll, Pitch and Yaw

The terms “roll”, “pitch” and “yaw” are use to describe the tilt of an object in 3-dimensional space. They each describe the angle of rotation of an object along a different axis. For a visual interpretation, visit this wiki: http://en.wikipedia.org/wiki/Flight_dynamics . If we use an airplane as an example, think of the initial position of the plane (when roll, pitch and yaw are all 0 degrees) to be the same position a plane would be in if it was parked on the ground. Pitch would be used to describe the rotation of the airplane if it was taking off or landing. If the nose of the plane is pointing up, it has a positive pitch and pointing down is negative. Roll would describe the airplane’s rotation when it tilts from side to side (raising one wing higher than the other). Yaw is the rotation the airplane would experience is you were able to just spin a plane around it center to face any of the cardinal directions (North, South, East or West).

Peguin API

Our first attempt at programming with tilt used an external API called Penguin (http://penguinsflash.wordpress.com/). Penguin includes an AIR app that resembles an iPhone/iTouch to emulate tilting a device. To use the emulator, you must have it running at the same time as your app. Tilting the on-screen iPhone using your mouse will update data in an XML file which specifies it’s tilt. The Penguin class, references this XML file and can therefore use it to receive information on tilt in realtime and use it in your currently running swf. These values can be referenced by using the pitch, roll and yaw properties of your instance of the Penguin Class (ex. myPenguin.pitch ). These properties are given in the units of degrees. Thinking in terms of what may be capable in the future on mobile devices, Pengin also gives the ability to manipulate and receive data on the movement of the iPhone simulation along the 6 axises (moving the phone along around the x-y plane, as well as forward and back along the z-axis).  Unfortunately, although pitch and roll can be controlled at the same time, yaw can only be controlled on its own using the interface.

WiiFlash

Wii Remotes or “Wiimotes” are able to sense tilt so we decided to try using this tilt data with Flash. We did this using WiiFlash (http://wiiflash.bytearray.org/). I won’t describe the setup process in this post, but I’ll just mention that the wiimotes were connected to the computer via bluetooth, a small app called the Wii Server is run while the wiimote is in use and the WiiFlash classes make it possible to access data from the wiimote in flash. The tilt data is returned in radians instead of degrees (radians are easily converted to degree by multiplying by (180/PI). In addition, yaw data does not seem to work as might be expected and I really haven’t figured it out.  I don’t won’t to put my speculations about it on record so all I’ll say is it doesn’t work when the wiimote is completely horizontal.

Differences Between Emulations and the AccelerometerEvent Class

As of writing this, the Adobe CS5 collection is still a few days away from releasing, but Lee Brimelow at gotoAndLearn.com has a demonstration (http://www.gotoandlearn.com/play?id=116) of using CS5 to publish to the iPhone and in his example he actually uses the Accelerometer classes.

According to the documentation as of posting this, the Accelerometer Event class doesn’t refer to roll, pitch and yaw as Penguin and WiiFlash did, but instead it refers the force of acceleration along the x, y and z axis (accelerationX, accelerationY, accelerationZ) .  In addition, instead of data related to angles (degrees and radians), these properties are returned in the unit of g’s (1 g = gravity on earth = 9.8m/s/s). It would seem that because of these differences, this acceleration data would need to be treated differently from the tilt data we were receiving using WiiFlash, but from Lee’s example it seem that both can be applied in a vary similar manner. However, if you actually wished to figure out a tilt angle, some conversion factor would need to be applied.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: