diff org/games.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 f0562b9bde94
children b1b90c4ab0bf
line wrap: on
line diff
     1.1 --- a/org/games.org	Wed Nov 02 11:03:12 2011 -0700
     1.2 +++ b/org/games.org	Thu Nov 03 08:28:26 2011 -0700
     1.3 @@ -1,16 +1,18 @@
     1.4 -#+title: Games! Games! Games! <3
     1.5 +#+title: jMonkeyEngine3 from Clojure
     1.6  #+author: Robert McIntyre
     1.7  #+email: rlm@mit.edu
     1.8 -#+description: Simulating senses for AI research using JMonkeyEngine3
     1.9 +#+description: Using jMonkeyEngine3 from clojure
    1.10 +#+keywords: clojure, jMonkeyEngine3, tutorial, examples
    1.11  #+SETUPFILE: ../../aurellem/org/setup.org
    1.12  #+INCLUDE: ../../aurellem/org/level-0.org
    1.13  #+babel: :mkdirp yes :noweb yes :exports both
    1.14  
    1.15 +[TABLE-OF-CONTENTS]
    1.16  
    1.17 -* Games!
    1.18  
    1.19  Here are the jMonkeyEngine "Hello" programs translated to clojure.
    1.20 -** Hello Simple App
    1.21 +
    1.22 +* Hello Simple App
    1.23  Here is the hello world example for jme3 in clojure.  It's a more or
    1.24  less direct translation from the java source [[http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplication][here]].
    1.25  
    1.26 @@ -20,13 +22,14 @@
    1.27  
    1.28  #+srcname: hello-simple-app
    1.29  #+begin_src clojure :results silent
    1.30 -(ns hello.hello-simple-app)
    1.31 -(require 'cortex.import)
    1.32 -(use 'clojure.contrib.def)
    1.33 -(rlm.rlm-commands/help)
    1.34 -(cortex.import/mega-import-jme3)
    1.35 -(use 'cortex.world)
    1.36 -
    1.37 +(ns hello.hello-simple-app
    1.38 +  (:use cortex.world)
    1.39 +  (:import com.jme3.math.Vector3f)
    1.40 +  (:import com.jme3.material.Material)
    1.41 +  (:import com.jme3.scene.Geometry)
    1.42 +  (:import com.jme3.math.ColorRGBA)
    1.43 +  (:import com.jme3.app.SimpleApplication)
    1.44 +  (:import com.jme3.scene.shape.Box))
    1.45  
    1.46  (def cube (Box. Vector3f/ZERO 1 1 1))
    1.47  
    1.48 @@ -62,8 +65,31 @@
    1.49  #+caption: the simplest JME game.
    1.50  [[../images/simple-app.jpg]]
    1.51  
    1.52 +* Simpler HelloSimpleApp
    1.53  
    1.54 -** Hello Physics
    1.55 +#+srcname: hello-simpler-app
    1.56 +#+begin_src clojure 
    1.57 +(ns hello.hello-simpler-app
    1.58 +  (:use cortex.world)
    1.59 +  (:use cortex.util)
    1.60 +  (:import com.jme3.math.ColorRGBA)
    1.61 +  (:import com.jme3.scene.Node))
    1.62 +
    1.63 +(defn simpler-world
    1.64 +  "The jMonkeyEngine3 Hello World program.  Displays a blue 3D cube in
    1.65 +   a basic 3D world."
    1.66 +  []
    1.67 +  (world (doto (Node.)
    1.68 +           (.attachChild
    1.69 +            (box 1 1 1
    1.70 +                 :color ColorRGBA/Blue :physical? false)))
    1.71 +         {} no-op no-op))
    1.72 +#+end_src
    1.73 +
    1.74 +More information about the jMonkeyEngine3 hello world program can be
    1.75 +found [[http://jmonkeyengine.org/wiki/doku.php/starter:hello_world][here]].
    1.76 +
    1.77 +* COMMENT Hello Physics
    1.78  From http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_physics
    1.79  
    1.80  #+srcname: brick-wall-header
    1.81 @@ -90,7 +116,7 @@
    1.82  (def brick-length 0.48)
    1.83  (def brick-width 0.24)
    1.84  (def brick-height 0.12)
    1.85 -
    1.86 +(def gravity (Vector3f. 0 -9.81 0))
    1.87  
    1.88  (defn brick* [position]
    1.89    (doto (box brick-length brick-height brick-width
    1.90 @@ -126,8 +152,8 @@
    1.91    (fn [game value]
    1.92      (println-repl "set gravity to " new-value)
    1.93      (if value
    1.94 -      (set-gravity* game new-value)
    1.95 -      (set-gravity* game gravity))))
    1.96 +      (set-gravity game new-value)
    1.97 +      (set-gravity game gravity))))
    1.98  
    1.99  (defn fire-cannon-ball 
   1.100    ([node]
   1.101 @@ -216,10 +242,10 @@
   1.102  #+caption: the brick wall after it has been knocked over by a "pok\eacute{}ball"
   1.103  [[../images/brick-wall-knocked-down.jpg]]
   1.104  
   1.105 -** Other Brick Games
   1.106 +* COMMENT Other Brick Games
   1.107  #+srcname: other-games
   1.108  #+begin_src clojure :results silent
   1.109 -(ns cortex.other-games
   1.110 +(ns hello.other-games
   1.111     {:author "Dylan Holmes"})
   1.112  (use 'cortex.world)
   1.113  (use 'hello.brick-wall)
   1.114 @@ -364,15 +390,15 @@
   1.115  #+caption: floating dominos
   1.116  [[../images/dominos.jpg]]
   1.117  
   1.118 -** Hello Loop
   1.119 +* Hello Loop
   1.120  #+srcname: hello-loop
   1.121  #+begin_src clojure :results silent
   1.122 -(ns hello.loop)
   1.123 -(use 'cortex.world)
   1.124 -(use 'cortex.import)
   1.125 -(cortex.import/mega-import-jme3)
   1.126 -(rlm.rlm-commands/help)
   1.127 -
   1.128 +(ns hello.loop
   1.129 +  (:use cortex.world)
   1.130 +  (:use cortex.util)
   1.131 +  (:import com.jme3.math.ColorRGBA)
   1.132 +  (:import com.jme3.scene.Node))
   1.133 +  
   1.134  (defn blue-cube []
   1.135    (box 1 1 1
   1.136         :color ColorRGBA/Blue
   1.137 @@ -391,7 +417,7 @@
   1.138  	   (.rotate cube 0.0 (* 2 tpf) 0.0)))))	 	 		  
   1.139  #+end_src
   1.140     
   1.141 -** Hello Collision
   1.142 +* COMMENT Hello Collision
   1.143  
   1.144  #+srcname: hello-collision
   1.145  #+begin_src clojure :results silent
   1.146 @@ -513,7 +539,7 @@
   1.147  	  update-fn)))
   1.148  #+end_src
   1.149  
   1.150 -** Hello Terrain
   1.151 +* COMMENT Hello Terrain
   1.152  #+srcname: hello-terrain
   1.153  #+begin_src clojure :results silent
   1.154  (ns hello.terrain)
   1.155 @@ -663,12 +689,13 @@
   1.156        no-op))))
   1.157  #+end_src
   1.158  
   1.159 -** Hello Materials
   1.160 +* COMMENT Hello Materials
   1.161  #+srcname: material
   1.162  #+begin_src clojure :results silent
   1.163  (ns hello.material)
   1.164  (use 'cortex.world)
   1.165  (use 'cortex.import)
   1.166 +(use 'cortex.util)
   1.167  (use 'clojure.contrib.def)
   1.168  (cortex.import/mega-import-jme3)
   1.169  (rlm.rlm-commands/help)
   1.170 @@ -717,7 +744,7 @@
   1.171  	(doto
   1.172  	  (.setTexture "DiffuseMap" 
   1.173                         (.loadTexture (asset-manager)
   1.174 -                                     "Textures/Terrain/Pond/Pond.png"))
   1.175 +                                     "Textures/Terrain/Pond/Pond.jpg"))
   1.176  	  (.setTexture "NormalMap"
   1.177                         (.loadTexture (asset-manager)
   1.178                                       "Textures/Terrain/Pond/Pond_normal.png"))
   1.179 @@ -755,7 +782,12 @@
   1.180  <<hello-simple-app>>
   1.181  #+end_src
   1.182  
   1.183 -#+begin_src clojure :tangle ../src/cortex/other_games.clj
   1.184 +#+begin_src clojure :tangle ../src/hello/hello_simpler_app.clj
   1.185 +<<hello-simpler-app>>
   1.186 +#+end_src
   1.187 +
   1.188 +
   1.189 +#+begin_src clojure :tangle ../src/hello/other_games.clj
   1.190  <<other-games>>
   1.191  #+end_src
   1.192