PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/hello-world.lisp

https://github.com/Ralith/buclet
Lisp | 65 lines | 32 code | 17 blank | 16 comment | 1 complexity | a3ef793ef3dcc6b4ccb7558cbb5b91ef MD5 | raw file
Possible License(s): BSD-3-Clause
  1. ;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
  2. ;;;;
  3. ;;;; hello-world.lisp
  4. ;;;;
  5. ;;;; author: Erik Winkels (aerique@xs4all.nl)
  6. ;;;;
  7. ;;;; See the LICENSE file in the clois-lane root directory for more info.
  8. ;;;;
  9. ;;;; See: http://www.continuousphysics.com/mediawiki-1.5.8/index.php?title=Hello_World
  10. ;;; Packages
  11. ;(asdf :buclet)
  12. (defpackage :pl-hello-world
  13. (:use :cl :pl :sb-cga))
  14. (in-package :pl-hello-world)
  15. ;;; Variables
  16. (defparameter *dynamics-world* nil)
  17. (defparameter *fall-rigid-body* nil)
  18. (defparameter *fall-shape* nil)
  19. (defparameter *ground-rigid-body* nil)
  20. (defparameter *ground-shape* nil)
  21. (defparameter *physics-sdk* nil)
  22. ;;; Functions
  23. (defun quat (a b c d)
  24. (make-array 4 :element-type 'single-float :initial-contents (list a b c d)))
  25. (defun start-simulation ()
  26. (set-position *fall-rigid-body* (vec 0.0 50.0 0.0))
  27. (set-orientation *fall-rigid-body* (quat 0.0 0.0 0.0 1.0))
  28. (loop for i from 0 to 300
  29. with sim-step = (/ 1.0 60.0)
  30. do (step-simulation *dynamics-world* sim-step 10 sim-step)
  31. (format t "~A: sphere Y position: ~A~%"
  32. i (aref (get-position *fall-rigid-body*) 1))
  33. (sleep sim-step)))
  34. ;;; Initialisation
  35. (setf *physics-sdk* (new-bullet-sdk))
  36. (setf *dynamics-world* (create-dynamics-world *physics-sdk* :dbvt))
  37. (setf *ground-shape* (new-static-plane-shape (vec 0.0 1.0 0.0) 1.0))
  38. (setf *ground-rigid-body* (create-rigid-body 0.0 *ground-shape*))
  39. (set-position *ground-rigid-body* (vec 0.0 -1.0 0.0))
  40. (set-orientation *ground-rigid-body* (quat 0.0 0.0 0.0 1.0))
  41. (add-rigid-body *dynamics-world* *ground-rigid-body*)
  42. (setf *fall-shape* (new-sphere-shape 1.0))
  43. (setf *fall-rigid-body* (create-rigid-body 1.0 *fall-shape*))
  44. (set-position *fall-rigid-body* (vec 0.0 50.0 0.0))
  45. (set-orientation *fall-rigid-body* (quat 0.0 0.0 0.0 1.0))
  46. (add-rigid-body *dynamics-world* *fall-rigid-body*)
  47. ;;; Main Program
  48. ;(start-simulation)