effects.monkey2 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Import "assets/"
  6. Using std..
  7. Using mojo..
  8. Using mojo3d..
  9. Class MyWindow Extends Window
  10. Field _scene:Scene
  11. Field _camera:Camera
  12. Field _light:Light
  13. Field _donut:Model
  14. Field _bloom:BloomEffect
  15. Field _mono:MonochromeEffect
  16. Field _godrays:GodraysEffect
  17. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  18. Super.New( title,width,height,flags )
  19. _scene=Scene.GetCurrent()
  20. _scene.ClearColor=Color.Sky
  21. 'create camera
  22. '
  23. _camera=New Camera( self )
  24. _camera.Move( 0,10,-10 )
  25. New FlyBehaviour( _camera )
  26. 'create light
  27. '
  28. _light=New Light
  29. _light.Rotate( 120,0,0 )
  30. 'create effects
  31. '
  32. _godrays=New GodraysEffect
  33. _godrays.Enabled=false
  34. _godrays.Light=_light
  35. _bloom=New BloomEffect
  36. _bloom.Enabled=False
  37. _scene.AddPostEffect( _bloom )
  38. _mono=New MonochromeEffect
  39. _mono.Enabled=False
  40. _scene.AddPostEffect( _mono )
  41. _scene.AddPostEffect( _godrays )
  42. Local material:=New PbrMaterial( New Color( 2,.5,0,1 ),0,1 )
  43. _donut=Model.CreateTorus( 2,.5,48,24,material )
  44. _donut.AddComponent<RotateBehaviour>().Speed=New Vec3f( .1,.2,.3 )
  45. _donut.Move( 0,10,0 )
  46. End
  47. Method OnRender( canvas:Canvas ) Override
  48. RequestRender()
  49. If Keyboard.KeyHit( Key.Key1 ) _godrays.Enabled=Not _godrays.Enabled
  50. If Keyboard.KeyHit( Key.Key2 ) _bloom.Enabled=Not _bloom.Enabled
  51. If Keyboard.KeyHit( Key.Key3 ) _mono.Enabled=Not _mono.Enabled
  52. _scene.Update()
  53. _scene.Render( canvas )
  54. canvas.DrawText( "(1) Godrays="+_godrays.Enabled,0,0 )
  55. canvas.DrawText( "(2) Bloom="+_bloom.Enabled,0,16 )
  56. canvas.DrawText( "(3) Monochrome="+_mono.Enabled,0,32 )
  57. End
  58. End
  59. Function Main()
  60. SetConfig( "MOJO_OPENGL_PROFILE","es" )
  61. New AppInstance
  62. New MyWindow
  63. App.Run()
  64. End