코드보기.
package { /***************************************************************** * Description : Away3D Phong & Light Example * Class Name : SampleAway3D ( Document Class ) * Linkage FLA : SampleAway3D.fla * Extends : Sprite * Company : Belong to www.as3.kr. * Author : JINSANG YUN ( a.k.a. Wooyaggo victim4@gmail.com ) * Last modified : 2008-09-17 * * Copyright www.as3.kr. All Rights Reserved. ******************************************************************/ import away3d.cameras.HoverCamera3D; import away3d.containers.Scene3D; import away3d.containers.View3D; import away3d.core.render.Renderer; import away3d.lights.DirectionalLight3D; import away3d.materials.PhongColorMaterial; import away3d.primitives.Cube; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; public class SampleAway3D extends Sprite { // primitive elements, scene, camera and view. private var view: View3D; private var scene: Scene3D; private var camera: HoverCamera3D; private var cube: Cube; private var light: DirectionalLight3D; public function SampleAway3D() { this .initScene(); this .initCamera(); this .initView(); this .initObjects(); this .initLights(); this .initListeners(); } private function initScene(): void { // create default scene. this .scene = new Scene3D(); } private function initCamera(): void { this .camera = new HoverCamera3D( { zoom: 3, focus: 100, distance: 100 } ); this .camera.tiltangle = 40; this .camera.targettiltangle = 40; this .camera.mintiltangle = -50; this .camera.maxtiltangle = 50; this .camera.yfactor = 1; this .camera.steps = 7; } private function initView(): void { // create view with scene and camera. this .view = new View3D( { scene: this .scene, camera: this .camera } ); this .view.x = this .stage.stageWidth/2; this .view.y = this .stage.stageHeight/2; this .addChild( this .view ); } private function initObjects(): void { // create cube have a phong material. this .cube = new Cube( { material: new PhongColorMaterial( { color: 0xCCCCCC, specular: 0.6 } ) } ); this .scene.addChild( this .cube ); } private function initLights(): void { // create and locate light. this .light = new DirectionalLight3D( { color: 0xFFFFFF, ambient: 0.25, diffuse: 0.75, specular: 0.9 } ); this .light.x = 40000; this .light.z = 40000; this .light.y = 40000; this .scene.addChild( this .light ); } private function initListeners(): void { this .stage.addEventListener( MouseEvent.MOUSE_DOWN, dragStart ); this .stage.addEventListener( MouseEvent.MOUSE_UP, dragStop ); this .stage.addEventListener( Event.ENTER_FRAME, enterFrame ); } private function enterFrame( e: Event ): void { this .camera.hover(); this .light.x = this .camera.x; this .light.y = this .camera.y; this .light.z = this .camera.z; this .view.render(); } private function dragStart( e: MouseEvent ): void { this .lastx = this .view.mouseX; this .lasty = this .view.mouseY; this .stage.addEventListener( Event.ENTER_FRAME, drag ); } private function dragStop( e: MouseEvent ): void { this .stage.removeEventListener( Event.ENTER_FRAME, drag ); } private const DRAG_RATING: Number = 0.5; private var dragx: Number; private var dragy: Number; private var lastx: Number; private var lasty: Number; private function drag( e: Event ): void { this .dragx = this .view.mouseX - lastx; this .dragy = this .view.mouseY - lasty; this .lastx = this .view.mouseX; this .lasty = this .view.mouseY; this .camera.targetpanangle += this .dragx * DRAG_RATING; this .camera.targettiltangle += this .dragy * DRAG_RATING; } } }
코드보기.