Permalink
Browse files

migrate math into cantor

  • Loading branch information...
1 parent b7bbd47 commit 4572735f1eb4c2cb5f0efd1fb22103389db06d9c @ztellman committed Apr 24, 2010
View
@@ -1,6 +1,7 @@
(defproject penumbra "0.6.0-SNAPSHOT"
:description "An idiomatic wrapper for OpenGL"
- :dependencies [[slick-util "1.0.0"]]
+ :dependencies [[slick-util "1.0.0"]
+ [cantor "0.1.0-SNAPSHOT"]]
:native-dependencies [[penumbra/lwjgl "2.4.2"]]
:dev-dependencies [[native-deps "1.0.0"]
[lein-clojars "0.5.0-SNAPSHOT"]
@@ -7,8 +7,9 @@
;; You must not remove this notice, or any other, from this software.
(ns example.game.asteroids
- (:use [penumbra opengl geometry]
- [clojure.contrib.seq :only (separate)])
+ (:use [penumbra opengl]
+ [clojure.contrib.seq :only (separate)]
+ [cantor core])
(:require [penumbra.app :as app]
[penumbra.text :as text]
[penumbra.time :as time]
@@ -22,7 +23,7 @@
"Makes the position wrap around from right to left, bottom to top"
[pos]
(sub
- (modv
+ (mod*
(add pos *dim*)
(mul *dim* 2))
*dim*))
@@ -7,7 +7,8 @@
;; You must not remove this notice, or any other, from this software.
(ns example.gpgpu.fluid
- (:use [penumbra opengl compute geometry])
+ (:use [penumbra opengl compute]
+ [cantor core])
(:require [penumbra.app :as app]
[penumbra.text :as text]
[penumbra.opengl.texture :as tex]
@@ -7,7 +7,8 @@
;; You must not remove this notice, or any other, from this software.
(ns example.opengl.gears
- (:use [penumbra opengl geometry])
+ (:use [penumbra opengl]
+ [cantor core])
(:require [penumbra.app :as app]
[penumbra.text :as text]))
@@ -7,8 +7,9 @@
;; You must not remove this notice, or any other, from this software.
(ns example.opengl.marble
- (:use [penumbra opengl geometry compute]
- [penumbra.opengl core teapot])
+ (:use [penumbra opengl compute]
+ [penumbra.opengl core teapot]
+ [cantor core])
(:require [penumbra.app :as app]
[penumbra.text :as text]
[penumbra.data :as data]))
@@ -29,8 +29,9 @@
(defn display [_ state]
(translate -0.5 -0.5 -5)
- (render-to-screen
+ (blit!
(with-pipeline program [{:tint [1. 1. 0.]} (app/size)]
+ (clear)
(draw-triangles
(attribute :alpha 0.) (vertex 0 0)
(attribute :alpha 0.5) (vertex 0 1)
View
@@ -11,7 +11,7 @@
[penumbra.opengl.texture :as tex]
[clojure.contrib.def :only (defmacro-)])
(:use [penumbra.opengl.core :only (*render-to-screen?*)]
- [penumbra.geometry :only (rectangle)]))
+ [cantor.core :only (rectangle-factors)]))
(defmacro defmap [name & body]
`(def ~name (glsl/create-map-template (quote ~body))))
@@ -37,5 +37,5 @@
(/ (count s) (apply * tuple-or-dim)))
dim (if-not (number? tuple-or-dim)
tuple-or-dim
- (rectangle (/ (count s) tuple)))]
+ (rectangle-factors (/ (count s) tuple)))]
(apply tex/wrap (list* s tuple dim params)))))
View
@@ -6,8 +6,7 @@
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
-(ns penumbra.data
- (:use [penumbra.geometry :only (rectangle)]))
+(ns penumbra.data)
(defprotocol Data
(acquire! [d] "Increments the reference count.")
@@ -8,11 +8,10 @@
(ns penumbra.opengl.geometry
(:use [clojure.contrib.def :only (defmacro- defvar)]
- [penumbra.geometry]
+ [cantor.core]
[penumbra.opengl.core])
(:require [penumbra.opengl.effects :as fx])
- (:import [penumbra.geometry Vec2 Vec3]
- [org.lwjgl BufferUtils]))
+ (:import [org.lwjgl BufferUtils]))
;;;
@@ -32,49 +31,49 @@
(defn vertex
([v]
(cond
- (instance? Vec2 v) (vertex (.x #^Vec2 v) (.y #^Vec2 v))
- (instance? Vec3 v) (vertex (.x #^Vec3 v) (.y #^Vec3 v) (.z #^Vec3 v))
+ (vec2? v) (vertex (v 0) (v 1))
+ (vec3? v) (vertex (v 0) (v 1) (v 2))
:else (apply vertex v)))
([x y] (vertex x y 0))
([x y z] (vertex- *renderer* x y z))
([x y z w] (vertex x y z)))
(defn texture
([v] (cond
- (instance? Vec2 v) (texture (.x #^Vec2 v) (.y #^Vec2 v))
- (instance? Vec3 v) (texture (.x #^Vec3 v) (.y #^Vec3 v) (.z #^Vec3 v))
+ (vec2? v) (texture (v 0) (v 1))
+ (vec3? v) (texture (v 0) (v 1) (v 2))
(number? v) (texture- *renderer* v)
:else (apply texture v)))
([u v] (texture- *renderer* u v))
([u v w] (texture- *renderer* u v w)))
(defn normal
([v] (cond
- (instance? Vec2 v) (normal (.x #^Vec2 v) (.y #^Vec2 v))
- (instance? Vec3 v) (normal (.x #^Vec3 v) (.y #^Vec3 v) (.z #^Vec3 v))
+ (vec2? v) (normal (v 0) (v 1))
+ (vec3? v) (normal (v 0) (v 1) (v 2))
:else (apply normal v)))
([x y z] (normal- *renderer* x y z)))
(defn translate
([v] (cond
- (instance? Vec2 v) (translate (.x #^Vec2 v) (.y #^Vec2 v))
- (instance? Vec3 v) (translate (.x #^Vec3 v) (.y #^Vec3 v) (.z #^Vec3 v))
+ (vec2? v) (translate (v 0) (v 1))
+ (vec3? v) (translate (v 0) (v 1) (v 2))
:else (apply translate v)))
([x y] (translate x y 0))
([x y z] (translate- *renderer* x y z)))
(defn scale
([v] (cond
- (instance? Vec2 v) (scale (.x #^Vec2 v) (.y #^Vec2 v))
- (instance? Vec3 v) (scale (.x #^Vec3 v) (.y #^Vec3 v) (.z #^Vec3 v))
+ (vec2? v) (scale (v 0) (v 1))
+ (vec3? v) (scale (v 0) (v 1) (v 2))
:else (apply scale v)))
([x y] (scale x y 1))
([x y z] (scale- *renderer* x y z)))
(defn color
([c] (cond
- (instance? Vec2 c) (color (.x #^Vec2 c) (.y #^Vec2 c))
- (instance? Vec3 c) (color (.x #^Vec3 c) (.y #^Vec3 c) (.z #^Vec3 c))
+ (vec2? c) (color (c 0) (c 1))
+ (vec3? c) (color (c 0) (c 1) (c 2))
:else (apply color c)))
([r g b] (color r g b 1))
([r g b a] (color- *renderer* r g b a)))
@@ -173,13 +172,13 @@
Renderer
(vertex- [_ x y z]
(if (and *intra-primitive-transform* @*intra-primitive-transform*)
- (let [v (transform @*transform-matrix* (vec3 x y z))]
- (vertex- *outer-renderer* (.x #^Vec3 v) (.y #^Vec3 v) (.z #^Vec3 v)))
+ (let [v (transform-vector @*transform-matrix* (vec3 x y z))]
+ (vertex- *outer-renderer* (v 0) (v 1) (v 2)))
(vertex- *outer-renderer* x y z)))
(normal- [_ x y z]
(if (and *intra-primitive-transform* @*intra-primitive-transform*)
- (let [v (transform (normal-matrix @*transform-matrix*) (vec3 x y z))]
- (normal- *outer-renderer* (.x #^Vec3 v) (.y #^Vec3 v) (.z #^Vec3 v)))
+ (let [v (transform-vector (normal-matrix @*transform-matrix*) (vec3 x y z))]
+ (normal- *outer-renderer* (v 0) (v 1) (v 2)))
(normal- *outer-renderer* x y z)))
(texture- [_ u]
(texture- *outer-renderer* u))
@@ -9,7 +9,6 @@
(ns penumbra.opengl.texture
(:use [clojure.contrib.def :only (defmacro- defn-memo)])
(:use [clojure.contrib.seq :only (separate)])
- (:use [penumbra.geometry :only (rectangle)])
(:use [penumbra.opengl core])
(:use [penumbra data])
(:import [org.lwjgl BufferUtils])
View
@@ -7,7 +7,6 @@
;; You must not remove this notice, or any other, from this software.
(ns penumbra.time
- (:use [penumbra.geometry :only [lerp]])
(:use [clojure.contrib.def :only [defn-memo]]))
(defn wall-time []
@@ -8,8 +8,8 @@
(ns penumbra.translate.operators
(:use [clojure.walk]
- [penumbra.geometry]
[penumbra.translate core]
+ [cantor.core :only (rectangle-factors)]
[clojure.contrib.seq :only (indexed group-by separate)]
[clojure.contrib.def :only (defn-memo defvar-)]
[penumbra.translate.core])
@@ -204,7 +204,7 @@
(defmethod signature [:params :dim :elements] [params dim & elements]
(let [elements (remove #(and (vector? %) (empty? %)) (process-elements elements))
- dim (if (number? dim) (rectangle dim) dim)]
+ dim (if (number? dim) (rectangle-factors dim) dim)]
{:signature [(map *typeof-param* params) (map *typeof-element* elements)]
:params params
:elements elements
@@ -218,7 +218,7 @@
(if (nil? e)
(throw (Exception. (str "Element at position " idx " is nil")))))
(let [dim
- (if (number? dim) (rectangle dim) dim)
+ (if (number? dim) (rectangle-factors dim) dim)
program*
(let [program
(apply-transforms

0 comments on commit 4572735

Please sign in to comment.