annotate org/test-creature.org @ 79:01dbdb0d5500

offset cone joints achieved!
author Robert McIntyre <rlm@mit.edu>
date Wed, 04 Jan 2012 21:03:25 -0700
parents 77b506ac64f3
children 7af5ef686539
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@73 53 (defn load-blender-model
rlm@73 54 "Load a .blend file using an asset folder relative path."
rlm@73 55 [^String model]
rlm@73 56 (.loadModel
rlm@73 57 (doto (asset-manager)
rlm@73 58 (.registerLoader BlenderModelLoader (into-array String ["blend"])))
rlm@73 59 model))
rlm@73 60
rlm@74 61 (defn meta-data [blender-node key]
rlm@74 62 (if-let [data (.getUserData blender-node "properties")]
rlm@74 63 (.findValue data key)
rlm@74 64 nil))
rlm@73 65
rlm@78 66 (defn blender-to-jme
rlm@78 67 "Convert from Blender coordinates to JME coordinates"
rlm@78 68 [#^Vector3f in]
rlm@78 69 (Vector3f. (.getX in)
rlm@78 70 (.getZ in)
rlm@78 71 (- (.getY in))))
rlm@74 72
rlm@79 73 (defn jme-to-blender
rlm@79 74 "Convert from JME coordinates to Blender coordinates"
rlm@79 75 [#^Vector3f in]
rlm@79 76 (Vector3f. (.getX in)
rlm@79 77 (- (.getZ in))
rlm@79 78 (.getY in)))
rlm@79 79
rlm@78 80 (defn joint-targets
rlm@78 81 "Return the two closest two objects to the joint object, ordered
rlm@78 82 from bottom to top according to the joint's rotation."
rlm@78 83 [#^Node parts #^Node joint]
rlm@78 84 ;;(println (meta-data joint "joint"))
rlm@78 85 (.getWorldRotation joint)
rlm@78 86 (loop [radius (float 0.01)]
rlm@78 87 (let [results (CollisionResults.)]
rlm@78 88 (.collideWith
rlm@78 89 parts
rlm@78 90 (BoundingBox. (.getWorldTranslation joint)
rlm@78 91 radius radius radius)
rlm@78 92 results)
rlm@78 93 (let [targets
rlm@78 94 (distinct
rlm@78 95 (map #(.getGeometry %) results))]
rlm@78 96 (if (>= (count targets) 2)
rlm@78 97 (sort-by
rlm@79 98 #(let [v
rlm@79 99 (jme-to-blender
rlm@79 100 (.mult
rlm@79 101 (.inverse (.getWorldRotation joint))
rlm@79 102 (.subtract (.getWorldTranslation %)
rlm@79 103 (.getWorldTranslation joint))))]
rlm@79 104 (println-repl (.getName %) ":" v)
rlm@79 105 (.dot (Vector3f. 1 1 1)
rlm@79 106 v))
rlm@78 107 (take 2 targets))
rlm@78 108 (recur (float (* radius 2))))))))
rlm@74 109
rlm@78 110 (defn connect
rlm@78 111 "here are some examples:
rlm@78 112 {:type :point}
rlm@78 113 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)}
rlm@78 114 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
rlm@74 115
rlm@78 116 {:type :cone :limit-xz 0]
rlm@79 117 :limit-xy 0]
rlm@79 118 :twist 0]} (use XZY rotation mode in blender!)"
rlm@78 119 ([#^Node obj-a #^Node obj-b #^Node joint]
rlm@78 120 (let [center-a (.getWorldTranslation obj-a)
rlm@78 121 center-b (.getWorldTranslation obj-b)
rlm@78 122 joint-center (.getWorldTranslation joint)
rlm@78 123 pivot-a (.subtract joint-center center-a)
rlm@78 124 pivot-b (.subtract joint-center center-b)
rlm@78 125 control-a (.getControl obj-a RigidBodyControl)
rlm@78 126 control-b (.getControl obj-b RigidBodyControl)]
rlm@78 127 ;; A side-effect of creating a joint registers
rlm@78 128 ;; it with both physics objects which in turn
rlm@78 129 ;; will register the joint with the physics system
rlm@78 130 ;; when the simulation is started.
rlm@78 131 (if-let [constraints
rlm@78 132 (map-vals
rlm@78 133 eval
rlm@78 134 (read-string
rlm@78 135 (meta-data joint "joint")))]
rlm@74 136
rlm@78 137 (let [joint-type (:type constraints)]
rlm@78 138 (println-repl "creating joint between"
rlm@78 139 (.getName obj-a) "and" (.getName obj-b))
rlm@78 140 (cond (= :point joint-type)
rlm@78 141 (do
rlm@78 142 (println-repl "creating POINT joint")
rlm@78 143 (Point2PointJoint.
rlm@78 144 control-a
rlm@78 145 control-b
rlm@78 146 pivot-a
rlm@78 147 pivot-b))
rlm@78 148 (= :hinge joint-type)
rlm@78 149 (do
rlm@78 150 (println-repl "creating HINGE joint")
rlm@78 151 (let [axis (if-let
rlm@78 152 [axis (:axis constraints)]
rlm@78 153 axis
rlm@78 154 Vector3f/UNIT_X)
rlm@78 155 [limit-1 limit-2] (:limit constraints)
rlm@78 156 hinge-axis
rlm@78 157 (.mult
rlm@78 158 (.getWorldRotation joint)
rlm@78 159 (blender-to-jme axis))]
rlm@78 160 (doto
rlm@78 161 (HingeJoint.
rlm@78 162 control-a
rlm@78 163 control-b
rlm@78 164 pivot-a
rlm@78 165 pivot-b
rlm@78 166 hinge-axis
rlm@78 167 hinge-axis)
rlm@78 168 (.setLimit limit-1 limit-2))))
rlm@78 169 (= :cone joint-type)
rlm@78 170 (do
rlm@78 171 (let [limit-xy (:limit-xz constraints)
rlm@79 172 limit-yz (:limit-xy constraints)
rlm@78 173 twist (:twist constraints)]
rlm@78 174
rlm@78 175 (println-repl "creating CONE joint")
rlm@78 176 (doto
rlm@78 177 (ConeJoint.
rlm@78 178 control-a
rlm@78 179 control-b
rlm@78 180 pivot-a
rlm@78 181 pivot-b
rlm@79 182
rlm@78 183 (doto (Matrix3f.)
rlm@78 184 (.fromStartEndVectors
rlm@78 185 Vector3f/UNIT_X
rlm@78 186 (.normalize
rlm@78 187 (.subtract
rlm@79 188 (.getWorldTranslation joint)
rlm@79 189 (.getWorldTranslation obj-a)))))
rlm@79 190 (doto (Matrix3f.)
rlm@79 191 (.set (.getWorldRotation joint)))
rlm@79 192
rlm@79 193 )
rlm@78 194 (.setLimit (float limit-xy)
rlm@78 195 (float limit-yz)
rlm@78 196 (float twist)))))
rlm@78 197 true
rlm@78 198 (println-repl
rlm@78 199 "joint-type" joint-type "not recognized")))
rlm@78 200
rlm@78 201 (println-repl "could not find joint meta-data!")))))
rlm@74 202
rlm@78 203 (defn assemble-creature [#^Node pieces joints]
rlm@78 204 (dorun
rlm@78 205 (map
rlm@78 206 (fn [geom]
rlm@78 207 (let [physics-control
rlm@78 208 (RigidBodyControl.
rlm@78 209 (HullCollisionShape.
rlm@78 210 (.getMesh geom))
rlm@78 211 (if-let [mass (meta-data geom "mass")]
rlm@78 212 (do
rlm@78 213 (println-repl
rlm@78 214 "setting" (.getName geom) "mass to" (float mass))
rlm@78 215 (float mass))
rlm@78 216 (float 1)))]
rlm@78 217
rlm@78 218 (.addControl geom physics-control)))
rlm@78 219 (filter #(isa? (class %) Geometry )
rlm@78 220 (node-seq pieces))))
rlm@77 221
rlm@78 222 (dorun
rlm@78 223 (map
rlm@78 224 (fn [joint]
rlm@78 225 (let [[obj-a obj-b]
rlm@78 226 (joint-targets pieces joint)]
rlm@78 227 (connect obj-a obj-b joint)))
rlm@78 228 joints))
rlm@78 229 pieces)
rlm@74 230
rlm@78 231 (defn blender-creature [blender-path]
rlm@78 232 (let [model (load-blender-model blender-path)
rlm@78 233 joints
rlm@78 234 (if-let [joint-node (.getChild model "joints")]
rlm@78 235 (seq (.getChildren joint-node))
rlm@78 236 (do (println-repl "could not find joints node")
rlm@78 237 []))]
rlm@78 238 (assemble-creature model joints)))
rlm@74 239
rlm@78 240 (def hand "Models/creature1/one.blend")
rlm@74 241
rlm@78 242 (def worm "Models/creature1/try-again.blend")
rlm@78 243
rlm@78 244 (defn test-creature [thing]
rlm@78 245 (world
rlm@78 246 (nodify [(blender-creature thing)
rlm@78 247 (box 10 2 10 :position (Vector3f. 0 -5.5 0)
rlm@78 248 :color ColorRGBA/Gray :mass 0)])
rlm@78 249 standard-debug-controls
rlm@78 250 (comp light-up-everything enable-debug
rlm@78 251 (fn [world]
rlm@78 252 (.setTimer world (NanoTimer.))
rlm@78 253 ;;(set-gravity world (Vector3f. 0 0 0))
rlm@78 254 (speed-up world)
rlm@78 255 world
rlm@78 256 ))
rlm@78 257 no-op))
rlm@78 258
rlm@78 259 (defn world-setup [joint]
rlm@78 260 (let [top (doto
rlm@78 261 (sphere 0.1 :physical? false :color ColorRGBA/Yellow
rlm@78 262 :position (Vector3f. 0 7 0))
rlm@78 263 (.addControl
rlm@78 264 (RigidBodyControl.
rlm@78 265 (CapsuleCollisionShape. 0.5 1.5 1) (float 15))))
rlm@78 266 bottom (doto
rlm@78 267 (sphere 0.1 :physical? false :color ColorRGBA/DarkGray
rlm@78 268 :position (Vector3f. 0 -1 0))
rlm@78 269 (.addControl
rlm@78 270 (RigidBodyControl.
rlm@78 271 (CapsuleCollisionShape. 0.5 1.5 1) (float 0))))
rlm@78 272 table (box 10 2 10 :position (Vector3f. 0 -6 0)
rlm@78 273 :color ColorRGBA/Gray :mass 0)
rlm@78 274 a (.getControl top RigidBodyControl)
rlm@78 275 b (.getControl bottom RigidBodyControl)]
rlm@78 276 (cond
rlm@78 277 (= joint :point)
rlm@78 278 (doto
rlm@78 279 (Point2PointJoint. a b
rlm@78 280 (Vector3f. 0 -2 0)
rlm@78 281 (Vector3f. 0 2 0))
rlm@78 282 (.setCollisionBetweenLinkedBodys false))
rlm@78 283 (= joint :hinge)
rlm@78 284 (doto
rlm@78 285 (HingeJoint.
rlm@78 286 a b
rlm@78 287 (Vector3f. 0 -2 0)
rlm@78 288 (Vector3f. 0 2 0)
rlm@78 289 (Vector3f. 0 0 1)
rlm@78 290 (Vector3f. 0 0 1)
rlm@78 291
rlm@78 292 )
rlm@78 293 (.setCollisionBetweenLinkedBodys false)
rlm@78 294 ;;(.setLimit (- Math/PI) Math/PI)
rlm@78 295 )
rlm@78 296 (= joint :cone)
rlm@78 297 ;; note to self -- jbullet does NOT implement cone joints
rlm@78 298 ;; correctly. You must use plain ol' bullet for this to work.
rlm@78 299 ;; It's faster anyway, so whatever.
rlm@78 300
rlm@78 301 (doto (ConeJoint.
rlm@78 302 a b
rlm@78 303 (Vector3f. 0 -5 0)
rlm@78 304 (Vector3f. 0 2 0)
rlm@78 305
rlm@78 306 (doto (Matrix3f.)
rlm@78 307 (.fromStartEndVectors Vector3f/UNIT_X
rlm@78 308 Vector3f/UNIT_Y))
rlm@78 309 (doto (Matrix3f.)
rlm@78 310 (.fromStartEndVectors Vector3f/UNIT_X
rlm@78 311 (.normalize
rlm@78 312 (Vector3f. 5 5 0))))
rlm@78 313 )
rlm@78 314 ;;(.setAngularOnly true)
rlm@78 315
rlm@78 316 (.setCollisionBetweenLinkedBodys false)
rlm@78 317 (.setLimit (* 1 (/ Math/PI 4))
rlm@78 318 (* 1 (/ Math/PI 2))
rlm@78 319 (* 0 (/ Math/PI 4)))
rlm@78 320
rlm@78 321 )
rlm@78 322 (= joint :six)
rlm@78 323 (doto
rlm@78 324 (SixDofJoint.
rlm@78 325 a b
rlm@78 326 (Vector3f. 0 -2 0)
rlm@78 327 (Vector3f. 0 2 0)
rlm@78 328 ;;(doto (Matrix3f.)
rlm@78 329 ;; (.fromStartEndVectors Vector3f/UNIT_X
rlm@78 330 ;; Vector3f/UNIT_Y))
rlm@78 331 ;;(doto (Matrix3f.)
rlm@78 332 ;; (.fromStartEndVectors Vector3f/UNIT_X
rlm@78 333 ;; Vector3f/UNIT_Y))
rlm@78 334 true)
rlm@78 335 (.setCollisionBetweenLinkedBodys false)
rlm@78 336 (.setAngularLowerLimit (Vector3f. 0
rlm@78 337 (- (/ Math/PI 2))
rlm@78 338 0))
rlm@78 339
rlm@78 340 (.setAngularUpperLimit (Vector3f. 0
rlm@78 341 (/ Math/PI 2)
rlm@78 342 0))
rlm@78 343 (.setLinearLowerLimit (Vector3f. 0 0 0))
rlm@78 344 (.setLinearUpperLimit (Vector3f. 0 0 0))
rlm@78 345
rlm@78 346 )
rlm@78 347
rlm@78 348
rlm@78 349
rlm@78 350
rlm@78 351
rlm@78 352 )
rlm@78 353
rlm@78 354 [top bottom table]))
rlm@78 355
rlm@78 356
rlm@78 357 (defn test-joint [joint]
rlm@78 358 (let [[top bottom floor] (world-setup joint)
rlm@78 359 control (.getControl top RigidBodyControl)
rlm@78 360 move-up? (atom false)
rlm@78 361 move-down? (atom false)
rlm@78 362 move-left? (atom false)
rlm@78 363 move-right? (atom false)
rlm@78 364 roll-left? (atom false)
rlm@78 365 roll-right? (atom false)
rlm@78 366 timer (atom 0)]
rlm@78 367
rlm@78 368 (world
rlm@78 369 (nodify [top bottom floor])
rlm@78 370 (merge standard-debug-controls
rlm@78 371 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@78 372 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@78 373 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@78 374 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@78 375 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@78 376 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@78 377
rlm@78 378 (fn [world]
rlm@78 379 (light-up-everything world)
rlm@78 380 (enable-debug world)
rlm@78 381 (set-gravity world (Vector3f. 0 0 0))
rlm@78 382 )
rlm@78 383
rlm@78 384 (fn [world _]
rlm@78 385 (if (zero? (rem (swap! timer inc) 100))
rlm@78 386 (do
rlm@78 387 ;; (println-repl @timer)
rlm@78 388 (.attachChild (.getRootNode world)
rlm@78 389 (sphere 0.05 :color ColorRGBA/Yellow
rlm@78 390 :position (.getWorldTranslation top)
rlm@78 391 :physical? false))))
rlm@78 392 (if @move-up?
rlm@78 393 (.applyTorque control
rlm@78 394 (.mult (.getPhysicsRotation control)
rlm@78 395 (Vector3f. 0 0 10))))
rlm@78 396 (if @move-down?
rlm@78 397 (.applyTorque control
rlm@78 398 (.mult (.getPhysicsRotation control)
rlm@78 399 (Vector3f. 0 0 -10))))
rlm@78 400 (if @move-left?
rlm@78 401 (.applyTorque control
rlm@78 402 (.mult (.getPhysicsRotation control)
rlm@78 403 (Vector3f. 0 10 0))))
rlm@78 404 (if @move-right?
rlm@78 405 (.applyTorque control
rlm@78 406 (.mult (.getPhysicsRotation control)
rlm@78 407 (Vector3f. 0 -10 0))))
rlm@78 408 (if @roll-left?
rlm@78 409 (.applyTorque control
rlm@78 410 (.mult (.getPhysicsRotation control)
rlm@78 411 (Vector3f. -1 0 0))))
rlm@78 412 (if @roll-right?
rlm@78 413 (.applyTorque control
rlm@78 414 (.mult (.getPhysicsRotation control)
rlm@78 415 (Vector3f. 1 0 0))))))))
rlm@78 416 #+end_src
rlm@78 417
rlm@78 418
rlm@78 419 * COMMENT purgatory
rlm@78 420 #+begin_src clojure
rlm@77 421 (defn bullet-trans []
rlm@77 422 (let [obj-a (sphere 0.5 :color ColorRGBA/Red
rlm@77 423 :position (Vector3f. -10 5 0))
rlm@77 424 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 425 :position (Vector3f. -10 -5 0)
rlm@77 426 :mass 0)
rlm@77 427 control-a (.getControl obj-a RigidBodyControl)
rlm@77 428 control-b (.getControl obj-b RigidBodyControl)
rlm@77 429 swivel
rlm@77 430 (.toRotationMatrix
rlm@77 431 (doto (Quaternion.)
rlm@77 432 (.fromAngleAxis (/ Math/PI 2)
rlm@77 433 Vector3f/UNIT_X)))]
rlm@77 434 (doto
rlm@77 435 (ConeJoint.
rlm@77 436 control-a control-b
rlm@77 437 (Vector3f. 0 5 0)
rlm@77 438 (Vector3f. 0 -5 0)
rlm@77 439 swivel swivel)
rlm@77 440 (.setLimit (* 0.6 (/ Math/PI 4))
rlm@77 441 (/ Math/PI 4)
rlm@77 442 (* Math/PI 0.8)))
rlm@77 443 (world (nodify
rlm@77 444 [obj-a obj-b])
rlm@77 445 standard-debug-controls
rlm@77 446 enable-debug
rlm@77 447 no-op)))
rlm@74 448
rlm@74 449
rlm@77 450 (defn bullet-trans* []
rlm@77 451 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
rlm@77 452 :position (Vector3f. 5 0 0)
rlm@77 453 :mass 90)
rlm@77 454 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 455 :position (Vector3f. -5 0 0)
rlm@77 456 :mass 0)
rlm@77 457 control-a (.getControl obj-a RigidBodyControl)
rlm@77 458 control-b (.getControl obj-b RigidBodyControl)
rlm@77 459 move-up? (atom nil)
rlm@77 460 move-down? (atom nil)
rlm@77 461 move-left? (atom nil)
rlm@77 462 move-right? (atom nil)
rlm@77 463 roll-left? (atom nil)
rlm@77 464 roll-right? (atom nil)
rlm@77 465 force 100
rlm@77 466 swivel
rlm@77 467 (.toRotationMatrix
rlm@77 468 (doto (Quaternion.)
rlm@77 469 (.fromAngleAxis (/ Math/PI 2)
rlm@77 470 Vector3f/UNIT_X)))
rlm@77 471 x-move
rlm@77 472 (doto (Matrix3f.)
rlm@77 473 (.fromStartEndVectors Vector3f/UNIT_X
rlm@77 474 (.normalize (Vector3f. 1 1 0))))
rlm@77 475
rlm@77 476 timer (atom 0)]
rlm@77 477 (doto
rlm@77 478 (ConeJoint.
rlm@77 479 control-a control-b
rlm@77 480 (Vector3f. -8 0 0)
rlm@77 481 (Vector3f. 2 0 0)
rlm@77 482 ;;swivel swivel
rlm@77 483 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
rlm@77 484 x-move Matrix3f/IDENTITY
rlm@77 485 )
rlm@77 486 (.setCollisionBetweenLinkedBodys false)
rlm@77 487 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
rlm@77 488 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
rlm@77 489 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
rlm@77 490 (world (nodify
rlm@77 491 [obj-a obj-b])
rlm@77 492 (merge standard-debug-controls
rlm@77 493 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@77 494 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@77 495 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@77 496 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@77 497 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@77 498 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@77 499
rlm@77 500 (fn [world]
rlm@77 501 (enable-debug world)
rlm@77 502 (set-gravity world Vector3f/ZERO)
rlm@77 503 )
rlm@77 504
rlm@77 505 (fn [world _]
rlm@77 506
rlm@77 507 (if @move-up?
rlm@77 508 (.applyForce control-a
rlm@77 509 (Vector3f. force 0 0)
rlm@77 510 (Vector3f. 0 0 0)))
rlm@77 511 (if @move-down?
rlm@77 512 (.applyForce control-a
rlm@77 513 (Vector3f. (- force) 0 0)
rlm@77 514 (Vector3f. 0 0 0)))
rlm@77 515 (if @move-left?
rlm@77 516 (.applyForce control-a
rlm@77 517 (Vector3f. 0 force 0)
rlm@77 518 (Vector3f. 0 0 0)))
rlm@77 519 (if @move-right?
rlm@77 520 (.applyForce control-a
rlm@77 521 (Vector3f. 0 (- force) 0)
rlm@77 522 (Vector3f. 0 0 0)))
rlm@77 523
rlm@77 524 (if @roll-left?
rlm@77 525 (.applyForce control-a
rlm@77 526 (Vector3f. 0 0 force)
rlm@77 527 (Vector3f. 0 0 0)))
rlm@77 528 (if @roll-right?
rlm@77 529 (.applyForce control-a
rlm@77 530 (Vector3f. 0 0 (- force))
rlm@77 531 (Vector3f. 0 0 0)))
rlm@77 532
rlm@77 533 (if (zero? (rem (swap! timer inc) 100))
rlm@77 534 (.attachChild
rlm@77 535 (.getRootNode world)
rlm@77 536 (sphere 0.05 :color ColorRGBA/Yellow
rlm@77 537 :physical? false :position
rlm@77 538 (.getWorldTranslation obj-a)))))
rlm@77 539 )
rlm@77 540 ))
rlm@77 541
rlm@77 542
rlm@77 543
rlm@73 544 #+end_src
rlm@73 545
rlm@73 546
rlm@73 547 * COMMENT generate source
rlm@73 548 #+begin_src clojure :tangle ../src/cortex/silly.clj
rlm@73 549 <<body-1>>
rlm@73 550 #+end_src
rlm@73 551