comparison org/skin.org @ 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
comparison
equal deleted inserted replaced
6:e3c6d1c1cb00 7:9ccfbcbed90a
97 (defn new-touch [#^Geometry geom] 97 (defn new-touch [#^Geometry geom]
98 (dorun (map 98 (dorun (map
99 (comp no-op #(.getCenter %)) 99 (comp no-op #(.getCenter %))
100 (triangles geom)))) 100 (triangles geom))))
101 101
102 102 (defn get-ray-origin
103 103 [geom tri]
104 104 (let [new (Vector3f.)]
105 (defn normal-arrows 105 (.calculateCenter tri)
106 "returns a node containing arrows which point 106 (.localToWorld geom (.get tri 1) new)
107 in the normal direction of each face of the 107 new))
108 given Geometry" 108
109 [#^Geometry geom] 109 (defn get-ray-direction
110 (let [node (Node.)] 110 [geom tri]
111 (dorun 111 (let [new (Vector3f.)]
112 (map #(.attachChild node %) 112 (.calculateNormal tri)
113 (map 113 (.localToWorld geom (.getNormal tri) new)
114 (fn [tri] 114 new
115 (make-shape 115 Vector3f/UNIT_Y))
116
117 (defn ray-origin-debug
118 [ray]
119 (make-shape
116 (assoc base-shape 120 (assoc base-shape
117 :shape (Sphere. 5 5 0.05) 121 :shape (Sphere. 5 5 0.05)
118 :name "arrow" 122 :name "arrow"
119 :color ColorRGBA/Orange 123 :color ColorRGBA/Orange
120 :texture false 124 :texture false
121 :asset-manager (asset-manager)
122 :physical? false 125 :physical? false
123 ;;:rotation
124 ;;(.mult
125 ;; (doto (Quaternion.)
126 ;; (.lookAt (.getNormal tri)
127 ;; Vector3f/UNIT_Y))
128 ;; (.getLocalRotation geom))
129 :position 126 :position
130 (.add 127 (.getOrigin ray))))
131 (.getCenter tri)
132 (.getLocalTranslation geom)))))
133 (triangles geom))))
134 node))
135
136
137 (defn get-ray-origin
138 [geom tri]
139 (.add
140 (.getCenter tri)
141 (.getLocalTranslation geom)))
142
143 (defn get-ray-direction
144 [geom tri]
145 (.mult (.getLocalRotation geom)
146 (.getNormal tri)))
147 128
148 (defn ray-debug [ray] 129 (defn ray-debug [ray]
149 (make-shape 130 (make-shape
150 (assoc 131 (assoc
151 base-shape 132 base-shape
183 ) 164 )
184 165
185 (defn touch-percieve [limit geom node debug-node] 166 (defn touch-percieve [limit geom node debug-node]
186 (let [normals (normal-rays limit geom)] 167 (let [normals (normal-rays limit geom)]
187 (.detachAllChildren debug-node) 168 (.detachAllChildren debug-node)
188 (.attachChild debug-node (normal-arrows geom)) 169
189 170
190 (println-repl "---------") 171 (println-repl "---------")
191 (doall 172 (doall
192 (for [ray normals] 173 (for [ray normals]
193 (do 174 (do
194 (let [results (CollisionResults.)] 175 (let [results (CollisionResults.)]
195 (.attachChild debug-node (ray-debug ray)) 176 (.attachChild debug-node (ray-debug ray))
177 (.attachChild debug-node (ray-origin-debug ray))
196 (.collideWith geom ray results) 178 (.collideWith geom ray results)
197 179
198 ;;(println-repl (.size results) "results for " ray) 180 ;;(println-repl (.size results) "results for " ray)
199 ;;(doall (map (partial collision-debug node) results)) 181 ;;(doall (map (partial collision-debug node) results))
200 (.size results) 182 (.size results)
201 )))))) 183 ))))))
202
203 (defn arrow-view [obj]
204 (view (doto (Node.)
205 (.attachChild (normal-arrows obj))
206 (.attachChild obj))))
207
208 184
209 (defn make-touch [#^Geometry geom] 185 (defn make-touch [#^Geometry geom]
210 (let [tri (Triangle.) 186 (let [tri (Triangle.)
211 mesh (.getMesh geom) 187 mesh (.getMesh geom)
212 controls! (transient [])] 188 controls! (transient [])]