Skip to content

Commit

Permalink
* src/clj_nehe/tutorial11.clj: added prim-float prim-int to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Apr 13, 2010
1 parent 9807462 commit 1e3d649
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/clj_nehe/tutorial11.clj
@@ -1,8 +1,9 @@
(ns clj-nehe.tutorial11
(:use [penumbra opengl geometry]
[penumbra.opengl.texture :only [gl-tex-coord-2]]
[penumbra.opengl.core :only [gl-import]])
(:use [clojure.contrib.duck-streams :only [pwd]])
[penumbra.opengl.core :only [gl-import]]
[clojure.contrib.duck-streams :only [pwd]]
[clj-nehe.utils])
(:require [penumbra.app :as app]))

;; -----------------------------------------------------------------------------
Expand All @@ -13,10 +14,21 @@
(def *height* 480)

(defn gen-points [n]
(into [] (for [x (range 45) y (range 45)]
[(- (/ x 5.0) 4.5)
(- (/ y 5.0) 4.5)
(Math/sin (* (/ (* (/ (mod (+ x n) 45) 5.0) 40.0) 360.0) (* Math/PI 2.0)))])))
(let [n (int n)]
(into []
(for [x (range 45) y (range 45)]
(let [x (float x)
y (float y)]
[(prim-float - (prim-float / x 5.0) 4.5)
(prim-float - (prim-float / y 5.0) 4.5)
(Math/sin
(prim-float *
(prim-float /
(prim-float *
(prim-float / (mod (int (+ x (float n))) (int 45)) 5.0)
40.0)
360.0)
(prim-float * Math/PI 2.0)))])))))

(defn points []
((fn points* [n]
Expand Down Expand Up @@ -73,16 +85,16 @@

(defn reshape [[x y width height] state]
(viewport 0 0 width height)
(frustum-view 45 (/ (double width) height) 0.1 100)
(frustum-view 45 (prim-float / width height) 0.1 100)
(load-identity)
state)

(defn update [[delta time] state]
(-> state
(update-in [:xrot] #(+ % 0.3))
(update-in [:yrot] #(+ % 0.2))
(update-in [:zrot] #(+ % 0.4))
(update-in [:points] next)))
(-> state
(update-in [:xrot] (fn [xr] (prim-float + xr 0.3)))
(update-in [:yrot] (fn [yr] (prim-float + yr 0.2)))
(update-in [:zrot] (fn [zr] (prim-float + zr 0.4)))
(update-in [:points] next)))

(defn key-press [key state]
(condp = key
Expand All @@ -101,10 +113,12 @@
(let [tex-points (:tex-points state)
points (first (:points state))]
(doseq [i (range 0 1980 45) j (range 44)]
(let [tl (+ i j)
bl (+ i (inc j))
br (+ (+ i 45) (inc j))
tr (+ (+ i 45) j)
(let [i (int i)
j (int j)
tl (+ i j)
bl (+ i (int (inc j)))
br (prim-int + i 45 (inc j))
tr (prim-int + i 45 j)
vs [[(tex-points tl) (points tl)]
[(tex-points bl) (points bl)]
[(tex-points br) (points br)]
Expand Down
3 changes: 3 additions & 0 deletions src/clj_nehe/utils.clj
Expand Up @@ -9,6 +9,9 @@
`(~fn (~type ~a)
(prim ~fn ~type ~b ~@rest))))

(defmacro prim-int [fn & rest]
`(prim ~fn int ~@rest))

(defmacro prim-float [fn & rest]
`(prim ~fn float ~@rest))

Expand Down

0 comments on commit 1e3d649

Please sign in to comment.