view org/games.org @ 34:183744c179e6

MASSIVE cleanup, especially in the vision code
author Robert McIntyre <rlm@mit.edu>
date Thu, 03 Nov 2011 08:28:26 -0700
parents f0562b9bde94
children b1b90c4ab0bf
line wrap: on
line source
1 #+title: jMonkeyEngine3 from Clojure
2 #+author: Robert McIntyre
3 #+email: rlm@mit.edu
4 #+description: Using jMonkeyEngine3 from clojure
5 #+keywords: clojure, jMonkeyEngine3, tutorial, examples
6 #+SETUPFILE: ../../aurellem/org/setup.org
7 #+INCLUDE: ../../aurellem/org/level-0.org
8 #+babel: :mkdirp yes :noweb yes :exports both
10 [TABLE-OF-CONTENTS]
13 Here are the jMonkeyEngine "Hello" programs translated to clojure.
15 * Hello Simple App
16 Here is the hello world example for jme3 in clojure. It's a more or
17 less direct translation from the java source [[http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication][here]].
19 Of note is the fact that since we don't have access to the
20 =AssetManager= via extendig =SimpleApplication=, we have to build one
21 ourselves.
23 #+srcname: hello-simple-app
24 #+begin_src clojure :results silent
25 (ns hello.hello-simple-app
26 (:use cortex.world)
27 (:import com.jme3.math.Vector3f)
28 (:import com.jme3.material.Material)
29 (:import com.jme3.scene.Geometry)
30 (:import com.jme3.math.ColorRGBA)
31 (:import com.jme3.app.SimpleApplication)
32 (:import com.jme3.scene.shape.Box))
34 (def cube (Box. Vector3f/ZERO 1 1 1))
36 (def geom (Geometry. "Box" cube))
38 (def mat (Material. (asset-manager) "Common/MatDefs/Misc/Unshaded.j3md"))
40 (.setColor mat "Color" ColorRGBA/Blue)
42 (.setMaterial geom mat)
44 (defn simple-app []
45 (doto
46 (proxy [SimpleApplication] []
47 (simpleInitApp
48 []
49 ;; Don't take control of the mouse
50 (org.lwjgl.input.Mouse/setGrabbed false)
51 (.attachChild (.getRootNode this) geom)))
52 ;; don't show a menu to change options.
53 (.setShowSettings false)
54 (.setPauseOnLostFocus false)
55 (.setSettings *app-settings*)))
56 #+end_src
58 Running this program will begin a new jMonkeyEngine game which
59 displays a single blue cube.
61 #+begin_src clojure :exports code :results silent
62 (.start (hello.hello-simple-app/simple-app))
63 #+end_src
65 #+caption: the simplest JME game.
66 [[../images/simple-app.jpg]]
68 * Simpler HelloSimpleApp
70 #+srcname: hello-simpler-app
71 #+begin_src clojure
72 (ns hello.hello-simpler-app
73 (:use cortex.world)
74 (:use cortex.util)
75 (:import com.jme3.math.ColorRGBA)
76 (:import com.jme3.scene.Node))
78 (defn simpler-world
79 "The jMonkeyEngine3 Hello World program. Displays a blue 3D cube in
80 a basic 3D world."
81 []
82 (world (doto (Node.)
83 (.attachChild
84 (box 1 1 1
85 :color ColorRGBA/Blue :physical? false)))
86 {} no-op no-op))
87 #+end_src
89 More information about the jMonkeyEngine3 hello world program can be
90 found [[http://jmonkeyengine.org/wiki/doku.php/starter:hello_world][here]].
92 * COMMENT Hello Physics
93 From http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_physics
95 #+srcname: brick-wall-header
96 #+begin_src clojure :results silent
97 (ns hello.brick-wall)
98 (require 'cortex.import)
99 (use 'clojure.contrib.def)
100 (rlm.rlm-commands/help)
101 (cortex.import/mega-import-jme3)
102 (use '[pokemon [lpsolve :only [constant-map]]])
103 (use 'cortex.world)
104 (use 'cortex.util)
105 #+end_src
107 #+srcname: brick-wall-body
108 #+begin_src clojure :results silent
109 (in-ns 'hello.brick-wall)
111 (defn floor
112 "make a sturdy, unmovable physical floor"
113 []
114 (box 20 1 20 :mass 0 :color false :position (Vector3f. 0 -2 0)))
116 (def brick-length 0.48)
117 (def brick-width 0.24)
118 (def brick-height 0.12)
119 (def gravity (Vector3f. 0 -9.81 0))
121 (defn brick* [position]
122 (doto (box brick-length brick-height brick-width
123 :position position :name "brick"
124 :material "Common/MatDefs/Misc/Unshaded.j3md"
125 :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
126 :mass 36)
127 (->
128 (.getMesh)
129 (.scaleTextureCoordinates (Vector2f. 1 0.5)))
130 ;;(.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
131 )
132 )
134 (defn inception-brick-wall
135 "construct a physical brick wall"
136 []
137 (let [node (Node. "brick-wall")]
138 (dorun
139 (map (comp #(.attachChild node %) brick*)
140 (for
141 [x (range 15)
142 y (range 10)
143 z (range 1)]
144 (Vector3f.
145 (* brick-length x 1.03)
146 (* brick-width y y 10)
147 (* brick-height z)))))
148 node))
150 (defn gravity-toggle
151 [new-value]
152 (fn [game value]
153 (println-repl "set gravity to " new-value)
154 (if value
155 (set-gravity game new-value)
156 (set-gravity game gravity))))
158 (defn fire-cannon-ball
159 ([node]
160 (fn [game value]
161 (if (not value)
162 (let [camera (.getCamera game)
163 cannon-ball
164 (sphere 0.7
165 :material "Common/MatDefs/Misc/Unshaded.j3md"
166 :texture "Textures/PokeCopper.jpg"
167 :position
168 (.add (.getLocation camera)
169 (.mult (.getDirection camera) (float 1)))
170 :mass 3)] ;200 0.05
171 (.setShadowMode cannon-ball RenderQueue$ShadowMode/CastAndReceive)
172 (.setLinearVelocity
173 (.getControl cannon-ball RigidBodyControl)
174 (.mult (.getDirection camera) (float 50))) ;50
175 (add-element game cannon-ball (if node node (.getRootNode game)))))))
176 ([]
177 (fire-cannon-ball false)))
180 (defn floor* []
181 (doto (box 10 0.1 5 :name "floor" ;10 0.1 5 ; 240 0.1 240
182 :material "Common/MatDefs/Misc/Unshaded.j3md"
183 :texture "Textures/Terrain/Pond/Pond.png"
184 :position (Vector3f. 0 -0.1 0 )
185 :mass 0)
186 (->
187 (.getMesh)
188 (.scaleTextureCoordinates (Vector2f. 3 6)));64 64
189 (->
190 (.getMaterial)
191 (.getTextureParam "ColorMap")
192 (.getTextureValue)
193 (.setWrap Texture$WrapMode/Repeat))
194 (.setShadowMode RenderQueue$ShadowMode/Receive)
195 ))
197 (defn brick-wall* []
198 (let [node (Node. "brick-wall")]
199 (dorun
200 (map
201 (comp #(.attachChild node %) brick*)
202 (for [y (range 15)
203 x (range 4)
204 z (range 1)]
205 (Vector3f.
206 (+ (* 2 x brick-length)
207 (if (even? (+ y z))
208 (/ brick-length 4) (/ brick-length -4)))
209 (+ (* brick-height (inc (* 2 y))))
210 (* 2 z brick-width) ))))
211 (.setShadowMode node RenderQueue$ShadowMode/CastAndReceive)
212 node))
214 (defn brick-wall-game-run []
215 (doto
216 (world
217 (doto (Node.) (.attachChild (floor*))
218 (.attachChild (brick-wall*))
219 )
220 {"key-i" (gravity-toggle (Vector3f. 0 0 -9.81))
221 "key-m" (gravity-toggle (Vector3f. 0 0 9.81))
222 "key-l" (gravity-toggle (Vector3f. 9.81 0 0))
223 "key-j" (gravity-toggle (Vector3f. -9.81 0 0))
224 "key-k" (gravity-toggle Vector3f/ZERO)
225 "key-u" (gravity-toggle (Vector3f. 0 9.81 0))
226 "key-o" (gravity-toggle (Vector3f. 0 -9.81 0))
227 "key-f" (fn[game value]
228 (if (not value) (add-element game (brick-wall*))))
229 "key-return" (fire-cannon-ball)}
230 position-camera
231 (fn [& _]))
232 (.start)))
233 #+end_src
235 #+begin_src clojure :results silent
236 (hello.brick-wall/brick-wall-game-run)
237 #+end_src
239 #+caption: the brick wall standing
240 [[../images/brick-wall-standing.jpg]]
242 #+caption: the brick wall after it has been knocked over by a "pok\eacute{}ball"
243 [[../images/brick-wall-knocked-down.jpg]]
245 * COMMENT Other Brick Games
246 #+srcname: other-games
247 #+begin_src clojure :results silent
248 (ns hello.other-games
249 {:author "Dylan Holmes"})
250 (use 'cortex.world)
251 (use 'hello.brick-wall)
252 (use 'cortex.import)
253 (cortex.import/mega-import-jme3)
255 (defn scad [position]
256 (doto (box 0.1 0.1 0.1
257 :position position :name "brick"
258 :material "Common/MatDefs/Misc/Unshaded.j3md"
259 :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
260 :mass 20)
261 (->
262 (.getMesh)
263 (.scaleTextureCoordinates (Vector2f. 1 0.5))
264 )
265 (-> (.getControl RigidBodyControl)
266 (.setLinearVelocity (Vector3f. 0 100 0))
267 )
269 ;;(.setShadowMode RenderQueue$ShadowMode/Cast)
270 ))
273 (defn shrapnel []
274 (let [node (Node. "explosion-day")]
275 (dorun
276 (map
277 (comp #(.attachChild node %) scad)
278 (for [y (range 15)
279 x (range 4)
280 z (range 1)]
281 (Vector3f.
282 (+ (* 2 x brick-height)
283 (if (even? (+ y z)) (/ brick-height 4) (/ brick-height -4)))
284 (+ (* brick-height (inc (* 2 y))))
285 (* 2 z brick-height) ))))
286 node))
289 (def domino-height 0.48)
290 (def domino-thickness 0.12)
291 (def domino-width 0.24)
293 (def domino-thickness 0.05)
294 (def domino-width 0.5)
295 (def domino-height 1)
297 (defn domino
298 ([position]
299 (domino position (Quaternion/IDENTITY)))
300 ([position rotation]
301 (doto (box domino-width domino-height domino-thickness
302 :position position :name "domino"
303 :material "Common/MatDefs/Misc/Unshaded.j3md"
304 :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
305 :mass 1
306 :rotation rotation)
307 (.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
308 )))
311 (defn domino-row []
312 (let [node (Node. "domino-row")]
313 (dorun
314 (map
315 (comp #(.attachChild node %) domino)
316 (for [
317 z (range 10)
318 x (range 5)
319 ]
320 (Vector3f.
321 (+ (* z domino-width) (* x 5 domino-width))
322 (/ domino-height 1)
323 (* -5.5 domino-thickness z) ))))
325 node))
327 (defn domino-cycle []
328 (let [node (Node. "domino-cycle")]
329 (dorun
330 (map
331 (comp #(.attachChild node %) (partial apply domino) )
332 (for [n (range 720)]
333 (let [space (* domino-height 5.5)
334 r (fn[n] (* (+ n 3) domino-width 0.5))
335 t (fn[n] (reduce
336 +
337 (map
338 (fn dt[n] (/ space (* 2 (Math/PI) (r n))))
339 (range n))))
340 t (t n)
341 r (r n)
342 ct (Math/cos t)
343 st (Math/sin t)
344 ]
345 (list
346 (Vector3f.
347 (* -1 r st)
348 (/ domino-height 1)
349 (* r ct))
350 (.fromAngleAxis (Quaternion.)
351 (- (/ 3.1415926 2) t) (Vector3f. 0 1 0))
352 )))
353 ))
354 node))
357 (defn domino-game-run []
358 (doto
359 (world
360 (doto (Node.) (.attachChild (floor*))
361 )
362 {"key-i" (gravity-toggle (Vector3f. 0 0 -9.81))
363 "key-m" (gravity-toggle (Vector3f. 0 0 9.81))
364 "key-l" (gravity-toggle (Vector3f. 9.81 0 0))
365 "key-j" (gravity-toggle (Vector3f. -9.81 0 0))
366 "key-k" (gravity-toggle (Vector3f. 0 9.81 0) )
367 "key-u" (fn[g v] ((gravity-toggle (Vector3f. 0 -0 0)) g true))
368 "key-o" (gravity-toggle (Vector3f. 0 -9.81 0))
370 "key-space"
371 (fn[game value]
373 (if (not value)
374 (let [d (domino (Vector3f. 0 (/ domino-height 0.25) 0)
375 (.fromAngleAxis (Quaternion.)
376 (/ Math/PI 2) (Vector3f. 0 1 0)))]
377 (add-element game d))))
378 "key-f"
379 (fn[game value](if (not value) (add-element game (domino-cycle))))
380 "key-return" (fire-cannon-ball)}
381 position-camera
382 (fn [& _]))
383 (.start)))
384 #+end_src
386 #+begin_src clojure :results silent
387 (cortex.other-games/domino-game-run)
388 #+end_src
390 #+caption: floating dominos
391 [[../images/dominos.jpg]]
393 * Hello Loop
394 #+srcname: hello-loop
395 #+begin_src clojure :results silent
396 (ns hello.loop
397 (:use cortex.world)
398 (:use cortex.util)
399 (:import com.jme3.math.ColorRGBA)
400 (:import com.jme3.scene.Node))
402 (defn blue-cube []
403 (box 1 1 1
404 :color ColorRGBA/Blue
405 :texture false
406 :material "Common/MatDefs/Misc/Unshaded.j3md"
407 :name "blue-cube"
408 :physical? false))
410 (defn blue-cube-game []
411 (let [cube (blue-cube)
412 root (doto (Node.) (.attachChild cube))]
413 (world root
414 {}
415 no-op
416 (fn [game tpf]
417 (.rotate cube 0.0 (* 2 tpf) 0.0)))))
418 #+end_src
420 * COMMENT Hello Collision
422 #+srcname: hello-collision
423 #+begin_src clojure :results silent
424 (ns hello.collision)
425 (use 'cortex.world)
426 (use 'cortex.import)
427 (use 'clojure.contrib.def)
430 (cortex.import/mega-import-jme3)
431 (rlm.rlm-commands/help)
432 (use '[hello [brick-wall :only [fire-cannon-ball brick-wall*]]])
435 (defn environment []
436 (let
437 [scene-model
438 (doto
439 (.loadModel
440 (doto (asset-manager)
441 (.registerLocator
442 "/home/r/cortex/assets/zips/town.zip" ZipLocator))
443 "main.scene")
444 (.setLocalScale (float 2.0)))
445 collision-shape
446 (CollisionShapeFactory/createMeshShape #^Node scene-model)
447 landscape (RigidBodyControl. collision-shape 0)]
448 (.setShadowMode scene-model RenderQueue$ShadowMode/CastAndReceive)
449 (.addControl scene-model landscape)
450 scene-model))
452 (defn player-fn []
453 (doto
454 (CharacterControl.
455 (CapsuleCollisionShape. (float 1.5) (float 6)(float 1))
456 (float 0.05))
457 (.setJumpSpeed 20)
458 (.setFallSpeed 30)
459 (.setGravity 30) ;30
460 (.setPhysicsLocation (Vector3f. 0 10 0))))
462 (defn lights []
463 [(doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 1 1 1 1) (float 1))))
464 (doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 1 0.7 0 1) (float 1))))
465 (doto (DirectionalLight.)
466 (.setColor (.mult ColorRGBA/White (float 0.9) ))
467 (.setDirection (.normalizeLocal (Vector3f. 2.8 -28 2.8))))])
469 (defn night-lights []
470 [(doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 0.275 0.467 0.784 1) (float 0.3))))
471 (doto (DirectionalLight.)
472 (.setColor (.mult ColorRGBA/White (float 0.2) ))
473 (.setDirection (.normalizeLocal (Vector3f. 2.8 -28 2.8))))])
475 (def player (atom (player-fn)))
477 (defn setup-fn [game]
478 (dorun (map #(.addLight (.getRootNode game) %) (lights)))
479 ;; set the color of the sky
480 (.setBackgroundColor (.getViewPort game) (ColorRGBA. 0.3 0.4 0.9 1))
481 ;(.setBackgroundColor (.getViewPort game) (ColorRGBA. 0 0 0 1)
482 (doto (.getFlyByCamera game)
483 (.setMoveSpeed (float 100))
484 (.setRotationSpeed 3))
485 (.add
486 (.getPhysicsSpace
487 (.getState (.getStateManager game) BulletAppState))
488 @player)
490 (doto (Node.) (.attachChild (.getRootNode game))
491 (.attachChild (brick-wall*))
492 )
494 )
497 (def walking-up? (atom false))
498 (def walking-down? (atom false))
499 (def walking-left? (atom false))
500 (def walking-right? (atom false))
502 (defn set-walk [walk-atom game value]
503 ;;(println-repl "setting stuff to " value)
504 (reset! walk-atom value))
506 (defn responses []
507 {"key-w" (partial set-walk walking-up?)
508 "key-d" (partial set-walk walking-right?)
509 "key-s" (partial set-walk walking-down?)
510 "key-a" (partial set-walk walking-left?)
511 "key-return" (fire-cannon-ball)
512 "key-space" (fn [game value] (.jump @player))
513 })
515 (defn update-fn
516 [game tpf]
517 (let [camera (.getCamera game)
518 cam-dir (.multLocal
519 (.clone
520 (.getDirection camera)) (float 0.6))
521 cam-left (.multLocal
522 (.clone
523 (.getLeft camera)) (float 0.4))
524 walk-direction (Vector3f. 0 0 0)]
526 (cond
527 @walking-up? (.addLocal walk-direction cam-dir)
528 @walking-right? (.addLocal walk-direction (.negate cam-left))
529 @walking-down? (.addLocal walk-direction (.negate cam-dir))
530 @walking-left? (.addLocal walk-direction cam-left))
531 (.setWalkDirection @player walk-direction)
532 (.setLocation camera (.getPhysicsLocation @player))))
534 (defn run-game []
535 (.start
536 (world (environment)
537 (responses)
538 setup-fn
539 update-fn)))
540 #+end_src
542 * COMMENT Hello Terrain
543 #+srcname: hello-terrain
544 #+begin_src clojure :results silent
545 (ns hello.terrain)
546 (use 'cortex.world)
547 (use 'cortex.import)
548 (use 'clojure.contrib.def)
549 (import jme3tools.converters.ImageToAwt)
552 (cortex.import/mega-import-jme3)
553 (rlm.rlm-commands/help)
554 (use '[hello [brick-wall :only [fire-cannon-ball brick-wall*]]])
557 (defn setup-fn [type game]
558 (.setMoveSpeed (.getFlyByCamera game) 50)
559 (.setFrustumFar (.getCamera game) 10000)
560 (let [env (environment type)
561 cameras [(.getCamera game)]
562 control (TerrainLodControl. env cameras)]
563 ;;(.addControl env control)
564 (.attachChild (.getRootNode game) env)))
566 (defn environment [type]
567 (let
568 [mat_terrain
569 (Material. (asset-manager) "Common/MatDefs/Terrain/Terrain.j3md")
570 grass (.loadTexture (asset-manager) "Textures/Terrain/splat/grass.jpg")
571 dirt (.loadTexture (asset-manager) "Textures/Terrain/splat/dirt.jpg")
572 rock (.loadTexture (asset-manager) "Textures/Terrain/splat/road.jpg")
573 heightmap-image (.loadTexture (asset-manager)
574 ({:mountain "Textures/Terrain/splat/mountains512.png"
575 :fortress "Textures/Terrain/splat/fortress512.png"
576 }type))
577 heightmap (ImageBasedHeightMap.
578 (ImageToAwt/convert (.getImage heightmap-image) false true 0))
579 terrain (do (.load heightmap)
580 (TerrainQuad. "my terrain" 65 513 (.getHeightMap heightmap)))
581 ]
583 (dorun (map #(.setWrap % Texture$WrapMode/Repeat)
584 [grass dirt rock]))
586 (doto mat_terrain
587 (.setTexture "Tex1" grass)
588 (.setFloat "Tex1Scale" (float 64))
590 (.setTexture "Tex2" dirt)
591 (.setFloat "Tex2Scale" (float 32))
593 (.setTexture "Tex3" rock)
594 (.setFloat "Tex3Scale" (float 128))
596 (.setTexture "Alpha"
597 (.loadTexture
598 (asset-manager)
599 ({:mountain "Textures/Terrain/splat/alphamap.png"
600 :fortress "Textures/Terrain/splat/alphamap2.png"} type))))
602 (doto terrain
603 (.setMaterial mat_terrain)
604 (.setLocalTranslation 0 -100 0)
605 (.setLocalScale 2 1 2))))
609 (defn run-terrain-game [type]
610 (.start
611 (world
612 (Node.)
613 {}
614 (partial setup-fn type)
615 no-op)))
616 #+end_src
620 #+srcname: hello-animation
621 #+begin_src clojure :results silent
622 (ns hello.animation)
623 (use 'cortex.world)
624 (use 'cortex.import)
625 (use 'clojure.contrib.def)
626 (cortex.import/mega-import-jme3)
627 (rlm.rlm-commands/help)
628 (use '[hello [collision :only [lights]]])
630 (defn stand
631 [channel]
632 (doto channel
633 (.setAnim "stand" (float 0.5))
634 (.setLoopMode LoopMode/DontLoop)
635 (.setSpeed (float 1))))
637 (defn anim-listener []
638 (proxy [AnimEventListener] []
639 (onAnimChange
640 [control channel animation-name]
641 (println-repl "RLM --- onAnimChange"))
642 (onAnimCycleDone
643 [control channel animation-name]
644 (if (= animation-name "Walk")
645 (stand channel)
646 ))))
648 (defn setup-fn [channel game]
649 (dorun (map #(.addLight (.getRootNode game) %) (lights)))
650 ;; set the color of the sky
651 (.setBackgroundColor (.getViewPort game) (ColorRGBA. 0.3 0.4 0.9 1))
652 ;(.setBackgroundColor (.getViewPort game) (ColorRGBA. 0 0 0 1)
653 (.setAnim channel "stand")
654 (doto (.getFlyByCamera game)
655 (.setMoveSpeed (float 10))
656 (.setRotationSpeed 1)))
658 (defn walk [channel]
659 (println-repl "zzz")
660 (doto channel
661 (.setAnim "Walk" (float 0.5))
662 (.setLoopMode LoopMode/Loop)))
665 (defn key-map [channel]
666 {"key-space" (fn [game value]
667 (if (not value)
668 (walk channel)))})
670 (defn player []
671 (let [model (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml")
672 control (.getControl model AnimControl)]
673 (.setLocalScale model (float 0.5))
674 (.clearListeners control)
675 (.addListener control (anim-control))
676 model))
680 (defn run-anim-game []
681 (let [ninja (player)
682 control (.getControl ninja AnimControl)
683 channel (.createChannel control)]
684 (.start
685 (world
686 ninja
687 (key-map channel)
688 (partial setup-fn channel)
689 no-op))))
690 #+end_src
692 * COMMENT Hello Materials
693 #+srcname: material
694 #+begin_src clojure :results silent
695 (ns hello.material)
696 (use 'cortex.world)
697 (use 'cortex.import)
698 (use 'cortex.util)
699 (use 'clojure.contrib.def)
700 (cortex.import/mega-import-jme3)
701 (rlm.rlm-commands/help)
703 (defn simple-cube []
704 (box 1 1 1
705 :position (Vector3f. -3 1.1 0)
706 :material "Common/MatDefs/Misc/Unshaded.j3md"
707 :texture "Interface/Logo/Monkey.jpg"
708 :physical? false))
710 (defn leaky-box []
711 (box 1 1 1
712 :position (Vector3f. 3 -1 0)
713 :material "Common/MatDefs/Misc/ColoredTextured.j3md"
714 :texture "Textures/ColoredTex/Monkey.png"
715 :color (ColorRGBA. 1 0 1 1)
716 :physical? false))
718 (defn transparent-box []
719 (doto
720 (box 1 1 0.1
721 :position Vector3f/ZERO
722 :name "window frame"
723 :material "Common/MatDefs/Misc/Unshaded.j3md"
724 :texture "Textures/ColoredTex/Monkey.png"
725 :physical? false)
726 (-> (.getMaterial)
727 (.getAdditionalRenderState)
728 (.setBlendMode RenderState$BlendMode/Alpha))
729 (.setQueueBucket RenderQueue$Bucket/Transparent)))
731 (defn bumpy-sphere []
732 (doto
733 (sphere 2
734 :position (Vector3f. 0 2 -2)
735 :name "Shiny rock"
736 :material "Common/MatDefs/Light/Lighting.j3md"
737 :texture false
738 :physical? false)
739 (-> (.getMesh)
740 (doto
741 (.setTextureMode Sphere$TextureMode/Projected)
742 (TangentBinormalGenerator/generate)))
743 (-> (.getMaterial)
744 (doto
745 (.setTexture "DiffuseMap"
746 (.loadTexture (asset-manager)
747 "Textures/Terrain/Pond/Pond.jpg"))
748 (.setTexture "NormalMap"
749 (.loadTexture (asset-manager)
750 "Textures/Terrain/Pond/Pond_normal.png"))
751 (.setFloat "Shininess" (float 5))))
752 (.rotate (float 1.6) 0 0)))
755 (defn start-game []
756 (.start
757 (world
758 (let [root (Node.)]
759 (dorun (map #(.attachChild root %)
760 [(simple-cube) (leaky-box) (transparent-box) (bumpy-sphere)]))
761 root)
762 {}
763 (fn [world]
764 (let [sun (doto (DirectionalLight.)
765 (.setDirection (.normalizeLocal (Vector3f. 1 0 -2)))
766 (.setColor ColorRGBA/White))]
767 (.addLight (.getRootNode world) sun)))
768 no-op
769 )))
770 #+end_src
774 * COMMENT code generation
776 #+begin_src clojure :tangle ../src/hello/brick_wall.clj
777 <<brick-wall-header>>
778 <<brick-wall-body>>
779 #+end_src
781 #+begin_src clojure :tangle ../src/hello/hello_simple_app.clj
782 <<hello-simple-app>>
783 #+end_src
785 #+begin_src clojure :tangle ../src/hello/hello_simpler_app.clj
786 <<hello-simpler-app>>
787 #+end_src
790 #+begin_src clojure :tangle ../src/hello/other_games.clj
791 <<other-games>>
792 #+end_src
794 #+begin_src clojure :tangle ../src/hello/loop.clj
795 <<hello-loop>>
796 #+end_src
798 #+begin_src clojure :tangle ../src/hello/collision.clj
799 <<hello-collision>>
800 #+end_src
802 #+begin_src clojure :tangle ../src/hello/terrain.clj
803 <<hello-terrain>>
804 #+end_src
806 #+begin_src clojure :tangle ../src/hello/animation.clj
807 <<hello-animation>>
808 #+end_src
810 #+begin_src clojure :tangle ../src/hello/material.clj
811 <<material>>
812 #+end_src