annotate org/test-creature.org @ 98:5b23961433e3

going to create bitmaps for touch sensing
author Robert McIntyre <rlm@mit.edu>
date Wed, 11 Jan 2012 21:30:26 -0700
parents 2ff8c7c4e64d
children b7a3ba5e879b
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@96 128 (defn local-to-world
rlm@96 129 "Convert the local coordinates into coordinates into world relative
rlm@96 130 coordinates"
rlm@96 131 [#^Spatial object local-coordinate]
rlm@96 132 (let [world-coordinate (Vector3f.)]
rlm@96 133 (.localToWorld object local-coordinate world-coordinate)
rlm@96 134 world-coordinate))
rlm@96 135
rlm@96 136
rlm@87 137 (defmulti joint-dispatch
rlm@87 138 "Translate blender pseudo-joints into real JME joints."
rlm@88 139 (fn [constraints & _]
rlm@87 140 (:type constraints)))
rlm@87 141
rlm@87 142 (defmethod joint-dispatch :point
rlm@87 143 [constraints control-a control-b pivot-a pivot-b rotation]
rlm@87 144 (println-repl "creating POINT2POINT joint")
rlm@87 145 (Point2PointJoint.
rlm@87 146 control-a
rlm@87 147 control-b
rlm@87 148 pivot-a
rlm@87 149 pivot-b))
rlm@87 150
rlm@87 151 (defmethod joint-dispatch :hinge
rlm@87 152 [constraints control-a control-b pivot-a pivot-b rotation]
rlm@87 153 (println-repl "creating HINGE joint")
rlm@87 154 (let [axis
rlm@87 155 (if-let
rlm@87 156 [axis (:axis constraints)]
rlm@87 157 axis
rlm@87 158 Vector3f/UNIT_X)
rlm@87 159 [limit-1 limit-2] (:limit constraints)
rlm@87 160 hinge-axis
rlm@87 161 (.mult
rlm@87 162 rotation
rlm@87 163 (blender-to-jme axis))]
rlm@87 164 (doto
rlm@87 165 (HingeJoint.
rlm@87 166 control-a
rlm@87 167 control-b
rlm@87 168 pivot-a
rlm@87 169 pivot-b
rlm@87 170 hinge-axis
rlm@87 171 hinge-axis)
rlm@87 172 (.setLimit limit-1 limit-2))))
rlm@87 173
rlm@87 174 (defmethod joint-dispatch :cone
rlm@87 175 [constraints control-a control-b pivot-a pivot-b rotation]
rlm@87 176 (let [limit-xz (:limit-xz constraints)
rlm@87 177 limit-xy (:limit-xy constraints)
rlm@87 178 twist (:twist constraints)]
rlm@87 179
rlm@87 180 (println-repl "creating CONE joint")
rlm@87 181 (println-repl rotation)
rlm@87 182 (println-repl
rlm@87 183 "UNIT_X --> " (.mult rotation (Vector3f. 1 0 0)))
rlm@87 184 (println-repl
rlm@87 185 "UNIT_Y --> " (.mult rotation (Vector3f. 0 1 0)))
rlm@87 186 (println-repl
rlm@87 187 "UNIT_Z --> " (.mult rotation (Vector3f. 0 0 1)))
rlm@87 188 (doto
rlm@87 189 (ConeJoint.
rlm@87 190 control-a
rlm@87 191 control-b
rlm@87 192 pivot-a
rlm@87 193 pivot-b
rlm@87 194 rotation
rlm@87 195 rotation)
rlm@87 196 (.setLimit (float limit-xz)
rlm@87 197 (float limit-xy)
rlm@87 198 (float twist)))))
rlm@87 199
rlm@88 200 (defn connect
rlm@87 201 "here are some examples:
rlm@87 202 {:type :point}
rlm@87 203 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)}
rlm@87 204 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
rlm@87 205
rlm@89 206 {:type :cone :limit-xz 0]
rlm@89 207 :limit-xy 0]
rlm@89 208 :twist 0]} (use XZY rotation mode in blender!)"
rlm@87 209 [#^Node obj-a #^Node obj-b #^Node joint]
rlm@87 210 (let [control-a (.getControl obj-a RigidBodyControl)
rlm@87 211 control-b (.getControl obj-b RigidBodyControl)
rlm@87 212 joint-center (.getWorldTranslation joint)
rlm@87 213 joint-rotation (.toRotationMatrix (.getWorldRotation joint))
rlm@87 214 pivot-a (world-to-local obj-a joint-center)
rlm@87 215 pivot-b (world-to-local obj-b joint-center)]
rlm@89 216
rlm@87 217 (if-let [constraints
rlm@87 218 (map-vals
rlm@87 219 eval
rlm@87 220 (read-string
rlm@87 221 (meta-data joint "joint")))]
rlm@89 222 ;; A side-effect of creating a joint registers
rlm@89 223 ;; it with both physics objects which in turn
rlm@89 224 ;; will register the joint with the physics system
rlm@89 225 ;; when the simulation is started.
rlm@87 226 (do
rlm@87 227 (println-repl "creating joint between"
rlm@87 228 (.getName obj-a) "and" (.getName obj-b))
rlm@87 229 (joint-dispatch constraints
rlm@87 230 control-a control-b
rlm@87 231 pivot-a pivot-b
rlm@87 232 joint-rotation))
rlm@87 233 (println-repl "could not find joint meta-data!"))))
rlm@87 234
rlm@78 235 (defn assemble-creature [#^Node pieces joints]
rlm@78 236 (dorun
rlm@78 237 (map
rlm@78 238 (fn [geom]
rlm@78 239 (let [physics-control
rlm@78 240 (RigidBodyControl.
rlm@78 241 (HullCollisionShape.
rlm@78 242 (.getMesh geom))
rlm@78 243 (if-let [mass (meta-data geom "mass")]
rlm@78 244 (do
rlm@78 245 (println-repl
rlm@78 246 "setting" (.getName geom) "mass to" (float mass))
rlm@78 247 (float mass))
rlm@78 248 (float 1)))]
rlm@78 249
rlm@78 250 (.addControl geom physics-control)))
rlm@78 251 (filter #(isa? (class %) Geometry )
rlm@78 252 (node-seq pieces))))
rlm@78 253 (dorun
rlm@78 254 (map
rlm@78 255 (fn [joint]
rlm@78 256 (let [[obj-a obj-b]
rlm@78 257 (joint-targets pieces joint)]
rlm@88 258 (connect obj-a obj-b joint)))
rlm@78 259 joints))
rlm@78 260 pieces)
rlm@74 261
rlm@78 262 (defn blender-creature [blender-path]
rlm@78 263 (let [model (load-blender-model blender-path)
rlm@78 264 joints
rlm@78 265 (if-let [joint-node (.getChild model "joints")]
rlm@78 266 (seq (.getChildren joint-node))
rlm@78 267 (do (println-repl "could not find joints node")
rlm@78 268 []))]
rlm@78 269 (assemble-creature model joints)))
rlm@74 270
rlm@78 271 (def hand "Models/creature1/one.blend")
rlm@74 272
rlm@78 273 (def worm "Models/creature1/try-again.blend")
rlm@78 274
rlm@90 275 (def touch "Models/creature1/touch.blend")
rlm@90 276
rlm@90 277 (defn worm-model [] (load-blender-model worm))
rlm@90 278
rlm@80 279 (defn x-ray [#^ColorRGBA color]
rlm@80 280 (doto (Material. (asset-manager)
rlm@80 281 "Common/MatDefs/Misc/Unshaded.j3md")
rlm@80 282 (.setColor "Color" color)
rlm@80 283 (-> (.getAdditionalRenderState)
rlm@80 284 (.setDepthTest false))))
rlm@80 285
rlm@78 286 (defn test-creature [thing]
rlm@80 287 (let [x-axis
rlm@80 288 (box 1 0.01 0.01 :physical? false :color ColorRGBA/Red)
rlm@80 289 y-axis
rlm@80 290 (box 0.01 1 0.01 :physical? false :color ColorRGBA/Green)
rlm@80 291 z-axis
rlm@80 292 (box 0.01 0.01 1 :physical? false :color ColorRGBA/Blue)]
rlm@78 293 (world
rlm@78 294 (nodify [(blender-creature thing)
rlm@81 295 (box 10 2 10 :position (Vector3f. 0 -9 0)
rlm@80 296 :color ColorRGBA/Gray :mass 0)
rlm@80 297 x-axis y-axis z-axis
rlm@80 298 ])
rlm@78 299 standard-debug-controls
rlm@90 300 (fn [world]
rlm@90 301 (light-up-everything world)
rlm@90 302 (enable-debug world)
rlm@90 303 ;;(com.aurellem.capture.Capture/captureVideo
rlm@90 304 ;; world (file-str "/home/r/proj/ai-videos/hand"))
rlm@90 305 (.setTimer world (NanoTimer.))
rlm@93 306 (set-gravity world (Vector3f. 0 0 0))
rlm@90 307 (speed-up world)
rlm@90 308 )
rlm@90 309 no-op
rlm@90 310 ;;(let [timer (atom 0)]
rlm@90 311 ;; (fn [_ _]
rlm@90 312 ;; (swap! timer inc)
rlm@90 313 ;; (if (= (rem @timer 60) 0)
rlm@90 314 ;; (println-repl (float (/ @timer 60))))))
rlm@90 315 )))
rlm@90 316
rlm@90 317
rlm@91 318 (defn colorful []
rlm@91 319 (.getChild (worm-model) "worm-21"))
rlm@90 320
rlm@90 321 (import jme3tools.converters.ImageToAwt)
rlm@90 322
rlm@90 323 (import ij.ImagePlus)
rlm@90 324
rlm@90 325 (defn triangle-indices
rlm@90 326 "Get the triangle vertex indices of a given triangle from a given
rlm@90 327 mesh."
rlm@90 328 [#^Mesh mesh triangle-index]
rlm@90 329 (let [indices (int-array 3)]
rlm@90 330 (.getTriangle mesh triangle-index indices)
rlm@90 331 (vec indices)))
rlm@90 332
rlm@90 333 (defn uv-coord
rlm@90 334 "Get the uv-coordinates of the vertex named by vertex-index"
rlm@90 335 [#^Mesh mesh vertex-index]
rlm@90 336 (let [UV-buffer
rlm@90 337 (.getData
rlm@90 338 (.getBuffer
rlm@90 339 mesh
rlm@90 340 VertexBuffer$Type/TexCoord))]
rlm@91 341 (Vector2f.
rlm@91 342 (.get UV-buffer (* vertex-index 2))
rlm@91 343 (.get UV-buffer (+ 1 (* vertex-index 2))))))
rlm@90 344
rlm@93 345 (defn tri-uv-coord
rlm@93 346 "Get the uv-cooridnates of the triangle's verticies."
rlm@93 347 [#^Mesh mesh #^Triangle triangle]
rlm@93 348 (map (partial uv-coord mesh)
rlm@93 349 (triangle-indices mesh (.getIndex triangle))))
rlm@93 350
rlm@91 351 (defn touch-receptor-image
rlm@97 352 "Return the touch-sensor distribution image in ImagePlus format, or
rlm@97 353 nil if it does not exist."
rlm@91 354 [#^Geometry obj]
rlm@97 355 (let [mat (.getMaterial obj)]
rlm@97 356 (if-let [texture-param
rlm@97 357 (.getTextureParam
rlm@97 358 mat
rlm@97 359 MaterialHelper/TEXTURE_TYPE_DIFFUSE)]
rlm@97 360 (let
rlm@97 361 [texture
rlm@97 362 (.getTextureValue texture-param)
rlm@97 363 im (.getImage texture)]
rlm@97 364 (ImagePlus.
rlm@97 365 "UV-map"
rlm@97 366 (ImageToAwt/convert im false false 0))))))
rlm@97 367
rlm@90 368
rlm@91 369
rlm@91 370 (import ij.process.ImageProcessor)
rlm@91 371 (import java.awt.image.BufferedImage)
rlm@91 372
rlm@91 373 (defprotocol Frame
rlm@91 374 (frame [this]))
rlm@91 375
rlm@91 376 (extend-type BufferedImage
rlm@91 377 Frame
rlm@91 378 (frame [image]
rlm@91 379 (merge
rlm@91 380 (apply
rlm@91 381 hash-map
rlm@91 382 (interleave
rlm@91 383 (doall (for [x (range (.getWidth image)) y (range (.getHeight image))]
rlm@91 384 (vector x y)))
rlm@91 385 (doall (for [x (range (.getWidth image)) y (range (.getHeight image))]
rlm@91 386 (let [data (.getRGB image x y)]
rlm@91 387 (hash-map :r (bit-shift-right (bit-and 0xff0000 data) 16)
rlm@91 388 :g (bit-shift-right (bit-and 0x00ff00 data) 8)
rlm@91 389 :b (bit-and 0x0000ff data)))))))
rlm@91 390 {:width (.getWidth image) :height (.getHeight image)})))
rlm@91 391
rlm@91 392
rlm@91 393 (extend-type ImagePlus
rlm@91 394 Frame
rlm@91 395 (frame [image+]
rlm@91 396 (frame (.getBufferedImage image+))))
rlm@91 397
rlm@94 398
rlm@92 399 (def white -1)
rlm@94 400
rlm@91 401 (defn filter-pixels
rlm@91 402 "List the coordinates of all pixels matching pred."
rlm@92 403 {:author "Dylan Holmes"}
rlm@91 404 [pred #^ImageProcessor ip]
rlm@91 405 (let
rlm@91 406 [width (.getWidth ip)
rlm@91 407 height (.getHeight ip)]
rlm@91 408 ((fn accumulate [x y matches]
rlm@91 409 (cond
rlm@91 410 (>= y height) matches
rlm@91 411 (>= x width) (recur 0 (inc y) matches)
rlm@91 412 (pred (.getPixel ip x y))
rlm@91 413 (recur (inc x) y (conj matches (Vector2f. x y)))
rlm@91 414 :else (recur (inc x) y matches)))
rlm@91 415 0 0 [])))
rlm@91 416
rlm@91 417 (defn white-coordinates
rlm@91 418 "List the coordinates of all the white pixels in an image."
rlm@91 419 [#^ImageProcessor ip]
rlm@92 420 (filter-pixels #(= % white) ip))
rlm@91 421
rlm@91 422 (defn same-side? [p1 p2 ref p]
rlm@91 423 (<=
rlm@91 424 0
rlm@91 425 (.dot
rlm@91 426 (.cross (.subtract p2 p1) (.subtract p p1))
rlm@91 427 (.cross (.subtract p2 p1) (.subtract ref p1)))))
rlm@91 428
rlm@94 429
rlm@94 430 (defn triangle->matrix4f
rlm@94 431 "Converts the triangle into a 4x4 matrix of vertices: The first
rlm@94 432 three columns contain the vertices of the triangle; the last
rlm@94 433 contains the unit normal of the triangle. The bottom row is filled
rlm@94 434 with 1s."
rlm@94 435 [#^Triangle t]
rlm@94 436 (let [mat (Matrix4f.)
rlm@94 437 [vert-1 vert-2 vert-3]
rlm@94 438 ((comp vec map) #(.get t %) (range 3))
rlm@94 439 unit-normal (do (.calculateNormal t)(.getNormal t))
rlm@94 440 vertices [vert-1 vert-2 vert-3 unit-normal]]
rlm@94 441
rlm@94 442 (dorun
rlm@94 443 (for [row (range 4) col (range 3)]
rlm@94 444 (do
rlm@94 445 (.set mat col row (.get (vertices row)col))
rlm@94 446 (.set mat 3 row 1))))
rlm@94 447 mat))
rlm@94 448
rlm@94 449 (defn triangle-transformation
rlm@94 450 "Returns the affine transformation that converts each vertex in the
rlm@94 451 first triangle into the corresponding vertex in the second
rlm@94 452 triangle."
rlm@94 453 [#^Triangle tri-1 #^Triangle tri-2]
rlm@94 454 (.mult
rlm@94 455 (triangle->matrix4f tri-2)
rlm@94 456 (.invert (triangle->matrix4f tri-1))))
rlm@94 457
rlm@94 458 (def death (Triangle.
rlm@94 459 (Vector3f. 1 1 1)
rlm@94 460 (Vector3f. 1 2 3)
rlm@94 461 (Vector3f. 5 6 7)))
rlm@94 462
rlm@94 463 (def death-2 (Triangle.
rlm@94 464 (Vector3f. 2 2 2)
rlm@94 465 (Vector3f. 1 1 1)
rlm@94 466 (Vector3f. 0 1 0)))
rlm@94 467
rlm@94 468 (defn vector2f->vector3f [v]
rlm@94 469 (Vector3f. (.getX v) (.getY v) 0))
rlm@94 470
rlm@94 471
rlm@94 472 (extend-type Triangle
rlm@94 473 Textual
rlm@94 474 (text [t]
rlm@94 475 (println "Triangle: " \newline (.get1 t) \newline
rlm@94 476 (.get2 t) \newline (.get3 t))))
rlm@94 477
rlm@94 478
rlm@94 479 (defn map-triangle [f #^Triangle tri]
rlm@94 480 (Triangle.
rlm@94 481 (f 0 (.get1 tri))
rlm@94 482 (f 1 (.get2 tri))
rlm@94 483 (f 2 (.get3 tri))))
rlm@94 484
rlm@94 485 (defn triangle-seq [#^Triangle tri]
rlm@94 486 [(.get1 tri) (.get2 tri) (.get3 tri)])
rlm@94 487
rlm@94 488 (defn vector3f-seq [#^Vector3f v]
rlm@94 489 [(.getX v) (.getY v) (.getZ v)])
rlm@94 490
rlm@91 491 (defn inside-triangle?
rlm@94 492 "Is the point inside the triangle? Now what do we do?
rlm@94 493 You might want to hold on there"
rlm@95 494 {:author "Dylan Holmes"}
rlm@94 495 [tri p]
rlm@94 496 (let [[vert-1 vert-2 vert-3] (triangle-seq tri)]
rlm@94 497 (and
rlm@94 498 (same-side? vert-1 vert-2 vert-3 p)
rlm@94 499 (same-side? vert-2 vert-3 vert-1 p)
rlm@94 500 (same-side? vert-3 vert-1 vert-2 p))))
rlm@91 501
rlm@94 502 (defn uv-triangle
rlm@94 503 "Convert the mesh triangle into the cooresponding triangle in
rlm@94 504 UV-space. Z-component of these triangles is always zero."
rlm@94 505 [#^Mesh mesh #^Triangle tri]
rlm@94 506 (apply #(Triangle. %1 %2 %3)
rlm@94 507 (map vector2f->vector3f
rlm@94 508 (tri-uv-coord mesh tri))))
rlm@91 509
rlm@94 510 (defn pixel-triangle
rlm@94 511 "Convert the mesh triange into the corresponding triangle in
rlm@94 512 UV-pixel-space. Z compenent will be zero."
rlm@94 513 [#^Mesh mesh #^Triangle tri width height]
rlm@94 514 (map-triangle (fn [_ v]
rlm@94 515 (Vector3f. (* width (.getX v))
rlm@94 516 (* height (.getY v))
rlm@94 517 0))
rlm@94 518 (uv-triangle mesh tri)))
rlm@93 519
rlm@96 520 (def rasterize pixel-triangle)
rlm@96 521
rlm@96 522
rlm@94 523 (defn triangle-bounds
rlm@94 524 "Dimensions of the bounding square of the triangle in the form
rlm@94 525 [x y width height].
rlm@94 526 Assumes that the triangle lies in the XY plane."
rlm@94 527 [#^Triangle tri]
rlm@94 528 (let [verts (map vector3f-seq (triangle-seq tri))
rlm@94 529 x (apply min (map first verts))
rlm@94 530 y (apply min (map second verts))]
rlm@93 531
rlm@94 532 [x y
rlm@94 533 (- (apply max (map first verts)) x)
rlm@94 534 (- (apply max (map second verts)) y)
rlm@94 535 ]))
rlm@93 536
rlm@93 537
rlm@97 538 (defn locate-feelers
rlm@94 539 "Search the geometry's tactile UV image for touch sensors, returning
rlm@94 540 their positions in geometry-relative coordinates."
rlm@94 541 [#^Geometry geo]
rlm@97 542 (if-let [image (touch-receptor-image geo)]
rlm@97 543 (let [mesh (.getMesh geo)
rlm@97 544 tris (triangles geo)
rlm@97 545
rlm@97 546
rlm@97 547 width (.getWidth image)
rlm@97 548 height (.getHeight image)
rlm@97 549
rlm@97 550 ;; for each triangle
rlm@97 551 sensor-coords
rlm@97 552 (fn [tri]
rlm@97 553 ;; translate triangle to uv-pixel-space
rlm@97 554 (let [uv-tri
rlm@97 555 (pixel-triangle mesh tri width height)
rlm@97 556 bounds (vec (triangle-bounds uv-tri))]
rlm@97 557
rlm@97 558 ;; get that part of the picture
rlm@97 559
rlm@97 560 (apply #(.setRoi image %1 %2 %3 %4) bounds)
rlm@97 561 (let [cutout (.crop (.getProcessor image))
rlm@97 562 ;; extract white pixels inside triangle
rlm@97 563 cutout-tri
rlm@97 564 (map-triangle
rlm@97 565 (fn [_ v]
rlm@97 566 (.subtract
rlm@97 567 v
rlm@97 568 (Vector3f. (bounds 0) (bounds 1) (float 0))))
rlm@97 569 uv-tri)
rlm@97 570 whites (filter (partial inside-triangle? cutout-tri)
rlm@97 571 (map vector2f->vector3f
rlm@97 572 (white-coordinates cutout)))
rlm@97 573 ;; translate pixel coordinates to world-space
rlm@97 574 transform (triangle-transformation cutout-tri tri)]
rlm@97 575 (map #(.mult transform %) whites))))]
rlm@97 576 (vec (map sensor-coords tris)))
rlm@97 577 (repeat (count (triangles geo)) [])))
rlm@97 578
rlm@97 579 (defn enable-touch [#^Geometry geo]
rlm@97 580 (let [feeler-coords (locate-feelers geo)
rlm@96 581 tris (triangles geo)
rlm@97 582 limit 0.1]
rlm@97 583 (fn [node]
rlm@97 584 (let [sensor-origins
rlm@97 585 (map
rlm@97 586 #(map (partial local-to-world geo) %)
rlm@97 587 feeler-coords)
rlm@97 588 triangle-normals
rlm@97 589 (map (partial get-ray-direction geo)
rlm@97 590 tris)
rlm@97 591 rays
rlm@97 592 (flatten
rlm@97 593 (map (fn [origins norm]
rlm@97 594 (map #(doto (Ray. % norm)
rlm@97 595 (.setLimit limit)) origins))
rlm@97 596 sensor-origins triangle-normals))]
rlm@97 597 (for [ray rays]
rlm@97 598 (do
rlm@97 599 (let [results (CollisionResults.)]
rlm@97 600 (.collideWith node ray results)
rlm@97 601 (let [touch-objects
rlm@97 602 (set
rlm@97 603 (filter #(not (= geo %))
rlm@97 604 (map #(.getGeometry %) results)))]
rlm@97 605 (count touch-objects)))))))))
rlm@94 606
rlm@97 607 (defn touch [#^Node pieces]
rlm@97 608 (let [touch-components
rlm@97 609 (map enable-touch
rlm@97 610 (filter #(isa? (class %) Geometry)
rlm@97 611 (node-seq pieces)))]
rlm@97 612 (fn [node]
rlm@97 613 (reduce into [] (map #(% node) touch-components)))))
rlm@96 614
rlm@97 615
rlm@91 616
rlm@91 617
rlm@91 618
rlm@91 619
rlm@91 620 (defn all-names []
rlm@91 621 (concat
rlm@91 622 (re-split #"\n" (slurp (file-str
rlm@91 623 "/home/r/proj/names/dist.female.first")))
rlm@91 624 (re-split #"\n" (slurp (file-str
rlm@91 625 "/home/r/proj/names/dist.male.first")))
rlm@91 626 (re-split #"\n" (slurp (file-str
rlm@91 627 "/home/r/proj/names/dist.all.last")))))
rlm@90 628
rlm@90 629
rlm@90 630
rlm@90 631
rlm@90 632
rlm@90 633
rlm@90 634
rlm@90 635
rlm@90 636
rlm@90 637 (defrecord LulzLoader [])
rlm@90 638 (defprotocol Lulzable (load-lulz [this]))
rlm@90 639 (extend-type LulzLoader
rlm@90 640 Lulzable
rlm@90 641 (load-lulz [this] (println "the lulz have arrived!")))
rlm@90 642
rlm@78 643
rlm@78 644 (defn world-setup [joint]
rlm@90 645 (let [joint-position (Vector3f. 0 0 0)
rlm@83 646 joint-rotation
rlm@83 647 (.toRotationMatrix
rlm@83 648 (.mult
rlm@83 649 (doto (Quaternion.)
rlm@83 650 (.fromAngleAxis
rlm@83 651 (* 1 (/ Math/PI 4))
rlm@85 652 (Vector3f. -1 0 0)))
rlm@85 653 (doto (Quaternion.)
rlm@85 654 (.fromAngleAxis
rlm@85 655 (* 1 (/ Math/PI 2))
rlm@85 656 (Vector3f. 0 0 1)))))
rlm@84 657 top-position (.mult joint-rotation (Vector3f. 8 0 0))
rlm@83 658
rlm@83 659 origin (doto
rlm@83 660 (sphere 0.1 :physical? false :color ColorRGBA/Cyan
rlm@84 661 :position top-position))
rlm@83 662 top (doto
rlm@78 663 (sphere 0.1 :physical? false :color ColorRGBA/Yellow
rlm@84 664 :position top-position)
rlm@83 665
rlm@78 666 (.addControl
rlm@78 667 (RigidBodyControl.
rlm@83 668 (CapsuleCollisionShape. 0.5 1.5 1) (float 20))))
rlm@78 669 bottom (doto
rlm@78 670 (sphere 0.1 :physical? false :color ColorRGBA/DarkGray
rlm@83 671 :position (Vector3f. 0 0 0))
rlm@83 672 (.addControl
rlm@78 673 (RigidBodyControl.
rlm@78 674 (CapsuleCollisionShape. 0.5 1.5 1) (float 0))))
rlm@83 675 table (box 10 2 10 :position (Vector3f. 0 -20 0)
rlm@78 676 :color ColorRGBA/Gray :mass 0)
rlm@78 677 a (.getControl top RigidBodyControl)
rlm@78 678 b (.getControl bottom RigidBodyControl)]
rlm@83 679
rlm@78 680 (cond
rlm@83 681 (= joint :cone)
rlm@83 682
rlm@83 683 (doto (ConeJoint.
rlm@83 684 a b
rlm@87 685 (world-to-local top joint-position)
rlm@87 686 (world-to-local bottom joint-position)
rlm@83 687 joint-rotation
rlm@83 688 joint-rotation
rlm@83 689 )
rlm@78 690
rlm@83 691
rlm@83 692 (.setLimit (* (/ 10) Math/PI)
rlm@83 693 (* (/ 4) Math/PI)
rlm@83 694 0)))
rlm@83 695 [origin top bottom table]))
rlm@78 696
rlm@78 697 (defn test-joint [joint]
rlm@83 698 (let [[origin top bottom floor] (world-setup joint)
rlm@78 699 control (.getControl top RigidBodyControl)
rlm@78 700 move-up? (atom false)
rlm@78 701 move-down? (atom false)
rlm@78 702 move-left? (atom false)
rlm@78 703 move-right? (atom false)
rlm@78 704 roll-left? (atom false)
rlm@78 705 roll-right? (atom false)
rlm@78 706 timer (atom 0)]
rlm@78 707
rlm@78 708 (world
rlm@83 709 (nodify [top bottom floor origin])
rlm@78 710 (merge standard-debug-controls
rlm@78 711 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@78 712 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@78 713 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@78 714 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@78 715 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@78 716 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@78 717
rlm@78 718 (fn [world]
rlm@78 719 (light-up-everything world)
rlm@78 720 (enable-debug world)
rlm@78 721 (set-gravity world (Vector3f. 0 0 0))
rlm@78 722 )
rlm@78 723
rlm@78 724 (fn [world _]
rlm@78 725 (if (zero? (rem (swap! timer inc) 100))
rlm@78 726 (do
rlm@78 727 ;; (println-repl @timer)
rlm@78 728 (.attachChild (.getRootNode world)
rlm@78 729 (sphere 0.05 :color ColorRGBA/Yellow
rlm@78 730 :position (.getWorldTranslation top)
rlm@83 731 :physical? false))
rlm@83 732 (.attachChild (.getRootNode world)
rlm@83 733 (sphere 0.05 :color ColorRGBA/LightGray
rlm@83 734 :position (.getWorldTranslation bottom)
rlm@83 735 :physical? false))))
rlm@83 736
rlm@78 737 (if @move-up?
rlm@78 738 (.applyTorque control
rlm@78 739 (.mult (.getPhysicsRotation control)
rlm@78 740 (Vector3f. 0 0 10))))
rlm@78 741 (if @move-down?
rlm@78 742 (.applyTorque control
rlm@78 743 (.mult (.getPhysicsRotation control)
rlm@78 744 (Vector3f. 0 0 -10))))
rlm@78 745 (if @move-left?
rlm@78 746 (.applyTorque control
rlm@78 747 (.mult (.getPhysicsRotation control)
rlm@78 748 (Vector3f. 0 10 0))))
rlm@78 749 (if @move-right?
rlm@78 750 (.applyTorque control
rlm@78 751 (.mult (.getPhysicsRotation control)
rlm@78 752 (Vector3f. 0 -10 0))))
rlm@78 753 (if @roll-left?
rlm@78 754 (.applyTorque control
rlm@78 755 (.mult (.getPhysicsRotation control)
rlm@78 756 (Vector3f. -1 0 0))))
rlm@78 757 (if @roll-right?
rlm@78 758 (.applyTorque control
rlm@78 759 (.mult (.getPhysicsRotation control)
rlm@78 760 (Vector3f. 1 0 0))))))))
rlm@83 761
rlm@83 762
rlm@97 763 (defn locate-feelers*
rlm@97 764 "Search the geometry's tactile UV image for touch sensors, returning
rlm@97 765 their positions in geometry-relative coordinates."
rlm@97 766 [#^Geometry geo]
rlm@97 767 (let [uv-image (touch-receptor-image geo)
rlm@97 768 width (.getWidth uv-image)
rlm@97 769 height (.getHeight uv-image)
rlm@97 770
rlm@97 771 mesh (.getMesh geo)
rlm@97 772 mesh-tris (triangles geo)
rlm@97 773
rlm@97 774 ;; for each triangle
rlm@97 775 sensor-coords
rlm@97 776 (fn [tri]
rlm@97 777 ;; translate triangle to uv-pixel-space
rlm@97 778 (let [uv-tri
rlm@97 779 (rasterize mesh tri width height)
rlm@97 780 bounds (vec (triangle-bounds uv-tri))]
rlm@97 781
rlm@97 782 ;; get that part of the picture
rlm@97 783
rlm@97 784 (apply (partial (memfn setRoi) uv-image) bounds)
rlm@97 785 (let [cutout (.crop (.getProcessor uv-image))
rlm@97 786 ;; extract white pixels inside triangle
rlm@97 787 cutout-tri
rlm@97 788 (map-triangle
rlm@97 789 (fn [_ v]
rlm@97 790 (.subtract
rlm@97 791 v
rlm@97 792 (Vector3f. (bounds 0) (bounds 1) (float 0))))
rlm@97 793 uv-tri)
rlm@97 794 whites (filter (partial inside-triangle? cutout-tri)
rlm@97 795 (map vector2f->vector3f
rlm@97 796 (white-coordinates cutout)))
rlm@97 797 ;; translate pixel coordinates to world-space
rlm@97 798 transform (triangle-transformation cutout-tri tri)]
rlm@97 799 (map #(.mult transform %) whites))))]
rlm@97 800
rlm@97 801
rlm@97 802
rlm@97 803 (for [mesh-tri mesh-tris]
rlm@97 804
rlm@97 805 (let [uv-tri (rasterize mesh mesh-tri width height)
rlm@97 806 bounding-box (vec (triangle-bounds uv-tri))]
rlm@97 807 (apply (partial (memfn setRoi) uv-image) bounding-box)
rlm@97 808 ))
rlm@97 809 (vec (map sensor-coords mesh-tris))))
rlm@97 810
rlm@97 811
rlm@97 812 (defn tactile-coords [#^Geometry obj]
rlm@97 813 (let [mesh (.getMesh obj)
rlm@97 814 num-triangles (.getTriangleCount mesh)
rlm@97 815 num-verticies (.getVertexCount mesh)
rlm@97 816 uv-coord (partial uv-coord mesh)
rlm@97 817 triangle-indices (partial triangle-indices mesh)
rlm@97 818 receptors (touch-receptor-image obj)
rlm@97 819 tris (triangles obj)
rlm@97 820 ]
rlm@97 821 (map
rlm@97 822 (fn [[tri-1 tri-2 tri-3]]
rlm@97 823 (let [width (.getWidth receptors)
rlm@97 824 height (.getHeight receptors)
rlm@97 825 uv-1 (uv-coord tri-1)
rlm@97 826 uv-2 (uv-coord tri-2)
rlm@97 827 uv-3 (uv-coord tri-3)
rlm@97 828 x-coords (map #(.getX %) [uv-1 uv-2 uv-3])
rlm@97 829 y-coords (map #(.getY %) [uv-1 uv-2 uv-3])
rlm@97 830 max-x (Math/ceil (* width (apply max x-coords)))
rlm@97 831 min-x (Math/floor (* width (apply min x-coords)))
rlm@97 832 max-y (Math/ceil (* height (apply max y-coords)))
rlm@97 833 min-y (Math/floor (* height (apply min y-coords)))
rlm@97 834
rlm@97 835 image-1 (Vector2f. (* width (.getX uv-1))
rlm@97 836 (* height (.getY uv-1)))
rlm@97 837 image-2 (Vector2f. (* width (.getX uv-2))
rlm@97 838 (* height (.getY uv-2)))
rlm@97 839 image-3 (Vector2f. (* width (.getX uv-3))
rlm@97 840 (* height (.getY uv-3)))
rlm@97 841 left-corner
rlm@97 842 (Vector2f. min-x min-y)
rlm@97 843 ]
rlm@97 844
rlm@97 845 (.setRoi receptors min-x min-y (- max-x min-x) (- max-y min-y))
rlm@97 846 (let [processor (.crop (.getProcessor receptors))]
rlm@97 847 (map
rlm@97 848 #(.add left-corner %)
rlm@97 849
rlm@97 850 (filter
rlm@97 851 (partial
rlm@97 852 inside-triangle?
rlm@97 853 (.subtract image-1 left-corner)
rlm@97 854 (.subtract image-2 left-corner)
rlm@97 855 (.subtract image-3 left-corner))
rlm@97 856 (white-coordinates processor))))
rlm@97 857 )) (map triangle-indices (range num-triangles)))))
rlm@83 858
rlm@87 859 #+end_src
rlm@83 860
rlm@87 861 #+results: body-1
rlm@87 862 : #'cortex.silly/test-joint
rlm@78 863
rlm@78 864
rlm@78 865 * COMMENT purgatory
rlm@78 866 #+begin_src clojure
rlm@77 867 (defn bullet-trans []
rlm@77 868 (let [obj-a (sphere 0.5 :color ColorRGBA/Red
rlm@77 869 :position (Vector3f. -10 5 0))
rlm@77 870 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 871 :position (Vector3f. -10 -5 0)
rlm@77 872 :mass 0)
rlm@77 873 control-a (.getControl obj-a RigidBodyControl)
rlm@77 874 control-b (.getControl obj-b RigidBodyControl)
rlm@77 875 swivel
rlm@77 876 (.toRotationMatrix
rlm@77 877 (doto (Quaternion.)
rlm@77 878 (.fromAngleAxis (/ Math/PI 2)
rlm@77 879 Vector3f/UNIT_X)))]
rlm@77 880 (doto
rlm@77 881 (ConeJoint.
rlm@77 882 control-a control-b
rlm@77 883 (Vector3f. 0 5 0)
rlm@77 884 (Vector3f. 0 -5 0)
rlm@77 885 swivel swivel)
rlm@77 886 (.setLimit (* 0.6 (/ Math/PI 4))
rlm@77 887 (/ Math/PI 4)
rlm@77 888 (* Math/PI 0.8)))
rlm@77 889 (world (nodify
rlm@77 890 [obj-a obj-b])
rlm@77 891 standard-debug-controls
rlm@77 892 enable-debug
rlm@77 893 no-op)))
rlm@74 894
rlm@74 895
rlm@77 896 (defn bullet-trans* []
rlm@77 897 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red
rlm@77 898 :position (Vector3f. 5 0 0)
rlm@77 899 :mass 90)
rlm@77 900 obj-b (sphere 0.5 :color ColorRGBA/Blue
rlm@77 901 :position (Vector3f. -5 0 0)
rlm@77 902 :mass 0)
rlm@77 903 control-a (.getControl obj-a RigidBodyControl)
rlm@77 904 control-b (.getControl obj-b RigidBodyControl)
rlm@77 905 move-up? (atom nil)
rlm@77 906 move-down? (atom nil)
rlm@77 907 move-left? (atom nil)
rlm@77 908 move-right? (atom nil)
rlm@77 909 roll-left? (atom nil)
rlm@77 910 roll-right? (atom nil)
rlm@77 911 force 100
rlm@77 912 swivel
rlm@77 913 (.toRotationMatrix
rlm@77 914 (doto (Quaternion.)
rlm@77 915 (.fromAngleAxis (/ Math/PI 2)
rlm@77 916 Vector3f/UNIT_X)))
rlm@77 917 x-move
rlm@77 918 (doto (Matrix3f.)
rlm@77 919 (.fromStartEndVectors Vector3f/UNIT_X
rlm@77 920 (.normalize (Vector3f. 1 1 0))))
rlm@77 921
rlm@77 922 timer (atom 0)]
rlm@77 923 (doto
rlm@77 924 (ConeJoint.
rlm@77 925 control-a control-b
rlm@77 926 (Vector3f. -8 0 0)
rlm@77 927 (Vector3f. 2 0 0)
rlm@77 928 ;;swivel swivel
rlm@77 929 ;;Matrix3f/IDENTITY Matrix3f/IDENTITY
rlm@77 930 x-move Matrix3f/IDENTITY
rlm@77 931 )
rlm@77 932 (.setCollisionBetweenLinkedBodys false)
rlm@77 933 (.setLimit (* 1 (/ Math/PI 4)) ;; twist
rlm@77 934 (* 1 (/ Math/PI 4)) ;; swing span in X-Y plane
rlm@77 935 (* 0 (/ Math/PI 4)))) ;; swing span in Y-Z plane
rlm@77 936 (world (nodify
rlm@77 937 [obj-a obj-b])
rlm@77 938 (merge standard-debug-controls
rlm@77 939 {"key-r" (fn [_ pressed?] (reset! move-up? pressed?))
rlm@77 940 "key-t" (fn [_ pressed?] (reset! move-down? pressed?))
rlm@77 941 "key-f" (fn [_ pressed?] (reset! move-left? pressed?))
rlm@77 942 "key-g" (fn [_ pressed?] (reset! move-right? pressed?))
rlm@77 943 "key-v" (fn [_ pressed?] (reset! roll-left? pressed?))
rlm@77 944 "key-b" (fn [_ pressed?] (reset! roll-right? pressed?))})
rlm@77 945
rlm@77 946 (fn [world]
rlm@77 947 (enable-debug world)
rlm@77 948 (set-gravity world Vector3f/ZERO)
rlm@77 949 )
rlm@77 950
rlm@77 951 (fn [world _]
rlm@77 952
rlm@77 953 (if @move-up?
rlm@77 954 (.applyForce control-a
rlm@77 955 (Vector3f. force 0 0)
rlm@77 956 (Vector3f. 0 0 0)))
rlm@77 957 (if @move-down?
rlm@77 958 (.applyForce control-a
rlm@77 959 (Vector3f. (- force) 0 0)
rlm@77 960 (Vector3f. 0 0 0)))
rlm@77 961 (if @move-left?
rlm@77 962 (.applyForce control-a
rlm@77 963 (Vector3f. 0 force 0)
rlm@77 964 (Vector3f. 0 0 0)))
rlm@77 965 (if @move-right?
rlm@77 966 (.applyForce control-a
rlm@77 967 (Vector3f. 0 (- force) 0)
rlm@77 968 (Vector3f. 0 0 0)))
rlm@77 969
rlm@77 970 (if @roll-left?
rlm@77 971 (.applyForce control-a
rlm@77 972 (Vector3f. 0 0 force)
rlm@77 973 (Vector3f. 0 0 0)))
rlm@77 974 (if @roll-right?
rlm@77 975 (.applyForce control-a
rlm@77 976 (Vector3f. 0 0 (- force))
rlm@77 977 (Vector3f. 0 0 0)))
rlm@77 978
rlm@77 979 (if (zero? (rem (swap! timer inc) 100))
rlm@77 980 (.attachChild
rlm@77 981 (.getRootNode world)
rlm@77 982 (sphere 0.05 :color ColorRGBA/Yellow
rlm@77 983 :physical? false :position
rlm@77 984 (.getWorldTranslation obj-a)))))
rlm@77 985 )
rlm@77 986 ))
rlm@77 987
rlm@77 988
rlm@77 989
rlm@73 990 #+end_src
rlm@73 991
rlm@73 992
rlm@73 993 * COMMENT generate source
rlm@73 994 #+begin_src clojure :tangle ../src/cortex/silly.clj
rlm@73 995 <<body-1>>
rlm@73 996 #+end_src
rlm@73 997
rlm@94 998
rlm@94 999
rlm@94 1000
rlm@94 1001
rlm@94 1002 (defn transform-trianglesdsd
rlm@94 1003 "Transform that converts each vertex in the first triangle
rlm@94 1004 into the corresponding vertex in the second triangle."
rlm@94 1005 [#^Triangle tri-1 #^Triangle tri-2]
rlm@94 1006 (let [in [(.get1 tri-1)
rlm@94 1007 (.get2 tri-1)
rlm@94 1008 (.get3 tri-1)]
rlm@94 1009 out [(.get1 tri-2)
rlm@94 1010 (.get2 tri-2)
rlm@94 1011 (.get3 tri-2)]]
rlm@94 1012 (let [translate (doto (Matrix4f.) (.setTranslation (.negate (in 0))))
rlm@94 1013 in* [(.mult translate (in 0))
rlm@94 1014 (.mult translate (in 1))
rlm@94 1015 (.mult translate (in 2))]
rlm@94 1016 final-translation
rlm@94 1017 (doto (Matrix4f.)
rlm@94 1018 (.setTranslation (out 1)))
rlm@94 1019
rlm@94 1020 rotate-1
rlm@94 1021 (doto (Matrix3f.)
rlm@94 1022 (.fromStartEndVectors
rlm@94 1023 (.normalize
rlm@94 1024 (.subtract
rlm@94 1025 (in* 1) (in* 0)))
rlm@94 1026 (.normalize
rlm@94 1027 (.subtract
rlm@94 1028 (out 1) (out 0)))))
rlm@94 1029 in** [(.mult rotate-1 (in* 0))
rlm@94 1030 (.mult rotate-1 (in* 1))
rlm@94 1031 (.mult rotate-1 (in* 2))]
rlm@94 1032 scale-factor-1
rlm@94 1033 (.mult
rlm@94 1034 (.normalize
rlm@94 1035 (.subtract
rlm@94 1036 (out 1)
rlm@94 1037 (out 0)))
rlm@94 1038 (/ (.length
rlm@94 1039 (.subtract (out 1)
rlm@94 1040 (out 0)))
rlm@94 1041 (.length
rlm@94 1042 (.subtract (in** 1)
rlm@94 1043 (in** 0)))))
rlm@94 1044 scale-1 (doto (Matrix4f.) (.setScale scale-factor-1))
rlm@94 1045 in*** [(.mult scale-1 (in** 0))
rlm@94 1046 (.mult scale-1 (in** 1))
rlm@94 1047 (.mult scale-1 (in** 2))]
rlm@94 1048
rlm@94 1049
rlm@94 1050
rlm@94 1051
rlm@94 1052
rlm@94 1053 ]
rlm@94 1054
rlm@94 1055 (dorun (map println in))
rlm@94 1056 (println)
rlm@94 1057 (dorun (map println in*))
rlm@94 1058 (println)
rlm@94 1059 (dorun (map println in**))
rlm@94 1060 (println)
rlm@94 1061 (dorun (map println in***))
rlm@94 1062 (println)
rlm@94 1063
rlm@94 1064 )))
rlm@94 1065
rlm@94 1066
rlm@94 1067
rlm@94 1068
rlm@94 1069
rlm@94 1070
rlm@94 1071
rlm@94 1072
rlm@94 1073
rlm@94 1074
rlm@94 1075
rlm@94 1076
rlm@94 1077
rlm@94 1078
rlm@94 1079
rlm@94 1080
rlm@94 1081
rlm@94 1082
rlm@94 1083 )
rlm@94 1084
rlm@94 1085