/Interpreter/Script/test_both.io

http://github.com/dennisferron/LikeMagic-All · Unknown · 275 lines · 195 code · 80 blank · 0 comment · 0 complexity · 6eb7533d67ae2a527686e0d3b8e20daf MD5 · raw file

  1. w := dimension2du clone do( set(800, 600) )
  2. events := ScriptedEventReceiver new
  3. device := CppFunc createDevice(EDT_OPENGL, w, 16, false, false, false, events)
  4. //device := CppFunc createDevice(EDT_DIRECT3D9, w, 16, false, false, false, nil)
  5. //device := CppFunc createDevice(EDT_BURNINGSVIDEO, w, 16, false, false, false, nil)
  6. //device setWindowCaption("Test Title Change")
  7. driver := device getVideoDriver
  8. //mat2d := driver getMaterial2D
  9. //texture := mat2d get_TextureLayer(0)
  10. //texture set_BilinearFilter(true)
  11. //fsStr := irrFsStr newFromCStr("Media/2ddemo.png")
  12. //images := driver getTexture(fsStr)
  13. //driver makeColorKeyTextureAtPos(images, vector2di newWithXY(0,0), false)
  14. videoData := SExposedVideoData new
  15. imp1 := recti newWithXYXY(349,15,385,78)
  16. imp2 := recti newWithXYXY(387,15,423,78)
  17. //driver getMaterial2D set_AntiAliasing(EAAM_FULL_BASIC)
  18. smgr := device getSceneManager
  19. cameraNode := smgr addCameraSceneNode(
  20. nil, // parent
  21. vector3df newWithXYZ(0, 0, -200), // position
  22. vector3df newWithXYZ(0, 0, 0), // lookat
  23. -1, // id
  24. true // makeActive
  25. )
  26. //smgr addCameraSceneNodeFPS(nil, 100, 0.005, -1, nil, 0, false, 0.010, false, true)
  27. geometry := smgr getGeometryCreator
  28. wallMesh := geometry createCylinderMesh(
  29. 10, // radius
  30. 1000, // length
  31. 16, // tessellation (number of quads around)
  32. SColor newWithARGB(255, 200, 60, 240), // color
  33. false, // closeTop
  34. 0 // oblique
  35. )
  36. wallNode1 := smgr addMeshSceneNode(
  37. wallMesh, // mesh
  38. nil, // parent
  39. -1, // id
  40. vector3df newWithXYZ(-120,-120,0), // position
  41. vector3df clone, // rotation
  42. vector3df newWithXYZ(1,1,1), // scale
  43. false // alsoAddIfMeshPointerZero
  44. )
  45. wallNode2 := smgr addMeshSceneNode(
  46. wallMesh, // mesh
  47. nil, // parent
  48. -1, // id
  49. vector3df newWithXYZ(120,-120,0), // position
  50. vector3df clone, // rotation
  51. vector3df newWithXYZ(1,1,1), // scale
  52. false // alsoAddIfMeshPointerZero
  53. )
  54. wallNode1 setMaterialFlag(EMF_LIGHTING, true)
  55. wallNode2 setMaterialFlag(EMF_LIGHTING, true)
  56. ballMesh := geometry createSphereMesh(
  57. 2, // radius
  58. 16, // polyCountX
  59. 16 // polyCountY
  60. )
  61. ballNode := smgr addMeshSceneNode(
  62. ballMesh, // mesh
  63. nil, // parent
  64. -1, // id
  65. vector3df newWithXYZ(60,30,0), // position
  66. vector3df clone, // rotation
  67. vector3df newWithXYZ(1,1,1), // scale
  68. false // alsoAddIfMeshPointerZero
  69. )
  70. ballNode setMaterialFlag(EMF_LIGHTING, true)
  71. LM := LikeMagic classes
  72. ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
  73. collisionConfiguration := LM btDefaultCollisionConfiguration new
  74. ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
  75. dispatcher := LM btCollisionDispatcher new(collisionConfiguration)
  76. ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
  77. overlappingPairCache := LM btDbvtBroadphase new()
  78. ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
  79. solver := LM btSequentialImpulseConstraintSolver new
  80. dynamicsWorld := LM btDiscreteDynamicsWorld new(dispatcher,overlappingPairCache,solver,collisionConfiguration)
  81. // Gravity in feet per second per second
  82. dynamicsWorld setGravity(LM btVector3 new(0,-32.174,0))
  83. ///create a few basic rigid bodies
  84. groundShape := LM btBoxShape new(LM btVector3 new(5,5,5))
  85. groundTransform := LM btTransform new
  86. groundTransform setIdentity
  87. groundTransform setOrigin(LM btVector3 new(0,-50,0))
  88. mass := 0
  89. //rigidbody is dynamic if and only if mass is non zero, otherwise static
  90. isDynamic := (mass != 0)
  91. localInertia := LM btVector3 new(0,0,0)
  92. if (isDynamic)
  93. groundShape calculateLocalInertia(mass,localInertia)
  94. //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
  95. groundMotionState := LM PhysicsAnimator new(groundTransform, CppFunc getIdentityTransform)
  96. rbInfo := LM btRigidBodyConstructionInfo new(mass,groundMotionState,groundShape,localInertia)
  97. groundRigidBody := LM btRigidBody new(rbInfo)
  98. //add the body to the dynamics world
  99. dynamicsWorld addRigidBody(groundRigidBody)
  100. groundMesh := geometry createCubeMesh(
  101. vector3df new(10, 10, 10)
  102. )
  103. groundNode := smgr addMeshSceneNode(
  104. groundMesh, // mesh
  105. nil, // parent
  106. -1, // id
  107. vector3df new(0), // position
  108. vector3df new, // rotation
  109. vector3df new(1), // scale
  110. false // alsoAddIfMeshPointerZero
  111. )
  112. groundNode addAnimator(groundMotionState)
  113. //create a dynamic rigidbody
  114. //btCollisionShape* colShape := LM btBoxShape new(LM btVector3 new(1,1,1))
  115. colShape := LM btSphereShape new(2)
  116. /// Create Dynamic Objects
  117. startTransform := LM btTransform new
  118. startTransform setIdentity()
  119. mass := 1
  120. //rigidbody is dynamic if and only if mass is non zero, otherwise static
  121. isDynamic := (mass != 0)
  122. localInertia := LM btVector3 new(0,0,0)
  123. if (isDynamic)
  124. colShape calculateLocalInertia(mass,localInertia)
  125. startTransform setOrigin(LM btVector3 new(0,50,0))
  126. //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
  127. ballMotionState := LM PhysicsAnimator new(startTransform, CppFunc getIdentityTransform)
  128. rbInfo := LM btRigidBodyConstructionInfo new(mass, ballMotionState, colShape, localInertia)
  129. fallRigidBody := LM btRigidBody new(rbInfo)
  130. dynamicsWorld addRigidBody(fallRigidBody)
  131. ballNode addAnimator(ballMotionState)
  132. smgr addLightSceneNode(
  133. nil, // parent
  134. vector3df newWithXYZ(0, 0, -2000), // position
  135. SColorf newWithRGBA(1,1,1,1), // color
  136. 1000, // radius
  137. -1 // id
  138. )
  139. title := driver getName .. " FPS: "
  140. frames := 0
  141. time := 0
  142. lasttime := 0
  143. playerX := 0
  144. playerY := 0
  145. playerXV := 0
  146. playerYV := 0
  147. cameraY := 0
  148. cameraZ := 0
  149. cameraLookY := 0
  150. while(device run,
  151. lasttime = time
  152. time = device getTimer() getTime()
  153. dynamicsWorld stepSimulation((time-lasttime)/1000,10,1/60)
  154. trans := LM btTransform new
  155. fallRigidBody getMotionState_c() getWorldTransform(trans)
  156. spherePos := trans getOrigin_c()
  157. //writeln("sphere: ", spherePos getY())
  158. if (events IsKeyDown(KEY_LEFT), playerXV = -3)
  159. if (events IsKeyDown(KEY_RIGHT), playerXV = 3)
  160. if (events IsKeyDown(KEY_UP), playerYV = 4)
  161. //if (events IsKeyDown(KEY_DOWN), playerY = playerY - 1)
  162. if (playerXV > 0, playerXV = playerXV - 0.05)
  163. if (playerXV < 0, playerXV = playerXV + 0.05)
  164. if (playerX < -100, playerXV = 3.5)
  165. if (playerX > 100, playerXV = -3.5)
  166. playerX = playerX + playerXV
  167. playerYV = playerYV - 0.1
  168. playerY = playerY + playerYV
  169. if (playerY < -100, playerY = -100; playerYV = 0)
  170. cameraYAdj := 0.5*(playerYV abs)
  171. targetY := playerY
  172. if (playerYV < 0 and cameraY < playerY, targetY = playerY + -10*playerYV; cameraYAdj = 2*playerYV abs)
  173. if (cameraY < targetY, cameraY = cameraY + cameraYAdj)
  174. if (cameraY > targetY, cameraY = cameraY - cameraYAdj)
  175. cameraZAdj := 0.5*(playerYV abs)
  176. if (cameraZ + 5 < (2*playerYV abs), cameraZ = cameraZ + cameraZAdj)
  177. if (cameraZ - 5 > (2*playerYV abs), cameraZ = cameraZ - cameraZAdj)
  178. cameraLookAdj := 0.5 + (playerYV abs)
  179. targetLookY := (cameraY + playerY)/2 + 200*playerYV
  180. if (cameraLookY < targetLookY, cameraLookY = cameraLookY + cameraLookAdj)
  181. if (cameraLookY > targetLookY, cameraLookY = cameraLookY - cameraLookAdj)
  182. cameraNode setPosition(vector3df newWithXYZ(0, 0, -150))
  183. cameraNode setTarget(vector3df newWithXYZ(0, 0, 0))
  184. driver beginScene(true, true, SColor newWithARGB(255,8,16,35), videoData, nil)
  185. smgr drawAll
  186. driver endScene
  187. // Set window caption should no longer act strange with the fixed string conversions in LikeMagic.
  188. frames = frames + 1
  189. if (frames % 100 == 0,
  190. device setWindowCaption(title .. (driver getFPS asString))
  191. )
  192. )
  193. device drop
  194. dynamicsWorld removeRigidBody(fallRigidBody)
  195. dynamicsWorld removeRigidBody(groundRigidBody)