# HG changeset patch # User Robert McIntyre # Date 1319392121 25200 # Node ID a149692d3d1fd3bea12cfd8a28aa133446c74283 # Parent 0251b7e7609f935a88c467517f114f4d5d1450a1 remove old GhostControl touch code diff -r 0251b7e7609f -r a149692d3d1f org/skin.org --- a/org/skin.org Sun Oct 23 10:09:02 2011 -0700 +++ b/org/skin.org Sun Oct 23 10:48:41 2011 -0700 @@ -26,60 +26,10 @@ (import java.util.logging.Level) (import java.util.logging.Logger) +(use 'hello.brick-wall) -;; looks like we can use GhostControls for implementing touch. -;; for example: -(def rc (GhostControl. (BoxCollisionShape. (Vector3f. 2 2 2)))) -(def shifted-sphere - (doto (CompoundCollisionShape.) - (.addChildShape (SphereCollisionShape. 3) (Vector3f. 1 0 0)))) - -(def gc (GhostControl. shifted-sphere)) -(def b (box 1 1 1 :mass 1)) -(.addControl b rc) -(.addControl b gc) - - -(defn looksies! [] - (view b)) - -;; overlapping objects can be gotten via =.getOverlappingCount= and -;; =.getOverlappingObjects= - -;; looks like I might be able to place a small "touch-sphere" whther -;; on every triangle in the object's mesh, or at the verticies, using -;; .getTriangleCount() on the mesh gotten by .getMesh() - -;; this way, I can create a mesh and just divide up it's faces using -;; blender, and this will create the touch sensor distribution. - - -(defn make-touch-sphere [#^Geometry geom] - (let [tri (Triangle.) - mesh (.getMesh geom) - controls! (transient [])] - (dorun - (for [n (range (.getTriangleCount mesh))] - (do - (.getTriangle mesh n tri) - (.calculateCenter tri) - (let [control - (doto - (GhostControl. - (doto (CompoundCollisionShape.) - (.addChildShape - (SphereCollisionShape. (float 0.1)) - (.mult (.getCenter tri) (float 1))) - (.setMargin -0.1))) - (.setApplyPhysicsLocal true))] - - (.addControl geom control) - (conj! controls! control))))) - (persistent! controls!))) - - (defn triangles [#^Geometry geom] (let [mesh (.getMesh geom) @@ -94,11 +44,6 @@ (persistent! triangles))) -(defn new-touch [#^Geometry geom] - (dorun (map - (comp no-op #(.getCenter %)) - (triangles geom)))) - (defn get-ray-origin [geom tri] (let [new (Vector3f.)] @@ -194,83 +139,6 @@ answer ))))))) -(defn make-touch [#^Geometry geom] - (let [tri (Triangle.) - mesh (.getMesh geom) - controls! (transient [])] - (dorun - (for [n (range (.getTriangleCount mesh))] - (do - (.getTriangle mesh n tri) - (.calculateCenter tri) - (.calculateNormal tri) -;; (println-repl tri) -;; (println-repl (.get1 tri)) -;; (println-repl (.get2 tri)) -;; (println-repl (.get3 tri)) -;; (println-repl (.getCenter tri)) -;; (println-repl (.getNormal tri)) - (let [control - (doto - (GhostControl. - - (doto (CompoundCollisionShape.) - (.addChildShape - (SimplexCollisionShape. Vector3f/ZERO) - (.mult (.getCenter tri) (float 1))) - (.setMargin 0) - )) - (.setApplyPhysicsLocal true))] - (.addControl geom control) - (conj! controls! control))))) - (persistent! controls!))) - -(use 'hello.brick-wall) - - - - - - -(defn touch-reception [controls] - (let [control - (first - (filter - #(< 2 (.getOverlappingCount %)) controls))] - (if (not (nil? control)) - (println - (seq - (.getOverlappingObjects control)))))) - -(defn touch-print [controls] - (println - (map #(count (.getNonGhostOverlappingObjects %)) controls))) - -(defn set-debug-color [#^ColorRGBA color #^GhostControl gc] - (.setColor (.getMaterial (.getChild (.getDebugShape gc) 0)) "Color" color)) - -(defn html-color [html-str] - ((fn [[r g b]] (ColorRGBA. r g b (float 1))) - (map #(float (/ (Integer/parseInt % 16) 255)) - (map (partial apply str) (partition 2 html-str))))) - -(defn color-touch [controls] - (no-exceptions - (dorun - (map - (fn [control] - (case (count (.getNonGhostOverlappingObjects control)) - 0 (set-debug-color ColorRGBA/Gray control) - 1 (set-debug-color ColorRGBA/Blue control) - 2 (set-debug-color ColorRGBA/Green control) - 3 (set-debug-color ColorRGBA/Yellow control) - 4 (set-debug-color ColorRGBA/Orange control) - 5 (set-debug-color ColorRGBA/Red control) - 6 (set-debug-color ColorRGBA/Magenta control) - 7 (set-debug-color ColorRGBA/Pink control) - 8 (set-debug-color ColorRGBA/White control))) - controls)))) - (defn enable-debug [world] (.enableDebug (.getPhysicsSpace @@ -279,6 +147,14 @@ BulletAppState)) (asset-manager))) +(defn no-logging [] + (.setLevel (Logger/getLogger "com.jme3") Level/OFF)) + +(defn set-accuracy [world new-accuracy] + (let [physics-manager (.getState (.getStateManager world) BulletAppState)] + (.setAccuracy (.getPhysicsSpace physics-manager) (float new-accuracy)))) + + (defn transparent-sphere [] (doto (make-shape @@ -313,7 +189,6 @@ (.setBlendMode RenderState$BlendMode/Alpha)) (.setQueueBucket RenderQueue$Bucket/Transparent))) - (defn transparent-floor [] (doto (box 5 0.2 5 :mass 0 :position (Vector3f. 0 -2 0) @@ -325,14 +200,6 @@ (.setBlendMode RenderState$BlendMode/Alpha)) (.setQueueBucket RenderQueue$Bucket/Transparent))) - -(defn no-logging [] - (.setLevel (Logger/getLogger "com.jme3") Level/OFF)) - -(defn set-accuracy [world new-accuracy] - (let [physics-manager (.getState (.getStateManager world) BulletAppState)] - (.setAccuracy (.getPhysicsSpace physics-manager) (float new-accuracy)))) - (defn test-skin [] (let [b (transparent-box) @@ -344,18 +211,11 @@ ;;(make-touch b) debug-node (Node.) node (doto (Node.) (.attachChild b) (.attachChild f) - (.attachChild debug-node)) - - ] + (.attachChild debug-node))] (world - node - {"key-return" (fire-cannon-ball) - "key-space" (fn [game value] - (if value - (println-repl (touch-percieve 0.2 b node debug-node)))) - } + {"key-return" (fire-cannon-ball)} ;;no-op (fn [world] ;; (Capture/SimpleCaptureVideo @@ -364,12 +224,13 @@ ;; (no-logging) (enable-debug world) ;; (set-accuracy world (/ 1 60)) - ) + ) (fn [& _] - ;;(println-repl + (println-repl (touch-percieve 0.2 b node debug-node) - ;;(Thread/sleep 10) + ) + (Thread/sleep 10) ;;(touch-print controls) ;;(color-touch controls) ))))