Mercurial > cortex
comparison org/util.org @ 50:b1b90c4ab0bf
trying to resolve problem with skeleton debugging
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 14 Nov 2011 18:46:34 -0700 |
parents | ee55966ce7f6 |
children | e5e627f50a3a |
comparison
equal
deleted
inserted
replaced
49:96a41b384100 | 50:b1b90c4ab0bf |
---|---|
69 * Utilities | 69 * Utilities |
70 | 70 |
71 The utilities here come in three main groups: | 71 The utilities here come in three main groups: |
72 - Changing settings in a running =Application= | 72 - Changing settings in a running =Application= |
73 - Creating objects | 73 - Creating objects |
74 - Debug Actions | |
74 - Visualizing objects | 75 - Visualizing objects |
76 | |
75 | 77 |
76 | 78 |
77 *** Changing Settings | 79 *** Changing Settings |
78 | 80 |
79 #+srcname: util | 81 #+srcname: util |
272 (make-shape (assoc options | 274 (make-shape (assoc options |
273 :shape (Sphere. 32 32 (float r)))))) | 275 :shape (Sphere. 32 32 (float r)))))) |
274 ([] (sphere 0.5))) | 276 ([] (sphere 0.5))) |
275 #+end_src | 277 #+end_src |
276 | 278 |
277 *** Viewing Objects | 279 |
278 | 280 *** Debug Actions |
279 #+srcname: world-view | 281 #+srcname: debug-actions |
280 #+begin_src clojure :results silent | 282 #+begin_src clojure :results silent |
281 (in-ns 'cortex.util) | |
282 | |
283 (defprotocol Viewable | |
284 (view [something])) | |
285 | |
286 (extend-type com.jme3.scene.Geometry | |
287 Viewable | |
288 (view [geo] | |
289 (view (doto (Node.)(.attachChild geo))))) | |
290 | |
291 (defn basic-light-setup | 283 (defn basic-light-setup |
292 "returns a sequence of lights appropiate for fully lighting a scene" | 284 "returns a sequence of lights appropiate for fully lighting a scene" |
293 [] | 285 [] |
294 (conj | 286 (conj |
295 (doall | 287 (doall |
316 [world] | 308 [world] |
317 (dorun | 309 (dorun |
318 (map | 310 (map |
319 #(.addLight (.getRootNode world) %) | 311 #(.addLight (.getRootNode world) %) |
320 (basic-light-setup)))) | 312 (basic-light-setup)))) |
313 | |
314 (defn fire-cannon-ball | |
315 "Creates a function that fires a cannon-ball from the current game's | |
316 camera. The cannon-ball will be attached to the node if provided, or | |
317 to the game's RootNode if no node is provided." | |
318 ([node] | |
319 (fn [game value] | |
320 (if (not value) | |
321 (let [camera (.getCamera game) | |
322 cannon-ball | |
323 (sphere 0.7 | |
324 :material "Common/MatDefs/Misc/Unshaded.j3md" | |
325 :texture "Textures/PokeCopper.jpg" | |
326 :position | |
327 (.add (.getLocation camera) | |
328 (.mult (.getDirection camera) (float 1))) | |
329 :mass 3)] ;200 0.05 | |
330 (.setLinearVelocity | |
331 (.getControl cannon-ball RigidBodyControl) | |
332 (.mult (.getDirection camera) (float 50))) ;50 | |
333 (add-element game cannon-ball (if node node (.getRootNode game))))))) | |
334 ([] | |
335 (fire-cannon-ball false))) | |
336 #+end_src | |
337 | |
338 | |
339 *** Viewing Objects | |
340 | |
341 #+srcname: world-view | |
342 #+begin_src clojure :results silent | |
343 (in-ns 'cortex.util) | |
344 | |
345 (defprotocol Viewable | |
346 (view [something])) | |
347 | |
348 (extend-type com.jme3.scene.Geometry | |
349 Viewable | |
350 (view [geo] | |
351 (view (doto (Node.)(.attachChild geo))))) | |
321 | 352 |
322 (extend-type com.jme3.scene.Node | 353 (extend-type com.jme3.scene.Node |
323 Viewable | 354 Viewable |
324 (view | 355 (view |
325 [node] | 356 [node] |
349 | 380 |
350 | 381 |
351 #+begin_src clojure :tangle ../src/cortex/util.clj :noweb yes | 382 #+begin_src clojure :tangle ../src/cortex/util.clj :noweb yes |
352 <<util>> | 383 <<util>> |
353 <<shapes>> | 384 <<shapes>> |
385 <<debug-actions>> | |
354 <<world-view>> | 386 <<world-view>> |
355 #+end_src | 387 #+end_src |
356 | 388 |
357 | 389 |
358 | 390 |