Mercurial > cortex
changeset 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 |
files | org/skin.org |
diffstat | 1 files changed, 15 insertions(+), 154 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/skin.org Sun Oct 23 10:09:02 2011 -0700 1.2 +++ b/org/skin.org Sun Oct 23 10:48:41 2011 -0700 1.3 @@ -26,60 +26,10 @@ 1.4 1.5 (import java.util.logging.Level) 1.6 (import java.util.logging.Logger) 1.7 +(use 'hello.brick-wall) 1.8 1.9 1.10 1.11 -;; looks like we can use GhostControls for implementing touch. 1.12 -;; for example: 1.13 -(def rc (GhostControl. (BoxCollisionShape. (Vector3f. 2 2 2)))) 1.14 -(def shifted-sphere 1.15 - (doto (CompoundCollisionShape.) 1.16 - (.addChildShape (SphereCollisionShape. 3) (Vector3f. 1 0 0)))) 1.17 - 1.18 -(def gc (GhostControl. shifted-sphere)) 1.19 -(def b (box 1 1 1 :mass 1)) 1.20 -(.addControl b rc) 1.21 -(.addControl b gc) 1.22 - 1.23 - 1.24 -(defn looksies! [] 1.25 - (view b)) 1.26 - 1.27 -;; overlapping objects can be gotten via =.getOverlappingCount= and 1.28 -;; =.getOverlappingObjects= 1.29 - 1.30 -;; looks like I might be able to place a small "touch-sphere" whther 1.31 -;; on every triangle in the object's mesh, or at the verticies, using 1.32 -;; .getTriangleCount() on the mesh gotten by .getMesh() 1.33 - 1.34 -;; this way, I can create a mesh and just divide up it's faces using 1.35 -;; blender, and this will create the touch sensor distribution. 1.36 - 1.37 - 1.38 -(defn make-touch-sphere [#^Geometry geom] 1.39 - (let [tri (Triangle.) 1.40 - mesh (.getMesh geom) 1.41 - controls! (transient [])] 1.42 - (dorun 1.43 - (for [n (range (.getTriangleCount mesh))] 1.44 - (do 1.45 - (.getTriangle mesh n tri) 1.46 - (.calculateCenter tri) 1.47 - (let [control 1.48 - (doto 1.49 - (GhostControl. 1.50 - (doto (CompoundCollisionShape.) 1.51 - (.addChildShape 1.52 - (SphereCollisionShape. (float 0.1)) 1.53 - (.mult (.getCenter tri) (float 1))) 1.54 - (.setMargin -0.1))) 1.55 - (.setApplyPhysicsLocal true))] 1.56 - 1.57 - (.addControl geom control) 1.58 - (conj! controls! control))))) 1.59 - (persistent! controls!))) 1.60 - 1.61 - 1.62 (defn triangles [#^Geometry geom] 1.63 (let 1.64 [mesh (.getMesh geom) 1.65 @@ -94,11 +44,6 @@ 1.66 (persistent! triangles))) 1.67 1.68 1.69 -(defn new-touch [#^Geometry geom] 1.70 - (dorun (map 1.71 - (comp no-op #(.getCenter %)) 1.72 - (triangles geom)))) 1.73 - 1.74 (defn get-ray-origin 1.75 [geom tri] 1.76 (let [new (Vector3f.)] 1.77 @@ -194,83 +139,6 @@ 1.78 answer 1.79 ))))))) 1.80 1.81 -(defn make-touch [#^Geometry geom] 1.82 - (let [tri (Triangle.) 1.83 - mesh (.getMesh geom) 1.84 - controls! (transient [])] 1.85 - (dorun 1.86 - (for [n (range (.getTriangleCount mesh))] 1.87 - (do 1.88 - (.getTriangle mesh n tri) 1.89 - (.calculateCenter tri) 1.90 - (.calculateNormal tri) 1.91 -;; (println-repl tri) 1.92 -;; (println-repl (.get1 tri)) 1.93 -;; (println-repl (.get2 tri)) 1.94 -;; (println-repl (.get3 tri)) 1.95 -;; (println-repl (.getCenter tri)) 1.96 -;; (println-repl (.getNormal tri)) 1.97 - (let [control 1.98 - (doto 1.99 - (GhostControl. 1.100 - 1.101 - (doto (CompoundCollisionShape.) 1.102 - (.addChildShape 1.103 - (SimplexCollisionShape. Vector3f/ZERO) 1.104 - (.mult (.getCenter tri) (float 1))) 1.105 - (.setMargin 0) 1.106 - )) 1.107 - (.setApplyPhysicsLocal true))] 1.108 - (.addControl geom control) 1.109 - (conj! controls! control))))) 1.110 - (persistent! controls!))) 1.111 - 1.112 -(use 'hello.brick-wall) 1.113 - 1.114 - 1.115 - 1.116 - 1.117 - 1.118 - 1.119 -(defn touch-reception [controls] 1.120 - (let [control 1.121 - (first 1.122 - (filter 1.123 - #(< 2 (.getOverlappingCount %)) controls))] 1.124 - (if (not (nil? control)) 1.125 - (println 1.126 - (seq 1.127 - (.getOverlappingObjects control)))))) 1.128 - 1.129 -(defn touch-print [controls] 1.130 - (println 1.131 - (map #(count (.getNonGhostOverlappingObjects %)) controls))) 1.132 - 1.133 -(defn set-debug-color [#^ColorRGBA color #^GhostControl gc] 1.134 - (.setColor (.getMaterial (.getChild (.getDebugShape gc) 0)) "Color" color)) 1.135 - 1.136 -(defn html-color [html-str] 1.137 - ((fn [[r g b]] (ColorRGBA. r g b (float 1))) 1.138 - (map #(float (/ (Integer/parseInt % 16) 255)) 1.139 - (map (partial apply str) (partition 2 html-str))))) 1.140 - 1.141 -(defn color-touch [controls] 1.142 - (no-exceptions 1.143 - (dorun 1.144 - (map 1.145 - (fn [control] 1.146 - (case (count (.getNonGhostOverlappingObjects control)) 1.147 - 0 (set-debug-color ColorRGBA/Gray control) 1.148 - 1 (set-debug-color ColorRGBA/Blue control) 1.149 - 2 (set-debug-color ColorRGBA/Green control) 1.150 - 3 (set-debug-color ColorRGBA/Yellow control) 1.151 - 4 (set-debug-color ColorRGBA/Orange control) 1.152 - 5 (set-debug-color ColorRGBA/Red control) 1.153 - 6 (set-debug-color ColorRGBA/Magenta control) 1.154 - 7 (set-debug-color ColorRGBA/Pink control) 1.155 - 8 (set-debug-color ColorRGBA/White control))) 1.156 - controls)))) 1.157 - 1.158 (defn enable-debug [world] 1.159 (.enableDebug 1.160 (.getPhysicsSpace 1.161 @@ -279,6 +147,14 @@ 1.162 BulletAppState)) 1.163 (asset-manager))) 1.164 1.165 +(defn no-logging [] 1.166 + (.setLevel (Logger/getLogger "com.jme3") Level/OFF)) 1.167 + 1.168 +(defn set-accuracy [world new-accuracy] 1.169 + (let [physics-manager (.getState (.getStateManager world) BulletAppState)] 1.170 + (.setAccuracy (.getPhysicsSpace physics-manager) (float new-accuracy)))) 1.171 + 1.172 + 1.173 (defn transparent-sphere [] 1.174 (doto 1.175 (make-shape 1.176 @@ -313,7 +189,6 @@ 1.177 (.setBlendMode RenderState$BlendMode/Alpha)) 1.178 (.setQueueBucket RenderQueue$Bucket/Transparent))) 1.179 1.180 - 1.181 (defn transparent-floor [] 1.182 (doto 1.183 (box 5 0.2 5 :mass 0 :position (Vector3f. 0 -2 0) 1.184 @@ -325,14 +200,6 @@ 1.185 (.setBlendMode RenderState$BlendMode/Alpha)) 1.186 (.setQueueBucket RenderQueue$Bucket/Transparent))) 1.187 1.188 - 1.189 -(defn no-logging [] 1.190 - (.setLevel (Logger/getLogger "com.jme3") Level/OFF)) 1.191 - 1.192 -(defn set-accuracy [world new-accuracy] 1.193 - (let [physics-manager (.getState (.getStateManager world) BulletAppState)] 1.194 - (.setAccuracy (.getPhysicsSpace physics-manager) (float new-accuracy)))) 1.195 - 1.196 (defn test-skin [] 1.197 (let [b 1.198 (transparent-box) 1.199 @@ -344,18 +211,11 @@ 1.200 ;;(make-touch b) 1.201 debug-node (Node.) 1.202 node (doto (Node.) (.attachChild b) (.attachChild f) 1.203 - (.attachChild debug-node)) 1.204 - 1.205 - ] 1.206 + (.attachChild debug-node))] 1.207 1.208 (world 1.209 - 1.210 node 1.211 - {"key-return" (fire-cannon-ball) 1.212 - "key-space" (fn [game value] 1.213 - (if value 1.214 - (println-repl (touch-percieve 0.2 b node debug-node)))) 1.215 - } 1.216 + {"key-return" (fire-cannon-ball)} 1.217 ;;no-op 1.218 (fn [world] 1.219 ;; (Capture/SimpleCaptureVideo 1.220 @@ -364,12 +224,13 @@ 1.221 ;; (no-logging) 1.222 (enable-debug world) 1.223 ;; (set-accuracy world (/ 1 60)) 1.224 - ) 1.225 + ) 1.226 1.227 (fn [& _] 1.228 - ;;(println-repl 1.229 + (println-repl 1.230 (touch-percieve 0.2 b node debug-node) 1.231 - ;;(Thread/sleep 10) 1.232 + ) 1.233 + (Thread/sleep 10) 1.234 ;;(touch-print controls) 1.235 ;;(color-touch controls) 1.236 ))))