changeset 7:9ccfbcbed90a

refactored to help fix ray casting problem
author Robert McIntyre <rlm@mit.edu>
date Sun, 23 Oct 2011 00:49:33 -0700
parents e3c6d1c1cb00
children 522cf85fdb57
files org/skin.org
diffstat 1 files changed, 20 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/skin.org	Sun Oct 23 00:17:54 2011 -0700
     1.2 +++ b/org/skin.org	Sun Oct 23 00:49:33 2011 -0700
     1.3 @@ -99,51 +99,32 @@
     1.4            (comp no-op #(.getCenter %))
     1.5                (triangles geom))))
     1.6  
     1.7 +(defn get-ray-origin
     1.8 +  [geom tri]
     1.9 +  (let [new (Vector3f.)]
    1.10 +    (.calculateCenter tri)
    1.11 +    (.localToWorld geom (.get tri 1) new)
    1.12 +    new))
    1.13  
    1.14 -
    1.15 -        
    1.16 -(defn normal-arrows
    1.17 -  "returns a node containing arrows which point
    1.18 -   in the normal direction of each face of the
    1.19 -   given Geometry"
    1.20 -  [#^Geometry geom]
    1.21 -  (let [node (Node.)]
    1.22 -    (dorun
    1.23 -     (map #(.attachChild node %)
    1.24 -          (map 
    1.25 -           (fn [tri]
    1.26 -             (make-shape
    1.27 +(defn get-ray-direction
    1.28 +  [geom tri]
    1.29 +  (let [new (Vector3f.)]
    1.30 +    (.calculateNormal tri)
    1.31 +    (.localToWorld geom (.getNormal tri) new)
    1.32 +    new
    1.33 +    Vector3f/UNIT_Y))
    1.34 +  
    1.35 +(defn ray-origin-debug
    1.36 +  [ray]
    1.37 +  (make-shape
    1.38                (assoc base-shape
    1.39                  :shape (Sphere. 5 5 0.05)
    1.40                  :name "arrow"
    1.41                  :color ColorRGBA/Orange
    1.42                  :texture false
    1.43 -                :asset-manager (asset-manager)
    1.44                  :physical? false
    1.45 -                ;;:rotation
    1.46 -                ;;(.mult
    1.47 -                ;; (doto (Quaternion.)
    1.48 -                ;;   (.lookAt (.getNormal tri)
    1.49 -                ;;            Vector3f/UNIT_Y))
    1.50 -                ;; (.getLocalRotation geom))
    1.51                  :position
    1.52 -                (.add
    1.53 -                 (.getCenter tri)
    1.54 -                 (.getLocalTranslation geom)))))
    1.55 -           (triangles geom))))
    1.56 -    node))
    1.57 -
    1.58 -
    1.59 -(defn get-ray-origin
    1.60 -  [geom tri]
    1.61 -  (.add
    1.62 -   (.getCenter tri)
    1.63 -   (.getLocalTranslation geom)))
    1.64 -
    1.65 -(defn get-ray-direction
    1.66 -  [geom tri]
    1.67 -  (.mult (.getLocalRotation geom)
    1.68 -         (.getNormal tri)))
    1.69 +                (.getOrigin ray))))
    1.70  
    1.71  (defn ray-debug [ray]
    1.72    (make-shape
    1.73 @@ -185,7 +166,7 @@
    1.74  (defn touch-percieve [limit geom node debug-node]
    1.75    (let [normals  (normal-rays limit geom)]
    1.76      (.detachAllChildren debug-node)
    1.77 -    (.attachChild debug-node (normal-arrows geom))
    1.78 +
    1.79      
    1.80      (println-repl "---------")
    1.81      (doall
    1.82 @@ -193,6 +174,7 @@
    1.83         (do
    1.84           (let [results (CollisionResults.)]
    1.85             (.attachChild debug-node (ray-debug ray))
    1.86 +           (.attachChild debug-node (ray-origin-debug ray))
    1.87             (.collideWith geom ray results)
    1.88             
    1.89              ;;(println-repl (.size results) "results for " ray)
    1.90 @@ -200,12 +182,6 @@
    1.91             (.size results)
    1.92             ))))))
    1.93  
    1.94 -(defn arrow-view [obj]
    1.95 -  (view (doto (Node.)
    1.96 -          (.attachChild (normal-arrows obj))
    1.97 -          (.attachChild obj))))
    1.98 -
    1.99 -
   1.100  (defn make-touch [#^Geometry geom]
   1.101    (let [tri (Triangle.)
   1.102  	mesh (.getMesh geom)