comparison 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
comparison
equal deleted inserted replaced
46:286a00500ee5 47:ee55966ce7f6
90 (:import com.jme3.bullet.control.RigidBodyControl) 90 (:import com.jme3.bullet.control.RigidBodyControl)
91 (:import com.jme3.bullet.collision.shapes.GImpactCollisionShape) 91 (:import com.jme3.bullet.collision.shapes.GImpactCollisionShape)
92 (:import com.jme3.scene.shape.Box) 92 (:import com.jme3.scene.shape.Box)
93 (:import com.jme3.scene.Node) 93 (:import com.jme3.scene.Node)
94 (:import com.jme3.scene.shape.Sphere) 94 (:import com.jme3.scene.shape.Sphere)
95 (:import com.jme3.light.AmbientLight)
95 (:import com.jme3.light.DirectionalLight) 96 (:import com.jme3.light.DirectionalLight)
96 (:import com.jme3.math.ColorRGBA) 97 (:import com.jme3.math.ColorRGBA)
97 (:import com.jme3.bullet.BulletAppState) 98 (:import com.jme3.bullet.BulletAppState)
98 (:import com.jme3.material.Material) 99 (:import com.jme3.material.Material)
99 (:import com.jme3.scene.Geometry) 100 (:import com.jme3.scene.Geometry)
182 -->\"hello\"" 183 -->\"hello\""
183 [fn m] 184 [fn m]
184 (apply fn (reduce #(into %1 %2) [] m))) 185 (apply fn (reduce #(into %1 %2) [] m)))
185 186
186 #+end_src 187 #+end_src
188
189 #+results: util
190 : #'cortex.util/apply-map
187 191
188 192
189 *** Creating Basic Shapes 193 *** Creating Basic Shapes
190 194
191 #+srcname: shapes 195 #+srcname: shapes
282 (extend-type com.jme3.scene.Geometry 286 (extend-type com.jme3.scene.Geometry
283 Viewable 287 Viewable
284 (view [geo] 288 (view [geo]
285 (view (doto (Node.)(.attachChild geo))))) 289 (view (doto (Node.)(.attachChild geo)))))
286 290
291 (defn basic-light-setup
292 "returns a sequence of lights appropiate for fully lighting a scene"
293 []
294 (conj
295 (doall
296 (map
297 (fn [direction]
298 (doto (DirectionalLight.)
299 (.setDirection direction)
300 (.setColor ColorRGBA/White)))
301 [;; six faces of a cube
302 Vector3f/UNIT_X
303 Vector3f/UNIT_Y
304 Vector3f/UNIT_Z
305 (.mult Vector3f/UNIT_X (float -1))
306 (.mult Vector3f/UNIT_Y (float -1))
307 (.mult Vector3f/UNIT_Z (float -1))]))
308 (doto (AmbientLight.)
309 (.setColor ColorRGBA/White))))
310
311 (defn light-up-everything
312 "Add lights to a world appropiate for quickly seeing everything
313 in the scene. Adds six DirectionalLights facing in orthogonal
314 directions, and one AmbientLight to provide overall lighting
315 coverage."
316 [world]
317 (dorun
318 (map
319 #(.addLight (.getRootNode world) %)
320 (basic-light-setup))))
321
287 (extend-type com.jme3.scene.Node 322 (extend-type com.jme3.scene.Node
288 Viewable 323 Viewable
289 (view 324 (view
290 [node] 325 [node]
291 (.start 326 (.start
293 node 328 node
294 {} 329 {}
295 (fn [world] 330 (fn [world]
296 (enable-debug world) 331 (enable-debug world)
297 (set-gravity world Vector3f/ZERO) 332 (set-gravity world Vector3f/ZERO)
298 (let [sun 333 (light-up-everything world))
299 (doto (DirectionalLight.)
300 (.setDirection
301 (.normalizeLocal (Vector3f. 1 0 -2)))
302 (.setColor ColorRGBA/White))]
303 ;; lights are required to view some objects.
304 (.addLight (.getRootNode world) sun)))
305 no-op)))) 334 no-op))))
306 #+end_src 335 #+end_src
307 336
308 Here I make the =Viewable= protocol and extend it to JME's types. Now 337 Here I make the =Viewable= protocol and extend it to JME's types. Now
309 JME3's =hello-world= can be written as easily as: 338 JME3's =hello-world= can be written as easily as: