Mercurial > cortex
comparison org/skin.org @ 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 |
comparison
equal
deleted
inserted
replaced
9:7d0c0282c3a7 | 10:0251b7e7609f |
---|---|
138 (.add | 138 (.add |
139 (.getOrigin ray) | 139 (.getOrigin ray) |
140 (.mult (.getDirection ray) | 140 (.mult (.getDirection ray) |
141 (float (.getLimit ray)))))))) | 141 (float (.getLimit ray)))))))) |
142 | 142 |
143 | 143 |
144 | 144 (defn contact-color [contacts] |
145 (case contacts | |
146 0 ColorRGBA/Gray | |
147 1 ColorRGBA/Blue | |
148 2 ColorRGBA/Green | |
149 3 ColorRGBA/Yellow | |
150 4 ColorRGBA/Orange | |
151 5 ColorRGBA/Red | |
152 6 ColorRGBA/Magenta | |
153 7 ColorRGBA/Pink | |
154 8 ColorRGBA/White)) | |
145 | 155 |
146 (defn normal-rays | 156 (defn normal-rays |
147 "returns rays" | 157 "returns rays" |
148 [limit #^Geometry geom] | 158 [limit #^Geometry geom] |
149 (vec | 159 (vec |
151 (fn [tri] | 161 (fn [tri] |
152 (doto | 162 (doto |
153 (Ray. (get-ray-origin geom tri) | 163 (Ray. (get-ray-origin geom tri) |
154 (get-ray-direction geom tri)) | 164 (get-ray-direction geom tri)) |
155 | 165 |
156 (.setLimit limit))) | 166 (.setLimit limit) |
167 ) | |
168 ) | |
157 (triangles geom)))) | 169 (triangles geom)))) |
158 | 170 |
159 | 171 |
160 (defn collision-debug [node result] | 172 (defn collision-debug [node result] |
161 (println-repl "contact point: " (.getContactPoint result)) | 173 (println-repl "contact point: " (.getContactPoint result)) |
166 (.detachAllChildren debug-node) | 178 (.detachAllChildren debug-node) |
167 (doall | 179 (doall |
168 (for [ray normals] | 180 (for [ray normals] |
169 (do | 181 (do |
170 (let [results (CollisionResults.)] | 182 (let [results (CollisionResults.)] |
171 (.collideWith geom ray results) | 183 (.collideWith node ray results) |
172 (let [color (contact-color (.size results))] | 184 (let [answer (count (filter #(not (= geom (.getGeometry %))) results)) |
173 | 185 ;;color (contact-color answer) |
174 (.attachChild debug-node (ray-debug ray color)) | 186 ] |
175 (.attachChild debug-node (ray-origin-debug ray color)) | 187 ;;(dorun (map #(println-repl (.getName (.getGeometry %))) results)) |
176 ) | 188 ;;(.attachChild debug-node (ray-debug ray color)) |
189 ;;(.attachChild debug-node (ray-origin-debug ray color)) | |
177 | 190 |
178 (println-repl (.size results) "results for " ray) | 191 |
179 (doall (map (partial collision-debug node) results)) | 192 ;;(println-repl (.size results) "results for " ray) |
180 (.size results) | 193 ;;(doall (map (partial collision-debug node) results)) |
181 )))))) | 194 answer |
195 ))))))) | |
182 | 196 |
183 (defn make-touch [#^Geometry geom] | 197 (defn make-touch [#^Geometry geom] |
184 (let [tri (Triangle.) | 198 (let [tri (Triangle.) |
185 mesh (.getMesh geom) | 199 mesh (.getMesh geom) |
186 controls! (transient [])] | 200 controls! (transient [])] |
211 (conj! controls! control))))) | 225 (conj! controls! control))))) |
212 (persistent! controls!))) | 226 (persistent! controls!))) |
213 | 227 |
214 (use 'hello.brick-wall) | 228 (use 'hello.brick-wall) |
215 | 229 |
230 | |
231 | |
232 | |
233 | |
234 | |
216 (defn touch-reception [controls] | 235 (defn touch-reception [controls] |
217 (let [control | 236 (let [control |
218 (first | 237 (first |
219 (filter | 238 (filter |
220 #(< 2 (.getOverlappingCount %)) controls))] | 239 #(< 2 (.getOverlappingCount %)) controls))] |
280 (defn transparent-box [] | 299 (defn transparent-box [] |
281 (doto | 300 (doto |
282 (make-shape | 301 (make-shape |
283 (merge base-shape | 302 (merge base-shape |
284 {:position (Vector3f. 0 2 0) | 303 {:position (Vector3f. 0 2 0) |
285 :name "the blob." | 304 :name "box" |
286 :material "Common/MatDefs/Misc/Unshaded.j3md" | 305 :material "Common/MatDefs/Misc/Unshaded.j3md" |
287 :texture "Textures/purpleWisp.png" | 306 :texture "Textures/purpleWisp.png" |
288 :physical? true | 307 :physical? true |
289 :mass 70 | 308 :mass 70 |
290 :color ColorRGBA/Blue | 309 :color ColorRGBA/Blue |
297 | 316 |
298 (defn transparent-floor [] | 317 (defn transparent-floor [] |
299 (doto | 318 (doto |
300 (box 5 0.2 5 :mass 0 :position (Vector3f. 0 -2 0) | 319 (box 5 0.2 5 :mass 0 :position (Vector3f. 0 -2 0) |
301 :material "Common/MatDefs/Misc/Unshaded.j3md" | 320 :material "Common/MatDefs/Misc/Unshaded.j3md" |
302 :texture "Textures/redWisp.png") | 321 :texture "Textures/redWisp.png" |
322 :name "floor") | |
303 (-> (.getMaterial) | 323 (-> (.getMaterial) |
304 (.getAdditionalRenderState) | 324 (.getAdditionalRenderState) |
305 (.setBlendMode RenderState$BlendMode/Alpha)) | 325 (.setBlendMode RenderState$BlendMode/Alpha)) |
306 (.setQueueBucket RenderQueue$Bucket/Transparent))) | 326 (.setQueueBucket RenderQueue$Bucket/Transparent))) |
307 | 327 |
313 (let [physics-manager (.getState (.getStateManager world) BulletAppState)] | 333 (let [physics-manager (.getState (.getStateManager world) BulletAppState)] |
314 (.setAccuracy (.getPhysicsSpace physics-manager) (float new-accuracy)))) | 334 (.setAccuracy (.getPhysicsSpace physics-manager) (float new-accuracy)))) |
315 | 335 |
316 (defn test-skin [] | 336 (defn test-skin [] |
317 (let [b | 337 (let [b |
338 (transparent-box) | |
318 ;;(transparent-sphere) | 339 ;;(transparent-sphere) |
319 (transparent-box) | 340 ;;(sphere) |
320 f (transparent-floor) | 341 f (transparent-floor) |
321 ;;controls | 342 ;;controls |
322 ;;(make-touch-sphere b) | 343 ;;(make-touch-sphere b) |
323 ;;(make-touch b) | 344 ;;(make-touch b) |
324 debug-node (Node.) | 345 debug-node (Node.) |
330 (world | 351 (world |
331 | 352 |
332 node | 353 node |
333 {"key-return" (fire-cannon-ball) | 354 {"key-return" (fire-cannon-ball) |
334 "key-space" (fn [game value] | 355 "key-space" (fn [game value] |
335 (println-repl (touch-percieve 1 b node debug-node))) | 356 (if value |
357 (println-repl (touch-percieve 0.2 b node debug-node)))) | |
336 } | 358 } |
337 ;;no-op | 359 ;;no-op |
338 (fn [world] | 360 (fn [world] |
339 ;; (Capture/SimpleCaptureVideo | 361 ;; (Capture/SimpleCaptureVideo |
340 ;; world | 362 ;; world |
343 (enable-debug world) | 365 (enable-debug world) |
344 ;; (set-accuracy world (/ 1 60)) | 366 ;; (set-accuracy world (/ 1 60)) |
345 ) | 367 ) |
346 | 368 |
347 (fn [& _] | 369 (fn [& _] |
348 (Thread/sleep 10) | 370 ;;(println-repl |
371 (touch-percieve 0.2 b node debug-node) | |
372 ;;(Thread/sleep 10) | |
349 ;;(touch-print controls) | 373 ;;(touch-print controls) |
350 ;;(color-touch controls) | 374 ;;(color-touch controls) |
351 )))) | 375 )))) |
352 | 376 |
353 #+end_src | 377 #+end_src |
354 | 378 |
355 #+results: skin-main | 379 #+results: skin-main |
356 : #'body.skin/test-skin | 380 : #'body.skin/test-skin |
381 | |
382 | |
357 | 383 |
358 | 384 |
359 | 385 |
360 | 386 |
361 | 387 |