Mercurial > cortex
comparison org/test-creature.org @ 154:bb235258f835
deleted code from purgatory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 03 Feb 2012 06:01:22 -0700 |
parents | c95179907951 |
children | 95bf55614211 |
comparison
equal
deleted
inserted
replaced
153:c95179907951 | 154:bb235258f835 |
---|---|
1036 : #'cortex.silly/follow-test | 1036 : #'cortex.silly/follow-test |
1037 | 1037 |
1038 | 1038 |
1039 * COMMENT purgatory | 1039 * COMMENT purgatory |
1040 #+begin_src clojure | 1040 #+begin_src clojure |
1041 (defn bullet-trans [] | |
1042 (let [obj-a (sphere 0.5 :color ColorRGBA/Red | |
1043 :position (Vector3f. -10 5 0)) | |
1044 obj-b (sphere 0.5 :color ColorRGBA/Blue | |
1045 :position (Vector3f. -10 -5 0) | |
1046 :mass 0) | |
1047 control-a (.getControl obj-a RigidBodyControl) | |
1048 control-b (.getControl obj-b RigidBodyControl) | |
1049 swivel | |
1050 (.toRotationMatrix | |
1051 (doto (Quaternion.) | |
1052 (.fromAngleAxis (/ Math/PI 2) | |
1053 Vector3f/UNIT_X)))] | |
1054 (doto | |
1055 (ConeJoint. | |
1056 control-a control-b | |
1057 (Vector3f. 0 5 0) | |
1058 (Vector3f. 0 -5 0) | |
1059 swivel swivel) | |
1060 (.setLimit (* 0.6 (/ Math/PI 4)) | |
1061 (/ Math/PI 4) | |
1062 (* Math/PI 0.8))) | |
1063 (world (nodify | |
1064 [obj-a obj-b]) | |
1065 standard-debug-controls | |
1066 enable-debug | |
1067 no-op))) | |
1068 | |
1069 | 1041 |
1070 (defn bullet-trans* [] | 1042 (defn bullet-trans* [] |
1071 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red | 1043 (let [obj-a (box 1.5 0.5 0.5 :color ColorRGBA/Red |
1072 :position (Vector3f. 5 0 0) | 1044 :position (Vector3f. 5 0 0) |
1073 :mass 90) | 1045 :mass 90) |
1157 :physical? false :position | 1129 :physical? false :position |
1158 (.getWorldTranslation obj-a))))) | 1130 (.getWorldTranslation obj-a))))) |
1159 ) | 1131 ) |
1160 )) | 1132 )) |
1161 | 1133 |
1162 (defn transform-trianglesdsd | |
1163 "Transform that converts each vertex in the first triangle | |
1164 into the corresponding vertex in the second triangle." | |
1165 [#^Triangle tri-1 #^Triangle tri-2] | |
1166 (let [in [(.get1 tri-1) | |
1167 (.get2 tri-1) | |
1168 (.get3 tri-1)] | |
1169 out [(.get1 tri-2) | |
1170 (.get2 tri-2) | |
1171 (.get3 tri-2)]] | |
1172 (let [translate (doto (Matrix4f.) (.setTranslation (.negate (in 0)))) | |
1173 in* [(.mult translate (in 0)) | |
1174 (.mult translate (in 1)) | |
1175 (.mult translate (in 2))] | |
1176 final-translation | |
1177 (doto (Matrix4f.) | |
1178 (.setTranslation (out 1))) | |
1179 | |
1180 rotate-1 | |
1181 (doto (Matrix3f.) | |
1182 (.fromStartEndVectors | |
1183 (.normalize | |
1184 (.subtract | |
1185 (in* 1) (in* 0))) | |
1186 (.normalize | |
1187 (.subtract | |
1188 (out 1) (out 0))))) | |
1189 in** [(.mult rotate-1 (in* 0)) | |
1190 (.mult rotate-1 (in* 1)) | |
1191 (.mult rotate-1 (in* 2))] | |
1192 scale-factor-1 | |
1193 (.mult | |
1194 (.normalize | |
1195 (.subtract | |
1196 (out 1) | |
1197 (out 0))) | |
1198 (/ (.length | |
1199 (.subtract (out 1) | |
1200 (out 0))) | |
1201 (.length | |
1202 (.subtract (in** 1) | |
1203 (in** 0))))) | |
1204 scale-1 (doto (Matrix4f.) (.setScale scale-factor-1)) | |
1205 in*** [(.mult scale-1 (in** 0)) | |
1206 (.mult scale-1 (in** 1)) | |
1207 (.mult scale-1 (in** 2))] | |
1208 | |
1209 | |
1210 | |
1211 | |
1212 | |
1213 ] | |
1214 | |
1215 (dorun (map println in)) | |
1216 (println) | |
1217 (dorun (map println in*)) | |
1218 (println) | |
1219 (dorun (map println in**)) | |
1220 (println) | |
1221 (dorun (map println in***)) | |
1222 (println) | |
1223 | |
1224 )))) | |
1225 | |
1226 | |
1227 (defn world-setup [joint] | |
1228 (let [joint-position (Vector3f. 0 0 0) | |
1229 joint-rotation | |
1230 (.toRotationMatrix | |
1231 (.mult | |
1232 (doto (Quaternion.) | |
1233 (.fromAngleAxis | |
1234 (* 1 (/ Math/PI 4)) | |
1235 (Vector3f. -1 0 0))) | |
1236 (doto (Quaternion.) | |
1237 (.fromAngleAxis | |
1238 (* 1 (/ Math/PI 2)) | |
1239 (Vector3f. 0 0 1))))) | |
1240 top-position (.mult joint-rotation (Vector3f. 8 0 0)) | |
1241 | |
1242 origin (doto | |
1243 (sphere 0.1 :physical? false :color ColorRGBA/Cyan | |
1244 :position top-position)) | |
1245 top (doto | |
1246 (sphere 0.1 :physical? false :color ColorRGBA/Yellow | |
1247 :position top-position) | |
1248 | |
1249 (.addControl | |
1250 (RigidBodyControl. | |
1251 (CapsuleCollisionShape. 0.5 1.5 1) (float 20)))) | |
1252 bottom (doto | |
1253 (sphere 0.1 :physical? false :color ColorRGBA/DarkGray | |
1254 :position (Vector3f. 0 0 0)) | |
1255 (.addControl | |
1256 (RigidBodyControl. | |
1257 (CapsuleCollisionShape. 0.5 1.5 1) (float 0)))) | |
1258 table (box 10 2 10 :position (Vector3f. 0 -20 0) | |
1259 :color ColorRGBA/Gray :mass 0) | |
1260 a (.getControl top RigidBodyControl) | |
1261 b (.getControl bottom RigidBodyControl)] | |
1262 | |
1263 (cond | |
1264 (= joint :cone) | |
1265 | |
1266 (doto (ConeJoint. | |
1267 a b | |
1268 (world-to-local top joint-position) | |
1269 (world-to-local bottom joint-position) | |
1270 joint-rotation | |
1271 joint-rotation | |
1272 ) | |
1273 | |
1274 | |
1275 (.setLimit (* (/ 10) Math/PI) | |
1276 (* (/ 4) Math/PI) | |
1277 0))) | |
1278 [origin top bottom table])) | |
1279 | |
1280 (defn test-joint [joint] | 1134 (defn test-joint [joint] |
1281 (let [[origin top bottom floor] (world-setup joint) | 1135 (let [[origin top bottom floor] (world-setup joint) |
1282 control (.getControl top RigidBodyControl) | 1136 control (.getControl top RigidBodyControl) |
1283 move-up? (atom false) | 1137 move-up? (atom false) |
1284 move-down? (atom false) | 1138 move-down? (atom false) |
1339 (Vector3f. -1 0 0)))) | 1193 (Vector3f. -1 0 0)))) |
1340 (if @roll-right? | 1194 (if @roll-right? |
1341 (.applyTorque control | 1195 (.applyTorque control |
1342 (.mult (.getPhysicsRotation control) | 1196 (.mult (.getPhysicsRotation control) |
1343 (Vector3f. 1 0 0)))))))) | 1197 (Vector3f. 1 0 0)))))))) |
1344 | |
1345 | |
1346 | |
1347 (defprotocol Frame | |
1348 (frame [this])) | |
1349 | |
1350 (extend-type BufferedImage | |
1351 Frame | |
1352 (frame [image] | |
1353 (merge | |
1354 (apply | |
1355 hash-map | |
1356 (interleave | |
1357 (doall (for [x (range (.getWidth image)) y (range (.getHeight image))] | |
1358 (vector x y))) | |
1359 (doall (for [x (range (.getWidth image)) y (range (.getHeight image))] | |
1360 (let [data (.getRGB image x y)] | |
1361 (hash-map :r (bit-shift-right (bit-and 0xff0000 data) 16) | |
1362 :g (bit-shift-right (bit-and 0x00ff00 data) 8) | |
1363 :b (bit-and 0x0000ff data))))))) | |
1364 {:width (.getWidth image) :height (.getHeight image)}))) | |
1365 | |
1366 | |
1367 (extend-type ImagePlus | |
1368 Frame | |
1369 (frame [image+] | |
1370 (frame (.getBufferedImage image+)))) | |
1371 | |
1372 | |
1373 #+end_src | 1198 #+end_src |
1374 | 1199 |
1375 | 1200 |
1376 * COMMENT generate source | 1201 * COMMENT generate source |
1377 #+begin_src clojure :tangle ../src/cortex/silly.clj | 1202 #+begin_src clojure :tangle ../src/cortex/silly.clj |