|
4 | 4 | [opengl.geom :as geom]
|
5 | 5 | [opengl.util :as util]
|
6 | 6 | [opengl.b3d :as b3d]
|
| 7 | + [opengl.models :as m] |
7 | 8 | [opengl.route :as route]]
|
8 | 9 | (:gen-class))
|
9 | 10 |
|
| 11 | + |
| 12 | +(defn- apply-translate-to-mesh |
| 13 | + [mesh [tx ty tz] |
| 14 | + normal-transform1 |
| 15 | + normal-transform2] |
| 16 | + (m/create-mesh |
| 17 | + (map (fn [face] |
| 18 | + (let [verts |
| 19 | + (map (fn [vert] |
| 20 | + (let [[x y z] (geom/rotate-with-transform |
| 21 | + (geom/rotate-with-transform |
| 22 | + (:coordinate vert) normal-transform1) |
| 23 | + normal-transform2) |
| 24 | + [nx ny nz] (:normal vert) |
| 25 | + [nx' ny' nz'] (geom/rotate-with-transform |
| 26 | + (geom/rotate-with-transform |
| 27 | + [nx ny nz] normal-transform1) |
| 28 | + normal-transform2)] |
| 29 | + (let [v (m/create-vertex |
| 30 | + [(+ tx x) |
| 31 | + (+ ty y) |
| 32 | + (+ tz z)] |
| 33 | + (:texture-coordinate vert) |
| 34 | + [nx' ny' nz'])] |
| 35 | + v))) |
| 36 | + (:verts face))] |
| 37 | + (m/update-face face verts))) |
| 38 | + (:faces mesh)))) |
| 39 | + |
| 40 | +(defn- create-transformed-object |
| 41 | + [prototype pos base-transform aux-transform track-position] |
| 42 | + (map (fn [mesh] |
| 43 | + (apply-translate-to-mesh mesh pos aux-transform base-transform)) |
| 44 | + prototype)) |
| 45 | + |
| 46 | + |
10 | 47 | (defn- create-track-transforms-in-block-with-direction
|
11 | 48 | [block direction]
|
12 | 49 | (let [[dx dy] direction
|
|
52 | 89 | radius (:radius curves)
|
53 | 90 | cant (:cant curves)
|
54 | 91 | block-length (- (:end-ref block) (:start-ref block))]
|
55 |
| - (if (or (nil? radius) (= radius 0.0)) |
| 92 | + (if (or (nil? radius) (= (float radius) 0.0)) |
56 | 93 | (create-track-transforms-in-block-with-direction
|
57 | 94 | block direction)
|
58 |
| - (let [b (/ block-length (Math/abs radius)) |
59 |
| - c (Math/sqrt (* 2.0 radius radius (- 1.0 (Math/cos b)))) |
60 |
| - a (* -1.0 0.5 (Math/signum radius) b)] |
| 95 | + (let [b (/ block-length (Math/abs (float radius))) |
| 96 | + c (Math/sqrt (* 2.0 (float radius) (float radius) (- 1.0 (Math/cos b)))) |
| 97 | + a (* -1.0 0.5 (Math/signum (float radius)) b)] |
61 | 98 | (create-track-transforms-in-block-with-direction
|
62 | 99 | block
|
63 | 100 | (geom/rotate-vector-2d
|
|
77 | 114 |
|
78 | 115 | direction (:direction block)
|
79 | 116 | position (:position block)
|
| 117 | + |
| 118 | + zzz (println "Incoming" direction position) |
| 119 | + |
80 | 120 | curve (:curve block)
|
81 | 121 | height (or (:height block) 0.0)
|
| 122 | + |
| 123 | + ;;TODO remove me |
| 124 | + height 0.0 |
| 125 | + |
82 | 126 | block-length (- (:end-ref block) (:start-ref block))
|
83 | 127 |
|
84 | 128 | end-x (or end-x start-x)
|
85 | 129 | end-y (or end-y start-y)
|
86 | 130 |
|
87 | 131 | [dx dy] direction
|
88 | 132 | [pxo pyo pzo] position
|
| 133 | + |
89 | 134 | [px py pz] (geom/vector-add position [(* dy start-x) start-y (* -1.0 dx start-x)])
|
90 | 135 |
|
91 | 136 | px2 (+ (* dx block-length) pxo)
|
|
120 | 165 | (* 2.0 next-curve next-curve (- 1.0 (Math/cos b2))))
|
121 | 166 |
|
122 | 167 | a2 (* 0.5 (Math/signum next-curve) b2)
|
| 168 | + |
| 169 | + zzz (println "a2" a2 direction2) |
| 170 | + |
123 | 171 | [dx2 dy2] (geom/rotate-vector-2d direction2
|
124 | 172 | (Math/cos (- a2)) (Math/sin (- a2)))
|
125 | 173 |
|
| 174 | + zzz (println "dx2" dx2 dy2) |
| 175 | + |
126 | 176 | offset2 [(* dy2 end-x) end-y (* -1.0 dx2 end-x)]
|
127 | 177 | position2 (geom/vector-add offset2 [px2 py2 pz2])
|
128 | 178 |
|
| 179 | + zzz (println "op" offset2 position2) |
| 180 | + |
129 | 181 | [pdx pdy pdz] (geom/vector-normalize (geom/vector-sub position2 [px py pz]))
|
130 | 182 |
|
131 | 183 | [norm-x norm-z] (geom/vector-normalize [pdx pdz])
|
132 | 184 |
|
| 185 | + zzz (println "pdx pdy pdz" pdx pdy pdz) |
| 186 | + |
133 | 187 | rail-trans-z [pdx pdy pdz]
|
134 | 188 | rail-trans-x [norm-z 0.0 (* -1.0 norm-x)]
|
135 | 189 | rail-trans-y (geom/vector-cross rail-trans-z rail-trans-x)
|
|
167 | 221 | rail
|
168 | 222 | (if (or (= railidx 0) (nil? next-block))
|
169 | 223 | (create-transforms-for-player-rail block)
|
170 |
| - (create-transforms-for-rail block next-block rail) |
| 224 | + (do |
| 225 | + (create-transforms-for-rail block next-block rail)) |
171 | 226 | ))])
|
172 | 227 | (:rails block))))))
|
173 | 228 |
|
|
183 | 238 | (update-position-in-block (last blocks) block block-length))
|
184 | 239 | (next-block context block))))
|
185 | 240 | [] (:blocks context)))))
|
| 241 | + |
| 242 | +(defn- get-rail-aligned-objects-in-rail [context block rail] |
| 243 | + (let [[dx dy] (:start rail) |
| 244 | + [x y z] (:position block) |
| 245 | + x (+ dx x) |
| 246 | + y (+ dy y) |
| 247 | + pos [x y z] |
| 248 | + rail-transform (:rail-transform rail) |
| 249 | + track-pos (:start-ref block)] |
| 250 | + (create-transformed-object |
| 251 | + (:prototype rail) pos |
| 252 | + rail-transform geom/identity-transform |
| 253 | + track-pos))) |
| 254 | + |
| 255 | +(defn- get-rail-aligned-objects-in-block [context block] |
| 256 | + (apply |
| 257 | + concat |
| 258 | + (map |
| 259 | + #(get-rail-aligned-objects-in-rail context block (second %)) |
| 260 | + (:rails block)))) |
| 261 | + |
| 262 | +(defn get-drawable-objects-in-block [context block] |
| 263 | + (get-rail-aligned-objects-in-block context block)) |
| 264 | + |
| 265 | +(defn get-drawable-objects-in-context [context] |
| 266 | + (reduce (fn [objs block] |
| 267 | + (concat |
| 268 | + objs |
| 269 | + (get-drawable-objects-in-block context block))) |
| 270 | + [] |
| 271 | + (:blocks context))) |
| 272 | + |
| 273 | +(def context |
| 274 | + (create-geometries-for-blocks-in-context |
| 275 | + (route/parse-route-file "Flushing/test.csv"))) |
| 276 | + |
| 277 | +(def context (assoc context :blocks (take 10 (:blocks context)))) |
| 278 | +(def objs (get-drawable-objects-in-context context)) |
| 279 | + |
| 280 | +(def dummy 1) |
0 commit comments