jointchain.monkey2 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. Namespace myapp3d
  2. #Import "<std>"
  3. #Import "<mojo>"
  4. #Import "<mojo3d>"
  5. '#Reflect mojo3d
  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. _scene=New Scene( True )
  20. _scene.ClearColor = New Color( 0.2, 0.6, 1.0 )
  21. _scene.AmbientLight = _scene.ClearColor * 0.25
  22. _scene.FogColor = _scene.ClearColor
  23. _scene.FogFar = 1.0
  24. _scene.FogFar = 200.0
  25. 'create camera
  26. Local camera:=New Camera( Self )
  27. camera.AddComponent<FlyBehaviour>()
  28. camera.Move( 0,2.5,-5 )
  29. 'create light
  30. Local light:=New Light
  31. light.CastsShadow=True
  32. light.Rotate( 45, 45, 0 )
  33. 'create ground
  34. Local groundBox:=New Boxf( -100,-1,-100,100,0,100 )
  35. Local groundMaterial:=New PbrMaterial( Color.Lime )
  36. Local ground:=Model.CreateBox( groundBox,1,1,1,groundMaterial )
  37. ground.AddComponent<BoxCollider>().Box=groundBox
  38. ground.AddComponent<RigidBody>().Mass=0
  39. ground.CastsShadow=False
  40. 'create chain link
  41. Local box:=New Boxf( -.1,-.45,-.1,.1,.45,.1 )
  42. Local material:=New PbrMaterial( Color.Red, 0.05, 0.2 )
  43. Local model:=Model.CreateBox( box,1,1,1,material )
  44. model.AddComponent<BoxCollider>().Box=box
  45. model.AddComponent<RigidBody>()
  46. Local prev:Model
  47. For Local y:=0 Until 100
  48. Local copy:=model.Copy()
  49. copy.Position=New Vec3f( 0,y+10,0 )
  50. If prev
  51. Local joint:=copy.AddComponent<BallSocketJoint>()
  52. joint.ConnectedBody=prev.RigidBody
  53. joint.Pivot=New Vec3f( 0,-.5,0 )
  54. Endif
  55. prev=copy
  56. Next
  57. prev.RigidBody.Mass=0
  58. model.Visible=False
  59. If _scene.Editable
  60. _scene.Save( "jointchain-scene.mojo3d","modules/mojo3d/tests/assets/" )
  61. _scene=Scene.Load( "jointchain-scene.mojo3d" )
  62. Endif
  63. End
  64. Method OnRender( canvas:Canvas ) Override
  65. RequestRender()
  66. _scene.Update()
  67. _scene.Render( canvas )
  68. canvas.DrawText( "FPS="+App.FPS,0,0 )
  69. End
  70. End
  71. Function Main()
  72. New AppInstance
  73. New MyWindow
  74. App.Run()
  75. End