Created
August 18, 2019 10:13
-
-
Save paniq/bea06b8d194a494e4d5b5bce0a953949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using import ..tukan.libc | |
using import ..tukan.ode | |
using import ..tukan.sdl | |
let NUM_CONTACTS = 3 | |
let world = (dWorldCreate) | |
assert (world != null) | |
dWorldSetGravity world 0 -10 0 | |
let ground = | |
dCreatePlane null 0 1 0 0 | |
assert (ground != null) | |
let ball_geom = | |
dCreateSphere null 1 | |
assert (ball_geom != null) | |
let ball_body = | |
dBodyCreate world | |
assert (ball_body != null) | |
dGeomSetBody ball_geom ball_body | |
dBodySetPosition ball_body 0 50 0 | |
let jgroup = | |
dJointGroupCreate 0 | |
assert (jgroup != null) | |
for i in (range 0 (14 * 60)) | |
dWorldStep world (/ 1.0 60.0) | |
local contacts : (array dContact NUM_CONTACTS) | |
let num_collisions = | |
dCollide ball_geom ground NUM_CONTACTS | |
& (contacts @ 0 . geom) | |
sizeof dContact | |
dJointGroupEmpty jgroup | |
local BALL = "O" | |
for j in (range 0 num_collisions) | |
let surf = (contacts @ j . surface) | |
surf.mode = (dContactBounce as u32 as i32) | |
surf.mu = 250 | |
surf.bounce = 0.6 | |
surf.bounce_vel = 0.15 | |
let c = | |
dJointCreateContact world jgroup (& (contacts @ j)) | |
let b0 = | |
dGeomGetBody (contacts @ j . geom . g1) | |
let b1 = | |
dGeomGetBody (contacts @ j . geom . g2) | |
dJointAttach c b0 b1 | |
if ((ball_body == b0) | (ball_body == b1)) | |
BALL = "@" | |
let ypos = | |
(((dBodyGetPosition ball_body) @ 1) + 0.5) as i32 | |
printf "\r" | |
for j in (range 0 ypos) | |
printf " " | |
printf BALL | |
for j in (range 0 (50 - ypos)) | |
printf " " | |
fflush (stdout) | |
SDL_Delay 16 | |
printf "\n" | |
; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment