Plan3D.hx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package h3d.prim;
  2. class Plan3D extends Primitive {
  3. public var width(default,set) : Float;
  4. public var height(default,set) : Float;
  5. public function new(width = 1.0, height = 1.0) {
  6. this.width = width;
  7. this.height = height;
  8. }
  9. function set_width(w) {
  10. width = w;
  11. dispose();
  12. return w;
  13. }
  14. function set_height(h) {
  15. height = h;
  16. dispose();
  17. return h;
  18. }
  19. override function getBounds() {
  20. var b = new h3d.col.Bounds();
  21. b.xMin = 0;
  22. b.xMax = width;
  23. b.yMin = 0;
  24. b.yMax = height;
  25. b.zMin = b.zMax = 0;
  26. return b;
  27. }
  28. override function alloc( engine : h3d.Engine ) {
  29. var v = new hxd.FloatBuffer();
  30. var hw = width * 0.5, hh = height * 0.5;
  31. v.push( -hw);
  32. v.push( -hh);
  33. v.push( 0);
  34. v.push( 0);
  35. v.push( 1);
  36. v.push( 0);
  37. v.push( 0);
  38. v.push( 1);
  39. v.push( -hw);
  40. v.push( hh);
  41. v.push( 0);
  42. v.push( 0);
  43. v.push( 0);
  44. v.push( 0);
  45. v.push( 0);
  46. v.push( 1);
  47. v.push( hw);
  48. v.push( -hh);
  49. v.push( 1);
  50. v.push( 1);
  51. v.push( 0);
  52. v.push( 0);
  53. v.push( 1);
  54. v.push( hw);
  55. v.push( hh);
  56. v.push( 1);
  57. v.push( 0);
  58. v.push( 0);
  59. v.push( 0);
  60. v.push( 1);
  61. buffer = h3d.Buffer.ofFloats(v, 8, [Quads]);
  62. }
  63. override function render(engine:h3d.Engine) {
  64. if( buffer == null ) alloc(engine);
  65. engine.renderQuadBuffer(buffer);
  66. }
  67. }