Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

128 lines (94 sloc) 2.3 kb
(library (box2d-lite body)
(export make-body
body-position
body-rotation
body-velocity
body-angular-velocity
body-force
body-torque
body-width
body-friction
body-mass
body-inv-mass
body-i
body-inv-i
body-position-set!
body-rotation-set!
body-velocity-set!
body-angular-velocity-set!
body-force-set!
body-torque-set!
body-width-set!
body-friction-set!
body-mass-set!
body-inv-mass-set!
body-i-set!
body-inv-i-set!
is-body
import-body
create-body
;; body::set
)
(import (rnrs)
(box2d-lite util define-record-type)
(box2d-lite util math)
(box2d-lite vec))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-record-type++ body
is-body
import-body
(fields (mutable position)
(mutable rotation)
(mutable velocity)
(mutable angular-velocity)
(mutable force)
(mutable torque)
(mutable width)
(mutable friction)
(mutable mass)
(mutable inv-mass)
(mutable i)
(mutable inv-i))
(methods (set body::set)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (create-body)
(let ((b (make-body #f #f #f #f #f #f #f #f #f #f #f #f)))
(import-body b)
(position! (make-vec 0.0 0.0))
(rotation! 0.0)
(velocity! (make-vec 0.0 0.0))
(angular-velocity! 0.0)
(force! (make-vec 0.0 0.0))
(torque! 0.0)
(friction! 0.2)
(width! (make-vec 1.0 1.0))
(mass! FLT-MAX)
(inv-mass! 0.0)
(i! FLT-MAX)
(inv-i! 0.0)
b))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (body::set b w m)
(import-body b)
(is-vec width)
(position! (make-vec 0.0 0.0))
(rotation! 0.0)
(velocity! (make-vec 0.0 0.0))
(angular-velocity! 0.0)
(force! (make-vec 0.0 0.0))
(torque! 0.0)
(friction! 0.2)
(width! w)
(mass! m)
(if (< mass FLT-MAX)
(begin
(inv-mass! (/ 1.0 mass))
(i! (/ (* mass (+ (* width.x width.x) (* width.y width.y))) 12.0))
(inv-i! (/ 1.0 i)))
(begin
(inv-mass! 0.0)
(i! FLT-MAX)
(inv-i! 0.0)))
b)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
)
Jump to Line
Something went wrong with that request. Please try again.