Flash builder module: get your rss
// ActionScript file
//http://www.flash-3d.net/2010/11/loading-complex-models-with-away3d/
//http://www.mail-archive.com/away3d-dev@googlegroups.com/msg21922.html
//http://gestureworks.com/flash-tutorials/multitouch-away3d-application/
//http://www.brighthub.com/hubfolio/matthew-casperson/blog/archive/2009/08/23/tutorial-index.aspx
//http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=0&aid=278
//http://www.flashmagazine.com/tutorials/detail/away3d_basics_the_cameras/
//http://www.youtube.com/watch?v=oCltyflJdIM
import away3d.arcane;
import away3d.cameras.Camera3D;
import away3d.cameras.HoverCamera3D;
import away3d.containers.*;
import away3d.core.base.*;
import away3d.core.math.*;
import away3d.materials.ColorMaterial;
import away3d.primitives.Cube;
import away3d.primitives.Plane;
import away3d.primitives.Trident;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.system.System;
import flash.ui.Keyboard;
import mx.core.mx_internal;
import mx.effects.Zoom;
import mx.managers.SystemManager;
private var scene:Scene3D;
//private var camera_c:Camera3D;
private var view:View3D;
private var camera_c:HoverCamera3D;
private var cube:Cube;
private var cPlane:Plane;
private var axis:Trident;
private var toggle:Boolean = false;
private var lastPanAngle:Number;
private var lastTiltAngle:Number;
private var lastMouseX:Number;
private var lastMouseY:Number;
private var moveMouse:Boolean = false;
private var lastKey:uint;
private var keyIsDown:Boolean = false;
private function init():void
{ initEngine();
loadModel();
Rendering();
}
private function initEngine():void
{
camera_c = new HoverCamera3D({z:-500});
//camera_c = new Camera3D({z:-500});
view = new View3D({camera:camera_c});
//view.height = modelcontainer.height;
//view.width = modelcontainer.width;
view.x = modelcontainer.width/2;
view.y = modelcontainer.height/2;
chome.addChild(view);
}
protected function camera_clickHandler(event:MouseEvent = null):void
{ if(toggle){
toggle = false;
msg.text = "disable camera view";
} else {
toggle = true;
msg.text = "enable camera view";
}
}
protected function loadModel():void
{ var material:ColorMaterial = new ColorMaterial(0xff0000);
cube = new Cube(material);
view.scene.addChild(cube);
//axis = new Trident(200, true);
//view.scene.addChild(axis);
cPlane = new Plane({width:500,height:500,bothsides:true,z:0,ownCanvas:true});
cPlane.rotationX = 90;
//cPlane.rotationY = 180;
cPlane.y = -45;
view.scene.addChild(cPlane);
}
protected function Rendering():void
{ chome.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);
chome.addEventListener(MouseEvent.MOUSE_UP, MouseUp);
chome.addEventListener(Event.ENTER_FRAME, renderScene);
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
this.stage.addEventListener(KeyboardEvent.KEY_UP,keyUp);
}
private function renderScene(event:Event):void
{
if(keyIsDown){
// if the key is still pressed, just keep on moving
switch(lastKey){
case 87 : camera_c.moveUp(10); break;
case 83 : camera_c.moveDown(10); break;
case 65 : camera_c.moveLeft(10); break;
case 68 : camera_c.moveRight(10); break;
case Keyboard.UP : camera_c.moveForward(10); break;
case Keyboard.DOWN : camera_c.moveBackward(10); break;
}
}
var cameraSpeed:Number = 0.3;// Approximately same speed as mouse movement.
if (moveMouse)
{
camera_c.panAngle = cameraSpeed*(stage.mouseX - lastMouseX) + lastPanAngle;
camera_c.tiltAngle = cameraSpeed*(stage.mouseY - lastMouseY) + lastTiltAngle;
}
if(toggle){
cube.rotationY += 2;
camera_c.hover(true);
} else {
camera_c.hover(false);
cube.rotationY = 0;
}
view.render();
}
private function keyDown(e:KeyboardEvent):void
{ lastKey = e.keyCode;
keyIsDown = true;
}
private function keyUp(e:KeyboardEvent):void
{
keyIsDown = false;
}
private function m_out(event:MouseEvent):void
{
camera_c.zoom = stage.stageHeight;
camera_c.focus = stage.stageWidth;
}
private function m_over(event:MouseEvent):void
{
camera_c.zoom = (stage.mouseY/stage.stageHeight) * 4+0.5;
camera_c.focus = (stage.mouseX/stage.stageWidth) * 600;
}
private function MouseDown(event:MouseEvent):void { lastPanAngle = camera_c.panAngle;
lastTiltAngle = camera_c.tiltAngle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
moveMouse = true;
}
private function MouseUp(event:MouseEvent):void
{ moveMouse = false;
}
0 comments:
Post a Comment