달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
늣풀님의 작품을 보고
비슷하게 몰힐로 한번 테스트해보았다.

사실... 그냥 샘플보고 삽질하면서 해본것이라 맞게 했는지도 모르겠다. 

 Flash Flayer (RC 1) v11.0.r1.129 버전


허접 코드 참조
/*
* Copyright(c) 2011 monoDreamer, aka ryo (teatime2004@naver.com)
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURVector3DE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* 
* Jul 31, 2011 
*/
package codeonwort 
{ 
	import away3d.cameras.lenses.PerspectiveLens;
	import away3d.containers.ObjectContainer3D;
	import away3d.containers.View3D;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.geom.Vector3D;
	import flash.system.Security;
	import flash.utils.Timer;

	[SWF(width = "600", height = "600", backgroundColor = "0x0", frameRate = "60")]
	public class R3D3 extends Sprite
	{
	
		//----------------------------------------------------------------
		// Properties
		//----------------------------------------------------------------
		
		//----------------------------------------------------------------
		// Getter/Setter Method
		//----------------------------------------------------------------
		
		//----------------------------------------------------------------
		// Public method
		//----------------------------------------------------------------
		
		//----------------------------------------------------------------
		// Protected Method
		//----------------------------------------------------------------
		protected function render($e:Event):void
		{
			var i:int, w:Wire;
			for (i; i<_len; i++) {
				if (! updateWire(w = _particles[i]) ) {
					_container.removeChild(w);
					_container.addChild(w = _particles[i] = new Wire());
					updateWire(w);
				}
			}
			_container.rotationX += (mouseY - _cy)*.01;
			_container.rotationY += (mouseX - _cx)*.01;
			_view.render();
		}
		
		protected function updateWire($wire:Wire):Boolean
		{
			_data = $wire.data;
			var rnd:Number = Math.random();
			if ( _data.vr>0 ) rnd = rnd*.2 + .05;
			
			if (rnd < 0.05) {
				_data.vx = _data.vy = _data.vz = 0;
				_data.vr = V_RAD;
			}
			else if(rnd < 0.1) {
				_data.vr = _data.vx = _data.vz = 0
				_data.vy = V_DEG;
			}
			else if(rnd < 0.15) {
				_data.vr = _data.vx = _data.vz = 0
				_data.vy = -V_DEG;
			}
			else if(rnd < 0.2) {
				_data.vr = _data.vy = _data.vz = 0
				_data.vx = V_DEG;
			}
			else if(rnd < 0.25) {
				_data.vr = _data.vy = _data.vz = 0
				_data.vx = -V_DEG;
			}
			return $wire.update(_data);
		}
		
		//----------------------------------------------------------------
		// Constructor
		//----------------------------------------------------------------
		public function R3D3()
		{
			super();
			Security.allowDomain('*');
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}
		
		private function addedToStageHandler($e:Event):void
		{
			_cx = stage.stageWidth/2;
			_cy = stage.stageHeight/2;
			initView3D();
			initTimer();
			initWires();
			stage.addEventListener(Event.ENTER_FRAME, render);
		}
		
		//----------------------------------------------------------------
		// Private Method
		//----------------------------------------------------------------
		private function initView3D():void
		{
			_view = new View3D();
			_view.antiAlias = 4;
			
			_container = new ObjectContainer3D();
			_view.scene.addChild(_container);
			
			_view.camera.lens = new PerspectiveLens();
			_view.camera.lens.far = 2000;
			_view.camera.lens.near = 10;
			
			_controller = new HoverDragController(_view.camera, stage);
			_controller.radius = 410;
			
			addChild(_view);
		}
		
		private function initTimer():void
		{
			_timer = new Timer(1000);
			_timer.addEventListener(TimerEvent.TIMER, function($e:TimerEvent):void {
				if (_len < OBJ_MAX && Math.random() > .4) {
					_container.addChild(_particles[_len++]);
					if (_len == OBJ_MAX) {
						_timer.removeEventListener(TimerEvent.TIMER, arguments.callee);
						_timer.stop();
					}
				}
			});
			_timer.start();
		}
		
		private function initWires():void
		{
			_len = OBJ_MIN;
			_particles = new Vector.< Wire >(OBJ_MAX, true);
			for (var i:int=0; i;
		private var _data:Data = new Data();
		private var _len:int;
		private var _timer:Timer;
		private var _view:View3D;
		private var _controller:HoverDragController;
		private var _container:ObjectContainer3D;
		private var _cx:Number;
		private var _cy:Number;
	}
}

import away3d.containers.ObjectContainer3D;
import away3d.primitives.LineSegment;
import away3d.primitives.WireframePrimitiveBase;

import flash.geom.Matrix3D;
import flash.geom.Vector3D;

internal class Data
{
	public var vx:Number=0, vy:Number=0, vz:Number=0, vr:Number=0;
}

internal class Wire extends WireframePrimitiveBase
{
	public var lastIndex:int;

	public function Wire():void
	{
		super();
		reset();
	}
	
	public function reset():void
	{
		lastIndex = 0;
		_rc = 0xFF * Math.random();
		_gc = 0xFF * Math.random();
		_bc = 0xFF * Math.random();
		
		_r = 5 + 5 * Math.random();
		_th = 1;
		_rx = Math.random() * 360;
		_ry = Math.random() * 360;
		//_rz = Math.random() * 360;
		_def = new Vector3D();
		_mat = new Matrix3D();
		_mat.appendTranslation(0, 0, _r);
		_mat.appendRotation(_rx, Vector3D.X_AXIS);
		_mat.appendRotation(_ry, Vector3D.Y_AXIS);
		//_mat.appendRotation(_rz, Vector3D.Z_AXIS);
		_old = _mat.transformVector(_def);
	}
	
	private function kill():void
	{
		if (!_segments) return;
		var l:int = _segments.length;
		while(--l>-1) {
			_segments[l] = null;
		}
		_segments = null;
	}
	
	public var data:Data = new Data();
	public function update($data:Data):Boolean
	{
		if  (++lastIndex > BUFFER || _r > MAX_R) {
			kill();
			return false;
		}
		
		_r 	+= data.vr;
		_rx += data.vx;
		_ry += data.vy;
		//_rz += data.vz;
		
		var ac:Number = _r / MAX_R + .2;

		_mat.identity();
		_mat.appendTranslation(0, 0, _r);
		_mat.appendRotation(_rx, Vector3D.X_AXIS);
		_mat.appendRotation(_ry, Vector3D.Y_AXIS);
		//_mat.appendRotation(_rz, Vector3D.Z_AXIS);
		_new = _mat.transformVector(_def);
		
		_eco = (_rc*ac)<<16 | (_gc*ac)<<8 | (_bc*ac);
		
		addSegment(new LineSegment(_old, _new, _sco, _eco, _th*ac + 1));
		_old = _new.clone();
		_sco = _eco;
		return true;
	}
	
	override protected function buildGeometry():void {}
	
	private const MAX_R:int = 300;
	private const BUFFER:int = 1500;
	private var _r:Number;
	private var _ry:Number;
	private var _rx:Number;
	private var _rz:Number;
	private var _new:Vector3D;
	private var _old:Vector3D;
	private var _def:Vector3D;
	private var _mat:Matrix3D;
	private var _rc:Number;
	private var _gc:Number;
	private var _bc:Number;
	private var _th:Number;
	private var _sco:uint, _eco:uint;
}

'Action Script 3.0 > Lab. 2011' 카테고리의 다른 글

Away3D 4.0 테스트 #4  (4) 2011.08.27
Away3D 4.0 테스트 #3  (0) 2011.08.25
잉크 번짐 효과  (0) 2011.08.09
Away3D 4.0 테스트 #2 Environment Map  (0) 2011.08.04
30 x 66 테트리스  (0) 2011.06.20
Posted by 료~
|