Skip to content

Commit

Permalink
Added helloWorld
Browse files Browse the repository at this point in the history
  • Loading branch information
BradWBeer committed Apr 2, 2017
1 parent 227ee6b commit dcef94a
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions examples/helloWorld/helloWorld.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(ql:quickload :cl-chipmunk)
(ql:quickload :rtg-math)
(use-package :rtg-math)

(defparameter cspace nil)
(defparameter ground nil)

(defparameter ball-body nil)
(defparameter ball-shape nil)
(defparameter moment-of-inertia nil)

(defparameter dt 1/60)

(setf cspace (chip:cp-space-new))
(chip:cp-space-set-collision-slop cspace 2)
(chip:cp-space-set-iterations cspace 5)

(chip:cp-space-set-gravity cspace (v! 0 -100))

(setf ground
(chip::cp-segment-shape-new (chip:cp-space-get-static-body cspace)
(v! -20 5)
(v! 20 -5)
0))

(chip:cp-shape-set-friction ground 1)
(chip:cp-space-add-shape cspace ground)
(setf moment-of-inertia
(chip:cp-moment-for-circle 1 0 5))

(setf ball-body
(chip:cp-space-add-body cspace
(chip:cp-body-new 1 moment-of-inertia)))

(chip:cp-body-set-position ball-body (rtg-math:v! 0 10))


(setf ball-shape
(chip:cp-space-add-shape
cspace
(chip:cp-circle-shape-new ball-body 5)))

(chip:cp-shape-set-friction ball-shape 0.7)

(loop for i from 0 to 2 by dt
do (progn
(format t "p=~A v=~A~%"
(chip:cp-body-get-position ball-body)
(chip:cp-body-get-velocity ball-body))
(chip:cp-space-step cspace dt)))

(chip:cp-shape-free ball-shape)
(chip:cp-shape-free ground)
(chip:cp-body-free ball-body)
(chip:cp-space-free cspace)

0 comments on commit dcef94a

Please sign in to comment.