forked from: flash on 2010-2-12

by dizgid forked from flash on 2010-2-12 (diff: 147)
♥0 | Line 112 | Modified 2010-02-27 02:00:41 | MIT License
play

ActionScript3 source code

/**
 * Copyright dizgid ( http://wonderfl.net/user/dizgid )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/57Ep
 */

// forked from dizgid's flash on 2010-2-12
package {
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextField;
	import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.*;
    
    [SWF(backgroundColor="#FFFFFF", frameRate=24)]
    public class FlashTest extends Sprite {
    	
		private var my_mc:Plane;
		private var my_mc1:Plane;
		
		private var _camVec:Vector3D = new Vector3D(0,0,280);
		private var _planePos:Vector3D = new Vector3D(500,200,0);
		private var _scene:Sprite;
		private var _field:Sprite;
		
        public function FlashTest() {
            // write as3 code here..
            
			Debug.init();
			this.addChild(Debug.container);
            
            _scene  = new Sprite();
            this.addChild(_scene);
            
            _field  = new Sprite();
            _scene.addChild(_field);
            
            _scene.x = stage.stageWidth/2;
            _scene.y = stage.stageHeight/2;
           _scene.z = 880;
            //
            my_mc = new Plane();
            my_mc.x = _planePos.x;
            my_mc.y = _planePos.y;
            my_mc.z = _planePos.z;
            my_mc.rotationY = 90;
            my_mc.rotationX = -50;

			_field.addChild(my_mc);
			
			my_mc1 = new Plane();
            my_mc1.x = -_planePos.x;
            my_mc1.y = -_planePos.y;
            my_mc1.z = _planePos.z;
            my_mc1.rotationY = -90;

			_field.addChild(my_mc1);
			
			addEventListener(Event.ENTER_FRAME, update);
        }
	    private function update(eventObject:Event):void {
	    	_field.rotationY += 1.0;
	    	
		 // my_mc.rotationY += 1.0;
		 // my_mc.rotationX += 1.0;
		  
		  //my_mc1.rotationY += 1.0;
		  //my_mc1.rotationY += 1.0;
		  
		  my_mc.update(_camVec,  _scene);
		  my_mc1.update(_camVec, _scene);
		} 
    }
}


import flash.display.Sprite;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.*;

class Plane extends Sprite{
	
	public function Plane(){
		var size:Number = 300;
			var g:Graphics = this.graphics;
            g.beginFill(0xff0000);
            g.drawRect(-size/2, -size/2, size, size);
            g.endFill();
            
            var txt:TextField = new TextField();
            txt.defaultTextFormat = new TextFormat(null, 90);
            txt.autoSize = TextFieldAutoSize.LEFT;
            txt.text = "ABC";
            txt.x = -txt.width / 2;
            txt.y = -txt.height / 2;
            this.addChild(txt);
	}
	
	public function update(_camVec:Vector3D, target:Sprite):void
	{
		var mat:Matrix3D = this.transform.getRelativeMatrix3D(target);
		var ftontVec:Vector3D = mat.deltaTransformVector(new Vector3D(0, 0, 1));
		 var p:Vector3D = mat.position;
		 
		 var vv:Vector3D = this.transform.getRelativeMatrix3D(target).position;
		 Debug.log(String(target.z));
		 p.z += target.z;
		//p.add(target.transform.matrix3D.position);
		var tVec:Vector3D = _camVec.add(p);
		 
		  var nDotProduct:Number = tVec.dotProduct(ftontVec);
		  if (nDotProduct < 0) {
		    this.alpha = 0.5;
		  } else {
		    this.alpha = 1;
		  }
	}
}


import flash.display.Sprite
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextField;

class Debug extends Sprite{
	public static var debugTxt:TextField;
	public static var container:Sprite;
	
	public function Debug():void
	{
		
	}
	public static function init():void
	{
		debugTxt = new TextField();
		debugTxt.width = 400;
		debugTxt.text = "";
		Debug.container = new Sprite();
		Debug.container.addChild(debugTxt);
		
	}
	public static function log(str:String):void
	{
		debugTxt.text = "";
		debugTxt.appendText(str + "\n");
	}
}

Forked