particles.monkey2 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. Using std..
  6. Using mojo..
  7. Using mojo3d..
  8. Class MyWindow Extends Window
  9. Field _scene:Scene
  10. Field _camera:Camera
  11. Field _light:Light
  12. Field _ground:Model
  13. Field _particles:ParticleSystem
  14. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  15. Super.New( title,width,height,flags )
  16. _scene=Scene.GetCurrent()
  17. ' _scene.SkyTexture=Texture.Load( "asset::miramar-skybox.jpg",TextureFlags.FilterMipmap|TextureFlags.Cubemap )
  18. _scene.FogColor=Color.Sky
  19. _scene.FogNear=20
  20. _scene.FogFar=1000
  21. 'create camera
  22. '
  23. _camera=New Camera( Self )
  24. _camera.Near=.01
  25. _camera.Move( 0,1,-1 )
  26. New FlyBehaviour( _camera )
  27. 'create light
  28. '
  29. _light=New Light
  30. _light.Rotate( 60,45,0 ) 'aim directional light 'down' - Pi/2=90 degrees.
  31. 'create ground
  32. '
  33. _ground=Model.CreateBox( New Boxf( -50,-1,-50,50,0,50 ),1,1,1,New PbrMaterial( Color.Green * .5 ) )
  34. _particles=New ParticleSystem( 15000 )
  35. _particles.RotateX( -90 ) 'point upwards!
  36. Local pmaterial:=_particles.Material
  37. ' pmaterial.ColorTexture=Texture.Load( "asset::bluspark.png",TextureFlags.FilterMipmap )
  38. Local pbuffer:=_particles.ParticleBuffer
  39. pbuffer.Gravity=New Vec3f( 0,-9.81,0 ) 'gravity in world space in m/s^2.
  40. pbuffer.Duration=2.5 'how long a single particle lasts in seconds.
  41. pbuffer.Fade=0.0 'how long before paticle starts fading out in seconds.
  42. pbuffer.Colors=New Color[]( Color.White,Color.Yellow,Color.Orange,Color.Red )
  43. pbuffer.ConeAngle=30 'angle of particle emission cone.
  44. pbuffer.MinVelocity=15.0 'min particle velocity.
  45. pbuffer.MaxVelocity=20.0 'max particle velocity.
  46. pbuffer.MinSize=8.0 'min particle size.
  47. pbuffer.MaxSize=12.0 'max particle size.
  48. For Local an:=0 Until 360 Step 45
  49. Local pivot:=New Entity
  50. pivot.RotateY( an )
  51. pivot.MoveZ( 20 )
  52. pivot.Visible=True
  53. _particles.Copy( pivot )
  54. Next
  55. End
  56. Method OnRender( canvas:Canvas ) Override
  57. RequestRender()
  58. _scene.Update()
  59. _scene.Render( canvas )
  60. canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
  61. End
  62. End
  63. Function Main()
  64. New AppInstance
  65. New MyWindow
  66. App.Run()
  67. End