turtle.monkey2 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. Namespace myapp
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. #Import "<mojo3d-loaders>"
  6. #Import "assets/psionic/turtle1.b3d"
  7. #Import "assets/psionic/turtle1.png"
  8. #Import "util"
  9. Using std..
  10. Using mojo..
  11. Using mojo3d..
  12. Class MyWindow Extends Window
  13. Field _scene:Scene
  14. Field _camera:Camera
  15. Field _light:Light
  16. Field _ground:Model
  17. Field _turtle:Model
  18. Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
  19. Super.New( title,width,height,flags )
  20. 'create scene
  21. '
  22. _scene=Scene.GetCurrent()
  23. 'create camera
  24. '
  25. _camera=New Camera( Self )
  26. _camera.Near=.1
  27. _camera.Far=100
  28. _camera.Move( 0,10,-20 )
  29. New FlyBehaviour( _camera )
  30. 'create light
  31. '
  32. _light=New Light
  33. _light.Rotate( 75,15,0 ) 'aim directional light 'down' - Pi/2=90 degrees.
  34. _light.CastsShadow=True
  35. 'create ground
  36. '
  37. _ground=Model.CreateBox( New Boxf( -50,-5,-50,50,0,50 ),1,1,1,New PbrMaterial( Color.Green ) )
  38. _ground.CastsShadow=False
  39. 'create ground
  40. '
  41. ' _ground=Model.CreateBox( New Boxf( -50,-1,-50,50,0,50 ),1,1,1,New PbrMaterial( Color.Green,0,.5 ) )
  42. 'create turtle
  43. '
  44. _turtle=Model.LoadBoned( "asset::turtle1.b3d" )
  45. _turtle.Scale=New Vec3f( .125 )
  46. Local walk:=_turtle.Animator.Animations[0].Slice( "Walk",1,11,AnimationMode.Looping )
  47. _turtle.Animator.Animations.Add( walk )
  48. For Local i:=0 Until 360 Step 6
  49. Local copy:=_turtle.Copy()
  50. copy.RotateY( i )
  51. copy.MoveZ( 30 )
  52. copy.Animator.Animate( copy.Animator.Animations[0],Rnd(.5,1.0) )
  53. Next
  54. _turtle.Animator.Animate( "Walk" )
  55. End
  56. Method OnRender( canvas:Canvas ) Override
  57. RequestRender()
  58. _scene.Update()
  59. _camera.Render( canvas )
  60. canvas.Scale( Width/640.0,Height/480.0 )
  61. canvas.DrawText( "Width="+Width+", Height="+Height+", anim time="+_turtle.Animator.Time+", FPS="+App.FPS,0,0 )
  62. End
  63. End
  64. Function Main()
  65. New AppInstance
  66. New MyWindow
  67. App.Run()
  68. End