Skip to content

Commit cf454ef

Browse files
committed
Add some text
1 parent 02c47df commit cf454ef

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/opengl_visualization/main.clj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,22 +412,31 @@ void main()
412412

413413
;; ## Approximating a sphere
414414
;;
415-
;; Get corners of cube
415+
;; ### Creating the vertex data
416+
;;
417+
;; Get all points of cube.
416418
(def points (map #(apply vec3 %) (partition 3 vertices-cube)))
417419
points
418420

421+
;; Get one corner of each face.
419422
(def corners (map (fn [[i _ _ _]] (nth points i)) (partition 4 indices-cube)))
420423
corners
421424

425+
;; Get first spanning vectpr of face.
422426
(def u-vectors (map (fn [[i j _ _]] (sub (nth points j) (nth points i))) (partition 4 indices-cube)))
423427
u-vectors
424428

429+
;; Get second spanning vector of face.
425430
(def v-vectors (map (fn [[i _ _ l]] (sub (nth points l) (nth points i))) (partition 4 indices-cube)))
426431
v-vectors
427432

433+
;; Subsample the faces and project onto sphere by normalizing the vectors.
428434
(defn sphere-points [n c u v] (for [j (range (inc n)) i (range (inc n))] (normalize (add c (add (mult u (/ i n)) (mult v (/ j n)))))))
435+
436+
;; Connect points with faces to create a mesh.
429437
(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)])))
430438

439+
;; ### Rendering a coarse approximation of the sphere.
431440
(def n 2)
432441
(def vertices-sphere (float-array (flatten (map (partial sphere-points n) corners u-vectors v-vectors))))
433442
(def indices-sphere (int-array (flatten (map (partial sphere-indices n) (range 6)))))
@@ -443,6 +452,7 @@ v-vectors
443452
(GL11/glDrawElements GL11/GL_QUADS (count indices-sphere) GL11/GL_UNSIGNED_INT 0)
444453
(screenshot))
445454

455+
;; ### Rendering a fine approximation of the sphere.
446456
(def n2 16)
447457
(def vertices-sphere-2 (float-array (flatten (map (partial sphere-points n2) corners u-vectors v-vectors))))
448458
(def indices-sphere-2 (int-array (flatten (map (partial sphere-indices n2) (range 6)))))

0 commit comments

Comments
 (0)