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]
[com.badlogic.gdx.audio Sound]
[com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera
PerspectiveCamera]
PerspectiveCamera VertexAttributes$Usage]
[com.badlogic.gdx.graphics.g2d NinePatch ParticleEffect SpriteBatch
TextureRegion]
[com.badlogic.gdx.graphics.g3d Environment ModelBatch ModelInstance]

View File

@@ -12,7 +12,7 @@
([r g b a]
(doto (Gdx/gl)
(.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
"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))
(defmethod draw-entity! :model
[{:keys [^ModelBatch batch ^Environment attributes]}
[{:keys [^ModelBatch renderer ^Environment attributes]}
{:keys [^ModelInstance object]}]
(.render batch object attributes))
(.render renderer object attributes))
; draw
@@ -320,15 +320,17 @@ with the tiled map file at `path` and `unit` scale
(defn 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
"Returns an [PerspectiveCamera](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/PerspectiveCamera.html)
(perspective)"
[& options]
`(let [^PerspectiveCamera object# (perspective*)]
[fov vw vh & options]
`(let [^PerspectiveCamera object# (perspective* ~fov ~vw ~vh)]
(u/calls! object# ~@options)))
(defmacro perspective!
@@ -343,7 +345,6 @@ with the tiled map file at `path` and `unit` scale
(size! screen 480 360)"
[screen width height]
(let [^OrthographicCamera camera (u/get-obj screen :camera)]
(assert camera)
(.setToOrtho camera false width height)))
(defn width!
@@ -366,7 +367,6 @@ remains in tact
"Sets only the x position of the camera in `screen`"
[screen x]
(let [^Camera camera (u/get-obj screen :camera)]
(assert camera)
(set! (. (. camera position) x) x)
(.update camera)))
@@ -374,7 +374,6 @@ remains in tact
"Sets only the y position of the camera in `screen`"
[screen y]
(let [^Camera camera (u/get-obj screen :camera)]
(assert camera)
(set! (. (. camera position) y) y)
(.update camera)))
@@ -382,7 +381,6 @@ remains in tact
"Sets only the z position of the camera in `screen`"
[screen z]
(let [^Camera camera (u/get-obj screen :camera)]
(assert camera)
(set! (. (. camera position) z) z)
(.update camera)))
@@ -394,3 +392,31 @@ remains in tact
(when x (x! screen x))
(when y (y! screen y))
(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
"Returns an entity based on [ModelInstance](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/ModelInstance.html)"
[& args]
`(ModelInstance. ~@args))
`(u/create-entity (ModelInstance. ~@args)))
(defmacro model!
"Calls a single method on a `model`"
@@ -84,12 +84,18 @@
; material
(defn material*
"The function version of `material`"
[]
(Material.))
(defmacro material
"Returns a [Material](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Material.html)
(material)"
[& args]
`(Material. ~@args))
[& options]
`(let [^Material object# (material*)]
(u/calls! object# ~@options)))
(defmacro material!
"Calls a single method on a `material`"
@@ -120,7 +126,7 @@
(u/key->pascal k)))
(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))"
[type k & options]