comparison org/test-creature.org @ 79:01dbdb0d5500

offset cone joints achieved!
author Robert McIntyre <rlm@mit.edu>
date Wed, 04 Jan 2012 21:03:25 -0700
parents 77b506ac64f3
children 7af5ef686539
comparison
equal deleted inserted replaced
78:77b506ac64f3 79:01dbdb0d5500
67 "Convert from Blender coordinates to JME coordinates" 67 "Convert from Blender coordinates to JME coordinates"
68 [#^Vector3f in] 68 [#^Vector3f in]
69 (Vector3f. (.getX in) 69 (Vector3f. (.getX in)
70 (.getZ in) 70 (.getZ in)
71 (- (.getY in)))) 71 (- (.getY in))))
72
73 (defn jme-to-blender
74 "Convert from JME coordinates to Blender coordinates"
75 [#^Vector3f in]
76 (Vector3f. (.getX in)
77 (- (.getZ in))
78 (.getY in)))
72 79
73 (defn joint-targets 80 (defn joint-targets
74 "Return the two closest two objects to the joint object, ordered 81 "Return the two closest two objects to the joint object, ordered
75 from bottom to top according to the joint's rotation." 82 from bottom to top according to the joint's rotation."
76 [#^Node parts #^Node joint] 83 [#^Node parts #^Node joint]
86 (let [targets 93 (let [targets
87 (distinct 94 (distinct
88 (map #(.getGeometry %) results))] 95 (map #(.getGeometry %) results))]
89 (if (>= (count targets) 2) 96 (if (>= (count targets) 2)
90 (sort-by 97 (sort-by
91 #(.getY 98 #(let [v
92 (.mult 99 (jme-to-blender
93 (.inverse (.getWorldRotation joint)) 100 (.mult
94 (.subtract (.getWorldTranslation %) 101 (.inverse (.getWorldRotation joint))
95 (.getWorldTranslation joint)))) 102 (.subtract (.getWorldTranslation %)
103 (.getWorldTranslation joint))))]
104 (println-repl (.getName %) ":" v)
105 (.dot (Vector3f. 1 1 1)
106 v))
96 (take 2 targets)) 107 (take 2 targets))
97 (recur (float (* radius 2)))))))) 108 (recur (float (* radius 2))))))))
98 109
99 (defn connect 110 (defn connect
100 "here are some examples: 111 "here are some examples:
101 {:type :point} 112 {:type :point}
102 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)} 113 {:type :hinge :limit [0 (/ Math/PI 2)] :axis (Vector3f. 0 1 0)}
103 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints) 114 (:axis defaults to (Vector3f. 1 0 0) if not provided for hinge joints)
104 115
105 {:type :cone :limit-xz 0] 116 {:type :cone :limit-xz 0]
106 :limit-yz 0] 117 :limit-xy 0]
107 :twist 0]}" 118 :twist 0]} (use XZY rotation mode in blender!)"
108 ([#^Node obj-a #^Node obj-b #^Node joint] 119 ([#^Node obj-a #^Node obj-b #^Node joint]
109 (let [center-a (.getWorldTranslation obj-a) 120 (let [center-a (.getWorldTranslation obj-a)
110 center-b (.getWorldTranslation obj-b) 121 center-b (.getWorldTranslation obj-b)
111 joint-center (.getWorldTranslation joint) 122 joint-center (.getWorldTranslation joint)
112 pivot-a (.subtract joint-center center-a) 123 pivot-a (.subtract joint-center center-a)
156 hinge-axis) 167 hinge-axis)
157 (.setLimit limit-1 limit-2)))) 168 (.setLimit limit-1 limit-2))))
158 (= :cone joint-type) 169 (= :cone joint-type)
159 (do 170 (do
160 (let [limit-xy (:limit-xz constraints) 171 (let [limit-xy (:limit-xz constraints)
161 limit-yz (:limit-yz constraints) 172 limit-yz (:limit-xy constraints)
162 twist (:twist constraints)] 173 twist (:twist constraints)]
163 174
164 (println-repl "creating CONE joint") 175 (println-repl "creating CONE joint")
165 (doto 176 (doto
166 (ConeJoint. 177 (ConeJoint.
167 control-a 178 control-a
168 control-b 179 control-b
169 pivot-a 180 pivot-a
170 pivot-b 181 pivot-b
171 (doto (Matrix3f.) 182
172 (.fromStartEndVectors
173 Vector3f/UNIT_X
174 (.normalize
175 (.subtract (.getWorldTranslation joint)
176 (.getWorldTranslation obj-a)))))
177 (doto (Matrix3f.) 183 (doto (Matrix3f.)
178 (.fromStartEndVectors 184 (.fromStartEndVectors
179 Vector3f/UNIT_X 185 Vector3f/UNIT_X
180 (.normalize 186 (.normalize
181 (.subtract 187 (.subtract
182 (.getWorldTranslation obj-b) 188 (.getWorldTranslation joint)
183 (.getWorldTranslation joint)))))) 189 (.getWorldTranslation obj-a)))))
190 (doto (Matrix3f.)
191 (.set (.getWorldRotation joint)))
192
193 )
184 (.setLimit (float limit-xy) 194 (.setLimit (float limit-xy)
185 (float limit-yz) 195 (float limit-yz)
186 (float twist))))) 196 (float twist)))))
187 true 197 true
188 (println-repl 198 (println-repl