PageRenderTime 41ms CodeModel.GetById 20ms app.highlight 8ms RepoModel.GetById 12ms app.codeStats 0ms

/src/away3d/primitives/WireframeAxesGrid.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 104 lines | 80 code | 15 blank | 9 comment | 5 complexity | d7f363b0d12649d578bde0dcb5d10241 MD5 | raw file
  1package away3d.primitives
  2{
  3	import away3d.entities.SegmentSet;
  4
  5	import flash.geom.Vector3D;
  6
  7	/**
  8	* Class WireframeAxesGrid generates a grid of lines on a given plane<code>WireframeAxesGrid</code>
  9	* @param	subDivision		[optional] uint . Default is 10;
 10	* @param	gridSize				[optional] uint . Default is 100;
 11	* @param	thickness			[optional] Number . Default is 1;
 12	* @param	colorXY				[optional] uint. Default is 0x0000FF.
 13	* @param	colorZY				[optional] uint. Default is 0xFF0000. 
 14	* @param	colorXZ				[optional] uint. Default is 0x00FF00.
 15	*/
 16
 17	public class WireframeAxesGrid extends SegmentSet
 18	{
 19		private static const PLANE_ZY:String = "zy";
 20		private static const PLANE_XY:String = "xy";
 21		private static const PLANE_XZ:String = "xz";
 22
 23		public function WireframeAxesGrid(subDivision:uint = 10, gridSize:uint = 100, thickness:Number = 1, colorXY : uint = 0x0000FF, colorZY : uint = 0xFF0000, colorXZ : uint = 0x00FF00) {
 24			super();
 25
 26			if(subDivision == 0) subDivision = 1;
 27			if(thickness <= 0) thickness = 1;
 28			if(gridSize ==  0) gridSize = 1;
 29
 30			build(subDivision, gridSize, colorXY, thickness, PLANE_XY);
 31			build(subDivision, gridSize, colorZY, thickness, PLANE_ZY);
 32			build(subDivision, gridSize, colorXZ, thickness, PLANE_XZ);
 33		}
 34
 35		private function build(subDivision:uint, gridSize:uint, color:uint, thickness:Number, plane:String):void
 36		{
 37			var bound:Number = gridSize *.5;
 38			var step:Number = gridSize/subDivision;
 39			var v0 : Vector3D = new Vector3D(0, 0, 0) ;
 40			var v1 : Vector3D = new Vector3D(0, 0, 0) ;
 41			var inc:Number = -bound;
 42
 43			while(inc<=bound){
 44
 45				switch(plane){
 46					case PLANE_ZY:
 47						v0.x = 0;
 48						v0.y = inc;
 49						v0.z = bound;
 50						v1.x = 0;
 51						v1.y = inc;
 52						v1.z = -bound;
 53						addSegment( new LineSegment(v0, v1, color, color, thickness));
 54
 55						v0.z = inc;
 56						v0.x = 0;
 57						v0.y = bound;
 58						v1.x = 0;
 59						v1.y = -bound;
 60						v1.z = inc;
 61						addSegment(new LineSegment(v0, v1, color, color, thickness ));
 62						break;
 63
 64					case PLANE_XY:
 65						v0.x = bound;
 66						v0.y = inc;
 67						v0.z = 0;
 68						v1.x = -bound;
 69						v1.y = inc;
 70						v1.z = 0;
 71						addSegment( new LineSegment(v0, v1, color, color, thickness));
 72						v0.x = inc;
 73						v0.y = bound;
 74						v0.z = 0;
 75						v1.x = inc;
 76						v1.y = -bound;
 77						v1.z = 0;
 78						addSegment(new LineSegment(v0, v1, color, color, thickness ));
 79						break;
 80
 81					default:
 82						v0.x = bound;
 83						v0.y = 0;
 84						v0.z = inc;
 85						v1.x = -bound;
 86						v1.y = 0;
 87						v1.z = inc;
 88						addSegment( new LineSegment(v0, v1, color, color, thickness));
 89
 90						v0.x = inc;
 91						v0.y = 0;
 92						v0.z = bound;
 93						v1.x = inc;
 94						v1.y = 0;
 95						v1.z = -bound;
 96						addSegment(new LineSegment(v0, v1, color, color, thickness ));
 97				}
 98
 99				inc += step;
100			}
101		}
102
103	}
104}