Mercurial > cortex
view org/skin.org @ 11:a149692d3d1f
remove old GhostControl touch code
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 23 Oct 2011 10:48:41 -0700 |
parents | 0251b7e7609f |
children | 22c6878a1bc0 |
line wrap: on
line source
1 #+title: SKIN!2 #+author: Robert McIntyre3 #+email: rlm@mit.edu4 #+description: Simulating touch in JMonkeyEngine5 #+SETUPFILE: ../../aurellem/org/setup.org6 #+INCLUDE: ../../aurellem/org/level-0.org7 #+babel: :mkdirp yes :noweb yes9 let's see what checkboxes look like:11 * test [1/2]12 - [ ] item 113 - [X] item 216 * skin!18 #+srcname: skin-main19 #+begin_src clojure20 (ns body.skin)21 (use 'cortex.world)22 (use 'cortex.import)23 (use 'clojure.contrib.def)24 (cortex.import/mega-import-jme3)25 (rlm.rlm-commands/help)27 (import java.util.logging.Level)28 (import java.util.logging.Logger)29 (use 'hello.brick-wall)33 (defn triangles [#^Geometry geom]34 (let35 [mesh (.getMesh geom)36 triangles (transient [])]37 (dorun38 (for [n (range (.getTriangleCount mesh))]39 (let [tri (Triangle.)]40 (.getTriangle mesh n tri)41 (.calculateNormal tri)42 (.calculateCenter tri)43 (conj! triangles tri))))44 (persistent! triangles)))47 (defn get-ray-origin48 [geom tri]49 (let [new (Vector3f.)]50 (.calculateCenter tri)51 (.localToWorld geom (.getCenter tri) new)52 new))54 (defn get-ray-direction55 [geom tri]56 (let [n+c (Vector3f.)]57 (.calculateNormal tri)58 (.calculateCenter tri)59 (.localToWorld geom (.add (.getCenter tri) (.getNormal tri)) n+c)60 (.subtract n+c (get-ray-origin geom tri))61 ))63 (defn ray-origin-debug64 [ray color]65 (make-shape66 (assoc base-shape67 :shape (Sphere. 5 5 0.05)68 :name "arrow"69 :color color70 :texture false71 :physical? false72 :position73 (.getOrigin ray))))75 (defn ray-debug [ray color]76 (make-shape77 (assoc78 base-shape79 :name "debug-ray"80 :physical? false81 :shape (com.jme3.scene.shape.Line.82 (.getOrigin ray)83 (.add84 (.getOrigin ray)85 (.mult (.getDirection ray)86 (float (.getLimit ray))))))))89 (defn contact-color [contacts]90 (case contacts91 0 ColorRGBA/Gray92 1 ColorRGBA/Blue93 2 ColorRGBA/Green94 3 ColorRGBA/Yellow95 4 ColorRGBA/Orange96 5 ColorRGBA/Red97 6 ColorRGBA/Magenta98 7 ColorRGBA/Pink99 8 ColorRGBA/White))101 (defn normal-rays102 "returns rays"103 [limit #^Geometry geom]104 (vec105 (map106 (fn [tri]107 (doto108 (Ray. (get-ray-origin geom tri)109 (get-ray-direction geom tri))111 (.setLimit limit)112 )113 )114 (triangles geom))))117 (defn collision-debug [node result]118 (println-repl "contact point: " (.getContactPoint result))119 )121 (defn touch-percieve [limit geom node debug-node]122 (let [normals (normal-rays limit geom)]123 (.detachAllChildren debug-node)124 (doall125 (for [ray normals]126 (do127 (let [results (CollisionResults.)]128 (.collideWith node ray results)129 (let [answer (count (filter #(not (= geom (.getGeometry %))) results))130 ;;color (contact-color answer)131 ]132 ;;(dorun (map #(println-repl (.getName (.getGeometry %))) results))133 ;;(.attachChild debug-node (ray-debug ray color))134 ;;(.attachChild debug-node (ray-origin-debug ray color))137 ;;(println-repl (.size results) "results for " ray)138 ;;(doall (map (partial collision-debug node) results))139 answer140 )))))))142 (defn enable-debug [world]143 (.enableDebug144 (.getPhysicsSpace145 (.getState146 (.getStateManager world)147 BulletAppState))148 (asset-manager)))150 (defn no-logging []151 (.setLevel (Logger/getLogger "com.jme3") Level/OFF))153 (defn set-accuracy [world new-accuracy]154 (let [physics-manager (.getState (.getStateManager world) BulletAppState)]155 (.setAccuracy (.getPhysicsSpace physics-manager) (float new-accuracy))))158 (defn transparent-sphere []159 (doto160 (make-shape161 (merge base-shape162 {:position (Vector3f. 0 2 0)163 :name "the blob."164 :material "Common/MatDefs/Misc/Unshaded.j3md"165 :texture "Textures/purpleWisp.png"166 :physical? true167 :mass 70168 :color ColorRGBA/Blue169 :shape (Sphere. 10 10 1)}))170 (-> (.getMaterial)171 (.getAdditionalRenderState)172 (.setBlendMode RenderState$BlendMode/Alpha))173 (.setQueueBucket RenderQueue$Bucket/Transparent)))175 (defn transparent-box []176 (doto177 (make-shape178 (merge base-shape179 {:position (Vector3f. 0 2 0)180 :name "box"181 :material "Common/MatDefs/Misc/Unshaded.j3md"182 :texture "Textures/purpleWisp.png"183 :physical? true184 :mass 70185 :color ColorRGBA/Blue186 :shape (Box. 1 1 1)}))187 (-> (.getMaterial)188 (.getAdditionalRenderState)189 (.setBlendMode RenderState$BlendMode/Alpha))190 (.setQueueBucket RenderQueue$Bucket/Transparent)))192 (defn transparent-floor []193 (doto194 (box 5 0.2 5 :mass 0 :position (Vector3f. 0 -2 0)195 :material "Common/MatDefs/Misc/Unshaded.j3md"196 :texture "Textures/redWisp.png"197 :name "floor")198 (-> (.getMaterial)199 (.getAdditionalRenderState)200 (.setBlendMode RenderState$BlendMode/Alpha))201 (.setQueueBucket RenderQueue$Bucket/Transparent)))203 (defn test-skin []204 (let [b205 (transparent-box)206 ;;(transparent-sphere)207 ;;(sphere)208 f (transparent-floor)209 ;;controls210 ;;(make-touch-sphere b)211 ;;(make-touch b)212 debug-node (Node.)213 node (doto (Node.) (.attachChild b) (.attachChild f)214 (.attachChild debug-node))]216 (world217 node218 {"key-return" (fire-cannon-ball)}219 ;;no-op220 (fn [world]221 ;; (Capture/SimpleCaptureVideo222 ;; world223 ;; (file-str "/home/r/proj/cortex/tmp/blob.avi"))224 ;; (no-logging)225 (enable-debug world)226 ;; (set-accuracy world (/ 1 60))227 )229 (fn [& _]230 (println-repl231 (touch-percieve 0.2 b node debug-node)232 )233 (Thread/sleep 10)234 ;;(touch-print controls)235 ;;(color-touch controls)236 ))))238 #+end_src240 #+results: skin-main241 : #'body.skin/test-skin250 * COMMENT code generation251 #+begin_src clojure :tangle ../src/body/skin.clj :noweb yes252 <<skin-main>>253 #+end_src