Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 128 lines (94 sloc) 2.3 kB
e01e975 @dharmatech first commit
authored
1
2 (library (box2d-lite body)
3
4 (export make-body
5
6 body-position
7 body-rotation
8 body-velocity
9 body-angular-velocity
10 body-force
11 body-torque
12 body-width
13 body-friction
14 body-mass
15 body-inv-mass
16 body-i
17 body-inv-i
18
19 body-position-set!
20 body-rotation-set!
21 body-velocity-set!
22 body-angular-velocity-set!
23 body-force-set!
24 body-torque-set!
25 body-width-set!
26 body-friction-set!
27 body-mass-set!
28 body-inv-mass-set!
29 body-i-set!
30 body-inv-i-set!
31
32 is-body
33 import-body
34
35 create-body
36 ;; body::set
37 )
38
39 (import (rnrs)
40 (box2d-lite util define-record-type)
41 (box2d-lite util math)
42 (box2d-lite vec))
43
44 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
46 (define-record-type++ body
47 is-body
48 import-body
49 (fields (mutable position)
50 (mutable rotation)
51 (mutable velocity)
52 (mutable angular-velocity)
53 (mutable force)
54 (mutable torque)
55 (mutable width)
56 (mutable friction)
57 (mutable mass)
58 (mutable inv-mass)
59 (mutable i)
60 (mutable inv-i))
61 (methods (set body::set)))
62
63 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64
65 (define (create-body)
66
67 (let ((b (make-body #f #f #f #f #f #f #f #f #f #f #f #f)))
68
69 (import-body b)
70
71 (position! (make-vec 0.0 0.0))
72 (rotation! 0.0)
73 (velocity! (make-vec 0.0 0.0))
74 (angular-velocity! 0.0)
75 (force! (make-vec 0.0 0.0))
76 (torque! 0.0)
77 (friction! 0.2)
78
79 (width! (make-vec 1.0 1.0))
80 (mass! FLT-MAX)
81 (inv-mass! 0.0)
82 (i! FLT-MAX)
83 (inv-i! 0.0)
84
85 b))
86
87 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
88
89 (define (body::set b w m)
90
91 (import-body b)
92
93 (is-vec width)
94
95 (position! (make-vec 0.0 0.0))
96 (rotation! 0.0)
97 (velocity! (make-vec 0.0 0.0))
98 (angular-velocity! 0.0)
99 (force! (make-vec 0.0 0.0))
100 (torque! 0.0)
101 (friction! 0.2)
102
103 (width! w)
104 (mass! m)
105
106 (if (< mass FLT-MAX)
107
108 (begin
109
110 (inv-mass! (/ 1.0 mass))
111
112 (i! (/ (* mass (+ (* width.x width.x) (* width.y width.y))) 12.0))
113
114 (inv-i! (/ 1.0 i)))
115
116 (begin
117
118 (inv-mass! 0.0)
119
120 (i! FLT-MAX)
121
122 (inv-i! 0.0)))
123
124 b)
125
126 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127
128 )
Something went wrong with that request. Please try again.