PageRenderTime 35ms CodeModel.GetById 21ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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