Skip to content

Commit f23d6d9

Browse files
committed
Ball body
1 parent 5a1adeb commit f23d6d9

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

client/src/ball.lisp

+44-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
(in-package :mortar-combat)
22

33

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+
427
;;;
528
;;;
629
;;;
@@ -34,19 +57,37 @@
3457
;;;
3558
;;;
3659
(defclass ball-model (model)
37-
((mesh :initform nil)
38-
(program :initform nil)))
60+
(body mesh program))
3961

4062

4163
(defmethod initialization-flow ((this ball-model) &key)
42-
(with-slots (mesh program) this
64+
(with-slots (body mesh program) this
4365
(>> (resource-flow "mesh.Ball" (shading-program-resource-name "passthru-program"))
4466
(instantly (m p)
4567
(setf mesh m
4668
program p))
69+
(-> ((physics)) ()
70+
(setf body (make-instance 'ball-body)))
4771
(call-next-method))))
4872

4973

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+
5091
(defmethod model-graph-assembly-flow ((this ball-model))
5192
(with-slots (mesh program) this
5293
(scenegraph

client/src/main.lisp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
(in-package :mortar-combat)
22

33

4+
(define-constant +framestep+ 0.016)
45
(defvar *main-latch* (mt:make-latch))
56

67

8+
79
(defclass mortar-combat (enableable generic-system)
810
((scene :initform nil)
911
(keymap :initform (make-instance 'keymap))
@@ -23,6 +25,7 @@
2325
((projection-node :aspect (/ 800 600))
2426
((player-camera :player player)
2527
(room-model)
28+
(ball-model)
2629
((transform-node :translation (vec3 4.0 0.0 0.0))
2730
(mortar-model)
2831
((dude-model :color (vec3 0.9 0.4 0.4)))))))))
@@ -83,7 +86,9 @@
8386
scenegraph-root)))
8487
(concurrently ()
8588
(let (looped-flow)
86-
(setf looped-flow (>> (scene-processing-flow scene)
89+
(setf looped-flow (>> (-> ((physics)) ()
90+
(observe-universe +framestep+))
91+
(scene-processing-flow scene)
8792
(instantly ()
8893
(when (enabledp this)
8994
(run looped-flow)))))

client/src/room.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
(in-package :mortar-combat)
22

33

4-
4+
(defclass floor-geom (collidable plane-geom) ())
55
(defclass room-floor (disposable)
66
(geom))
77

88

99
(defmethod initialize-instance :after ((this room-floor) &key)
1010
(with-slots (geom) this
11-
(setf geom (make-instance 'plane-geom :normal (vec3 0.0 1.0 0.0)))))
11+
(setf geom (make-instance 'floor-geom :normal (vec3 0.0 1.0 0.0)))))
1212

1313

1414
(define-destructor room-floor (geom)

0 commit comments

Comments
 (0)