diff org/util.org @ 47:ee55966ce7f6

enhanced cortex.utils to do proper lighting when viewing objects
author Robert McIntyre <rlm@mit.edu>
date Fri, 11 Nov 2011 00:52:47 -0700
parents bc93abad23ee
children b1b90c4ab0bf
line wrap: on
line diff
     1.1 --- a/org/util.org	Thu Nov 10 23:24:02 2011 -0700
     1.2 +++ b/org/util.org	Fri Nov 11 00:52:47 2011 -0700
     1.3 @@ -92,6 +92,7 @@
     1.4    (:import com.jme3.scene.shape.Box)
     1.5    (:import com.jme3.scene.Node)
     1.6    (:import com.jme3.scene.shape.Sphere)
     1.7 +  (:import com.jme3.light.AmbientLight)
     1.8    (:import com.jme3.light.DirectionalLight)
     1.9    (:import com.jme3.math.ColorRGBA)
    1.10    (:import com.jme3.bullet.BulletAppState)
    1.11 @@ -185,6 +186,9 @@
    1.12  
    1.13  #+end_src
    1.14  
    1.15 +#+results: util
    1.16 +: #'cortex.util/apply-map
    1.17 +
    1.18  
    1.19  *** Creating Basic Shapes
    1.20  
    1.21 @@ -284,6 +288,37 @@
    1.22    (view [geo]
    1.23  	(view (doto (Node.)(.attachChild geo)))))
    1.24  
    1.25 +(defn basic-light-setup
    1.26 +  "returns a sequence of lights appropiate for fully lighting a scene"
    1.27 +  []
    1.28 +  (conj
    1.29 +   (doall
    1.30 +    (map
    1.31 +     (fn [direction]
    1.32 +       (doto (DirectionalLight.)
    1.33 +         (.setDirection direction)
    1.34 +         (.setColor ColorRGBA/White)))
    1.35 +     [;; six faces of a cube
    1.36 +      Vector3f/UNIT_X
    1.37 +      Vector3f/UNIT_Y
    1.38 +      Vector3f/UNIT_Z
    1.39 +      (.mult Vector3f/UNIT_X (float -1))
    1.40 +      (.mult Vector3f/UNIT_Y (float -1))
    1.41 +      (.mult Vector3f/UNIT_Z (float -1))]))
    1.42 +   (doto (AmbientLight.)
    1.43 +     (.setColor ColorRGBA/White))))
    1.44 +
    1.45 +(defn light-up-everything
    1.46 +  "Add lights to a world appropiate for quickly seeing everything
    1.47 +  in the scene.  Adds six DirectionalLights facing in orthogonal
    1.48 +  directions, and one AmbientLight to provide overall lighting
    1.49 +  coverage."
    1.50 +  [world]
    1.51 +  (dorun
    1.52 +   (map
    1.53 +    #(.addLight (.getRootNode world) %)
    1.54 +    (basic-light-setup))))
    1.55 +    
    1.56  (extend-type com.jme3.scene.Node
    1.57    Viewable
    1.58    (view 
    1.59 @@ -295,13 +330,7 @@
    1.60        (fn [world]
    1.61          (enable-debug world)
    1.62          (set-gravity world Vector3f/ZERO)
    1.63 -        (let [sun 
    1.64 -              (doto (DirectionalLight.)
    1.65 -                (.setDirection
    1.66 -                 (.normalizeLocal (Vector3f. 1 0 -2)))
    1.67 -                (.setColor ColorRGBA/White))]
    1.68 -          ;; lights are required to view some objects.
    1.69 -          (.addLight (.getRootNode world) sun)))
    1.70 +        (light-up-everything world))
    1.71        no-op))))
    1.72  #+end_src
    1.73