 
 (ns brevis.matrix
   (:use [brevis vector])
-  (:import [javax.vecmath Vector3d Vector4d Matrix4d]))
+  (:import [org.lwjgl.util.vector Vector3f Vector4f Matrix4f]
+           [java.nio FloatBuffer]
+           [org.lwjgl BufferUtils])
+  #_(:import [javax.vecmath Vector3d Vector4d Matrix4d]))
 
 (defonce x-axis (vec3 1 0 0))
 (defonce y-axis (vec3 0 1 0))
 (defonce z-axis (vec3 0 0 1))
 (defonce origin (vec4 0 0 0 1))
 
+#_(defn mat4
+   "Create a 4x4 matrix."  
+   ([ v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 ]
+     (Matrix4f.  v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15))
+   ([]
+     (mat4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)))
+
 (defn mat4
-  "Create a 4x4 matrix."  
-  ([ v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 ]
-    (Matrix4d.  v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15))
-  ([]
-    (mat4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)))
+   "Create a 4x4 matrix."  
+   ([float-buffer]     
+     (let [mat (Matrix4f.)]
+       (.load mat float-buffer)))
+   ([ v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 ]
+     (mat4 (FloatBuffer/wrap (float-array [v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15]))))
+   ([]
+     (mat4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)))
 
 #_(defonce identity4 (.setIdentity (mat4)))
 

(defn translate
  "Translate xform by vector"
  [xform v]
  (println xform v (position xform)) 
  (.setTranslation xform (add v (position xform)))
  xform)


(defn rotate-x
  "Rotate xform about x-axis by angle."
  [xform angle]
  (rotate xform x-axis angle)
  #_(.rotX xform angle)
  xform)

(defn rotate-y
  "rotate xform about y-axis by angle."
  [xform angle]
  (rotate xform y-axis angle)
  #_(.rotY xform angle)  
  xform)

(defn rotate-z
  "Rotate xform about z-axis by angle."
  [xform angle]
  (rotate xform z-axis angle)
  #_(.rotZ xform angle)
  xform)
  
(defn transform
  "Transform a vector."
  [xform v]
  (let [outv (vec4 0 0 0 0)]
    (def tmp001 {:xform xform :v v :outv outv})
    (Matrix4f/transform xform v outv)
    outv))

(defn identity-mat
