|
1 | 1 | (in-package :mortar-combat)
|
2 | 2 |
|
3 | 3 |
|
| 4 | +(defclass ball-geom (collidable sphere-geom) ()) |
| 5 | +(defclass ball-body (disposable) |
| 6 | + (body geom)) |
| 7 | + |
| 8 | + |
| 9 | +(defmethod initialize-instance :after ((this ball-body) &key) |
| 10 | + (with-slots (body geom) this |
| 11 | + (setf body (make-rigid-body) |
| 12 | + geom (make-instance 'ball-geom :radius 1.025)) |
| 13 | + (bind-geom geom body) |
| 14 | + |
| 15 | + (setf (position-of body) (vec3 0.0 10.0 0.0)))) |
| 16 | + |
| 17 | + |
| 18 | +(defmethod transform-of ((this ball-body)) |
| 19 | + (with-slots (body) this |
| 20 | + (transform-of body))) |
| 21 | + |
| 22 | + |
| 23 | +(define-destructor ball-body (body geom) |
| 24 | + (dispose geom) |
| 25 | + (dispose body)) |
| 26 | + |
4 | 27 | ;;;
|
5 | 28 | ;;;
|
6 | 29 | ;;;
|
|
34 | 57 | ;;;
|
35 | 58 | ;;;
|
36 | 59 | (defclass ball-model (model)
|
37 |
| - ((mesh :initform nil) |
38 |
| - (program :initform nil))) |
| 60 | + (body mesh program)) |
39 | 61 |
|
40 | 62 |
|
41 | 63 | (defmethod initialization-flow ((this ball-model) &key)
|
42 |
| - (with-slots (mesh program) this |
| 64 | + (with-slots (body mesh program) this |
43 | 65 | (>> (resource-flow "mesh.Ball" (shading-program-resource-name "passthru-program"))
|
44 | 66 | (instantly (m p)
|
45 | 67 | (setf mesh m
|
46 | 68 | program p))
|
| 69 | + (-> ((physics)) () |
| 70 | + (setf body (make-instance 'ball-body))) |
47 | 71 | (call-next-method))))
|
48 | 72 |
|
49 | 73 |
|
| 74 | +(defmethod discard-node :before ((this ball-model)) |
| 75 | + (with-slots (body) this |
| 76 | + (dispose body))) |
| 77 | + |
| 78 | + |
| 79 | +(defmethod scene-pass ((this ball-model) (pass simulation-pass) input) |
| 80 | + (with-slots (body) this |
| 81 | + (let ((result (transform-of body))) |
| 82 | + (call-next-method) |
| 83 | + result))) |
| 84 | + |
| 85 | + |
| 86 | +(defmethod scene-pass ((this ball-model) (pass rendering-pass) ball-transform) |
| 87 | + (let ((*model-matrix* (mult *model-matrix* ball-transform))) |
| 88 | + (call-next-method))) |
| 89 | + |
| 90 | + |
50 | 91 | (defmethod model-graph-assembly-flow ((this ball-model))
|
51 | 92 | (with-slots (mesh program) this
|
52 | 93 | (scenegraph
|
|
0 commit comments