Skip to content

Instantly share code, notes, and snippets.

@katopz
Created July 13, 2012 16:54
Show Gist options
  • Save katopz/3105956 to your computer and use it in GitHub Desktop.
Save katopz/3105956 to your computer and use it in GitHub Desktop.
/*
Gyroscope の ANE に付属の Gyroscope クラスをインポートして使用しています。
プロジェクトは FlashBuilder の ActionScript モバイルプロジェクトを
AIR for iOS(AIR 3.3)でビルドしました。
link
http://www.digifie.jp/blog/archives/998
http://www.adobe.com/devnet/air/native-extensions-for-air/extensions/gyroscope.html
*/
package
{
import away3d.cameras.Camera3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.loaders.Loader3D;
import away3d.loaders.parsers.Parsers;
import com.adobe.nativeExtensions.Gyroscope;
import com.adobe.nativeExtensions.GyroscopeEvent;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Vector3D;
import flash.net.URLRequest;
public class GyroscopeExample extends Sprite
{
private var _gyro:Gyroscope;
private var _view:View3D;
private var _scene:Scene3D;
private var _camera:Camera3D;
private var _loader:Loader3D;
public function GyroscopeExample()
{
Parsers.enableAllBundled();
if( Gyroscope.isSupported )
{
setupGyro();
}
setup3d();
}
private function setup3d():void
{
_view = addChild(new View3D()) as View3D;
_view.antiAlias = 4;
_view.backgroundColor = 0xFFFFFF;
_scene = _view.scene;
_camera = _view.camera;
_loader = new Loader3D(true, null);
_loader.load( new URLRequest("model/model.3ds"));
_scene.addChild( loader );
_loader.scaleX = _loader.scaleY = _loader.scaleZ = 6;
_loader.y = -500;
addEventListener( Event.ENTER_FRAME, render );
}
private function setupGyro():void
{
_gyro = new Gyroscope();
_gyro.setRequestedUpdateInterval( 50 );
_gyro.addEventListener( GyroscopeEvent.UPDATE, onChange );
}
private var _angleX:Number = 0;
private var _angleY:Number = 0;
private var _angleZ:Number = 0;
private function onChange( e:GyroscopeEvent ):void
{
angleX += e.x * .1;
angleY += e.y * .1;
angleZ += e.z * .1;
_camera.x = 1000 * Math.sin( _angleX );
_camera.z = 1000 * Math.cos( _angleZ );
_camera.y = 1000 * Math.sin( _angleY );
}
private function render( e:Event ):void
{
_camera.lookAt(new Vector3D());
_view.render();
}
}
}
@katopz
Copy link
Author

katopz commented Jul 13, 2012

haha, i got strong one ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment