spotlight.monkey2 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Namespace myapp3d
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Import "assets/monkey2-logo.png"
  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 _ground:Model
  14. Field _donut:Model
  15. Method New( title:String="Simple mojo3d app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  16. Super.New( title,width,height,flags )
  17. End
  18. Method OnCreateWindow() Override
  19. 'create (current) scene
  20. _scene=New Scene
  21. 'create camera
  22. _camera=New Camera( Self )
  23. _camera.AddComponent<FlyBehaviour>()
  24. _camera.Move( 0,2.5,-10 )
  25. 'create light
  26. _light=New Light
  27. _light.Type=LightType.Spot
  28. _light.Texture=Texture.Load( "asset::monkey2-logo.png" )'ColorTexture( Color.Red )
  29. _light.Range=25
  30. _light.InnerAngle=15
  31. _light.OuterAngle=45
  32. _light.CastsShadow=True
  33. _light.Position=New Vec3f( 0,10,0 )
  34. _light.Rotate( 90,0,0 )
  35. 'create ground
  36. Local groundBox:=New Boxf( -100,-1,-100,100,0,100 )
  37. Local groundMaterial:=New PbrMaterial( Color.Brown,0,1 )
  38. _ground=Model.CreateBox( groundBox,1,1,1,groundMaterial )
  39. _ground.CastsShadow=False
  40. 'create donut
  41. Local donutMaterial:=New PbrMaterial( Color.White,0,1 )
  42. _donut=Model.CreateTorus( 2,.5,48,24,donutMaterial )
  43. _donut.Move( 0,2.5,0 )
  44. _donut.AddComponent<RotateBehaviour>().Speed=New Vec3f( .2,.4,.6 )
  45. End
  46. Method OnRender( canvas:Canvas ) Override
  47. RequestRender()
  48. If Keyboard.KeyHit( Key.Space )
  49. Select _light.Type
  50. Case LightType.Directional
  51. _light.Type=LightType.Point
  52. Case LightType.Point
  53. _light.Type=LightType.Spot
  54. Case LightType.Spot
  55. _light.Type=LightType.Directional
  56. End
  57. Endif
  58. _scene.Update()
  59. _scene.Render( canvas )
  60. canvas.DrawText( "FPS="+App.FPS,0,0 )
  61. End
  62. End
  63. Function Main()
  64. New AppInstance
  65. New MyWindow
  66. App.Run()
  67. End