diff org/util.org @ 34:183744c179e6

MASSIVE cleanup, especially in the vision code
author Robert McIntyre <rlm@mit.edu>
date Thu, 03 Nov 2011 08:28:26 -0700
parents 0206878c28b4
children bc93abad23ee
line wrap: on
line diff
     1.1 --- a/org/util.org	Wed Nov 02 11:03:12 2011 -0700
     1.2 +++ b/org/util.org	Thu Nov 03 08:28:26 2011 -0700
     1.3 @@ -6,12 +6,12 @@
     1.4  #+SETUPFILE: ../../aurellem/org/setup.org
     1.5  #+INCLUDE: ../../aurellem/org/level-0.org
     1.6  
     1.7 -* Utilities
     1.8 +[TABLE-OF-CONTENTS]
     1.9  
    1.10  These are a collection of functions to make programming jMonkeyEngine
    1.11  in clojure easier.
    1.12  
    1.13 -** Imports
    1.14 +* Imports
    1.15  
    1.16  #+srcname: import
    1.17  #+begin_src clojure :results silent
    1.18 @@ -53,7 +53,7 @@
    1.19  importing only the classes it actually needs.
    1.20  
    1.21  The =mega-import-jme3= is quite usefull for debugging purposes since
    1.22 -it allows completion for almost all of JME's classes.
    1.23 +it allows completion for almost all of JME's classes from the REPL.
    1.24  
    1.25  Out of curiousity, let's see just how many classes =mega-import-jme3=
    1.26  imports:
    1.27 @@ -66,7 +66,7 @@
    1.28  : 955 classes
    1.29  
    1.30  
    1.31 -** Utilities
    1.32 +* Utilities
    1.33  
    1.34  The utilities here come in three main groups:
    1.35   - Changing settings in a running =Application=
    1.36 @@ -79,8 +79,8 @@
    1.37  #+srcname: util
    1.38  #+begin_src clojure 
    1.39  (ns cortex.util
    1.40 -  "Utility functions for making jMonkeyEngine easier to program from
    1.41 -   clojure"
    1.42 +  "Utility functions for making jMonkeyEngine3 easier to program from
    1.43 +   clojure."
    1.44    {:author "Robert McIntyre"}
    1.45    (:use cortex.world)
    1.46    (:use clojure.contrib.def)
    1.47 @@ -105,16 +105,17 @@
    1.48    will always output to the REPL")
    1.49  
    1.50  (defn position-camera
    1.51 -  ([game position direction up]
    1.52 -     (doto (.getCamera game)
    1.53 +  "Change the position of the in-world camera."
    1.54 +  ([world position direction up]
    1.55 +     (doto (.getCamera world)
    1.56         (.setLocation )
    1.57         (.lookAt direction up)))
    1.58 -  ([game position direction]
    1.59 +  ([world position direction]
    1.60       (position-camera
    1.61 -      game position direction Vector3f/UNIT_Y)))
    1.62 +      world position direction Vector3f/UNIT_Y)))
    1.63  
    1.64  (defn enable-debug 
    1.65 -  "Turn on the debug wireframes for every object in this simulation"
    1.66 +  "Turn on debug wireframes for every object in this simulation."
    1.67    [world]
    1.68    (.enableDebug 
    1.69     (.getPhysicsSpace
    1.70 @@ -123,11 +124,11 @@
    1.71       BulletAppState))
    1.72     (asset-manager)))
    1.73  
    1.74 -(defn set-gravity
    1.75 +(defn set-gravity 
    1.76    "In order to change the gravity of a scene, it is not only necessary
    1.77     to set the gravity variable, but to \"tap\" every physics object in
    1.78     the scene to reactivate physics calculations."
    1.79 -  [game gravity]
    1.80 +  [world gravity]
    1.81    (traverse
    1.82     (fn [geom]
    1.83       (if-let
    1.84 @@ -137,20 +138,20 @@
    1.85  	 (.setGravity control gravity)
    1.86           ;; tappsies!
    1.87  	 (.applyImpulse control Vector3f/ZERO Vector3f/ZERO))))
    1.88 -   (.getRootNode game)))
    1.89 +   (.getRootNode world)))
    1.90  
    1.91  (defn add-element
    1.92 -  "Add the Spatial to the game's environment"
    1.93 -  ([game element node]
    1.94 +  "Add the Spatial to the world's environment"
    1.95 +  ([world element node]
    1.96    (.addAll
    1.97     (.getPhysicsSpace
    1.98      (.getState
    1.99 -     (.getStateManager game)
   1.100 +     (.getStateManager world)
   1.101       BulletAppState))
   1.102      element)
   1.103    (.attachChild node element))
   1.104 -  ([game element]
   1.105 -     (add-element game element (.getRootNode game))))
   1.106 +  ([world element]
   1.107 +     (add-element world element (.getRootNode world))))
   1.108  
   1.109  (defn apply-map
   1.110    "Like apply, but works for maps and functions that expect an
   1.111 @@ -186,7 +187,7 @@
   1.112     GImpact?
   1.113     ])
   1.114  
   1.115 -(def base-shape
   1.116 +(defvar base-shape
   1.117       (shape-description.
   1.118        "default-shape"
   1.119        false
   1.120 @@ -201,7 +202,8 @@
   1.121        Quaternion/IDENTITY
   1.122        (Box. Vector3f/ZERO 0.5 0.5 0.5)
   1.123        true
   1.124 -      false))
   1.125 +      false)
   1.126 +     "Basic settings for shapes.")
   1.127  
   1.128  (defn make-shape
   1.129    [#^shape-description d]
   1.130 @@ -210,8 +212,9 @@
   1.131  	geom (Geometry. (:name d) (:shape d))]
   1.132      (if (:texture d)
   1.133        (let [key (TextureKey. (:texture d))]
   1.134 -	(.setGenerateMips key true)
   1.135 -	(.setTexture mat "ColorMap" (.loadTexture asset-manager key))))
   1.136 +	;;(.setGenerateMips key true)
   1.137 +	;;(.setTexture mat "ColorMap" (.loadTexture asset-manager key))
   1.138 +        ))
   1.139      (if (:color d) (.setColor mat "Color" (:color d)))
   1.140      (.setMaterial geom mat)
   1.141      (if-let [rotation (:rotation d)] (.rotate geom rotation))
   1.142 @@ -248,7 +251,6 @@
   1.143    ([] (sphere 0.5)))
   1.144  #+end_src
   1.145  
   1.146 -
   1.147  *** Viewing Objects
   1.148  
   1.149  #+srcname: world-view
   1.150 @@ -279,12 +281,13 @@
   1.151                  (.setDirection
   1.152                   (.normalizeLocal (Vector3f. 1 0 -2)))
   1.153                  (.setColor ColorRGBA/White))]
   1.154 +          ;; lights are required to view some objects.
   1.155            (.addLight (.getRootNode world) sun)))
   1.156        no-op))))
   1.157  #+end_src
   1.158  
   1.159  Here I make the =Viewable= protocol and extend it to JME's types.  Now
   1.160 -hello-world can be written as easily as:
   1.161 +JME3's =hello-world= can be written as easily as:
   1.162  
   1.163  #+begin_src clojure :results silent
   1.164  (cortex.util/view (cortex.util/box))