annotate org/test-creature.org @ 88:3e929630a25f

multimethod dispatch works
author Robert McIntyre <rlm@mit.edu>
date Sat, 07 Jan 2012 05:24:14 -0700
parents af1bb43661f9
children cd5151b5e7c3
rev   line source
rlm@73 1 #+title: First attempt at a creature!
rlm@73 2 #+author: Robert McIntyre
rlm@73 3 #+email: rlm@mit.edu
rlm@73 4 #+description:
rlm@73 5 #+keywords: simulation, jMonkeyEngine3, clojure
rlm@73 6 #+SETUPFILE: ../../aurellem/org/setup.org
rlm@73 7 #+INCLUDE: ../../aurellem/org/level-0.org
rlm@73 8
rlm@73 9 * Intro
rlm@73 10 So far, I've made the following senses --
rlm@73 11 - Vision
rlm@73 12 - Hearing
rlm@73 13 - Touch
rlm@73 14 - Proprioception
rlm@73 15
rlm@73 16 And one effector:
rlm@73 17 - Movement
rlm@73 18
rlm@73 19 However, the code so far has only enabled these senses, but has not
rlm@73 20 actually implemented them. For example, there is still a lot of work
rlm@73 21 to be done for vision. I need to be able to create an /eyeball/ in
rlm@73 22 simulation that can be moved around and see the world from different
rlm@73 23 angles. I also need to determine weather to use log-polar or cartesian
rlm@73 24 for the visual input, and I need to determine how/wether to
rlm@73 25 disceritise the visual input.
rlm@73 26
rlm@73 27 I also want to be able to visualize both the sensors and the
rlm@73 28 effectors in pretty pictures. This semi-retarted creature will by my
rlm@73 29 first attempt at bringing everything together.
rlm@73 30
rlm@73 31 * The creature's body
rlm@73 32
rlm@73 33 Still going to do an eve-like body in blender, but due to problems
rlm@73 34 importing the joints, etc into jMonkeyEngine3, I',m going to do all
rlm@73 35 the connecting here in clojure code, using the names of the individual
rlm@73 36 components and trial and error. Later, I'll maybe make some sort of
rlm@73 37 creature-building modifications to blender that support whatever
rlm@73 38 discreitized senses I'm going to make.
rlm@73 39
rlm@73 40 #+name: body-1
rlm@73 41 #+begin_src clojure
rlm@73 42 (ns cortex.silly
rlm@73 43 "let's play!"
rlm@73 44 {:author "Robert McIntyre"})
rlm@73 45
rlm@73 46 ;; TODO remove this!
rlm@73 47 (require 'cortex.import)
rlm@73 48 (cortex.import/mega-import-jme3)
rlm@73 49 (use '(cortex world util body hearing touch vision))
rlm@73 50
rlm@73 51 (rlm.rlm-commands/help)
rlm@73 52
rlm@87 53 (declare joint-create)
rlm@83 54
rlm@83 55 (defn load-bullet []
rlm@84 56 (let [sim (world (Node.) {} no-op no-op)]
rlm@84 57 (.enqueue
rlm@84 58 sim
rlm@84 59 (fn []
rlm@84 60 (.stop sim)))
rlm@84 61 (.start sim)))
rlm@83 62
rlm@73 63 (defn load-blender-model
rlm@73 64 "Load a .blend file using an asset folder relative path."
rlm@73 65 [^String model]
rlm@73 66 (.loadModel
rlm@73 67 (doto (asset-manager)
rlm@73 68 (.registerLoader BlenderModelLoader (into-array String ["blend"])))
rlm@73 69 model))
rlm@73 70
rlm@74 71 (defn meta-data [blender-node key]
rlm@74 72 (if-let [data (.getUserData blender-node "properties")]
rlm@74 73 (.findValue data key)
rlm@74 74 nil))
rlm@73 75
rlm@78 76 (defn blender-to-jme
rlm@78 77 "Convert from Blender coordinates to JME coordinates"
rlm@78 78 [#^Vector3f in]
rlm@78 79 (Vector3f. (.getX in)
rlm@78 80 (.getZ in)
rlm@78 81 (- (.getY in))))
rlm@74 82
rlm@79 83 (defn jme-to-blender
rlm@79 84 "Convert from JME coordinates to Blender coordinates"
rlm@79 85 [#^Vector3f in]
rlm@79 86 (Vector3f. (.getX in)
rlm@79 87 (- (.getZ in))
rlm@79 88 (.getY in)))
rlm@79 89
rlm@78 90 (defn joint-targets
rlm@78 91 "Return the two closest two objects to the joint object, ordered
rlm@78 92 from bottom to top according to the joint's rotation."
rlm@78 93 [#^Node parts #^Node joint]
rlm@78 94 ;;(println (meta-data joint "joint"))
rlm@78 95 (.getWorldRotation joint)
rlm@78 96 (loop [radius (float 0.01)]
rlm@78 97 (let [results (CollisionResults.)]
rlm@78 98 (.collideWith
rlm@78 99 parts
rlm@78 100 (BoundingBox. (.getWorldTranslation joint)
rlm@78 101 radius radius radius)
rlm@78 102 results)
rlm@78 103 (let [targets
rlm@78 104 (distinct
rlm@78 105 (map #(.getGeometry %) results))]
rlm@78 106 (if (>= (count targets) 2)
rlm@78 107 (sort-by
rlm@79 108 #(let [v
rlm@79 109 (jme-to-blender
rlm@79 110 (.mult
rlm@79 111 (.inverse (.getWorldRotation joint))
rlm@79 112 (.subtract (.getWorldTranslation %)
rlm@79 113 (.getWorldTranslation joint))))]
rlm@79 114 (println-repl (.getName %) ":" v)
rlm@79 115 (.dot (Vector3f. 1 1 1)
rlm@79 116 v))
rlm@78 117 (take 2 targets))
rlm@78 118 (recur (float (* radius 2))))))))
rlm@74 119
rlm@87 120 (defn world-to-local
rlm@87 121 "Convert the world coordinates into coordinates relative to the
rlm@87 122 object (i.e. local coordinates), taking into account the rotation
rlm@87 123 of object."
rlm@87 124 [#^Spatial object world-coordinate]
rlm@87 125 (let [out (Vector3f.)]
rlm@88 126 (.worldToLocal object world-coordinate out) out))
rlm@87 127
rlm@87 128 (defmulti joint-dispatch
rlm@87 129 "Translate blender pseudo-joints into real JME joints."
rlm@88 130 (fn [constraints & _]
rlm@87 131 (:type constraints)))
rlm@87 132
rlm@87 133 (defmethod joint-dispatch :point
rlm@87 134 [constraints control-a control-b pivot-a pivot-b rotation]
rlm@87 135 (println-repl "creating POINT2POINT joint")
rlm@87 136 (Point2PointJoint.
rlm@87 137 control-a
rlm@87 138 control-b
rlm@87 139 pivot-a
rlm@87 140 pivot-b))
rlm@87 141
rlm@87 142 (defmethod joint-dispatch :hinge
rlm@87 143 [constraints control-a control-b pivot-a pivot-b rotation]
rlm@87 144 (println-repl "creating HINGE joint")
rlm@87 145 (let [axis
rlm@87 146 (if-let
rlm@87 147 [axis (:axis constraints)]
rlm@87 148 axis
rlm@87 149 Vector3f/UNIT_X)
rlm@87 150 [limit-1 limit-2] (:limit constraints)
rlm@87 151 hinge-axis
rlm@87 152 (.mult
rlm@87 153 rotation
rlm@87 154 (blender-to-jme axis))]
rlm@87 155 (doto
rlm@87 156 (HingeJoint.
rlm@87 157 control-a
rlm@87 158 control-b
rlm@87 159 pivot-a
rlm@87 160 pivot-b
rlm@87 161 hinge-axis
rlm@87 162 hinge-axis)
rlm@87 163 (.setLimit limit-1 limit-2))))
rlm@87 164
rlm@87 165
rlm@87 166 (defmethod joint-dispatch :cone
rlm@87 167 [constraints control-a control-b pivot-a pivot-b rotation]
rlm@87 168 (let [limit-xz (:limit-xz constraints)
rlm@87 169 limit-xy (:limit-xy constraints)
rlm@87 170 twist (:twist constraints)]
rlm@87 171
rlm@87 172
rlm@87 173 (println-repl "creating CONE joint")
rlm@87 174 (println-repl rotation)
rlm@87 175 (println-repl
rlm@87 176 "UNIT_X --> " (.mult rotation (Vector3f. 1 0 0)))
rlm@87 177 (println-repl
rlm@87 178 "UNIT_Y --> " (.mult rotation (Vector3f. 0 1 0)))
rlm@87 179 (println-repl
rlm@87 180 "UNIT_Z --> " (.mult rotation (Vector3f. 0 0 1)))
rlm@87 181 (doto
rlm@87 182 (ConeJoint.
rlm@87 183 control-a
rlm@87 184 control-b
rlm@87 185 pivot-a
rlm@87 186 pivot-b
rlm@87 187 rotation
rlm@87 188 rotation)
rlm@87 189 (.setLimit (float limit-xz)
rlm@87 190 (float limit-xy)
rlm@87 191 (float twist)))))
rlm@87 192
rlm@87 193
rlm@87 194
rlm@88 195 (defn connect
rlm@87 196 "here are some examples:
rlm@87 197 {:type :point}
rlm@87 198 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)}
rlm@87 199 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
rlm@87 200
rlm@87 201 {:type :cone :limit-xz 0]
rlm@87 202 :limit-xy 0]
rlm@87 203 :twist 0]} (use XZY rotation mode in blender!)"
rlm@87 204 [#^Node obj-a #^Node obj-b #^Node joint]
rlm@87 205 (let [control-a (.getControl obj-a RigidBodyControl)
rlm@87 206 control-b (.getControl obj-b RigidBodyControl)
rlm@87 207 joint-center (.getWorldTranslation joint)
rlm@87 208 joint-rotation (.toRotationMatrix (.getWorldRotation joint))
rlm@87 209 pivot-a (world-to-local obj-a joint-center)
rlm@87 210 pivot-b (world-to-local obj-b joint-center)]
rlm@87 211 ;; A side-effect of creating a joint registers
rlm@87 212 ;; it with both physics objects which in turn
rlm@87 213 ;; will register the joint with the physics system
rlm@87 214 ;; when the simulation is started.
rlm@87 215 (if-let [constraints
rlm@87 216 (map-vals
rlm@87 217 eval
rlm@87 218 (read-string
rlm@87 219 (meta-data joint "joint")))]
rlm@87 220 (do
rlm@87 221 (println-repl "creating joint between"
rlm@87 222 (.getName obj-a) "and" (.getName obj-b))
rlm@87 223 (joint-dispatch constraints
rlm@87 224 control-a control-b
rlm@87 225 pivot-a pivot-b
rlm@87 226 joint-rotation))
rlm@87 227
rlm@87 228 (println-repl "could not find joint meta-data!"))))
rlm@87 229
rlm@78 230 (defn assemble-creature [#^Node pieces joints]
rlm@78 231 (dorun
rlm@78 232 (map
rlm@78 233 (fn [geom]
rlm@78 234 (let [physics-control
rlm@78 235 (RigidBodyControl.
rlm@78 236 (HullCollisionShape.
rlm@78 237 (.getMesh geom))
rlm@78 238 (if-let [mass (meta-data geom "mass")]
rlm@78 239 (do
rlm@78 240 (println-repl
rlm@78 241 "setting" (.getName geom) "mass to" (float mass))
rlm@78 242 (float mass))
rlm@78 243 (float 1)))]
rlm@78 244
rlm@78 245 (.addControl geom physics-control)))
rlm@78 246 (filter #(isa? (class %) Geometry )
rlm@78 247 (node-seq pieces))))
rlm@77 248
rlm@78 249 (dorun
rlm@78 250 (map
rlm@78 251 (fn [joint]
rlm@78 252 (let [[obj-a obj-b]
rlm@78 253 (joint-targets pieces joint)]
rlm@88 254 (connect obj-a obj-b joint)))
rlm@78 255 joints))
rlm@78 256 pieces)
rlm@74 257
rlm@78 258 (defn blender-creature [blender-path]
rlm@78 259 (let [model (load-blender-model blender-path)
rlm@78 260 joints
rlm@78 261 (if-let [joint-node (.getChild model "joints")]
rlm@78 262 (seq (.getChildren joint-node))
rlm@78 263 (do (println-repl "could not find joints node")
rlm@78 264 []))]
rlm@78 265 (assemble-creature model joints)))
rlm@74 266
rlm@78 267 (def hand "Models/creature1/one.blend")
rlm@74 268
rlm@78 269 (def worm "Models/creature1/try-again.blend")
rlm@78 270
rlm@80 271 (defn x-ray [#^ColorRGBA color]
rlm@80 272 (doto (Material. (asset-manager)
rlm@80 273 "Common/MatDefs/Misc/Unshaded.j3md")
rlm@80 274 (.setColor "Color" color)
rlm@80 275 (-> (.getAdditionalRenderState)
rlm@80 276 (.setDepthTest false))))
rlm@80 277
rlm@78 278 (defn test-creature [thing]
rlm@80 279 (let [x-axis
rlm@80 280 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red)
rlm@80 281 y-axis
rlm@80 282 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green)
rlm@80 283 z-axis
rlm@80 284 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)]
rlm@78 285 (world
rlm@78 286 (nodify [(blender-creature thing)
rlm@81 287 (box 10 2 10 :position (Vector3f. 0 -9 0)
rlm@80 288 :color ColorRGBA/Gray :mass 0)
rlm@80 289 x-axis y-axis z-axis
rlm@80 290 ])
rlm@78 291 standard-debug-controls
rlm@78 292 (comp light-up-everything enable-debug
rlm@78 293 (fn [world]
rlm@78 294 (.setTimer world (NanoTimer.))
rlm@87 295 ;;(set-gravity world (Vector3f. 0 0 0))
rlm@78 296 (speed-up world)
rlm@78 297 world
rlm@78 298 ))
rlm@80 299 no-op)))
rlm@78 300
rlm@78 301 (defn world-setup [joint]
rlm@83 302 (let [
rlm@83 303
rlm@84 304 joint-position (Vector3f. 0 0 0)
rlm@83 305 joint-rotation
rlm@83 306 (.toRotationMatrix
rlm@83 307 (.mult
rlm@83 308 (doto (Quaternion.)
rlm@83 309 (.fromAngleAxis
rlm@83 310 (* 1 (/ Math/PI 4))
rlm@85 311 (Vector3f. -1 0 0)))
rlm@85 312 (doto (Quaternion.)
rlm@85 313 (.fromAngleAxis
rlm@85 314 (* 1 (/ Math/PI 2))
rlm@85 315 (Vector3f. 0 0 1)))))
rlm@84 316 top-position (.mult joint-rotation (Vector3f. 8 0 0))
rlm@83 317
rlm@83 318 origin (doto
rlm@83 319 (sphere 0.1 :physical? false :color ColorRGBA/Cyan
rlm@84 320 :position top-position))
rlm@83 321 top (doto
rlm@78 322 (sphere 0.1 :physical? false :color ColorRGBA/Yellow
rlm@84 323 :position top-position)
rlm@83 324
rlm@78 325 (.addControl
rlm@78 326 (RigidBodyControl.
rlm@83 327 (CapsuleCollisionShape. 0.5 1.5 1) (float 20))))
rlm@78 328 bottom (doto
rlm@78 329 (sphere 0.1 :physical? false :color ColorRGBA/DarkGray
rlm@83 330 :position (Vector3f. 0 0 0))
rlm@83 331 (.addControl
rlm@78 332 (RigidBodyControl.
rlm@78 333 (CapsuleCollisionShape. 0.5 1.5 1) (float 0))))
rlm@83 334 table (box 10 2 10 :position (Vector3f. 0 -20 0)
rlm@78 335 :color ColorRGBA/Gray :mass 0)
rlm@78 336 a (.getControl top RigidBodyControl)
rlm@78 337 b (.getControl bottom RigidBodyControl)]
rlm@83 338
rlm@78 339 (cond
rlm@83 340 (= joint :cone)
rlm@83 341
rlm@83 342 (doto (ConeJoint.
rlm@83 343 a b
rlm@87 344 (world-to-local top joint-position)
rlm@87 345 (world-to-local bottom joint-position)
rlm@83 346 joint-rotation
rlm@83 347 joint-rotation
rlm@83 348 )
rlm@78 349
rlm@83 350
rlm@83 351 (.setLimit (* (/ 10) Math/PI)
rlm@83 352 (* (/ 4) Math/PI)
rlm@83 353 0)))
rlm@83 354 [origin top bottom table]))
rlm@78 355
rlm@78 356
rlm@78 357
rlm@78 358 (defn test-joint [joint]
rlm@83 359 (let [[origin top bottom floor] (world-setup joint)
rlm@78 360 control (.getControl top RigidBodyControl)
rlm@78 361 move-up? (atom false)
rlm@78 362 move-down? (atom false)
rlm@78 363 move-left? (atom false)
rlm@78 364 move-right? (atom false)
rlm@78 365 roll-left? (atom false)
rlm@78 366 roll-right? (atom false)
rlm@78 367 timer (atom 0)]
rlm@78 368
rlm@78 369 (world
rlm@83 370 (nodify [top bottom floor origin])
rlm@78 371 (merge standard-debug-controls
rlm@78 372 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@78 373 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@78 374 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@78 375 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@78 376 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@78 377 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@78 378
rlm@78 379 (fn [world]
rlm@78 380 (light-up-everything world)
rlm@78 381 (enable-debug world)
rlm@78 382 (set-gravity world (Vector3f. 0 0 0))
rlm@78 383 )
rlm@78 384
rlm@78 385 (fn [world _]
rlm@78 386 (if (zero? (rem (swap! timer inc) 100))
rlm@78 387 (do
rlm@78 388 ;; (println-repl @timer)
rlm@78 389 (.attachChild (.getRootNode world)
rlm@78 390 (sphere 0.05 :color ColorRGBA/Yellow
rlm@78 391 :position (.getWorldTranslation top)
rlm@83 392 :physical? false))
rlm@83 393 (.attachChild (.getRootNode world)
rlm@83 394 (sphere 0.05 :color ColorRGBA/LightGray
rlm@83 395 :position (.getWorldTranslation bottom)
rlm@83 396 :physical? false))))
rlm@83 397
rlm@78 398 (if @move-up?
rlm@78 399 (.applyTorque control
rlm@78 400 (.mult (.getPhysicsRotation control)
rlm@78 401 (Vector3f. 0 0 10))))
rlm@78 402 (if @move-down?
rlm@78 403 (.applyTorque control
rlm@78 404 (.mult (.getPhysicsRotation control)
rlm@78 405 (Vector3f. 0 0 -10))))
rlm@78 406 (if @move-left?
rlm@78 407 (.applyTorque control
rlm@78 408 (.mult (.getPhysicsRotation control)
rlm@78 409 (Vector3f. 0 10 0))))
rlm@78 410 (if @move-right?
rlm@78 411 (.applyTorque control
rlm@78 412 (.mult (.getPhysicsRotation control)
rlm@78 413 (Vector3f. 0 -10 0))))
rlm@78 414 (if @roll-left?
rlm@78 415 (.applyTorque control
rlm@78 416 (.mult (.getPhysicsRotation control)
rlm@78 417 (Vector3f. -1 0 0))))
rlm@78 418 (if @roll-right?
rlm@78 419 (.applyTorque control
rlm@78 420 (.mult (.getPhysicsRotation control)
rlm@78 421 (Vector3f. 1 0 0))))))))
rlm@83 422
rlm@83 423
rlm@83 424
rlm@87 425 #+end_src
rlm@83 426
rlm@87 427 #+results: body-1
rlm@87 428 : #'cortex.silly/test-joint
rlm@78 429
rlm@78 430
rlm@78 431 * COMMENT purgatory
rlm@78 432 #+begin_src clojure
rlm@77 433 (defn bullet-trans []
rlm@77 434 (let [obj-a (sphere 0.5 :color ColorRGBA/Red
rlm@77 435 :position (Vector3f. -10 5 0))
rlm@77 436 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 437 :position (Vector3f. -10 -5 0)
rlm@77 438 :mass 0)
rlm@77 439 control-a (.getControl obj-a RigidBodyControl)
rlm@77 440 control-b (.getControl obj-b RigidBodyControl)
rlm@77 441 swivel
rlm@77 442 (.toRotationMatrix
rlm@77 443 (doto (Quaternion.)
rlm@77 444 (.fromAngleAxis (/ Math/PI 2)
rlm@77 445 Vector3f/UNIT_X)))]
rlm@77 446 (doto
rlm@77 447 (ConeJoint.
rlm@77 448 control-a control-b
rlm@77 449 (Vector3f. 0 5 0)
rlm@77 450 (Vector3f. 0 -5 0)
rlm@77 451 swivel swivel)
rlm@77 452 (.setLimit (* 0.6 (/ Math/PI 4))
rlm@77 453 (/ Math/PI 4)
rlm@77 454 (* Math/PI 0.8)))
rlm@77 455 (world (nodify
rlm@77 456 [obj-a obj-b])
rlm@77 457 standard-debug-controls
rlm@77 458 enable-debug
rlm@77 459 no-op)))
rlm@74 460
rlm@74 461
rlm@77 462 (defn bullet-trans* []
rlm@77 463 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
rlm@77 464 :position (Vector3f. 5 0 0)
rlm@77 465 :mass 90)
rlm@77 466 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 467 :position (Vector3f. -5 0 0)
rlm@77 468 :mass 0)
rlm@77 469 control-a (.getControl obj-a RigidBodyControl)
rlm@77 470 control-b (.getControl obj-b RigidBodyControl)
rlm@77 471 move-up? (atom nil)
rlm@77 472 move-down? (atom nil)
rlm@77 473 move-left? (atom nil)
rlm@77 474 move-right? (atom nil)
rlm@77 475 roll-left? (atom nil)
rlm@77 476 roll-right? (atom nil)
rlm@77 477 force 100
rlm@77 478 swivel
rlm@77 479 (.toRotationMatrix
rlm@77 480 (doto (Quaternion.)
rlm@77 481 (.fromAngleAxis (/ Math/PI 2)
rlm@77 482 Vector3f/UNIT_X)))
rlm@77 483 x-move
rlm@77 484 (doto (Matrix3f.)
rlm@77 485 (.fromStartEndVectors Vector3f/UNIT_X
rlm@77 486 (.normalize (Vector3f. 1 1 0))))
rlm@77 487
rlm@77 488 timer (atom 0)]
rlm@77 489 (doto
rlm@77 490 (ConeJoint.
rlm@77 491 control-a control-b
rlm@77 492 (Vector3f. -8 0 0)
rlm@77 493 (Vector3f. 2 0 0)
rlm@77 494 ;;swivel swivel
rlm@77 495 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
rlm@77 496 x-move Matrix3f/IDENTITY
rlm@77 497 )
rlm@77 498 (.setCollisionBetweenLinkedBodys false)
rlm@77 499 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
rlm@77 500 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
rlm@77 501 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
rlm@77 502 (world (nodify
rlm@77 503 [obj-a obj-b])
rlm@77 504 (merge standard-debug-controls
rlm@77 505 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@77 506 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@77 507 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@77 508 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@77 509 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@77 510 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@77 511
rlm@77 512 (fn [world]
rlm@77 513 (enable-debug world)
rlm@77 514 (set-gravity world Vector3f/ZERO)
rlm@77 515 )
rlm@77 516
rlm@77 517 (fn [world _]
rlm@77 518
rlm@77 519 (if @move-up?
rlm@77 520 (.applyForce control-a
rlm@77 521 (Vector3f. force 0 0)
rlm@77 522 (Vector3f. 0 0 0)))
rlm@77 523 (if @move-down?
rlm@77 524 (.applyForce control-a
rlm@77 525 (Vector3f. (- force) 0 0)
rlm@77 526 (Vector3f. 0 0 0)))
rlm@77 527 (if @move-left?
rlm@77 528 (.applyForce control-a
rlm@77 529 (Vector3f. 0 force 0)
rlm@77 530 (Vector3f. 0 0 0)))
rlm@77 531 (if @move-right?
rlm@77 532 (.applyForce control-a
rlm@77 533 (Vector3f. 0 (- force) 0)
rlm@77 534 (Vector3f. 0 0 0)))
rlm@77 535
rlm@77 536 (if @roll-left?
rlm@77 537 (.applyForce control-a
rlm@77 538 (Vector3f. 0 0 force)
rlm@77 539 (Vector3f. 0 0 0)))
rlm@77 540 (if @roll-right?
rlm@77 541 (.applyForce control-a
rlm@77 542 (Vector3f. 0 0 (- force))
rlm@77 543 (Vector3f. 0 0 0)))
rlm@77 544
rlm@77 545 (if (zero? (rem (swap! timer inc) 100))
rlm@77 546 (.attachChild
rlm@77 547 (.getRootNode world)
rlm@77 548 (sphere 0.05 :color ColorRGBA/Yellow
rlm@77 549 :physical? false :position
rlm@77 550 (.getWorldTranslation obj-a)))))
rlm@77 551 )
rlm@77 552 ))
rlm@77 553
rlm@77 554
rlm@77 555
rlm@73 556 #+end_src
rlm@73 557
rlm@73 558
rlm@73 559 * COMMENT generate source
rlm@73 560 #+begin_src clojure :tangle ../src/cortex/silly.clj
rlm@73 561 <<body-1>>
rlm@73 562 #+end_src
rlm@73 563