/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

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