hingechain.monkey2 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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( -.2,-.45,-.01,.2,.45,.01 )
  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<HingeJoint>()
  52. joint.ConnectedBody=prev.RigidBody
  53. joint.Pivot=New Vec3f( 0,-.5,0 )
  54. joint.Axis=New Vec3f( 1,0,0 )
  55. joint.MinAngle=-90
  56. joint.MaxAngle=90
  57. Endif
  58. prev=copy
  59. Next
  60. prev.RigidBody.Mass=0
  61. model.Visible=False
  62. If _scene.Editable
  63. Print "Saving mojo3d scene file"
  64. _scene.Save( "hingechain-scene.mojo3d","modules/mojo3d/tests/assets/" )
  65. _scene=Scene.Load( "hingechain-scene.mojo3d" )
  66. Endif
  67. End
  68. Method OnRender( canvas:Canvas ) Override
  69. RequestRender()
  70. _scene.Update()
  71. _scene.Render( canvas )
  72. canvas.DrawText( "FPS="+App.FPS,0,0 )
  73. End
  74. End
  75. Function Main()
  76. New AppInstance
  77. New MyWindow
  78. App.Run()
  79. End