spotlight.monkey2 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Namespace myapp3d
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. 'uncomment this to create a mojo3d scene file in monkey2 dir!
  6. '#Reflect mojo3d
  7. #Import "assets/monkey2-logo.png"
  8. Using std..
  9. Using mojo..
  10. Using mojo3d..
  11. Class MyWindow Extends Window
  12. Field _scene:Scene
  13. Method New( title:String="Simple mojo3d app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  14. Super.New( title,width,height,flags )
  15. End
  16. Method OnCreateWindow() Override
  17. 'create (current) scene
  18. _scene=New Scene( True )
  19. _scene.ShadowAlpha=.75
  20. 'create camera
  21. Local camera:=New Camera( Self )
  22. camera.AddComponent<FlyBehaviour>()
  23. camera.Move( 0,2.5,-10 )
  24. 'create light
  25. Local light:=New Light
  26. light.Type=LightType.Spot
  27. light.Texture=_scene.LoadTexture( "asset::monkey2-logo.png" )
  28. light.Color=Color.White * 8
  29. light.Range=15
  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. Local 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. Local 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. If _scene.Editable _scene.Save( "spotlight-scene.mojo3d","modules/mojo3d/tests/assets/" ) ; _scene=Scene.Load( "spotlight-scene.mojo3d" )
  46. End
  47. Method OnRender( canvas:Canvas ) Override
  48. RequestRender()
  49. _scene.Update()
  50. _scene.Render( canvas )
  51. canvas.DrawText( "FPS="+App.FPS,0,0 )
  52. End
  53. End
  54. Function Main()
  55. New AppInstance
  56. New MyWindow
  57. App.Run()
  58. End