|
8 | 8 | :tags [:visualization]}}} |
9 | 9 | (ns opengl-visualization.main |
10 | 10 | (:require [clojure.java.io :as io] |
11 | | - [clojure.math :refer (to-radians)]) |
| 11 | + [clojure.math :refer (to-radians)] |
| 12 | + [fastmath.vector :refer (vec3 sub add mult)] |
| 13 | + ) |
12 | 14 | (:import [javax.imageio ImageIO] |
13 | 15 | [java.awt.image BufferedImage] |
14 | 16 | [org.lwjgl BufferUtils] |
@@ -241,6 +243,8 @@ void main() |
241 | 243 | (def height (int-array 1)) |
242 | 244 | (def channels (int-array 1)) |
243 | 245 | (def buffer (STBImage/stbi_load moon-png width height channels 4))) |
| 246 | +(aget width 0) |
| 247 | +(aget height 0) |
244 | 248 |
|
245 | 249 | ;; ### Set up the texture |
246 | 250 | (do |
@@ -425,8 +429,22 @@ void main() |
425 | 429 | (GL15/glDeleteBuffers vao)) |
426 | 430 |
|
427 | 431 | ;; ## Approximating a sphere |
| 432 | +;; |
| 433 | +;; Get corners of cube |
| 434 | +(def corners (map #(apply vec3 %) (partition 3 vertices-cube))) |
| 435 | +corners |
| 436 | + |
| 437 | +(def u-vectors (map (fn [[i j _ _]] (sub (nth corners j) (nth corners i))) (partition 4 indices-cube))) |
| 438 | +u-vectors |
| 439 | + |
| 440 | +(def v-vectors (map (fn [[i _ _ l]] (sub (nth corners l) (nth corners i))) (partition 4 indices-cube))) |
| 441 | +v-vectors |
428 | 442 |
|
| 443 | +(defn sphere-points [n c u v] (for [j (range (inc n)) i (range (inc n))] (add c (add (mult u (/ i n)) (mult v (/ j n)))))) |
| 444 | +(defn sphere-indices [n face] (for [j (range n) i (range n)] (let [offset (+ (* face (inc n) (inc n)) (* j (inc n)) i)] [offset (inc offset) (+ offset n 2) (+ offset n 1)]))) |
429 | 445 |
|
| 446 | +(def n 2) |
| 447 | +(def vertices-sphere (float-array (flatten (map (partial sphere-points n) corners u-vectors v-vectors)))) |
430 | 448 | (GL20/glDeleteProgram program) |
431 | 449 | (GL11/glDeleteTextures texture) |
432 | 450 |
|
|
0 commit comments