Created
October 7, 2011 04:59
-
-
Save wwwins/1269481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import away3d.animators.PathAnimator; | |
import away3d.cameras.Camera3D; | |
import away3d.containers.ObjectContainer3D; | |
import away3d.containers.Scene3D; | |
import away3d.containers.View3D; | |
import away3d.core.utils.Debug; | |
import away3d.materials.ColorMaterial; | |
import away3d.materials.VideoMaterial; | |
import away3d.primitives.Arrow; | |
import away3d.primitives.Plane; | |
import away3d.primitives.Trident; | |
import com.bit101.components.PushButton; | |
import flash.display.Sprite; | |
import flash.display.StageAlign; | |
import flash.display.StageScaleMode; | |
import flash.events.Event; | |
import flash.events.MouseEvent; | |
import flash.geom.Vector3D; | |
import myclass.data.PathAWpath_0; | |
public class Main extends Sprite | |
{ | |
private var scene:Scene3D; | |
private var camera:Camera3D; | |
private var view:View3D; | |
private var material:VideoMaterial; | |
private var container:ObjectContainer3D; | |
private var lastRotationX:Number; | |
private var lastRotationY:Number; | |
private var move:Boolean; | |
private var lastMouseY:Number; | |
private var lastMouseX:Number; | |
private var pa:PathAnimator; | |
private var time:Number; | |
private var loader:Loader3D; | |
private var pb:PushButton; | |
private var playAnimation:Boolean; | |
private var arrow:Arrow; | |
private var plane:Plane; | |
public function Main():void | |
{ | |
if (stage) init(); | |
else addEventListener(Event.ADDED_TO_STAGE, init); | |
} | |
private function init(e:Event = null):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
// entry point | |
stage.align = StageAlign.TOP_LEFT; | |
stage.scaleMode = StageScaleMode.NO_SCALE; | |
Debug.active = true; | |
playAnimation = false; | |
pb = new PushButton(this, 0, 0, "start", clickHandler); | |
init3D(); | |
} | |
private function clickHandler(e:MouseEvent):void | |
{ | |
time = 0; | |
var r:Array = [new Vector3D(0, 0, 0), new Vector3D(0, 0, 0), new Vector3D(0, 0, 0) ]; | |
var o:Object = { alignToPath:true, | |
targetobject:null, | |
rotations:r, | |
fps:30, | |
offset:new Vector3D(0,100,0) | |
}; | |
pa = new PathAnimator(new PathAWpath_0(), arrow, o); | |
playAnimation = true; | |
} | |
private function init3D():void | |
{ | |
scene = new Scene3D(); | |
camera = new Camera3D(); | |
camera.y = 1000; | |
camera.z = -2000; | |
view = new View3D(); | |
view.x = stage.stageWidth / 2; | |
view.y = stage.stageHeight / 2; | |
view.scene = scene; | |
view.camera = camera; | |
addChild(view); | |
var axis:Trident = new Trident(250, true); | |
scene.addChild(axis); | |
// 拿 flv 的材質 | |
material = new VideoMaterial(); | |
material.loop = true; | |
material.file = "video/1.flv"; | |
material.smooth = true; | |
plane = new Plane(); | |
plane.z = 0; | |
plane.width = 1000; | |
plane.height = 600; | |
plane.rotationX = 90; | |
plane.material = material; | |
arrow = new Arrow(); | |
arrow.width = 200; | |
arrow.height = 150; | |
arrow.tailLength = 50; | |
arrow.tailWidth = 125; | |
arrow.thickness = 50; | |
arrow.material = new ColorMaterial("random"); | |
container = new ObjectContainer3D(plane, arrow); | |
scene.addChild(container); | |
addEventListener(Event.ENTER_FRAME, _onEnterFrame); | |
addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage); | |
} | |
private function _onAddedToStage(e:Event):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, _onAddedToStage); | |
view.x = stage.stageWidth / 2; | |
view.y = stage.stageHeight / 2; | |
//stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); | |
//stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); | |
} | |
private function onMouseUp(e:MouseEvent):void | |
{ | |
move = false; | |
} | |
private function onMouseDown(e:MouseEvent):void | |
{ | |
lastRotationX = container.rotationX; | |
lastRotationY = cube.rotationY; | |
lastMouseX = mouseX; | |
lastMouseY = mouseY; | |
move = true; | |
} | |
private function _onEnterFrame(e:Event):void | |
{ | |
if (move) { | |
container.rotationX = (mouseY - lastMouseY)/10 + lastRotationX; | |
if (container.rotationX > 90) | |
container.rotationX = 90; | |
if (container.rotationX < -90) | |
container.rotationX = -90; | |
cube.rotationY = (lastMouseX - mouseX)/10 + lastRotationY; | |
} | |
if (playAnimation) { | |
// play fast or slow | |
time = (time +0.001 > 1)? 0 : time + 0.001; | |
pa.update(time); | |
// fixed arrow's rotation | |
arrow.rotationX -= 180; | |
camera.lookAt(arrow.position); | |
} | |
view.render(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment