Start g3d

This commit is contained in:
oakes
2014-01-29 01:45:08 -05:00
parent d52b189871
commit 1e83df1e92
3 changed files with 79 additions and 25 deletions

View File

@@ -7,6 +7,7 @@
PerspectiveCamera]
[com.badlogic.gdx.graphics.g2d NinePatch ParticleEffect SpriteBatch
TextureRegion]
[com.badlogic.gdx.graphics.g3d Environment ModelBatch ModelInstance]
[com.badlogic.gdx.input GestureDetector
GestureDetector$GestureListener]
[com.badlogic.gdx.maps MapLayer MapLayers]

View File

@@ -186,21 +186,7 @@ with the tiled map file at `path` and `unit` scale
`(let [^Stage object# (u/get-obj ~screen :renderer)]
(u/call! object# ~k ~@options)))
; batch
(defmulti batch
"Internal use only"
#(-> % :renderer class))
(defmethod batch BatchTiledMapRenderer
[{:keys [^BatchTiledMapRenderer renderer]}]
(.getSpriteBatch renderer))
(defmethod batch Stage
[{:keys [^Stage renderer]}]
(.getSpriteBatch renderer))
; rendering
; draw-entity
(defmulti draw-entity!
"Internal use only"
@@ -210,7 +196,6 @@ with the tiled map file at `path` and `unit` scale
(defmethod draw-entity! :texture
[^SpriteBatch batch {:keys [^TextureRegion object x y width height]}]
(assert object)
(let [x (float (or x 0))
y (float (or y 0))
width (float (or width (.getRegionWidth object)))
@@ -219,7 +204,6 @@ with the tiled map file at `path` and `unit` scale
(defmethod draw-entity! :nine-patch
[^SpriteBatch batch {:keys [^NinePatch object x y width height]}]
(assert object)
(let [x (float (or x 0))
y (float (or y 0))
width (float (or width (.getTotalWidth object)))
@@ -228,7 +212,6 @@ with the tiled map file at `path` and `unit` scale
(defmethod draw-entity! :particle-effect
[^SpriteBatch batch {:keys [^ParticleEffect object x y delta-time]}]
(assert object)
(let [x (float (or x 0))
y (float (or y 0))
delta-time (float (or delta-time (graphics! :get-delta-time)))]
@@ -237,7 +220,6 @@ with the tiled map file at `path` and `unit` scale
(defmethod draw-entity! :actor
[^SpriteBatch batch {:keys [^Actor object] :as entity}]
(assert object)
(doseq [[k v] entity]
(case k
:x (.setX object v)
@@ -247,19 +229,45 @@ with the tiled map file at `path` and `unit` scale
nil))
(.draw object batch 1))
(defn draw!
"Draws the `entities` with the renderer from `screen`
(defmethod draw-entity! :model
[{:keys [^ModelBatch batch ^Environment attributes]}
{:keys [^ModelInstance object]}]
(.render batch object attributes))
(draw! screen entities)"
[{:keys [renderer] :as screen} entities]
(assert renderer)
(let [^SpriteBatch batch (batch screen)]
; draw
(defmulti draw!
"Internal use only"
(fn [screen _] (-> screen :renderer class)))
(defmethod draw! BatchTiledMapRenderer
[{:keys [^BatchTiledMapRenderer renderer]} entities]
(let [^SpriteBatch batch (.getSpriteBatch renderer)]
(.begin batch)
(doseq [entity entities]
(draw-entity! batch entity))
(.end batch))
entities)
(defmethod draw! Stage
[{:keys [^Stage renderer]} entities]
(let [^SpriteBatch batch (.getSpriteBatch renderer)]
(.begin batch)
(doseq [entity entities]
(draw-entity! batch entity))
(.end batch))
entities)
(defmethod draw! ModelBatch
[{:keys [^ModelBatch renderer ^Camera camera] :as screen} entities]
(.begin renderer camera)
(doseq [entity entities]
(draw-entity! screen entity))
(.end renderer)
entities)
; render
(defn ^:private render-map!
"Internal use only"
[{:keys [^BatchTiledMapRenderer renderer ^Camera camera]}]

45
src/play_clj/g3d.clj Normal file
View File

@@ -0,0 +1,45 @@
(ns play-clj.g3d
(:require [play-clj.utils :as u])
(:import [com.badlogic.gdx.graphics.g3d Environment ModelBatch]))
; environment
(defn environment*
"The function version of `environment`"
[]
(Environment.))
(defmacro environment
"Returns an [Environment](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Environment.html)
(environment)"
[& options]
`(let [^Environment object# (environment*)]
(u/calls! object# ~@options)))
(defmacro environment!
"Calls a single method on an `environment`"
[screen k & options]
`(let [^Environment object# (u/get-obj ~screen :attributes)]
(u/call! object# ~k ~@options)))
; model-batch
(defn model-batch*
"The function version of `model-batch`"
[]
(ModelBatch.))
(defmacro model-batch
"Returns an [ModelBatch](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Environment.html)
(model-batch)"
[& options]
`(let [^ModelBatch object# (model-batch*)]
(u/calls! object# ~@options)))
(defmacro model-batch!
"Calls a single method on an `model-batch`"
[screen k & options]
`(let [^ModelBatch object# (u/get-obj ~screen :attributes)]
(u/call! object# ~k ~@options)))