Allow models to be rendered

This commit is contained in:
oakes
2014-01-29 17:21:05 -05:00
parent bf3399e504
commit b6f0883b9f
4 changed files with 48 additions and 16 deletions

View File

@@ -4,7 +4,7 @@
InputMultiplexer InputProcessor Net Screen] InputMultiplexer InputProcessor Net Screen]
[com.badlogic.gdx.audio Sound] [com.badlogic.gdx.audio Sound]
[com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera [com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera
PerspectiveCamera] PerspectiveCamera VertexAttributes$Usage]
[com.badlogic.gdx.graphics.g2d NinePatch ParticleEffect SpriteBatch [com.badlogic.gdx.graphics.g2d NinePatch ParticleEffect SpriteBatch
TextureRegion] TextureRegion]
[com.badlogic.gdx.graphics.g3d Environment ModelBatch ModelInstance] [com.badlogic.gdx.graphics.g3d Environment ModelBatch ModelInstance]

View File

@@ -12,7 +12,7 @@
([r g b a] ([r g b a]
(doto (Gdx/gl) (doto (Gdx/gl)
(.glClearColor (float r) (float g) (float b) (float a)) (.glClearColor (float r) (float g) (float b) (float a))
(.glClear GL20/GL_COLOR_BUFFER_BIT)))) (.glClear (bit-or GL20/GL_COLOR_BUFFER_BIT GL20/GL_DEPTH_BUFFER_BIT)))))
(defmacro color (defmacro color
"Returns a [Color](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Color.html) "Returns a [Color](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Color.html)

View File

@@ -230,9 +230,9 @@ with the tiled map file at `path` and `unit` scale
(.draw object batch 1)) (.draw object batch 1))
(defmethod draw-entity! :model (defmethod draw-entity! :model
[{:keys [^ModelBatch batch ^Environment attributes]} [{:keys [^ModelBatch renderer ^Environment attributes]}
{:keys [^ModelInstance object]}] {:keys [^ModelInstance object]}]
(.render batch object attributes)) (.render renderer object attributes))
; draw ; draw
@@ -320,15 +320,17 @@ with the tiled map file at `path` and `unit` scale
(defn perspective* (defn perspective*
"The function version of `perspective`" "The function version of `perspective`"
[] ([]
(PerspectiveCamera.)) (PerspectiveCamera.))
([field-of-view viewport-width viewport-height]
(PerspectiveCamera. field-of-view viewport-width viewport-height)))
(defmacro perspective (defmacro perspective
"Returns an [PerspectiveCamera](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/PerspectiveCamera.html) "Returns an [PerspectiveCamera](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/PerspectiveCamera.html)
(perspective)" (perspective)"
[& options] [fov vw vh & options]
`(let [^PerspectiveCamera object# (perspective*)] `(let [^PerspectiveCamera object# (perspective* ~fov ~vw ~vh)]
(u/calls! object# ~@options))) (u/calls! object# ~@options)))
(defmacro perspective! (defmacro perspective!
@@ -343,7 +345,6 @@ with the tiled map file at `path` and `unit` scale
(size! screen 480 360)" (size! screen 480 360)"
[screen width height] [screen width height]
(let [^OrthographicCamera camera (u/get-obj screen :camera)] (let [^OrthographicCamera camera (u/get-obj screen :camera)]
(assert camera)
(.setToOrtho camera false width height))) (.setToOrtho camera false width height)))
(defn width! (defn width!
@@ -366,7 +367,6 @@ remains in tact
"Sets only the x position of the camera in `screen`" "Sets only the x position of the camera in `screen`"
[screen x] [screen x]
(let [^Camera camera (u/get-obj screen :camera)] (let [^Camera camera (u/get-obj screen :camera)]
(assert camera)
(set! (. (. camera position) x) x) (set! (. (. camera position) x) x)
(.update camera))) (.update camera)))
@@ -374,7 +374,6 @@ remains in tact
"Sets only the y position of the camera in `screen`" "Sets only the y position of the camera in `screen`"
[screen y] [screen y]
(let [^Camera camera (u/get-obj screen :camera)] (let [^Camera camera (u/get-obj screen :camera)]
(assert camera)
(set! (. (. camera position) y) y) (set! (. (. camera position) y) y)
(.update camera))) (.update camera)))
@@ -382,7 +381,6 @@ remains in tact
"Sets only the z position of the camera in `screen`" "Sets only the z position of the camera in `screen`"
[screen z] [screen z]
(let [^Camera camera (u/get-obj screen :camera)] (let [^Camera camera (u/get-obj screen :camera)]
(assert camera)
(set! (. (. camera position) z) z) (set! (. (. camera position) z) z)
(.update camera))) (.update camera)))
@@ -394,3 +392,31 @@ remains in tact
(when x (x! screen x)) (when x (x! screen x))
(when y (y! screen y)) (when y (y! screen y))
(when z (z! screen z)))) (when z (z! screen z))))
(defn direction!
"Sets the directino of the camera in `screen`"
[screen x y z]
(let [^Camera camera (u/get-obj screen :camera)]
(.lookAt camera x y z)
(.update camera)))
(defn near!
"Sets the near clipping plane distance of the camera in `screen`"
[screen n]
(let [^Camera camera (u/get-obj screen :camera)]
(set! (. camera near) n)
(.update camera)))
(defn far!
"Sets the far clipping plane distance of the camera in `screen`"
[screen n]
(let [^Camera camera (u/get-obj screen :camera)]
(set! (. camera far) n)
(.update camera)))
; misc
(defmacro usage
"Returns a static field in [VertexAttributes.Usage](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/VertexAttributes.Usage.html)"
[k]
`~(u/gdx-field :graphics "VertexAttributes$Usage" (u/key->pascal k)))

View File

@@ -54,7 +54,7 @@
(defmacro model (defmacro model
"Returns an entity based on [ModelInstance](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/ModelInstance.html)" "Returns an entity based on [ModelInstance](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/ModelInstance.html)"
[& args] [& args]
`(ModelInstance. ~@args)) `(u/create-entity (ModelInstance. ~@args)))
(defmacro model! (defmacro model!
"Calls a single method on a `model`" "Calls a single method on a `model`"
@@ -84,12 +84,18 @@
; material ; material
(defn material*
"The function version of `material`"
[]
(Material.))
(defmacro material (defmacro material
"Returns a [Material](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Material.html) "Returns a [Material](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Material.html)
(material)" (material)"
[& args] [& options]
`(Material. ~@args)) `(let [^Material object# (material*)]
(u/calls! object# ~@options)))
(defmacro material! (defmacro material!
"Calls a single method on a `material`" "Calls a single method on a `material`"
@@ -120,7 +126,7 @@
(u/key->pascal k))) (u/key->pascal k)))
(defmacro attribute! (defmacro attribute!
"Calls a single method on a subclass of [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html) "Calls a static method in a subclass of [Attribute](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Attribute.html)
(attribute! :color :create-diffuse (color :blue))" (attribute! :color :create-diffuse (color :blue))"
[type k & options] [type k & options]