PageRenderTime 284ms CodeModel.GetById 140ms app.highlight 10ms RepoModel.GetById 131ms app.codeStats 0ms

/src/away3d/primitives/WireframeCube.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 139 lines | 102 code | 14 blank | 23 comment | 1 complexity | f09da7aa35be5094a2dcd77d4eea8d8c MD5 | raw file
  1package away3d.primitives
  2{
  3	import flash.geom.Vector3D;
  4	
  5	/**
  6	 * A WirefameCube primitive mesh.
  7	 */
  8	public class WireframeCube extends WireframePrimitiveBase
  9	{
 10		private var _width:Number;
 11		private var _height:Number;
 12		private var _depth:Number;
 13		
 14		/**
 15		 * Creates a new WireframeCube object.
 16		 * @param width The size of the cube along its X-axis.
 17		 * @param height The size of the cube along its Y-axis.
 18		 * @param depth The size of the cube along its Z-axis.
 19		 * @param color The colour of the wireframe lines
 20		 * @param thickness The thickness of the wireframe lines
 21		 */
 22		public function WireframeCube(width:Number = 100, height:Number = 100, depth:Number = 100, color:uint = 0xFFFFFF, thickness:Number = 1)
 23		{
 24			super(color, thickness);
 25			
 26			_width = width;
 27			_height = height;
 28			_depth = depth;
 29		}
 30		
 31		/**
 32		 * The size of the cube along its X-axis.
 33		 */
 34		public function get width():Number
 35		{
 36			return _width;
 37		}
 38		
 39		public function set width(value:Number):void
 40		{
 41			_width = value;
 42			invalidateGeometry();
 43		}
 44		
 45		/**
 46		 * The size of the cube along its Y-axis.
 47		 */
 48		public function get height():Number
 49		{
 50			return _height;
 51		}
 52		
 53		public function set height(value:Number):void
 54		{
 55			if (value <= 0)
 56				throw new Error("Value needs to be greater than 0");
 57			_height = value;
 58			invalidateGeometry();
 59		}
 60		
 61		/**
 62		 * The size of the cube along its Z-axis.
 63		 */
 64		public function get depth():Number
 65		{
 66			return _depth;
 67		}
 68		
 69		public function set depth(value:Number):void
 70		{
 71			_depth = value;
 72			invalidateGeometry();
 73		}
 74		
 75		/**
 76		 * @inheritDoc
 77		 */
 78		override protected function buildGeometry():void
 79		{
 80			var v0:Vector3D = new Vector3D();
 81			var v1:Vector3D = new Vector3D();
 82			var hw:Number = _width*.5;
 83			var hh:Number = _height*.5;
 84			var hd:Number = _depth*.5;
 85			
 86			v0.x = -hw;
 87			v0.y = hh;
 88			v0.z = -hd;
 89			v1.x = -hw;
 90			v1.y = -hh;
 91			v1.z = -hd;
 92			
 93			updateOrAddSegment(0, v0, v1);
 94			v0.z = hd;
 95			v1.z = hd;
 96			updateOrAddSegment(1, v0, v1);
 97			v0.x = hw;
 98			v1.x = hw;
 99			updateOrAddSegment(2, v0, v1);
100			v0.z = -hd;
101			v1.z = -hd;
102			updateOrAddSegment(3, v0, v1);
103			
104			v0.x = -hw;
105			v0.y = -hh;
106			v0.z = -hd;
107			v1.x = hw;
108			v1.y = -hh;
109			v1.z = -hd;
110			updateOrAddSegment(4, v0, v1);
111			v0.y = hh;
112			v1.y = hh;
113			updateOrAddSegment(5, v0, v1);
114			v0.z = hd;
115			v1.z = hd;
116			updateOrAddSegment(6, v0, v1);
117			v0.y = -hh;
118			v1.y = -hh;
119			updateOrAddSegment(7, v0, v1);
120			
121			v0.x = -hw;
122			v0.y = -hh;
123			v0.z = -hd;
124			v1.x = -hw;
125			v1.y = -hh;
126			v1.z = hd;
127			updateOrAddSegment(8, v0, v1);
128			v0.y = hh;
129			v1.y = hh;
130			updateOrAddSegment(9, v0, v1);
131			v0.x = hw;
132			v1.x = hw;
133			updateOrAddSegment(10, v0, v1);
134			v0.y = -hh;
135			v1.y = -hh;
136			updateOrAddSegment(11, v0, v1);
137		}
138	}
139}