changeset 30:0206878c28b4

going to start on games.org
author Robert McIntyre <rlm@mit.edu>
date Mon, 24 Oct 2011 12:43:58 -0700
parents 6372c108c5c6
children f0562b9bde94
files org/cortex.org org/games.org org/util.org
diffstat 3 files changed, 789 insertions(+), 791 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/cortex.org	Mon Oct 24 12:35:15 2011 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,789 +0,0 @@
     1.4 -#+title: Simulated Senses
     1.5 -#+author: Robert McIntyre
     1.6 -#+email: rlm@mit.edu
     1.7 -#+description: Simulating senses for AI research using JMonkeyEngine3
     1.8 -#+SETUPFILE: ../../aurellem/org/setup.org
     1.9 -#+INCLUDE: ../../aurellem/org/level-0.org
    1.10 -#+babel: :mkdirp yes :noweb yes :exports both
    1.11 -
    1.12 -
    1.13 -* Simulation Base
    1.14 -  
    1.15 -
    1.16 -** Hello
    1.17 -Here are the jmonkeyengine "Hello" programs translated to clojure.
    1.18 -*** Hello Simple App
    1.19 -Here is the hello world example for jme3 in clojure.  It's a more or
    1.20 -less direct translation from the java source [[http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication][here]].
    1.21 -
    1.22 -Of note is the fact that since we don't have access to the
    1.23 -=AssetManager= via extendig =SimpleApplication=, we have to build one
    1.24 -ourselves. 
    1.25 -
    1.26 -#+srcname: hello-simple-app
    1.27 -#+begin_src clojure :results silent
    1.28 -(ns hello.hello-simple-app)
    1.29 -(require 'cortex.import)
    1.30 -(use 'clojure.contrib.def)
    1.31 -(rlm.rlm-commands/help)
    1.32 -(cortex.import/mega-import-jme3)
    1.33 -(use 'cortex.world)
    1.34 -
    1.35 -
    1.36 -(def cube (Box. Vector3f/ZERO 1 1 1))
    1.37 -
    1.38 -(def geom (Geometry. "Box" cube))
    1.39 -
    1.40 -(def mat (Material. (asset-manager) "Common/MatDefs/Misc/Unshaded.j3md"))
    1.41 -
    1.42 -(.setColor mat "Color" ColorRGBA/Blue)
    1.43 -
    1.44 -(.setMaterial geom mat)
    1.45 -
    1.46 -(defn simple-app []
    1.47 -  (doto
    1.48 -      (proxy [SimpleApplication] []
    1.49 -	(simpleInitApp
    1.50 -	 []
    1.51 -	 ;; Don't take control of the mouse
    1.52 -	 (org.lwjgl.input.Mouse/setGrabbed false)
    1.53 -	 (.attachChild (.getRootNode this) geom)))
    1.54 -    ;; don't show a menu to change options.
    1.55 -    (.setShowSettings false)
    1.56 -    (.setPauseOnLostFocus false)
    1.57 -    (.setSettings *app-settings*)))
    1.58 -#+end_src
    1.59 -
    1.60 -Running this program will begin a new jMonkeyEngine game which
    1.61 -displays a single blue cube.
    1.62 -
    1.63 -#+begin_src clojure :exports code :results silent
    1.64 -(.start (hello.hello-simple-app/simple-app))
    1.65 -#+end_src
    1.66 -
    1.67 -#+caption: the simplest JME game.
    1.68 -[[./images/simple-app.jpg]]
    1.69 -
    1.70 -
    1.71 -
    1.72 -*** Hello Physics
    1.73 -From http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_physics
    1.74 -
    1.75 -#+srcname: brick-wall-header
    1.76 -#+begin_src clojure :results silent
    1.77 -(ns hello.brick-wall)
    1.78 -(require 'cortex.import)
    1.79 -(use 'clojure.contrib.def)
    1.80 -(rlm.rlm-commands/help)
    1.81 -(cortex.import/mega-import-jme3)
    1.82 -(use '[pokemon [lpsolve :only [constant-map]]])
    1.83 -(use 'cortex.world)
    1.84 -(use 'cortex.util)
    1.85 -#+end_src
    1.86 -
    1.87 -#+srcname: brick-wall-body
    1.88 -#+begin_src clojure :results silent
    1.89 -(in-ns 'hello.brick-wall)
    1.90 -
    1.91 -(defn floor
    1.92 -  "make a sturdy, unmovable physical floor"
    1.93 -  []
    1.94 -  (box 20 1 20 :mass 0 :color false :position (Vector3f. 0 -2 0)))
    1.95 -
    1.96 -(def brick-length 0.48)
    1.97 -(def brick-width 0.24)
    1.98 -(def brick-height 0.12)
    1.99 -
   1.100 -
   1.101 -(defn brick* [position]
   1.102 -  (doto (box brick-length brick-height brick-width
   1.103 -	     :position position :name "brick"
   1.104 -	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.105 -	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
   1.106 -	     :mass 36)
   1.107 -    (->
   1.108 -     (.getMesh)
   1.109 -     (.scaleTextureCoordinates (Vector2f. 1 0.5)))
   1.110 -    ;;(.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
   1.111 -    )
   1.112 -  )
   1.113 -
   1.114 -(defn inception-brick-wall
   1.115 -  "construct a physical brick wall"
   1.116 -  []
   1.117 -  (let [node (Node. "brick-wall")]
   1.118 -    (dorun
   1.119 -     (map (comp #(.attachChild node %) brick*)
   1.120 -	  (for
   1.121 -	      [x (range 15)
   1.122 -	       y (range 10)
   1.123 -	       z (range 1)]
   1.124 -	    (Vector3f.
   1.125 -	     (* brick-length x 1.03)
   1.126 -	     (* brick-width y y 10)
   1.127 -	     (* brick-height z)))))
   1.128 -    node))
   1.129 -
   1.130 -(defn gravity-toggle
   1.131 -  [new-value]
   1.132 -  (fn [game value]
   1.133 -    (println-repl "set gravity to " new-value)
   1.134 -    (if value
   1.135 -      (set-gravity* game new-value)
   1.136 -      (set-gravity* game gravity))))
   1.137 -
   1.138 -(defn fire-cannon-ball 
   1.139 -  ([node]
   1.140 -     (fn [game value]
   1.141 -       (if (not value)
   1.142 -         (let [camera (.getCamera game)
   1.143 -               cannon-ball
   1.144 -               (sphere  0.7 
   1.145 -                        :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.146 -                        :texture "Textures/PokeCopper.jpg"
   1.147 -                        :position
   1.148 -                        (.add (.getLocation camera)
   1.149 -                              (.mult (.getDirection camera) (float 1)))
   1.150 -                        :mass 3)] ;200 0.05
   1.151 -           (.setShadowMode cannon-ball RenderQueue$ShadowMode/CastAndReceive)
   1.152 -           (.setLinearVelocity
   1.153 -            (.getControl cannon-ball RigidBodyControl)
   1.154 -            (.mult (.getDirection camera) (float 50))) ;50
   1.155 -           (add-element game cannon-ball (if node node (.getRootNode game)))))))
   1.156 -  ([]
   1.157 -    (fire-cannon-ball false)))
   1.158 -  
   1.159 -
   1.160 -(defn floor* []
   1.161 -  (doto (box 10 0.1 5 :name "floor" ;10 0.1 5 ; 240 0.1 240
   1.162 -	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.163 -	     :texture "Textures/Terrain/Pond/Pond.png"
   1.164 -	     :position (Vector3f. 0 -0.1 0 )
   1.165 -	     :mass 0)
   1.166 -    (->
   1.167 -     (.getMesh)
   1.168 -     (.scaleTextureCoordinates (Vector2f. 3 6)));64 64
   1.169 -    (->
   1.170 -     (.getMaterial)
   1.171 -     (.getTextureParam "ColorMap")
   1.172 -     (.getTextureValue)
   1.173 -     (.setWrap Texture$WrapMode/Repeat))
   1.174 -    (.setShadowMode RenderQueue$ShadowMode/Receive)
   1.175 -  ))
   1.176 -    
   1.177 -(defn brick-wall* []
   1.178 -  (let [node (Node. "brick-wall")]
   1.179 -    (dorun
   1.180 -     (map
   1.181 -      (comp  #(.attachChild node %) brick*)
   1.182 -       (for [y (range 15)
   1.183 -	     x (range 4)
   1.184 -	     z (range 1)]
   1.185 -       	    (Vector3f.
   1.186 -       	     (+ (* 2 x brick-length)
   1.187 -		(if (even? (+ y z)) 
   1.188 -		  (/ brick-length 4) (/ brick-length -4)))
   1.189 -       	     (+ (* brick-height (inc (* 2 y))))
   1.190 -	     (* 2 z brick-width) ))))
   1.191 -    (.setShadowMode node RenderQueue$ShadowMode/CastAndReceive)
   1.192 -    node))
   1.193 -
   1.194 -(defn brick-wall-game-run []
   1.195 -  (doto
   1.196 -      (world
   1.197 -       (doto (Node.) (.attachChild (floor*))
   1.198 -	     (.attachChild (brick-wall*))
   1.199 -	     )
   1.200 -       {"key-i" (gravity-toggle (Vector3f. 0 0 -9.81))
   1.201 -	"key-m" (gravity-toggle (Vector3f. 0 0 9.81))
   1.202 -	"key-l" (gravity-toggle (Vector3f. 9.81 0 0))
   1.203 -	"key-j" (gravity-toggle (Vector3f. -9.81 0 0))
   1.204 -	"key-k" (gravity-toggle Vector3f/ZERO)
   1.205 -	"key-u" (gravity-toggle (Vector3f. 0 9.81 0))
   1.206 -	"key-o" (gravity-toggle (Vector3f. 0 -9.81 0))
   1.207 -	"key-f" (fn[game value] 
   1.208 -		  (if (not value) (add-element game (brick-wall*))))
   1.209 -	"key-return" (fire-cannon-ball)}
   1.210 -       position-camera
   1.211 -       (fn [& _]))     
   1.212 -    (.start)))
   1.213 -#+end_src
   1.214 -
   1.215 -#+begin_src clojure :results silent
   1.216 -(hello.brick-wall/brick-wall-game-run)
   1.217 -#+end_src
   1.218 -
   1.219 -#+caption: the brick wall standing
   1.220 -[[./images/brick-wall-standing.jpg]]
   1.221 -
   1.222 -#+caption: the brick wall after it has been knocked over by a "pok\eacute{}ball"
   1.223 -[[./images/brick-wall-knocked-down.jpg]]
   1.224 -
   1.225 -*** Other Brick Games
   1.226 -#+srcname: other-games
   1.227 -#+begin_src clojure :results silent
   1.228 -(ns cortex.other-games
   1.229 -   {:author "Dylan Holmes"})
   1.230 -(use 'cortex.world)
   1.231 -(use 'hello.brick-wall)
   1.232 -(use 'cortex.import)
   1.233 -(cortex.import/mega-import-jme3)
   1.234 -
   1.235 -(defn scad [position]
   1.236 -  (doto (box 0.1 0.1 0.1
   1.237 -	     :position position :name "brick"
   1.238 -	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.239 -	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
   1.240 -	     :mass 20)
   1.241 -    (->
   1.242 -     (.getMesh)
   1.243 -     (.scaleTextureCoordinates (Vector2f. 1 0.5))
   1.244 -     )
   1.245 -        (->	(.getControl RigidBodyControl)
   1.246 -	(.setLinearVelocity (Vector3f. 0 100 0))
   1.247 -	)
   1.248 -	
   1.249 -    ;;(.setShadowMode RenderQueue$ShadowMode/Cast)
   1.250 -    ))
   1.251 -
   1.252 -
   1.253 -(defn shrapnel []
   1.254 -  (let [node (Node. "explosion-day")]
   1.255 -    (dorun
   1.256 -     (map
   1.257 -      (comp  #(.attachChild node %) scad)
   1.258 -       (for [y (range 15)
   1.259 -	     x (range 4)
   1.260 -	     z (range 1)]
   1.261 -       	    (Vector3f.
   1.262 -       	     (+ (* 2 x brick-height)
   1.263 -		(if (even? (+ y z)) (/ brick-height 4) (/ brick-height -4)))
   1.264 -       	     (+ (* brick-height (inc (* 2 y))))
   1.265 -	     (* 2 z brick-height) ))))
   1.266 -    node))
   1.267 -
   1.268 -
   1.269 -(def domino-height 0.48)
   1.270 -(def domino-thickness 0.12)
   1.271 -(def domino-width 0.24)
   1.272 -
   1.273 -(def domino-thickness 0.05)
   1.274 -(def domino-width 0.5)
   1.275 -(def domino-height 1)
   1.276 -
   1.277 -(defn domino
   1.278 -  ([position]
   1.279 -     (domino position (Quaternion/IDENTITY)))
   1.280 -  ([position rotation]
   1.281 -     (doto (box domino-width domino-height domino-thickness
   1.282 -	     :position position :name "domino"
   1.283 -	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.284 -	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
   1.285 -	     :mass 1
   1.286 -	     :rotation rotation)
   1.287 -       (.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
   1.288 -       )))
   1.289 -
   1.290 -
   1.291 -(defn domino-row []
   1.292 -  (let [node (Node. "domino-row")]
   1.293 -    (dorun
   1.294 -     (map
   1.295 -      (comp  #(.attachChild node %) domino)
   1.296 -       (for [
   1.297 -	     z (range 10)
   1.298 -	     x (range 5)
   1.299 -	     ]
   1.300 -       	    (Vector3f.
   1.301 -	     (+ (* z domino-width) (* x 5 domino-width))
   1.302 -	     (/ domino-height 1)
   1.303 -	     (* -5.5 domino-thickness z) ))))
   1.304 -
   1.305 -    node))
   1.306 -
   1.307 -(defn domino-cycle []
   1.308 -  (let [node (Node. "domino-cycle")]
   1.309 -    (dorun
   1.310 -     (map
   1.311 -      (comp  #(.attachChild node %) (partial apply domino) ) 
   1.312 -      (for [n (range 720)]
   1.313 -	(let [space (* domino-height 5.5)
   1.314 -	      r (fn[n] (* (+ n 3) domino-width 0.5)) 
   1.315 -	      t (fn[n] (reduce
   1.316 -			+
   1.317 -			(map
   1.318 -			 (fn dt[n] (/ space (* 2 (Math/PI) (r n))))
   1.319 -			 (range n))))
   1.320 -	      t (t n)
   1.321 -	      r (r n)
   1.322 -	      ct (Math/cos t)
   1.323 -	      st (Math/sin t)
   1.324 -	      ]
   1.325 -	(list
   1.326 -       	    (Vector3f.
   1.327 -	     (* -1 r st)
   1.328 -	     (/ domino-height 1)
   1.329 -	     (* r ct))
   1.330 -	    (.fromAngleAxis (Quaternion.)
   1.331 -			    (- (/ 3.1415926 2) t) (Vector3f. 0 1 0))
   1.332 -	    )))
   1.333 -	))
   1.334 -    node))
   1.335 -
   1.336 -
   1.337 -(defn domino-game-run []
   1.338 -  (doto
   1.339 -      (world
   1.340 -       (doto (Node.) (.attachChild (floor*))
   1.341 -	     )
   1.342 -       {"key-i" (gravity-toggle (Vector3f. 0 0 -9.81))
   1.343 -	"key-m" (gravity-toggle (Vector3f. 0 0 9.81))
   1.344 -	"key-l" (gravity-toggle (Vector3f. 9.81 0 0))
   1.345 -	"key-j" (gravity-toggle (Vector3f. -9.81 0 0))
   1.346 -	"key-k" (gravity-toggle (Vector3f. 0 9.81 0) )
   1.347 -	"key-u" (fn[g v] ((gravity-toggle (Vector3f. 0 -0 0)) g true))
   1.348 -	"key-o" (gravity-toggle (Vector3f. 0 -9.81 0))
   1.349 -
   1.350 -	"key-space"
   1.351 -	(fn[game value]
   1.352 -	  
   1.353 -	  (if (not value)
   1.354 -	    (let [d (domino (Vector3f. 0 (/ domino-height 0.25) 0)
   1.355 -			    (.fromAngleAxis (Quaternion.)
   1.356 -					    (/ Math/PI 2) (Vector3f. 0 1 0)))]
   1.357 -	      (add-element game d))))
   1.358 -	"key-f"
   1.359 -	(fn[game value](if (not value) (add-element game (domino-cycle))))
   1.360 -	"key-return" (fire-cannon-ball)}
   1.361 -       position-camera
   1.362 -       (fn [& _]))     
   1.363 -    (.start)))       
   1.364 -#+end_src
   1.365 -
   1.366 -#+begin_src clojure :results silent
   1.367 -(cortex.other-games/domino-game-run)
   1.368 -#+end_src
   1.369 -
   1.370 -#+caption: floating dominos
   1.371 -[[./images/dominos.jpg]]
   1.372 -
   1.373 -*** Hello Loop
   1.374 -#+srcname: hello-loop
   1.375 -#+begin_src clojure :results silent
   1.376 -(ns hello.loop)
   1.377 -(use 'cortex.world)
   1.378 -(use 'cortex.import)
   1.379 -(cortex.import/mega-import-jme3)
   1.380 -(rlm.rlm-commands/help)
   1.381 -
   1.382 -(defn blue-cube []
   1.383 -  (box 1 1 1
   1.384 -       :color ColorRGBA/Blue
   1.385 -       :texture false
   1.386 -       :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.387 -       :name "blue-cube"
   1.388 -       :physical? false))
   1.389 -
   1.390 -(defn blue-cube-game []
   1.391 -  (let [cube (blue-cube)
   1.392 -	root (doto (Node.) (.attachChild cube))]
   1.393 -  (world root
   1.394 -	 {}
   1.395 -	 no-op
   1.396 -	 (fn [game tpf]
   1.397 -	   (.rotate cube 0.0 (* 2 tpf) 0.0)))))	 	 		  
   1.398 -#+end_src
   1.399 -
   1.400 -*** Hello Collision
   1.401 -
   1.402 -#+srcname: hello-collision
   1.403 -#+begin_src clojure :results silent
   1.404 -(ns hello.collision)
   1.405 -(use 'cortex.world)
   1.406 -(use 'cortex.import)
   1.407 -(use 'clojure.contrib.def)
   1.408 -
   1.409 -
   1.410 -(cortex.import/mega-import-jme3)
   1.411 -(rlm.rlm-commands/help)
   1.412 -(use '[hello [brick-wall :only [fire-cannon-ball brick-wall*]]])
   1.413 -
   1.414 -
   1.415 -(defn environment []
   1.416 -     (let
   1.417 -	 [scene-model
   1.418 -	  (doto
   1.419 -	      (.loadModel
   1.420 -	       (doto (asset-manager)
   1.421 -		 (.registerLocator
   1.422 -		  "/home/r/cortex/assets/zips/town.zip" ZipLocator))
   1.423 -	       "main.scene")
   1.424 -	    (.setLocalScale (float 2.0)))
   1.425 -	  collision-shape
   1.426 -	  (CollisionShapeFactory/createMeshShape #^Node scene-model)
   1.427 -	  landscape (RigidBodyControl. collision-shape 0)]
   1.428 -       (.setShadowMode scene-model RenderQueue$ShadowMode/CastAndReceive)
   1.429 -       (.addControl scene-model landscape)
   1.430 -       scene-model))
   1.431 -	  
   1.432 -(defn player-fn []
   1.433 -  (doto
   1.434 -      (CharacterControl.
   1.435 -       (CapsuleCollisionShape. (float 1.5) (float 6)(float 1))
   1.436 -       (float 0.05))
   1.437 -    (.setJumpSpeed 20)
   1.438 -    (.setFallSpeed 30)
   1.439 -    (.setGravity 30) ;30
   1.440 -    (.setPhysicsLocation (Vector3f. 0 10 0))))
   1.441 -
   1.442 -(defn lights []
   1.443 -  [(doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 1 1 1 1) (float 1))))
   1.444 -   (doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 1 0.7 0 1) (float 1))))
   1.445 -   (doto (DirectionalLight.)
   1.446 -     (.setColor (.mult ColorRGBA/White (float 0.9) ))
   1.447 -     (.setDirection (.normalizeLocal (Vector3f. 2.8 -28 2.8))))])
   1.448 -
   1.449 -(defn night-lights []
   1.450 -  [(doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 0.275 0.467 0.784 1) (float 0.3))))
   1.451 -   (doto (DirectionalLight.)
   1.452 -     (.setColor (.mult ColorRGBA/White (float 0.2) ))
   1.453 -     (.setDirection (.normalizeLocal (Vector3f. 2.8 -28 2.8))))])
   1.454 -
   1.455 -(def player (atom (player-fn)))
   1.456 -
   1.457 -(defn setup-fn [game]
   1.458 -  (dorun (map #(.addLight (.getRootNode game) %) (lights)))
   1.459 -  ;; set the color of the sky
   1.460 -  (.setBackgroundColor (.getViewPort game) (ColorRGBA. 0.3 0.4 0.9 1))
   1.461 -  ;(.setBackgroundColor (.getViewPort game) (ColorRGBA. 0 0 0 1)
   1.462 -  (doto (.getFlyByCamera game)
   1.463 -    (.setMoveSpeed (float 100))
   1.464 -    (.setRotationSpeed 3))
   1.465 -  (.add
   1.466 -   (.getPhysicsSpace
   1.467 -    (.getState (.getStateManager game) BulletAppState))
   1.468 -   @player)
   1.469 -
   1.470 -   (doto (Node.) (.attachChild (.getRootNode game))
   1.471 -	     (.attachChild (brick-wall*))
   1.472 -   )
   1.473 -
   1.474 -)
   1.475 -
   1.476 -
   1.477 -(def walking-up? (atom false))
   1.478 -(def walking-down? (atom false))
   1.479 -(def walking-left? (atom false))
   1.480 -(def walking-right? (atom false))
   1.481 -
   1.482 -(defn set-walk [walk-atom game value]
   1.483 -  ;;(println-repl "setting  stuff to " value)
   1.484 -  (reset! walk-atom value))
   1.485 -
   1.486 -(defn responses []
   1.487 -     {"key-w" (partial set-walk walking-up?)
   1.488 -      "key-d" (partial set-walk walking-right?)
   1.489 -      "key-s" (partial set-walk walking-down?)
   1.490 -      "key-a" (partial set-walk walking-left?)
   1.491 -      "key-return" (fire-cannon-ball)
   1.492 -      "key-space" (fn [game value] (.jump @player))
   1.493 -      })
   1.494 -     
   1.495 -(defn update-fn
   1.496 -  [game tpf]
   1.497 -  (let [camera (.getCamera game)         
   1.498 -	cam-dir (.multLocal
   1.499 -		 (.clone
   1.500 -		  (.getDirection camera)) (float 0.6))
   1.501 -	cam-left (.multLocal
   1.502 -		  (.clone
   1.503 -		   (.getLeft camera)) (float 0.4))
   1.504 -	walk-direction (Vector3f. 0 0 0)]
   1.505 -    
   1.506 -    (cond
   1.507 -     @walking-up?     (.addLocal walk-direction cam-dir)
   1.508 -     @walking-right?  (.addLocal walk-direction (.negate cam-left))
   1.509 -     @walking-down?   (.addLocal walk-direction (.negate cam-dir))
   1.510 -     @walking-left?   (.addLocal walk-direction cam-left))
   1.511 -    (.setWalkDirection @player walk-direction)
   1.512 -    (.setLocation camera (.getPhysicsLocation @player))))
   1.513 -    
   1.514 -(defn run-game []
   1.515 -  (.start
   1.516 -   (world (environment)
   1.517 -	  (responses)
   1.518 -	  setup-fn
   1.519 -	  update-fn)))
   1.520 -#+end_src
   1.521 -
   1.522 -*** Hello Terrain
   1.523 -#+srcname: hello-terrain
   1.524 -#+begin_src clojure :results silent
   1.525 -(ns hello.terrain)
   1.526 -(use 'cortex.world)
   1.527 -(use 'cortex.import)
   1.528 -(use 'clojure.contrib.def)
   1.529 -(import jme3tools.converters.ImageToAwt)
   1.530 -
   1.531 -
   1.532 -(cortex.import/mega-import-jme3)
   1.533 -(rlm.rlm-commands/help)
   1.534 -(use '[hello [brick-wall :only [fire-cannon-ball brick-wall*]]])
   1.535 -
   1.536 -
   1.537 -(defn setup-fn [type game]
   1.538 -  (.setMoveSpeed (.getFlyByCamera game) 50)
   1.539 -  (.setFrustumFar (.getCamera game) 10000)
   1.540 -  (let [env (environment type)
   1.541 -	cameras [(.getCamera game)]
   1.542 -	control (TerrainLodControl. env cameras)]
   1.543 -    ;;(.addControl env control)
   1.544 -    (.attachChild (.getRootNode game) env)))                
   1.545 -
   1.546 -(defn environment [type]
   1.547 -  (let
   1.548 -      [mat_terrain
   1.549 -       (Material. (asset-manager) "Common/MatDefs/Terrain/Terrain.j3md")
   1.550 -       grass (.loadTexture (asset-manager) "Textures/Terrain/splat/grass.jpg")
   1.551 -       dirt (.loadTexture (asset-manager) "Textures/Terrain/splat/dirt.jpg")
   1.552 -       rock (.loadTexture (asset-manager) "Textures/Terrain/splat/road.jpg")
   1.553 -       heightmap-image (.loadTexture (asset-manager)
   1.554 -				     ({:mountain "Textures/Terrain/splat/mountains512.png"
   1.555 -				       :fortress "Textures/Terrain/splat/fortress512.png"
   1.556 -				       }type))
   1.557 -       heightmap (ImageBasedHeightMap.
   1.558 -		  (ImageToAwt/convert (.getImage heightmap-image) false true 0))
   1.559 -       terrain (do (.load heightmap)
   1.560 -		   (TerrainQuad. "my terrain" 65 513 (.getHeightMap heightmap)))
   1.561 -       ]
   1.562 -    
   1.563 -    (dorun (map #(.setWrap % Texture$WrapMode/Repeat)
   1.564 -		[grass dirt rock]))
   1.565 -
   1.566 -    (doto mat_terrain
   1.567 -      (.setTexture "Tex1" grass)
   1.568 -      (.setFloat "Tex1Scale" (float 64))
   1.569 -
   1.570 -      (.setTexture "Tex2" dirt)
   1.571 -      (.setFloat "Tex2Scale" (float 32))
   1.572 -
   1.573 -      (.setTexture "Tex3" rock)
   1.574 -      (.setFloat "Tex3Scale" (float 128))
   1.575 -
   1.576 -      (.setTexture "Alpha"
   1.577 -		   (.loadTexture
   1.578 -		    (asset-manager) 
   1.579 -		    ({:mountain "Textures/Terrain/splat/alphamap.png"
   1.580 -		      :fortress "Textures/Terrain/splat/alphamap2.png"} type))))
   1.581 -
   1.582 -    (doto terrain
   1.583 -      (.setMaterial mat_terrain)
   1.584 -      (.setLocalTranslation 0 -100 0)
   1.585 -      (.setLocalScale 2 1 2))))
   1.586 -      
   1.587 -
   1.588 -
   1.589 -(defn run-terrain-game [type]
   1.590 -  (.start
   1.591 -   (world
   1.592 -    (Node.)
   1.593 -    {}
   1.594 -    (partial setup-fn type)
   1.595 -    no-op)))
   1.596 -#+end_src
   1.597 -
   1.598 -
   1.599 -
   1.600 -#+srcname: hello-animation
   1.601 -#+begin_src clojure :results silent
   1.602 -(ns hello.animation)
   1.603 -(use 'cortex.world)
   1.604 -(use 'cortex.import)
   1.605 -(use 'clojure.contrib.def)
   1.606 -(cortex.import/mega-import-jme3)
   1.607 -(rlm.rlm-commands/help)
   1.608 -(use '[hello [collision :only [lights]]])
   1.609 -
   1.610 -(defn stand
   1.611 -  [channel]
   1.612 -  (doto channel
   1.613 -    (.setAnim "stand" (float 0.5))
   1.614 -    (.setLoopMode LoopMode/DontLoop)
   1.615 -    (.setSpeed (float 1))))
   1.616 -
   1.617 -(defn anim-listener []
   1.618 -     (proxy [AnimEventListener] []
   1.619 -       (onAnimChange
   1.620 -	[control channel animation-name]
   1.621 -	(println-repl "RLM --- onAnimChange"))
   1.622 -       (onAnimCycleDone
   1.623 -	[control channel animation-name]
   1.624 -	(if (= animation-name "Walk")
   1.625 -	  (stand channel)
   1.626 -	  ))))
   1.627 -       
   1.628 -(defn setup-fn [channel game]
   1.629 -  (dorun (map #(.addLight (.getRootNode game) %) (lights)))
   1.630 -  ;; set the color of the sky
   1.631 -  (.setBackgroundColor (.getViewPort game) (ColorRGBA. 0.3 0.4 0.9 1))
   1.632 -  ;(.setBackgroundColor (.getViewPort game) (ColorRGBA. 0 0 0 1)
   1.633 -  (.setAnim channel "stand")
   1.634 -  (doto (.getFlyByCamera game)
   1.635 -    (.setMoveSpeed (float 10))
   1.636 -    (.setRotationSpeed 1)))
   1.637 -
   1.638 -(defn walk [channel]
   1.639 -  (println-repl "zzz")
   1.640 -  (doto channel
   1.641 -    (.setAnim "Walk" (float 0.5))
   1.642 -    (.setLoopMode LoopMode/Loop)))
   1.643 -    
   1.644 -
   1.645 -(defn key-map [channel]
   1.646 -  {"key-space" (fn [game value]
   1.647 -		 (if (not value)
   1.648 -		   (walk channel)))})
   1.649 -
   1.650 -(defn player []
   1.651 -  (let [model (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml")
   1.652 -	control (.getControl model AnimControl)]
   1.653 -    (.setLocalScale model (float 0.5))
   1.654 -    (.clearListeners control)
   1.655 -    (.addListener control (anim-control))
   1.656 -    model))
   1.657 -    
   1.658 -
   1.659 -
   1.660 -(defn run-anim-game []
   1.661 -  (let [ninja (player)
   1.662 -	control  (.getControl ninja AnimControl)
   1.663 -	channel (.createChannel control)]
   1.664 -    (.start
   1.665 -     (world
   1.666 -      ninja
   1.667 -      (key-map channel)
   1.668 -      (partial setup-fn channel)
   1.669 -      no-op))))
   1.670 -#+end_src
   1.671 -
   1.672 -*** Hello Materials
   1.673 -#+srcname: material
   1.674 -#+begin_src clojure :results silent
   1.675 -(ns hello.material)
   1.676 -(use 'cortex.world)
   1.677 -(use 'cortex.import)
   1.678 -(use 'clojure.contrib.def)
   1.679 -(cortex.import/mega-import-jme3)
   1.680 -(rlm.rlm-commands/help)
   1.681 -
   1.682 -(defn simple-cube []
   1.683 -  (box 1 1 1
   1.684 -       :position (Vector3f. -3 1.1 0)
   1.685 -       :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.686 -       :texture "Interface/Logo/Monkey.jpg"
   1.687 -       :physical? false))
   1.688 -
   1.689 -(defn leaky-box []
   1.690 -  (box 1 1 1
   1.691 -       :position (Vector3f. 3 -1 0)
   1.692 -       :material "Common/MatDefs/Misc/ColoredTextured.j3md"
   1.693 -       :texture  "Textures/ColoredTex/Monkey.png"
   1.694 -       :color    (ColorRGBA. 1 0 1 1)
   1.695 -       :physical? false))
   1.696 -
   1.697 -(defn transparent-box []
   1.698 -  (doto
   1.699 -      (box 1 1 0.1
   1.700 -	   :position Vector3f/ZERO
   1.701 -	   :name "window frame"
   1.702 -	   :material "Common/MatDefs/Misc/Unshaded.j3md"
   1.703 -	   :texture "Textures/ColoredTex/Monkey.png"
   1.704 -	   :physical? false)
   1.705 -    (-> (.getMaterial)
   1.706 -	(.getAdditionalRenderState)
   1.707 -	(.setBlendMode RenderState$BlendMode/Alpha))
   1.708 -    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   1.709 -                  
   1.710 -(defn bumpy-sphere []
   1.711 -  (doto 
   1.712 -      (sphere 2
   1.713 -	      :position (Vector3f. 0 2 -2)
   1.714 -	      :name "Shiny rock"
   1.715 -	      :material "Common/MatDefs/Light/Lighting.j3md"
   1.716 -	      :texture false
   1.717 -	      :physical? false)
   1.718 -    (-> (.getMesh)
   1.719 -	(doto 
   1.720 -	  (.setTextureMode Sphere$TextureMode/Projected)
   1.721 -	  (TangentBinormalGenerator/generate)))
   1.722 -    (-> (.getMaterial)
   1.723 -	(doto
   1.724 -	  (.setTexture "DiffuseMap" (.loadTexture (asset-manager)
   1.725 -						  "Textures/Terrain/Pond/Pond.png"))
   1.726 -	  (.setTexture "NormalMap"  (.loadTexture (asset-manager)
   1.727 -						  "Textures/Terrain/Pond/Pond_normal.png"))
   1.728 -	  (.setFloat   "Shininess"  (float 5))))
   1.729 -    (.rotate (float 1.6) 0 0)))
   1.730 -
   1.731 -
   1.732 -(defn start-game []
   1.733 -  (.start
   1.734 -   (world
   1.735 -    (let [root  (Node.)]
   1.736 -      (dorun (map #(.attachChild root %)
   1.737 -		  [(simple-cube) (leaky-box) (transparent-box) (bumpy-sphere)]))
   1.738 -      root)
   1.739 -    {}
   1.740 -    (fn [world]
   1.741 -      (let [sun (doto (DirectionalLight.)
   1.742 -		  (.setDirection (.normalizeLocal (Vector3f. 1 0 -2)))
   1.743 -		  (.setColor ColorRGBA/White))]
   1.744 -	(.addLight (.getRootNode world) sun)))
   1.745 -    no-op 
   1.746 -    )))
   1.747 -#+end_src
   1.748 -
   1.749 -
   1.750 -    
   1.751 -* COMMENT code generation
   1.752 -
   1.753 -#+begin_src clojure :tangle ../src/hello/brick_wall.clj
   1.754 -<<brick-wall-header>>
   1.755 -<<brick-wall-body>>
   1.756 -#+end_src
   1.757 -
   1.758 -#+begin_src clojure :tangle ../src/hello/hello_simple_app.clj
   1.759 -<<hello-simple-app>>
   1.760 -#+end_src
   1.761 -
   1.762 -#+begin_src clojure :tangle ../src/cortex/other_games.clj
   1.763 -<<other-games>>
   1.764 -#+end_src
   1.765 -
   1.766 -#+begin_src clojure :tangle ../src/hello/loop.clj
   1.767 -<<hello-loop>>
   1.768 -#+end_src
   1.769 -
   1.770 -#+begin_src clojure :tangle ../src/hello/collision.clj
   1.771 -<<hello-collision>>
   1.772 -#+end_src
   1.773 -
   1.774 -#+begin_src clojure :tangle ../src/hello/terrain.clj
   1.775 -<<hello-terrain>>
   1.776 -#+end_src
   1.777 -
   1.778 -#+begin_src clojure :tangle ../src/hello/animation.clj
   1.779 -<<hello-animation>>
   1.780 -#+end_src
   1.781 -
   1.782 -#+begin_src clojure :tangle ../src/hello/material.clj
   1.783 -<<material>>
   1.784 -#+end_src
   1.785 -
   1.786 -
   1.787 -  
   1.788 -
   1.789 -
   1.790 -
   1.791 -
   1.792 -
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/org/games.org	Mon Oct 24 12:43:58 2011 -0700
     2.3 @@ -0,0 +1,789 @@
     2.4 +#+title: Simulated Senses
     2.5 +#+author: Robert McIntyre
     2.6 +#+email: rlm@mit.edu
     2.7 +#+description: Simulating senses for AI research using JMonkeyEngine3
     2.8 +#+SETUPFILE: ../../aurellem/org/setup.org
     2.9 +#+INCLUDE: ../../aurellem/org/level-0.org
    2.10 +#+babel: :mkdirp yes :noweb yes :exports both
    2.11 +
    2.12 +
    2.13 +* Simulation Base
    2.14 +  
    2.15 +
    2.16 +** Hello
    2.17 +Here are the jmonkeyengine "Hello" programs translated to clojure.
    2.18 +*** Hello Simple App
    2.19 +Here is the hello world example for jme3 in clojure.  It's a more or
    2.20 +less direct translation from the java source [[http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication][here]].
    2.21 +
    2.22 +Of note is the fact that since we don't have access to the
    2.23 +=AssetManager= via extendig =SimpleApplication=, we have to build one
    2.24 +ourselves. 
    2.25 +
    2.26 +#+srcname: hello-simple-app
    2.27 +#+begin_src clojure :results silent
    2.28 +(ns hello.hello-simple-app)
    2.29 +(require 'cortex.import)
    2.30 +(use 'clojure.contrib.def)
    2.31 +(rlm.rlm-commands/help)
    2.32 +(cortex.import/mega-import-jme3)
    2.33 +(use 'cortex.world)
    2.34 +
    2.35 +
    2.36 +(def cube (Box. Vector3f/ZERO 1 1 1))
    2.37 +
    2.38 +(def geom (Geometry. "Box" cube))
    2.39 +
    2.40 +(def mat (Material. (asset-manager) "Common/MatDefs/Misc/Unshaded.j3md"))
    2.41 +
    2.42 +(.setColor mat "Color" ColorRGBA/Blue)
    2.43 +
    2.44 +(.setMaterial geom mat)
    2.45 +
    2.46 +(defn simple-app []
    2.47 +  (doto
    2.48 +      (proxy [SimpleApplication] []
    2.49 +	(simpleInitApp
    2.50 +	 []
    2.51 +	 ;; Don't take control of the mouse
    2.52 +	 (org.lwjgl.input.Mouse/setGrabbed false)
    2.53 +	 (.attachChild (.getRootNode this) geom)))
    2.54 +    ;; don't show a menu to change options.
    2.55 +    (.setShowSettings false)
    2.56 +    (.setPauseOnLostFocus false)
    2.57 +    (.setSettings *app-settings*)))
    2.58 +#+end_src
    2.59 +
    2.60 +Running this program will begin a new jMonkeyEngine game which
    2.61 +displays a single blue cube.
    2.62 +
    2.63 +#+begin_src clojure :exports code :results silent
    2.64 +(.start (hello.hello-simple-app/simple-app))
    2.65 +#+end_src
    2.66 +
    2.67 +#+caption: the simplest JME game.
    2.68 +[[./images/simple-app.jpg]]
    2.69 +
    2.70 +
    2.71 +
    2.72 +*** Hello Physics
    2.73 +From http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_physics
    2.74 +
    2.75 +#+srcname: brick-wall-header
    2.76 +#+begin_src clojure :results silent
    2.77 +(ns hello.brick-wall)
    2.78 +(require 'cortex.import)
    2.79 +(use 'clojure.contrib.def)
    2.80 +(rlm.rlm-commands/help)
    2.81 +(cortex.import/mega-import-jme3)
    2.82 +(use '[pokemon [lpsolve :only [constant-map]]])
    2.83 +(use 'cortex.world)
    2.84 +(use 'cortex.util)
    2.85 +#+end_src
    2.86 +
    2.87 +#+srcname: brick-wall-body
    2.88 +#+begin_src clojure :results silent
    2.89 +(in-ns 'hello.brick-wall)
    2.90 +
    2.91 +(defn floor
    2.92 +  "make a sturdy, unmovable physical floor"
    2.93 +  []
    2.94 +  (box 20 1 20 :mass 0 :color false :position (Vector3f. 0 -2 0)))
    2.95 +
    2.96 +(def brick-length 0.48)
    2.97 +(def brick-width 0.24)
    2.98 +(def brick-height 0.12)
    2.99 +
   2.100 +
   2.101 +(defn brick* [position]
   2.102 +  (doto (box brick-length brick-height brick-width
   2.103 +	     :position position :name "brick"
   2.104 +	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.105 +	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
   2.106 +	     :mass 36)
   2.107 +    (->
   2.108 +     (.getMesh)
   2.109 +     (.scaleTextureCoordinates (Vector2f. 1 0.5)))
   2.110 +    ;;(.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
   2.111 +    )
   2.112 +  )
   2.113 +
   2.114 +(defn inception-brick-wall
   2.115 +  "construct a physical brick wall"
   2.116 +  []
   2.117 +  (let [node (Node. "brick-wall")]
   2.118 +    (dorun
   2.119 +     (map (comp #(.attachChild node %) brick*)
   2.120 +	  (for
   2.121 +	      [x (range 15)
   2.122 +	       y (range 10)
   2.123 +	       z (range 1)]
   2.124 +	    (Vector3f.
   2.125 +	     (* brick-length x 1.03)
   2.126 +	     (* brick-width y y 10)
   2.127 +	     (* brick-height z)))))
   2.128 +    node))
   2.129 +
   2.130 +(defn gravity-toggle
   2.131 +  [new-value]
   2.132 +  (fn [game value]
   2.133 +    (println-repl "set gravity to " new-value)
   2.134 +    (if value
   2.135 +      (set-gravity* game new-value)
   2.136 +      (set-gravity* game gravity))))
   2.137 +
   2.138 +(defn fire-cannon-ball 
   2.139 +  ([node]
   2.140 +     (fn [game value]
   2.141 +       (if (not value)
   2.142 +         (let [camera (.getCamera game)
   2.143 +               cannon-ball
   2.144 +               (sphere  0.7 
   2.145 +                        :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.146 +                        :texture "Textures/PokeCopper.jpg"
   2.147 +                        :position
   2.148 +                        (.add (.getLocation camera)
   2.149 +                              (.mult (.getDirection camera) (float 1)))
   2.150 +                        :mass 3)] ;200 0.05
   2.151 +           (.setShadowMode cannon-ball RenderQueue$ShadowMode/CastAndReceive)
   2.152 +           (.setLinearVelocity
   2.153 +            (.getControl cannon-ball RigidBodyControl)
   2.154 +            (.mult (.getDirection camera) (float 50))) ;50
   2.155 +           (add-element game cannon-ball (if node node (.getRootNode game)))))))
   2.156 +  ([]
   2.157 +    (fire-cannon-ball false)))
   2.158 +  
   2.159 +
   2.160 +(defn floor* []
   2.161 +  (doto (box 10 0.1 5 :name "floor" ;10 0.1 5 ; 240 0.1 240
   2.162 +	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.163 +	     :texture "Textures/Terrain/Pond/Pond.png"
   2.164 +	     :position (Vector3f. 0 -0.1 0 )
   2.165 +	     :mass 0)
   2.166 +    (->
   2.167 +     (.getMesh)
   2.168 +     (.scaleTextureCoordinates (Vector2f. 3 6)));64 64
   2.169 +    (->
   2.170 +     (.getMaterial)
   2.171 +     (.getTextureParam "ColorMap")
   2.172 +     (.getTextureValue)
   2.173 +     (.setWrap Texture$WrapMode/Repeat))
   2.174 +    (.setShadowMode RenderQueue$ShadowMode/Receive)
   2.175 +  ))
   2.176 +    
   2.177 +(defn brick-wall* []
   2.178 +  (let [node (Node. "brick-wall")]
   2.179 +    (dorun
   2.180 +     (map
   2.181 +      (comp  #(.attachChild node %) brick*)
   2.182 +       (for [y (range 15)
   2.183 +	     x (range 4)
   2.184 +	     z (range 1)]
   2.185 +       	    (Vector3f.
   2.186 +       	     (+ (* 2 x brick-length)
   2.187 +		(if (even? (+ y z)) 
   2.188 +		  (/ brick-length 4) (/ brick-length -4)))
   2.189 +       	     (+ (* brick-height (inc (* 2 y))))
   2.190 +	     (* 2 z brick-width) ))))
   2.191 +    (.setShadowMode node RenderQueue$ShadowMode/CastAndReceive)
   2.192 +    node))
   2.193 +
   2.194 +(defn brick-wall-game-run []
   2.195 +  (doto
   2.196 +      (world
   2.197 +       (doto (Node.) (.attachChild (floor*))
   2.198 +	     (.attachChild (brick-wall*))
   2.199 +	     )
   2.200 +       {"key-i" (gravity-toggle (Vector3f. 0 0 -9.81))
   2.201 +	"key-m" (gravity-toggle (Vector3f. 0 0 9.81))
   2.202 +	"key-l" (gravity-toggle (Vector3f. 9.81 0 0))
   2.203 +	"key-j" (gravity-toggle (Vector3f. -9.81 0 0))
   2.204 +	"key-k" (gravity-toggle Vector3f/ZERO)
   2.205 +	"key-u" (gravity-toggle (Vector3f. 0 9.81 0))
   2.206 +	"key-o" (gravity-toggle (Vector3f. 0 -9.81 0))
   2.207 +	"key-f" (fn[game value] 
   2.208 +		  (if (not value) (add-element game (brick-wall*))))
   2.209 +	"key-return" (fire-cannon-ball)}
   2.210 +       position-camera
   2.211 +       (fn [& _]))     
   2.212 +    (.start)))
   2.213 +#+end_src
   2.214 +
   2.215 +#+begin_src clojure :results silent
   2.216 +(hello.brick-wall/brick-wall-game-run)
   2.217 +#+end_src
   2.218 +
   2.219 +#+caption: the brick wall standing
   2.220 +[[./images/brick-wall-standing.jpg]]
   2.221 +
   2.222 +#+caption: the brick wall after it has been knocked over by a "pok\eacute{}ball"
   2.223 +[[./images/brick-wall-knocked-down.jpg]]
   2.224 +
   2.225 +*** Other Brick Games
   2.226 +#+srcname: other-games
   2.227 +#+begin_src clojure :results silent
   2.228 +(ns cortex.other-games
   2.229 +   {:author "Dylan Holmes"})
   2.230 +(use 'cortex.world)
   2.231 +(use 'hello.brick-wall)
   2.232 +(use 'cortex.import)
   2.233 +(cortex.import/mega-import-jme3)
   2.234 +
   2.235 +(defn scad [position]
   2.236 +  (doto (box 0.1 0.1 0.1
   2.237 +	     :position position :name "brick"
   2.238 +	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.239 +	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
   2.240 +	     :mass 20)
   2.241 +    (->
   2.242 +     (.getMesh)
   2.243 +     (.scaleTextureCoordinates (Vector2f. 1 0.5))
   2.244 +     )
   2.245 +        (->	(.getControl RigidBodyControl)
   2.246 +	(.setLinearVelocity (Vector3f. 0 100 0))
   2.247 +	)
   2.248 +	
   2.249 +    ;;(.setShadowMode RenderQueue$ShadowMode/Cast)
   2.250 +    ))
   2.251 +
   2.252 +
   2.253 +(defn shrapnel []
   2.254 +  (let [node (Node. "explosion-day")]
   2.255 +    (dorun
   2.256 +     (map
   2.257 +      (comp  #(.attachChild node %) scad)
   2.258 +       (for [y (range 15)
   2.259 +	     x (range 4)
   2.260 +	     z (range 1)]
   2.261 +       	    (Vector3f.
   2.262 +       	     (+ (* 2 x brick-height)
   2.263 +		(if (even? (+ y z)) (/ brick-height 4) (/ brick-height -4)))
   2.264 +       	     (+ (* brick-height (inc (* 2 y))))
   2.265 +	     (* 2 z brick-height) ))))
   2.266 +    node))
   2.267 +
   2.268 +
   2.269 +(def domino-height 0.48)
   2.270 +(def domino-thickness 0.12)
   2.271 +(def domino-width 0.24)
   2.272 +
   2.273 +(def domino-thickness 0.05)
   2.274 +(def domino-width 0.5)
   2.275 +(def domino-height 1)
   2.276 +
   2.277 +(defn domino
   2.278 +  ([position]
   2.279 +     (domino position (Quaternion/IDENTITY)))
   2.280 +  ([position rotation]
   2.281 +     (doto (box domino-width domino-height domino-thickness
   2.282 +	     :position position :name "domino"
   2.283 +	     :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.284 +	     :texture "Textures/Terrain/BrickWall/BrickWall.jpg"
   2.285 +	     :mass 1
   2.286 +	     :rotation rotation)
   2.287 +       (.setShadowMode RenderQueue$ShadowMode/CastAndReceive)
   2.288 +       )))
   2.289 +
   2.290 +
   2.291 +(defn domino-row []
   2.292 +  (let [node (Node. "domino-row")]
   2.293 +    (dorun
   2.294 +     (map
   2.295 +      (comp  #(.attachChild node %) domino)
   2.296 +       (for [
   2.297 +	     z (range 10)
   2.298 +	     x (range 5)
   2.299 +	     ]
   2.300 +       	    (Vector3f.
   2.301 +	     (+ (* z domino-width) (* x 5 domino-width))
   2.302 +	     (/ domino-height 1)
   2.303 +	     (* -5.5 domino-thickness z) ))))
   2.304 +
   2.305 +    node))
   2.306 +
   2.307 +(defn domino-cycle []
   2.308 +  (let [node (Node. "domino-cycle")]
   2.309 +    (dorun
   2.310 +     (map
   2.311 +      (comp  #(.attachChild node %) (partial apply domino) ) 
   2.312 +      (for [n (range 720)]
   2.313 +	(let [space (* domino-height 5.5)
   2.314 +	      r (fn[n] (* (+ n 3) domino-width 0.5)) 
   2.315 +	      t (fn[n] (reduce
   2.316 +			+
   2.317 +			(map
   2.318 +			 (fn dt[n] (/ space (* 2 (Math/PI) (r n))))
   2.319 +			 (range n))))
   2.320 +	      t (t n)
   2.321 +	      r (r n)
   2.322 +	      ct (Math/cos t)
   2.323 +	      st (Math/sin t)
   2.324 +	      ]
   2.325 +	(list
   2.326 +       	    (Vector3f.
   2.327 +	     (* -1 r st)
   2.328 +	     (/ domino-height 1)
   2.329 +	     (* r ct))
   2.330 +	    (.fromAngleAxis (Quaternion.)
   2.331 +			    (- (/ 3.1415926 2) t) (Vector3f. 0 1 0))
   2.332 +	    )))
   2.333 +	))
   2.334 +    node))
   2.335 +
   2.336 +
   2.337 +(defn domino-game-run []
   2.338 +  (doto
   2.339 +      (world
   2.340 +       (doto (Node.) (.attachChild (floor*))
   2.341 +	     )
   2.342 +       {"key-i" (gravity-toggle (Vector3f. 0 0 -9.81))
   2.343 +	"key-m" (gravity-toggle (Vector3f. 0 0 9.81))
   2.344 +	"key-l" (gravity-toggle (Vector3f. 9.81 0 0))
   2.345 +	"key-j" (gravity-toggle (Vector3f. -9.81 0 0))
   2.346 +	"key-k" (gravity-toggle (Vector3f. 0 9.81 0) )
   2.347 +	"key-u" (fn[g v] ((gravity-toggle (Vector3f. 0 -0 0)) g true))
   2.348 +	"key-o" (gravity-toggle (Vector3f. 0 -9.81 0))
   2.349 +
   2.350 +	"key-space"
   2.351 +	(fn[game value]
   2.352 +	  
   2.353 +	  (if (not value)
   2.354 +	    (let [d (domino (Vector3f. 0 (/ domino-height 0.25) 0)
   2.355 +			    (.fromAngleAxis (Quaternion.)
   2.356 +					    (/ Math/PI 2) (Vector3f. 0 1 0)))]
   2.357 +	      (add-element game d))))
   2.358 +	"key-f"
   2.359 +	(fn[game value](if (not value) (add-element game (domino-cycle))))
   2.360 +	"key-return" (fire-cannon-ball)}
   2.361 +       position-camera
   2.362 +       (fn [& _]))     
   2.363 +    (.start)))       
   2.364 +#+end_src
   2.365 +
   2.366 +#+begin_src clojure :results silent
   2.367 +(cortex.other-games/domino-game-run)
   2.368 +#+end_src
   2.369 +
   2.370 +#+caption: floating dominos
   2.371 +[[./images/dominos.jpg]]
   2.372 +
   2.373 +*** Hello Loop
   2.374 +#+srcname: hello-loop
   2.375 +#+begin_src clojure :results silent
   2.376 +(ns hello.loop)
   2.377 +(use 'cortex.world)
   2.378 +(use 'cortex.import)
   2.379 +(cortex.import/mega-import-jme3)
   2.380 +(rlm.rlm-commands/help)
   2.381 +
   2.382 +(defn blue-cube []
   2.383 +  (box 1 1 1
   2.384 +       :color ColorRGBA/Blue
   2.385 +       :texture false
   2.386 +       :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.387 +       :name "blue-cube"
   2.388 +       :physical? false))
   2.389 +
   2.390 +(defn blue-cube-game []
   2.391 +  (let [cube (blue-cube)
   2.392 +	root (doto (Node.) (.attachChild cube))]
   2.393 +  (world root
   2.394 +	 {}
   2.395 +	 no-op
   2.396 +	 (fn [game tpf]
   2.397 +	   (.rotate cube 0.0 (* 2 tpf) 0.0)))))	 	 		  
   2.398 +#+end_src
   2.399 +
   2.400 +*** Hello Collision
   2.401 +
   2.402 +#+srcname: hello-collision
   2.403 +#+begin_src clojure :results silent
   2.404 +(ns hello.collision)
   2.405 +(use 'cortex.world)
   2.406 +(use 'cortex.import)
   2.407 +(use 'clojure.contrib.def)
   2.408 +
   2.409 +
   2.410 +(cortex.import/mega-import-jme3)
   2.411 +(rlm.rlm-commands/help)
   2.412 +(use '[hello [brick-wall :only [fire-cannon-ball brick-wall*]]])
   2.413 +
   2.414 +
   2.415 +(defn environment []
   2.416 +     (let
   2.417 +	 [scene-model
   2.418 +	  (doto
   2.419 +	      (.loadModel
   2.420 +	       (doto (asset-manager)
   2.421 +		 (.registerLocator
   2.422 +		  "/home/r/cortex/assets/zips/town.zip" ZipLocator))
   2.423 +	       "main.scene")
   2.424 +	    (.setLocalScale (float 2.0)))
   2.425 +	  collision-shape
   2.426 +	  (CollisionShapeFactory/createMeshShape #^Node scene-model)
   2.427 +	  landscape (RigidBodyControl. collision-shape 0)]
   2.428 +       (.setShadowMode scene-model RenderQueue$ShadowMode/CastAndReceive)
   2.429 +       (.addControl scene-model landscape)
   2.430 +       scene-model))
   2.431 +	  
   2.432 +(defn player-fn []
   2.433 +  (doto
   2.434 +      (CharacterControl.
   2.435 +       (CapsuleCollisionShape. (float 1.5) (float 6)(float 1))
   2.436 +       (float 0.05))
   2.437 +    (.setJumpSpeed 20)
   2.438 +    (.setFallSpeed 30)
   2.439 +    (.setGravity 30) ;30
   2.440 +    (.setPhysicsLocation (Vector3f. 0 10 0))))
   2.441 +
   2.442 +(defn lights []
   2.443 +  [(doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 1 1 1 1) (float 1))))
   2.444 +   (doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 1 0.7 0 1) (float 1))))
   2.445 +   (doto (DirectionalLight.)
   2.446 +     (.setColor (.mult ColorRGBA/White (float 0.9) ))
   2.447 +     (.setDirection (.normalizeLocal (Vector3f. 2.8 -28 2.8))))])
   2.448 +
   2.449 +(defn night-lights []
   2.450 +  [(doto (AmbientLight.) (.setColor (.mult (ColorRGBA. 0.275 0.467 0.784 1) (float 0.3))))
   2.451 +   (doto (DirectionalLight.)
   2.452 +     (.setColor (.mult ColorRGBA/White (float 0.2) ))
   2.453 +     (.setDirection (.normalizeLocal (Vector3f. 2.8 -28 2.8))))])
   2.454 +
   2.455 +(def player (atom (player-fn)))
   2.456 +
   2.457 +(defn setup-fn [game]
   2.458 +  (dorun (map #(.addLight (.getRootNode game) %) (lights)))
   2.459 +  ;; set the color of the sky
   2.460 +  (.setBackgroundColor (.getViewPort game) (ColorRGBA. 0.3 0.4 0.9 1))
   2.461 +  ;(.setBackgroundColor (.getViewPort game) (ColorRGBA. 0 0 0 1)
   2.462 +  (doto (.getFlyByCamera game)
   2.463 +    (.setMoveSpeed (float 100))
   2.464 +    (.setRotationSpeed 3))
   2.465 +  (.add
   2.466 +   (.getPhysicsSpace
   2.467 +    (.getState (.getStateManager game) BulletAppState))
   2.468 +   @player)
   2.469 +
   2.470 +   (doto (Node.) (.attachChild (.getRootNode game))
   2.471 +	     (.attachChild (brick-wall*))
   2.472 +   )
   2.473 +
   2.474 +)
   2.475 +
   2.476 +
   2.477 +(def walking-up? (atom false))
   2.478 +(def walking-down? (atom false))
   2.479 +(def walking-left? (atom false))
   2.480 +(def walking-right? (atom false))
   2.481 +
   2.482 +(defn set-walk [walk-atom game value]
   2.483 +  ;;(println-repl "setting  stuff to " value)
   2.484 +  (reset! walk-atom value))
   2.485 +
   2.486 +(defn responses []
   2.487 +     {"key-w" (partial set-walk walking-up?)
   2.488 +      "key-d" (partial set-walk walking-right?)
   2.489 +      "key-s" (partial set-walk walking-down?)
   2.490 +      "key-a" (partial set-walk walking-left?)
   2.491 +      "key-return" (fire-cannon-ball)
   2.492 +      "key-space" (fn [game value] (.jump @player))
   2.493 +      })
   2.494 +     
   2.495 +(defn update-fn
   2.496 +  [game tpf]
   2.497 +  (let [camera (.getCamera game)         
   2.498 +	cam-dir (.multLocal
   2.499 +		 (.clone
   2.500 +		  (.getDirection camera)) (float 0.6))
   2.501 +	cam-left (.multLocal
   2.502 +		  (.clone
   2.503 +		   (.getLeft camera)) (float 0.4))
   2.504 +	walk-direction (Vector3f. 0 0 0)]
   2.505 +    
   2.506 +    (cond
   2.507 +     @walking-up?     (.addLocal walk-direction cam-dir)
   2.508 +     @walking-right?  (.addLocal walk-direction (.negate cam-left))
   2.509 +     @walking-down?   (.addLocal walk-direction (.negate cam-dir))
   2.510 +     @walking-left?   (.addLocal walk-direction cam-left))
   2.511 +    (.setWalkDirection @player walk-direction)
   2.512 +    (.setLocation camera (.getPhysicsLocation @player))))
   2.513 +    
   2.514 +(defn run-game []
   2.515 +  (.start
   2.516 +   (world (environment)
   2.517 +	  (responses)
   2.518 +	  setup-fn
   2.519 +	  update-fn)))
   2.520 +#+end_src
   2.521 +
   2.522 +*** Hello Terrain
   2.523 +#+srcname: hello-terrain
   2.524 +#+begin_src clojure :results silent
   2.525 +(ns hello.terrain)
   2.526 +(use 'cortex.world)
   2.527 +(use 'cortex.import)
   2.528 +(use 'clojure.contrib.def)
   2.529 +(import jme3tools.converters.ImageToAwt)
   2.530 +
   2.531 +
   2.532 +(cortex.import/mega-import-jme3)
   2.533 +(rlm.rlm-commands/help)
   2.534 +(use '[hello [brick-wall :only [fire-cannon-ball brick-wall*]]])
   2.535 +
   2.536 +
   2.537 +(defn setup-fn [type game]
   2.538 +  (.setMoveSpeed (.getFlyByCamera game) 50)
   2.539 +  (.setFrustumFar (.getCamera game) 10000)
   2.540 +  (let [env (environment type)
   2.541 +	cameras [(.getCamera game)]
   2.542 +	control (TerrainLodControl. env cameras)]
   2.543 +    ;;(.addControl env control)
   2.544 +    (.attachChild (.getRootNode game) env)))                
   2.545 +
   2.546 +(defn environment [type]
   2.547 +  (let
   2.548 +      [mat_terrain
   2.549 +       (Material. (asset-manager) "Common/MatDefs/Terrain/Terrain.j3md")
   2.550 +       grass (.loadTexture (asset-manager) "Textures/Terrain/splat/grass.jpg")
   2.551 +       dirt (.loadTexture (asset-manager) "Textures/Terrain/splat/dirt.jpg")
   2.552 +       rock (.loadTexture (asset-manager) "Textures/Terrain/splat/road.jpg")
   2.553 +       heightmap-image (.loadTexture (asset-manager)
   2.554 +				     ({:mountain "Textures/Terrain/splat/mountains512.png"
   2.555 +				       :fortress "Textures/Terrain/splat/fortress512.png"
   2.556 +				       }type))
   2.557 +       heightmap (ImageBasedHeightMap.
   2.558 +		  (ImageToAwt/convert (.getImage heightmap-image) false true 0))
   2.559 +       terrain (do (.load heightmap)
   2.560 +		   (TerrainQuad. "my terrain" 65 513 (.getHeightMap heightmap)))
   2.561 +       ]
   2.562 +    
   2.563 +    (dorun (map #(.setWrap % Texture$WrapMode/Repeat)
   2.564 +		[grass dirt rock]))
   2.565 +
   2.566 +    (doto mat_terrain
   2.567 +      (.setTexture "Tex1" grass)
   2.568 +      (.setFloat "Tex1Scale" (float 64))
   2.569 +
   2.570 +      (.setTexture "Tex2" dirt)
   2.571 +      (.setFloat "Tex2Scale" (float 32))
   2.572 +
   2.573 +      (.setTexture "Tex3" rock)
   2.574 +      (.setFloat "Tex3Scale" (float 128))
   2.575 +
   2.576 +      (.setTexture "Alpha"
   2.577 +		   (.loadTexture
   2.578 +		    (asset-manager) 
   2.579 +		    ({:mountain "Textures/Terrain/splat/alphamap.png"
   2.580 +		      :fortress "Textures/Terrain/splat/alphamap2.png"} type))))
   2.581 +
   2.582 +    (doto terrain
   2.583 +      (.setMaterial mat_terrain)
   2.584 +      (.setLocalTranslation 0 -100 0)
   2.585 +      (.setLocalScale 2 1 2))))
   2.586 +      
   2.587 +
   2.588 +
   2.589 +(defn run-terrain-game [type]
   2.590 +  (.start
   2.591 +   (world
   2.592 +    (Node.)
   2.593 +    {}
   2.594 +    (partial setup-fn type)
   2.595 +    no-op)))
   2.596 +#+end_src
   2.597 +
   2.598 +
   2.599 +
   2.600 +#+srcname: hello-animation
   2.601 +#+begin_src clojure :results silent
   2.602 +(ns hello.animation)
   2.603 +(use 'cortex.world)
   2.604 +(use 'cortex.import)
   2.605 +(use 'clojure.contrib.def)
   2.606 +(cortex.import/mega-import-jme3)
   2.607 +(rlm.rlm-commands/help)
   2.608 +(use '[hello [collision :only [lights]]])
   2.609 +
   2.610 +(defn stand
   2.611 +  [channel]
   2.612 +  (doto channel
   2.613 +    (.setAnim "stand" (float 0.5))
   2.614 +    (.setLoopMode LoopMode/DontLoop)
   2.615 +    (.setSpeed (float 1))))
   2.616 +
   2.617 +(defn anim-listener []
   2.618 +     (proxy [AnimEventListener] []
   2.619 +       (onAnimChange
   2.620 +	[control channel animation-name]
   2.621 +	(println-repl "RLM --- onAnimChange"))
   2.622 +       (onAnimCycleDone
   2.623 +	[control channel animation-name]
   2.624 +	(if (= animation-name "Walk")
   2.625 +	  (stand channel)
   2.626 +	  ))))
   2.627 +       
   2.628 +(defn setup-fn [channel game]
   2.629 +  (dorun (map #(.addLight (.getRootNode game) %) (lights)))
   2.630 +  ;; set the color of the sky
   2.631 +  (.setBackgroundColor (.getViewPort game) (ColorRGBA. 0.3 0.4 0.9 1))
   2.632 +  ;(.setBackgroundColor (.getViewPort game) (ColorRGBA. 0 0 0 1)
   2.633 +  (.setAnim channel "stand")
   2.634 +  (doto (.getFlyByCamera game)
   2.635 +    (.setMoveSpeed (float 10))
   2.636 +    (.setRotationSpeed 1)))
   2.637 +
   2.638 +(defn walk [channel]
   2.639 +  (println-repl "zzz")
   2.640 +  (doto channel
   2.641 +    (.setAnim "Walk" (float 0.5))
   2.642 +    (.setLoopMode LoopMode/Loop)))
   2.643 +    
   2.644 +
   2.645 +(defn key-map [channel]
   2.646 +  {"key-space" (fn [game value]
   2.647 +		 (if (not value)
   2.648 +		   (walk channel)))})
   2.649 +
   2.650 +(defn player []
   2.651 +  (let [model (.loadModel (asset-manager) "Models/Oto/Oto.mesh.xml")
   2.652 +	control (.getControl model AnimControl)]
   2.653 +    (.setLocalScale model (float 0.5))
   2.654 +    (.clearListeners control)
   2.655 +    (.addListener control (anim-control))
   2.656 +    model))
   2.657 +    
   2.658 +
   2.659 +
   2.660 +(defn run-anim-game []
   2.661 +  (let [ninja (player)
   2.662 +	control  (.getControl ninja AnimControl)
   2.663 +	channel (.createChannel control)]
   2.664 +    (.start
   2.665 +     (world
   2.666 +      ninja
   2.667 +      (key-map channel)
   2.668 +      (partial setup-fn channel)
   2.669 +      no-op))))
   2.670 +#+end_src
   2.671 +
   2.672 +*** Hello Materials
   2.673 +#+srcname: material
   2.674 +#+begin_src clojure :results silent
   2.675 +(ns hello.material)
   2.676 +(use 'cortex.world)
   2.677 +(use 'cortex.import)
   2.678 +(use 'clojure.contrib.def)
   2.679 +(cortex.import/mega-import-jme3)
   2.680 +(rlm.rlm-commands/help)
   2.681 +
   2.682 +(defn simple-cube []
   2.683 +  (box 1 1 1
   2.684 +       :position (Vector3f. -3 1.1 0)
   2.685 +       :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.686 +       :texture "Interface/Logo/Monkey.jpg"
   2.687 +       :physical? false))
   2.688 +
   2.689 +(defn leaky-box []
   2.690 +  (box 1 1 1
   2.691 +       :position (Vector3f. 3 -1 0)
   2.692 +       :material "Common/MatDefs/Misc/ColoredTextured.j3md"
   2.693 +       :texture  "Textures/ColoredTex/Monkey.png"
   2.694 +       :color    (ColorRGBA. 1 0 1 1)
   2.695 +       :physical? false))
   2.696 +
   2.697 +(defn transparent-box []
   2.698 +  (doto
   2.699 +      (box 1 1 0.1
   2.700 +	   :position Vector3f/ZERO
   2.701 +	   :name "window frame"
   2.702 +	   :material "Common/MatDefs/Misc/Unshaded.j3md"
   2.703 +	   :texture "Textures/ColoredTex/Monkey.png"
   2.704 +	   :physical? false)
   2.705 +    (-> (.getMaterial)
   2.706 +	(.getAdditionalRenderState)
   2.707 +	(.setBlendMode RenderState$BlendMode/Alpha))
   2.708 +    (.setQueueBucket RenderQueue$Bucket/Transparent)))
   2.709 +                  
   2.710 +(defn bumpy-sphere []
   2.711 +  (doto 
   2.712 +      (sphere 2
   2.713 +	      :position (Vector3f. 0 2 -2)
   2.714 +	      :name "Shiny rock"
   2.715 +	      :material "Common/MatDefs/Light/Lighting.j3md"
   2.716 +	      :texture false
   2.717 +	      :physical? false)
   2.718 +    (-> (.getMesh)
   2.719 +	(doto 
   2.720 +	  (.setTextureMode Sphere$TextureMode/Projected)
   2.721 +	  (TangentBinormalGenerator/generate)))
   2.722 +    (-> (.getMaterial)
   2.723 +	(doto
   2.724 +	  (.setTexture "DiffuseMap" (.loadTexture (asset-manager)
   2.725 +						  "Textures/Terrain/Pond/Pond.png"))
   2.726 +	  (.setTexture "NormalMap"  (.loadTexture (asset-manager)
   2.727 +						  "Textures/Terrain/Pond/Pond_normal.png"))
   2.728 +	  (.setFloat   "Shininess"  (float 5))))
   2.729 +    (.rotate (float 1.6) 0 0)))
   2.730 +
   2.731 +
   2.732 +(defn start-game []
   2.733 +  (.start
   2.734 +   (world
   2.735 +    (let [root  (Node.)]
   2.736 +      (dorun (map #(.attachChild root %)
   2.737 +		  [(simple-cube) (leaky-box) (transparent-box) (bumpy-sphere)]))
   2.738 +      root)
   2.739 +    {}
   2.740 +    (fn [world]
   2.741 +      (let [sun (doto (DirectionalLight.)
   2.742 +		  (.setDirection (.normalizeLocal (Vector3f. 1 0 -2)))
   2.743 +		  (.setColor ColorRGBA/White))]
   2.744 +	(.addLight (.getRootNode world) sun)))
   2.745 +    no-op 
   2.746 +    )))
   2.747 +#+end_src
   2.748 +
   2.749 +
   2.750 +    
   2.751 +* COMMENT code generation
   2.752 +
   2.753 +#+begin_src clojure :tangle ../src/hello/brick_wall.clj
   2.754 +<<brick-wall-header>>
   2.755 +<<brick-wall-body>>
   2.756 +#+end_src
   2.757 +
   2.758 +#+begin_src clojure :tangle ../src/hello/hello_simple_app.clj
   2.759 +<<hello-simple-app>>
   2.760 +#+end_src
   2.761 +
   2.762 +#+begin_src clojure :tangle ../src/cortex/other_games.clj
   2.763 +<<other-games>>
   2.764 +#+end_src
   2.765 +
   2.766 +#+begin_src clojure :tangle ../src/hello/loop.clj
   2.767 +<<hello-loop>>
   2.768 +#+end_src
   2.769 +
   2.770 +#+begin_src clojure :tangle ../src/hello/collision.clj
   2.771 +<<hello-collision>>
   2.772 +#+end_src
   2.773 +
   2.774 +#+begin_src clojure :tangle ../src/hello/terrain.clj
   2.775 +<<hello-terrain>>
   2.776 +#+end_src
   2.777 +
   2.778 +#+begin_src clojure :tangle ../src/hello/animation.clj
   2.779 +<<hello-animation>>
   2.780 +#+end_src
   2.781 +
   2.782 +#+begin_src clojure :tangle ../src/hello/material.clj
   2.783 +<<material>>
   2.784 +#+end_src
   2.785 +
   2.786 +
   2.787 +  
   2.788 +
   2.789 +
   2.790 +
   2.791 +
   2.792 +
     3.1 --- a/org/util.org	Mon Oct 24 12:35:15 2011 -0700
     3.2 +++ b/org/util.org	Mon Oct 24 12:43:58 2011 -0700
     3.3 @@ -291,8 +291,6 @@
     3.4  #+end_src
     3.5  
     3.6  
     3.7 -
     3.8 -
     3.9  * COMMENT code generation
    3.10  #+begin_src clojure :tangle ../src/cortex/import.clj
    3.11  <<import>>