changeset 10:0251b7e7609f

finally got raycasting tough to work
author Robert McIntyre <rlm@mit.edu>
date Sun, 23 Oct 2011 10:09:02 -0700
parents 7d0c0282c3a7
children a149692d3d1f
files org/skin.org
diffstat 1 files changed, 43 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/skin.org	Sun Oct 23 01:27:20 2011 -0700
     1.2 +++ b/org/skin.org	Sun Oct 23 10:09:02 2011 -0700
     1.3 @@ -140,8 +140,18 @@
     1.4                (.mult (.getDirection ray)
     1.5                       (float (.getLimit ray))))))))
     1.6               
     1.7 -                               
     1.8  
     1.9 +(defn contact-color [contacts]
    1.10 +  (case contacts
    1.11 +    0 ColorRGBA/Gray
    1.12 +    1  ColorRGBA/Blue 
    1.13 +    2  ColorRGBA/Green 
    1.14 +    3  ColorRGBA/Yellow 
    1.15 +    4  ColorRGBA/Orange 
    1.16 +    5  ColorRGBA/Red 
    1.17 +    6  ColorRGBA/Magenta 
    1.18 +    7  ColorRGBA/Pink 
    1.19 +    8  ColorRGBA/White))
    1.20  
    1.21  (defn normal-rays
    1.22    "returns rays"
    1.23 @@ -153,7 +163,9 @@
    1.24            (Ray. (get-ray-origin geom tri)
    1.25                  (get-ray-direction geom tri))
    1.26                  
    1.27 -      (.setLimit limit)))
    1.28 +        (.setLimit limit)
    1.29 +        )
    1.30 +      )
    1.31      (triangles geom))))
    1.32  
    1.33  
    1.34 @@ -168,17 +180,19 @@
    1.35       (for [ray normals]
    1.36         (do
    1.37           (let [results (CollisionResults.)]
    1.38 -           (.collideWith geom ray results)
    1.39 -           (let [color (contact-color (.size results))]
    1.40 -             
    1.41 -             (.attachChild debug-node (ray-debug ray color))
    1.42 -             (.attachChild debug-node (ray-origin-debug ray color))
    1.43 -           )
    1.44 +           (.collideWith node ray results)
    1.45 +           (let [answer (count (filter #(not (= geom (.getGeometry %))) results)) 
    1.46 +                 ;;color (contact-color answer)
    1.47 +                 ]
    1.48 +             ;;(dorun (map #(println-repl (.getName (.getGeometry %))) results))
    1.49 +             ;;(.attachChild debug-node (ray-debug ray color))
    1.50 +             ;;(.attachChild debug-node (ray-origin-debug ray color))
    1.51             
    1.52 -           (println-repl (.size results) "results for " ray)
    1.53 -           (doall (map (partial collision-debug node) results))
    1.54 -           (.size results)
    1.55 -           ))))))
    1.56 +           
    1.57 +           ;;(println-repl (.size results) "results for " ray)
    1.58 +           ;;(doall (map (partial collision-debug node) results))
    1.59 +           answer
    1.60 +           )))))))
    1.61  
    1.62  (defn make-touch [#^Geometry geom]
    1.63    (let [tri (Triangle.)
    1.64 @@ -213,6 +227,11 @@
    1.65  
    1.66  (use 'hello.brick-wall)
    1.67  
    1.68 +
    1.69 +
    1.70 +
    1.71 +
    1.72 +
    1.73  (defn touch-reception [controls]
    1.74      (let [control
    1.75  	  (first 
    1.76 @@ -282,7 +301,7 @@
    1.77        (make-shape
    1.78         (merge base-shape
    1.79  	      {:position (Vector3f. 0 2 0)
    1.80 -	       :name "the blob."
    1.81 +	       :name "box"
    1.82  	       :material "Common/MatDefs/Misc/Unshaded.j3md"
    1.83  	       :texture "Textures/purpleWisp.png"
    1.84  	       :physical? true
    1.85 @@ -299,7 +318,8 @@
    1.86    (doto
    1.87        (box 5 0.2 5  :mass 0 :position (Vector3f. 0 -2 0)
    1.88             :material "Common/MatDefs/Misc/Unshaded.j3md"
    1.89 -           :texture "Textures/redWisp.png")
    1.90 +           :texture "Textures/redWisp.png"
    1.91 +           :name "floor")
    1.92      (-> (.getMaterial)
    1.93          (.getAdditionalRenderState)
    1.94          (.setBlendMode RenderState$BlendMode/Alpha))
    1.95 @@ -315,8 +335,9 @@
    1.96  
    1.97  (defn test-skin []
    1.98    (let [b
    1.99 +	(transparent-box)
   1.100  	;;(transparent-sphere)
   1.101 -	(transparent-box)
   1.102 +        ;;(sphere)
   1.103  	f (transparent-floor)
   1.104  	;;controls
   1.105  	;;(make-touch-sphere b)
   1.106 @@ -332,7 +353,8 @@
   1.107       node
   1.108       {"key-return" (fire-cannon-ball)
   1.109        "key-space"  (fn [game value]
   1.110 -      		    (println-repl (touch-percieve 1 b node debug-node)))
   1.111 +                     (if value
   1.112 +                     (println-repl (touch-percieve 0.2 b node debug-node))))
   1.113        }
   1.114       ;;no-op
   1.115       (fn [world]
   1.116 @@ -345,7 +367,9 @@
   1.117         )
   1.118  
   1.119       (fn [& _]
   1.120 -       (Thread/sleep 10)
   1.121 +       ;;(println-repl
   1.122 +        (touch-percieve 0.2 b node debug-node)
   1.123 +       ;;(Thread/sleep 10)
   1.124         ;;(touch-print controls)
   1.125         ;;(color-touch controls)
   1.126         ))))
   1.127 @@ -358,6 +382,8 @@
   1.128  
   1.129  
   1.130  
   1.131 +
   1.132 +
   1.133    
   1.134  
   1.135  * COMMENT code generation