Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Major change: Added fractal terrain and Skybox.

Source code restructured:
  * Utils for handling global variables and resources
    have been moved into utils.clj

    Added special functionality to load resources from class-path.

  * Enviroment.clj has been added, this generated as
    fractal landscape and adds a skybox.
  • Loading branch information...
commit 8ceb2d4a66ede63641b0bd65c759f4ef3275e71a 1 parent 795e17e
@LauJensen authored
View
1  .gitignore
@@ -1,3 +1,4 @@
*~
[#]*
*.class
+properties.cfg
View
1  src/dk/bestinclass/.#sofiaba.clj
View
8 src/dk/bestinclass/properties.cfg
@@ -1,8 +0,0 @@
-#Game Settings written by com.jme.app.BaseGame$BaseGameSettings at Thu Feb 19 23:28:31 CET 2009
-#Thu Feb 19 23:28:31 CET 2009
-FREQ=-1
-RENDERER=LWJGL
-WIDTH=800
-HEIGHT=600
-DEPTH=24
-FULLSCREEN=false
View
96 src/dk/bestinclass/sofiaba.clj
@@ -14,37 +14,26 @@
:extends com.jme.app.BaseGame
:main true
:exposes {display {:get getDisplay :set setDisplay}} )
- (:import (com.jme.app BaseGame SimpleGame AbstractGame AbstractGame$ConfigShowMode)
- (com.jme.image Texture)
- (com.jme.input FirstPersonHandler InputHandler KeyBindingManager KeyInput)
- (com.jme.light PointLight)
- (com.jme.math Vector3f)
- (com.jme.renderer Camera ColorRGBA)
- (com.jme.scene Node Text Spatial)
- (com.jme.scene.shape Box Sphere)
- (com.jme.scene.state LightState TextureState WireframeState ZBufferState)
- (com.jme.system DisplaySystem JmeException)
- (com.jme.bounding BoundingBox)
- (com.jme.util TextureManager Timer)
- (com.jme.util.geom Debugger)))
-
-
-;========= GLOBALS: START
-
-(def *globals* (ref (hash-map)))
-
-(defn $get
- " Retrieves the value in keyword k - Global vars "
- [k]
- (@*globals* k))
-
-(defn $set
- " Set the keyword k to a value - Global vars "
- [k value]
- (dosync
- (alter *globals* assoc k value)))
-
-;========== GLOBALS: STOP - MISC: START
+ (:import (com.jme.app BaseGame SimpleGame AbstractGame AbstractGame$ConfigShowMode)
+ (com.jme.image Texture)
+ (com.jme.input FirstPersonHandler InputHandler KeyBindingManager KeyInput)
+ (com.jme.light PointLight DirectionalLight)
+ (com.jme.math Vector3f)
+ (com.jme.renderer Camera ColorRGBA)
+ (com.jme.scene Node Text Spatial Skybox)
+ (com.jme.scene.shape Box Sphere)
+ (com.jme.scene.state LightState TextureState WireframeState ZBufferState)
+ (com.jme.system DisplaySystem JmeException)
+ (com.jme.bounding BoundingBox)
+ (com.jme.util TextureManager Timer)
+ (com.jme.util.geom Debugger)
+ (com.jmex.terrain TerrainBlock)
+ (com.jmex.terrain.util MidPointHeightMap ProceduralTextureGenerator)
+ (javax.swing ImageIcon))
+ (:load "sofiaba/utils"
+ "sofiaba/environment"))
+
+
(defstruct screen :width :height :depth :freq :fullscreen?)
@@ -73,6 +62,7 @@
tpf (.getTimePerFrame timer) ]
(.update timer)
(.. input (update tpf))
+ (. ($get :skybox) (setLocalTranslation (.getLocation ($get :camera))))
(.. rootNode (updateGeometricState tpf true))
(when (.. KeyBindingManager (getKeyBindingManager) (isValidCommand "exit"))
(.finish this)) ; This needs to be unset, otherwise SLIME requires a restart
@@ -102,9 +92,10 @@
(:freq screen) (:fullscreen? screen))))
(.. display (getRenderer) (setBackgroundColor ColorRGBA/black))
($set :camera (.. display (getRenderer) (createCamera (:width screen) (:height screen))))
- (.setFrustumPerspective ($get :camera) (float 45.0) (float (/ 640 480)) (float 1.0) (float 1000.0))
+ (.setFrustumPerspective ($get :camera) (float 45.0) (float (/ (:width screen) (:height screen)))
+ (float 1.0) (float 1000.0))
(let [ cam ($get :camera)
- loc (Vector3f. (float 0) (float 0) (float 25.0))
+ loc (Vector3f. (float 500) (float 150) (float 500.0))
left (Vector3f. (float -1.0) (float 0) (float 0))
up (Vector3f. (float 0) (float 1.0) (float 0.0))
dir (Vector3f. (float 0) (float 0) (float -1.0))
@@ -124,35 +115,48 @@
(defn -initGame
[this]
- ($set :rootNode (Node. "rootNode"))
- ($set :sphere (Sphere. "Sphere" 30 30 25))
- ($set :ts (.. ($get :display) (getRenderer) (createTextureState)))
- ($set :wireState [(.. ($get :display) (getRenderer) (createWireframeState)) false])
- (let [ pointLight (PointLight.)
- lightState (.. ($get :display) (getRenderer) (createLightState)) ]
- (doto ($get :ts)
- (.setEnabled true))
- (doto (first ($get :wireState))
- (.setEnabled false)) ; This is ugly, because it mathced the $set a couple of lines above
+ ($set :rootNode (Node. "rootNode"))
+ ($set :sphere (Sphere. "Sphere" 30 30 25))
+ ($set :ts (.. ($get :display) (getRenderer) (createTextureState)))
+ ($set :wireState [(.. ($get :display) (getRenderer) (createWireframeState)) false])
+ ($set :terrainBlock (buildTerrain))
+ ($set :skybox (makeSkybox))
+ (let [ pointLight (PointLight.)
+ directedLight (DirectionalLight. )
+ lightState (.. ($get :display) (getRenderer) (createLightState))
+ zBuffer (.. ($get :display) (getRenderer) (createZBufferState)) ]
+ (. ($get :ts) (setEnabled true))
+ (. (first ($get :wireState)) (setEnabled false)) ; This is ugly, because it mathced the $set a couple of lines above
(doto ($get :sphere)
(.setLocalTranslation (Vector3f. 0 0 -40))
(.setModelBound (BoundingBox.))
.updateModelBound
(.setRenderState ($get :ts)))
+ (doto zBuffer
+ (.setEnabled true)
+ (.setFunction com.jme.scene.state.ZBufferState$TestFunction/LessThanOrEqualTo))
(doto pointLight
(.setDiffuse (ColorRGBA. (float 1.0) (float 1.0) (float 1.0) (float 1.0)))
(.setAmbient (ColorRGBA. (float 0.5) (float 0.5) (float 0.5) (float 1.0)))
(.setLocation (Vector3f. 100 100 100))
(.setEnabled true))
+ (doto directedLight
+ (.setDiffuse (ColorRGBA. (float 1.0) (float 1.0) (float 1.0) (float 1.0)))
+ (.setAmbient (ColorRGBA. (float 0.5) (float 0.5) (float 0.5) (float 1.0)))
+ (.setDirection (Vector3f. 1 -1 0 ))
+ (.setEnabled true))
(doto lightState
(.setEnabled true)
- (.attach pointLight))
+ (.attach directedLight))
(doto ($get :rootNode)
(.setRenderState (first ($get :wireState)))
(.setRenderState lightState)
+ (.setRenderState zBuffer)
+ (.attachChild ($get :skybox))
(.attachChild ($get :sphere))
+ (.attachChild ($get :terrainBlock))
(.updateGeometricState (float 0.0) true)
- .updateRenderState)))
+ .updateRenderState)))
(defn -reinit
[this]
@@ -168,5 +172,5 @@
(defn -main
[]
(doto app
- (.setConfigShowMode AbstractGame$ConfigShowMode/AlwaysShow)
+ (.setConfigShowMode AbstractGame$ConfigShowMode/AlwaysShow (get-resource :logo))
.start))
View
66 src/dk/bestinclass/sofiaba/environment.clj
@@ -0,0 +1,66 @@
+;; Copyright (c) 2008,2009 Lau B. Jensen <lau.jensen {at} bestinclass.dk
+;;
+;; All rights reserved.
+;;
+;; The use and distribution terms for this software are covered by the
+;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;; which can be found in the file LICENSE.txt at the root of this distribution.
+;; By using this software in any fashion, you are agreeing to be bound by the
+;; terms of this license. You must not remove this notice, or any other, from
+;; this software.
+
+(clojure.core/in-ns 'dk.bestinclass.sofiaba)
+
+(def BilNoMipMap com.jme.image.Texture$MinificationFilter/BilinearNoMipMaps)
+(def Bil com.jme.image.Texture$MagnificationFilter/Bilinear)
+
+;======= TERRAIN: START
+
+(defn buildTerrain
+ []
+ (let [ heightMap (MidPointHeightMap. 64 (float 1.0))
+ terrainScale (Vector3f. 20 (float 0.5) 20)
+ terrainBlock (TerrainBlock. "Terrain" (.getSize heightMap) terrainScale
+ (.getHeightMap heightMap) (Vector3f. 0 0 0))
+ textGenerator (ProceduralTextureGenerator. heightMap)
+ textState (.. ($get :display) (getRenderer) (createTextureState)) ]
+ (doto terrainBlock
+ (.setModelBound (BoundingBox.))
+ .updateModelBound)
+ (doto textGenerator
+ (.addTexture (ImageIcon. (get-resource :grass)) -128 0 128)
+ (.addTexture (ImageIcon. (get-resource :dirt)) 0 128 255)
+ (.addTexture (ImageIcon. (get-resource :dirt)) 128 255 384)
+ (.createTexture 32))
+ (doto textState
+ (.setEnabled true)
+ (.setTexture
+ (TextureManager/loadTexture
+ (.getImage (.getImageIcon textGenerator)) BilNoMipMap Bil true)))
+ (. terrainBlock (setRenderState textState))
+ terrainBlock))
+
+;======= SKYBOX: START
+
+(defn makeSkybox
+ []
+ (let [ skyBox (Skybox. "Skybox" 10 10 10)
+ north (TextureManager/loadTexture (.getImage (ImageIcon. (get-resource :north)))
+ BilNoMipMap Bil true)
+ south (TextureManager/loadTexture (.getImage (ImageIcon. (get-resource :south)))
+ BilNoMipMap Bil true)
+ east (TextureManager/loadTexture (.getImage (ImageIcon. (get-resource :east)))
+ BilNoMipMap Bil true)
+ west (TextureManager/loadTexture (.getImage (ImageIcon. (get-resource :west)))
+ BilNoMipMap Bil true)
+ top (TextureManager/loadTexture (.getImage (ImageIcon. (get-resource :top)))
+ BilNoMipMap Bil true) ]
+ (doto skyBox
+ (.setTexture com.jme.scene.Skybox$Face/North north)
+ (.setTexture com.jme.scene.Skybox$Face/South south)
+ (.setTexture com.jme.scene.Skybox$Face/East east)
+ (.setTexture com.jme.scene.Skybox$Face/West west)
+ (.setTexture com.jme.scene.Skybox$Face/Up top)
+ (.setTexture com.jme.scene.Skybox$Face/Down top))
+ skyBox))
+
View
42 src/dk/bestinclass/sofiaba/terrain.clj
@@ -0,0 +1,42 @@
+;; Copyright (c) 2008,2009 Lau B. Jensen <lau.jensen {at} bestinclass.dk
+;;
+;; All rights reserved.
+;;
+;; The use and distribution terms for this software are covered by the
+;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;; which can be found in the file LICENSE.txt at the root of this distribution.
+;; By using this software in any fashion, you are agreeing to be bound by the
+;; terms of this license. You must not remove this notice, or any other, from
+;; this software.
+
+(clojure.core/in-ns 'dk.bestinclass.sofiaba)
+
+
+;======= TERRAIN: START
+
+(defn buildTerrain
+ []
+ (let [ heightMap (MidPointHeightMap. 64 (float 1.0))
+ terrainScale (Vector3f. 20 (float 0.5) 20)
+ terrainBlock (TerrainBlock. "Terrain" (.getSize heightMap) terrainScale
+ (.getHeightMap heightMap) (Vector3f. 0 0 0))
+ textGenerator (ProceduralTextureGenerator. heightMap)
+ textState (.. ($get :display) (getRenderer) (createTextureState)) ]
+ (doto terrainBlock
+ (.setModelBound (BoundingBox.))
+ .updateModelBound)
+ (doto textGenerator
+ (.addTexture (ImageIcon. (get-resource :grass)) -128 0 128)
+ (.addTexture (ImageIcon. (get-resource :dirt)) 0 128 255)
+ (.addTexture (ImageIcon. (get-resource :dirt)) 128 255 384)
+ (.createTexture 32))
+ (doto textState
+ (.setEnabled true)
+ (.setTexture
+ (TextureManager/loadTexture
+ (.getImage (.getImageIcon textGenerator))
+ com.jme.image.Texture$MinificationFilter/BilinearNoMipMaps
+ com.jme.image.Texture$MagnificationFilter/Bilinear true)))
+ (. terrainBlock (setRenderState textState))
+ terrainBlock))
+
View
53 src/dk/bestinclass/sofiaba/utils.clj
@@ -0,0 +1,53 @@
+;; Copyright (c) 2008,2009 Lau B. Jensen <lau.jensen {at} bestinclass.dk
+;;
+;; All rights reserved.
+;;
+;; The use and distribution terms for this software are covered by the
+;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;; which can be found in the file LICENSE.txt at the root of this distribution.
+;; By using this software in any fashion, you are agreeing to be bound by the
+;; terms of this license. You must not remove this notice, or any other, from
+;; this software.
+
+(clojure.core/in-ns 'dk.bestinclass.sofiaba)
+
+;========= GLOBALS: START
+
+(def *globals* (ref (hash-map)))
+
+(defn $get
+ " Retrieves the value in keyword k - Global vars "
+ [k]
+ (@*globals* k))
+
+(defn $set
+ " Set the keyword k to a value - Global vars "
+ [k value]
+ (dosync
+ (alter *globals* assoc k value)))
+
+;======= GLOBALS: STOP - RESOURCES: START
+
+(def *resources*
+ {:logo "res/logo.png"
+ :grass "res/textures/grass.jpg"
+ :dirt "res/textures/dirt.jpg"
+ :north "res/skybox/north.jpg"
+ :south "res/skybox/south.jpg"
+ :west "res/skybox/west.jpg"
+ :east "res/skybox/east.jpg"
+ :top "res/skybox/top.jpg"} )
+
+
+(defn get-resource-uri
+ [res]
+ (if-let [ uri (. (.. Class (forName "dk.bestinclass.sofiaba") (getClassLoader))
+ (findResource (str "dk/bestinclass/" res)))]
+ uri
+ (throw (Exception. (format "Resource not found: %s" res)))))
+
+(defn get-resource
+ [key]
+ (get-resource-uri (*resources* key)))
+
+;======= RESOURCES: STOP -
Please sign in to comment.
Something went wrong with that request. Please try again.