/examples3D/BrownianMotion/Alternativa3d/Main.as

https://github.com/404Assassin/Flint-examples · ActionScript · 97 lines · 56 code · 12 blank · 29 comment · 1 complexity · 47923e76466b456365d6feb42c0af23c MD5 · raw file

  1. /*
  2. * FLINT PARTICLE SYSTEM
  3. * .....................
  4. *
  5. * Author: Richard Lord
  6. * Copyright (c) Richard Lord 2008-2011
  7. * http://flintparticles.org/
  8. *
  9. * Licence Agreement
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a copy
  12. * of this software and associated documentation files (the "Software"), to deal
  13. * in the Software without restriction, including without limitation the rights
  14. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. * copies of the Software, and to permit persons to whom the Software is
  16. * furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in
  19. * all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. * THE SOFTWARE.
  28. */
  29. package
  30. {
  31. import alternativa.engine3d.core.Camera3D;
  32. import alternativa.engine3d.core.Object3D;
  33. import alternativa.engine3d.core.Resource;
  34. import alternativa.engine3d.core.View;
  35. import org.flintparticles.integration.alternativa3d.Alt3DRenderer;
  36. import org.flintparticles.threeD.emitters.Emitter3D;
  37. import flash.display.Sprite;
  38. import flash.display.Stage3D;
  39. import flash.events.Event;
  40. [SWF(width='400', height='400', frameRate='60', backgroundColor='#000000')]
  41. public class Main extends Sprite
  42. {
  43. private var emitter : Emitter3D;
  44. private var particleContainer : Object3D;
  45. private var camera : Camera3D;
  46. private var stage3D : Stage3D;
  47. private var renderer : Alt3DRenderer;
  48. public function Main()
  49. {
  50. camera = new Camera3D( 0.1, 10000 );
  51. camera.view = new View( stage.stageWidth, stage.stageHeight );
  52. camera.view.backgroundColor = 0x000000;
  53. camera.view.hideLogo();
  54. addChild( camera.view );
  55. addChild( camera.diagram );
  56. camera.rotationX = 0;
  57. camera.y = 0;
  58. camera.z = -360;
  59. stage3D = stage.stage3Ds[0];
  60. stage3D.addEventListener( Event.CONTEXT3D_CREATE, onContextCreate );
  61. stage3D.requestContext3D();
  62. }
  63. private function onContextCreate( event : Event ) : void
  64. {
  65. particleContainer = new Object3D();
  66. particleContainer.addChild( camera );
  67. renderer = new Alt3DRenderer( particleContainer );
  68. emitter = new BrownianMotion( stage );
  69. renderer.addEmitter( emitter );
  70. emitter.start();
  71. addEventListener( Event.ENTER_FRAME, render, false, 0, true );
  72. }
  73. private function render( ev : Event ) : void
  74. {
  75. // render the view
  76. camera.view.width = stage.stageWidth;
  77. camera.view.height = stage.stageHeight;
  78. camera.render( stage3D );
  79. for each ( var resource:Resource in particleContainer.getResources( true ) )
  80. {
  81. resource.upload( stage3D.context3D );
  82. }
  83. }
  84. }
  85. }