Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use system relative pathnames to find Horde3D.

  • Loading branch information...
commit 2d0d582918ad0396ad40dd2fe16396ed1777a466 1 parent 8b148c0
@anwyn authored
View
1  .gitignore
@@ -1,3 +1,4 @@
Horde3D_Log.html
EngineLog.html
*.fasl
+/Horde3D
View
22 README.org
@@ -114,9 +114,11 @@
- Install Lispbuilder SDL.
- - For now you have to adjust the *horde3d-home-directory* variable
- in src/examples.lisp to point to your Horde3D installation. The
- examples will load resources from there.
+ - Either you symlink the top level Horde3D directory with the name
+ 'Horde3D' into the top level directory of cl-horde3d, or you
+ adjust the *horde3d-home-directory* variable in src/examples.lisp
+ to point to your Horde3D installation. The examples will load
+ resources from there.
- Load the horde3d-examples system with asdf.
@@ -126,9 +128,13 @@
* Footnotes
-- [fn:1] http://common-lisp.net/project/cffi
-- [fn:2] [[http://horde3d.org]]
-- [fn:3] http://code.google.com/p/lispbuilder/wiki/LispbuilderSDL
-- [fn:4] http://www.libsdl.org
-- [fn:5] http://www.eclipse.org/legal/epl-v10.html
+[fn:1] http://common-lisp.net/project/cffi
+
+[fn:2] [[http://horde3d.org]]
+
+[fn:3] http://code.google.com/p/lispbuilder/wiki/LispbuilderSDL
+
+[fn:4] http://www.libsdl.org
+
+[fn:5] http://www.eclipse.org/legal/epl-v10.html
View
180 examples/chicago.lisp
@@ -1,13 +1,13 @@
;;; chicago.lisp --- horde3d example
-;;; _ _
-;;; ___| |__ (_) ___ __ _ __ _ ___
-;;; / __| '_ \| |/ __/ _` |/ _` |/ _ \
+;;; _ _
+;;; ___| |__ (_) ___ __ _ __ _ ___
+;;; / __| '_ \| |/ __/ _` |/ _` |/ _ \
;;; | (__| | | | | (_| (_| | (_| | (_) |
-;;; \___|_| |_|_|\___\__,_|\__, |\___/
-;;; |___/
+;;; \___|_| |_|_|\___\__,_|\__, |\___/
+;;; |___/
;;;
;;; Copyright (C) 2009 Ole Arndt <ole@sugarshark.com>
-;;;
+;;;
(in-package :horde3d-examples)
@@ -26,7 +26,7 @@
(defclass chicago-application (example-application)
((deferred-pipeline :accessor deferred-pipeline :initarg :deferred-pipeline)
(particles :accessor particles :initarg :particles
- :initform (make-array 100 :element-type '(or particle null)))))
+ :initform (make-array 100 :element-type '(or particle null) :initial-element nil))))
(defun chicago ()
(example-main-sdl
@@ -49,7 +49,7 @@
(dz particle) (* (cos ang) rad))))
(defmethod app-init ((app chicago-application))
-
+
;; Add resources
(let ((env-res (h3d:add-resource :scene-graph "models/platform/platform.scene.xml"))
(skybox-res (h3d:add-resource :scene-graph "models/skybox/skybox.scene.xml"))
@@ -94,7 +94,7 @@
(choose-destination p)
(h3d:set-node-transform (node p) (px p) 0.02 (pz p) 0 0 0 1 1 1)
(setf (aref (particles app) i) p))))
-
+
;; Mark end of frame
(h3d:finalize-frame))
@@ -102,7 +102,7 @@
(defmethod app-main-loop ((app chicago-application))
(unless (freeze? app)
(update-crowd app))
-
+
;; Set camera parameters
(with-accessors ((pos viewer-position)
(rot viewer-orientation)
@@ -114,7 +114,7 @@
(aref rot 0) (aref rot 1) 0 1 1 1 )
(when (> (stat-mode app) 0)
- (h3d:show-frame-statistics font panel (stat-mode app))
+ (h3d:show-frame-statistics font panel (stat-mode app))
;; Display weight
(h3d:show-text (format nil "Pipeline: ~a"
@@ -128,88 +128,92 @@
(h3d:show-overlay 0.75 0.8 0 1 0.75 1 0 0
1 1 1 0 1 0.8 1 1
1 1 1 1 (logo-resource app) 7)
-
+
;; Render scene
(h3d:render cam)))
(defun update-crowd (app)
(let ((d1 0.25) (d2 2.0) (d3 4.5)
- (f1 3.0) (f2 1.0) (f3 0.1))
- (declare (type single-float d1 d2 d3 f1 f2 f3)
- (optimize (speed 3)))
- (loop :for p :across (particles app) :do
- (let ((px (px p)) (pz (pz p))
- (dx (dx p)) (dz (dz p))
- (ox (ox p)) (oz (oz p))
- (fx 0.0) (fz 0.0))
- (declare (type single-float px pz dx dz ox oz fx fz))
- ;; reset force
- (let ((dist (sqrt (+ (* (- dx px) (- dx px))
- (* (- dz pz) (- dz pz))))))
- (declare (type single-float dist))
- (cond
- ((> dist 3.0)
- ;; destination not reached, walk towards destination
- (incf fx (* 0.035 (/ (- dx px) dist)))
- (incf fz (* 0.035 (/ (- dz pz) dist)))
- (loop :for p2 :across (particles app)
- :when (not (eq p p2)) :do
- (let* ((p2x (px p2))
- (p2z (pz p2))
- (dist2 (sqrt (+ (* (- px p2x) (- px p2x))
- (* (- pz p2z) (- pz p2z)))))
- (strength (cond
- ((and (<= dist2 d3) (> dist2 d2))
- (let* ((m (/ (- f3 0) (- d2 d3)))
- (n (- 0 (* m d3))))
- (+ (* m dist2) n)))
- ((and (<= dist2 d2) (> dist2 d1))
- (let* ((m (/ (- f2 f3) (- d1 d2)))
- (n (- f3 (* m d2))))
- (+ (* m dist2) n)))
- ((<= dist2 d1)
- (let* ((m (/ (- f1 f2) (- 0 d1)))
- (n (- f2 (* m d1))))
- (+ (* m dist2) n)))
- (t
- 0.0))))
- (declare (type single-float p2x p2z dist strength))
- (incf fx (* strength (the single-float (/ (- px p2x) dist2))))
- (incf fz (* strength (the single-float (/ (- pz p2z) dist2)))))))
- (t
- ;; near destination, choose a new one
- (choose-destination p)))
-
- ;; make force framerate independant
- (setf fx (* fx (/ 30.0 (curr-fps app)))
- fz (* fz (/ 30.0 (curr-fps app))))
-
- ;; set new position
- (incf px fx)
- (incf pz fz)
- (setf (px p) px)
- (setf (pz p) pz)
-
- ;; calculate orientation
- (setf ox (the single-float (/ (+ ox fx) 2.0)))
- (setf oz (the single-float (/ (+ oz fz) 2.0)))
-
- ;; update character position
- (let ((ry (radtodeg (if (/= oz 0.0) (atan ox oz) 0.0))))
- (declare (type single-float ry))
- (setf (ox p) ox)
- (setf (oz p) oz)
- (h3d:set-node-transform (node p) px 0.02 pz 0 ry 0 1 1 1))
-
- ;; update character animation
- (let ((vel (sqrt (+ (* fx fx) (* fz fz)))))
- (declare (type single-float vel))
- (incf (anim-time p) (* vel 35.0))
- (h3d:set-model-animation-parameters (node p) 0 (anim-time p) 1.0)))))))
-
-
-
-
+ (f1 3.0) (f2 1.0) (f3 0.1)
+ (fps (curr-fps app)))
+ (declare (type single-float d1 d2 d3 f1 f2 f3 fps)
+ (optimize (speed 3) (safety 1)))
+
+ (loop :for p :across (particles app)
+ :do
+ (let ((px (px p)) (pz (pz p))
+ (dx (dx p)) (dz (dz p))
+ (ox (ox p)) (oz (oz p))
+ (fx 0.0) (fz 0.0))
+ (declare (type single-float px pz dx dz ox oz fx fz))
+ ;; reset force
+ (let ((dist (sqrt (+ (* (- dx px) (- dx px))
+ (* (- dz pz) (- dz pz))))))
+ (declare (type single-float dist))
+ (cond
+ ((> dist 3.0)
+ ;; destination not reached, walk towards destination
+ (incf fx (* 0.035 (/ (- dx px) dist)))
+ (incf fz (* 0.035 (/ (- dz pz) dist)))
+ (loop :for p2 :across (particles app)
+ :when (not (eq p p2))
+ :do
+ (let* ((p2x (px p2))
+ (p2z (pz p2))
+ (dist2 (sqrt (+ (* (- px p2x) (- px p2x))
+ (* (- pz p2z) (- pz p2z)))))
+ (strength (cond
+ ((and (<= dist2 d3) (> dist2 d2))
+ (let* ((m (/ (- f3 0) (- d2 d3)))
+ (n (- 0 (* m d3))))
+ (+ (* m dist2) n)))
+ ((and (<= dist2 d2) (> dist2 d1))
+ (let* ((m (/ (- f2 f3) (- d1 d2)))
+ (n (- f3 (* m d2))))
+ (+ (* m dist2) n)))
+ ((<= dist2 d1)
+ (let* ((m (/ (- f1 f2) (- 0 d1)))
+ (n (- f2 (* m d1))))
+ (+ (* m dist2) n)))
+ (t
+ 0.0))))
+ (declare (type single-float p2x p2z dist strength))
+ (incf fx (* strength (the single-float (/ (- px p2x) dist2))))
+ (incf fz (* strength (the single-float (/ (- pz p2z) dist2)))))))
+ (t
+ ;; near destination, choose a new one
+ (choose-destination p)))
+
+ ;; make force framerate independant
+ (setf fx (* fx (coerce (/ 30.0f0 fps) 'single-float))
+ fz (* fz (coerce (/ 30.0f0 fps) 'single-float)))
+
+ ;; set new position
+ (incf px fx)
+ (incf pz fz)
+ (setf (px p) px)
+ (setf (pz p) pz)
+
+ ;; calculate orientation
+ (setf ox (the single-float (/ (+ ox fx) 2.0)))
+ (setf oz (the single-float (/ (+ oz fz) 2.0)))
+
+ ;; update character position
+ (let ((ry (radtodeg (if (/= oz 0.0) (atan ox oz) 0.0))))
+ (declare (type single-float ry))
+ (setf (ox p) ox)
+ (setf (oz p) oz)
+ (h3d:set-node-transform (node p) px 0.02 pz 0 ry 0 1 1 1))
+
+ ;; update character animation
+ (let ((vel (sqrt (+ (* fx fx) (* fz fz)))))
+ (declare (type single-float vel))
+ (incf (anim-time p) (* vel 35.0))
+ (h3d:set-model-animation-parameters (node p) 0 (anim-time p) 1.0)))))))
+
+
+
+
;;; chicago.lisp ends here
View
74 examples/examples.lisp
@@ -1,22 +1,20 @@
;;; examples.lisp --- Examples of the standard horde3d distribution ported to Lisp
-;;; _
-;;; _____ ____ _ _ __ ___ _ __ | | ___ ___
+;;; _
+;;; _____ ____ _ _ __ ___ _ __ | | ___ ___
;;; / _ \ \/ / _` | '_ ` _ \| '_ \| |/ _ \/ __|
;;; | __/> < (_| | | | | | | |_) | | __/\__ \
;;; \___/_/\_\__,_|_| |_| |_| .__/|_|\___||___/
-;;; |_|
+;;; |_|
;;;
;;; Copyright (C) 2009 Ole Arndt <ole@sugarshark.com>
-;;;
+;;;
(in-package :horde3d-examples)
(defparameter *horde3d-home-directory*
- #p"/home/ole/src/graphics//Horde3D_SDK_1.0.0_Beta4/")
-
-;; (defparameter *horde3d-home-directory*
-;; #p"/home/ole/src/graphics//Horde3D/")
+ (asdf:system-relative-pathname (asdf:find-system :horde3d-examples)
+ (make-pathname :directory '(:relative "Horde3D"))))
(defclass example-application ()
((viewer-position :accessor viewer-position :initarg :viewer-position :initform (make-array 3 :initial-element 0.0 :element-type '(or null single-float)))
@@ -28,10 +26,10 @@
(fullscreen :accessor fullscreen? :initarg :fullscreen :initform nil)
(width :accessor width :initarg :width)
(height :accessor height :initarg :height)
-
+
(hdr-pipeline :accessor hdr-pipeline :initarg :hdr-pipeline)
(fwd-pipeline :accessor fwd-pipeline :initarg :fwd-pipeline)
-
+
(camera-node :accessor camera-node :initarg :camera-node)
(anim-time :accessor anim-time :initarg :anim-time :initform 0.0)
@@ -41,7 +39,7 @@
(logo-resource :accessor logo-resource :initarg :logo-resource)
(font-resource :accessor font-resource :initarg :font-resource)
(panel-resource :accessor panel-resource :initarg :panel-resource)
-
+
(content-path :accessor content-path :initarg :content-path)
(debug-view :accessor show-debug-view? :initarg :show-debug-view :initform nil)
(wire-frame :accessor show-wire-frame? :initarg :show-wire-frame :initform nil)
@@ -53,13 +51,12 @@
(defgeneric app-init (app)
(:method :before ((app example-application))
(h3d:init)
- (h3d:set-options :load-textures 1
- :texture-compression 0
- :fast-animation 0
- :max-anisotropy 4
- :shadow-map-size 2048)
- (setf (hdr-pipeline app) (h3d:add-resource :pipeline "pipelines/hdr.pipeline.xml" 0)
- (fwd-pipeline app) (h3d:add-resource :pipeline "pipelines/forward.pipeline.xml" 0)
+ (h3d:set-option :load-textures 1)
+ (h3d:set-option :texture-compression 0)
+ (h3d:set-option :fast-animation 0)
+ (h3d:set-option :max-anisotropy 4)
+ (h3d:set-option :shadow-map-size 2048)
+ (setf (fwd-pipeline app) (h3d:add-resource :pipeline "pipelines/forward.pipeline.xml" 0)
(font-resource app) (h3d:add-resource :material "overlays/font.material.xml" 0)
(panel-resource app) (h3d:add-resource :material "overlays/panel.material.xml" 0)
(logo-resource app) (h3d:add-resource :material "overlays/logo.material.xml" 0))))
@@ -69,8 +66,8 @@
(declare (ignore app)))
(:method :after ((app example-application))
- (declare (ignore app))
- (h3d:release)))
+ (declare (ignore app))
+ (h3d:release)))
(defgeneric app-resize (app width height)
(:documentation "Set window of app to new width and height.")
@@ -87,7 +84,7 @@
(defgeneric app-key-press-event (app key)
(:documentation "Key handler")
-
+
(:method ((app example-application) key)
(declare (ignore app key)))
@@ -99,12 +96,12 @@
(:method ((app example-application) (key (eql :sdl-key-f1)))
(toggle-fullscreen app))
-
+
(:method ((app example-application) (key (eql :sdl-key-f3)))
(with-accessors ((cam camera-node)) app
- (if (eql (h3d:node-parameter cam :camera-pipeline-resource) (hdr-pipeline app))
- (setf (h3d:node-parameter cam :camera-pipeline-resource) (fwd-pipeline app))
- (setf (h3d:node-parameter cam :camera-pipeline-resource) (hdr-pipeline app)))))
+ (if (eql (h3d:node-parameter cam :camera-pipeline-resource) (fwd-pipeline app))
+ (setf (h3d:node-parameter cam :camera-pipeline-resource) (hdr-pipeline app))
+ (setf (h3d:node-parameter cam :camera-pipeline-resource) (fwd-pipeline app)))))
(:method ((app example-application) (key (eql :sdl-key-f7)))
(setf (show-debug-view? app) (not (show-debug-view? app))))
@@ -132,13 +129,11 @@
(declaim (inline degtorad))
(defun degtorad (angle)
- (declare (type single-float angle))
- (the single-float (* angle (/ pi 180.0))))
+ (coerce (* angle (/ pi 180.0)) 'single-float))
(declaim (inline radtodeg))
(defun radtodeg (angle)
- (declare (type single-float angle))
- (the single-float (* angle (/ 180.0 pi))))
+ (coerce (* angle (/ 180.0 pi)) 'single-float))
(defun handle-movement (app)
(let ((curr-vel (/ (velocity app) (curr-fps app))))
@@ -204,10 +199,10 @@
(setf (fullscreen? app) (if (fullscreen? app) nil t))
(app-init app)
(app-resize app width height))))
-
+
(defun example-main-sdl (app &key (width 800) (height 600) (caption "Horde3D example"))
- "Main example function. This function contains the game loop. Call it with an
+ "Main example function. This function contains the game loop. Call it with an
instance of a class derived from example-application."
(sdl:with-init ()
(sdl:window width height
@@ -215,16 +210,24 @@ instance of a class derived from example-application."
:flags sdl:sdl-opengl
:title-caption caption
:icon-caption caption)
+
+ (setf (sdl:frame-rate) 0)
+ (sdl:enable-unicode)
+
(app-init app)
(app-resize app width height)
- (setf (sdl:frame-rate) 0)
- (sdl:enable-unicode t)
+
(let ((frames 0)
(fps 100.0)
(mx 0)
(my 0)
(m-init nil))
(sdl:with-events ()
+ ;; Redraw display
+ (:video-expose-event ()
+ (sdl:update-display))
+
+ ;; leave example
(:quit-event () (app-release app) t)
(:active-event (:gain gain)
@@ -235,7 +238,7 @@ instance of a class derived from example-application."
(when (null m-init)
(setf m-init t)
(setf mx x my y))
-
+
(when (not (freeze? app))
(app-mouse-move-event app (- x mx) (- y my)))
@@ -253,9 +256,6 @@ instance of a class derived from example-application."
(setf (gethash key (keys app)) nil)
(app-key-release-event app key))
- ;; Redraw display
- (:video-expose-event () (sdl:update-display))
-
;; Do work
(:idle ()
(when (>= (incf frames) 3)
View
42 examples/knight.lisp
@@ -1,13 +1,13 @@
;;; knight.lisp --- The knight example from the horde3d distribution
-;;; _ _ _ _
-;;; | | ___ __ (_) __ _| |__ | |_
+;;; _ _ _ _
+;;; | | ___ __ (_) __ _| |__ | |_
;;; | |/ / '_ \| |/ _` | '_ \| __|
-;;; | <| | | | | (_| | | | | |_
+;;; | <| | | | | (_| | | | | |_
;;; |_|\_\_| |_|_|\__, |_| |_|\__|
-;;; |___/
+;;; |___/
;;;
;;; Copyright (C) 2009 Ole Arndt <ole@sugarshark.com>
-;;;
+;;;
(in-package :horde3d-examples)
@@ -24,17 +24,19 @@
:initial-contents '(7.0 15.0 0.0))
:stat-mode 2
:anim-weight 0.0
- :content-path (merge-pathnames (make-pathname :directory "Horde3D/Binaries/Content/")
- *horde3d-home-directory*))
+ :content-path (merge-pathnames
+ (make-pathname :directory '(:relative "Horde3D" "Binaries" "Content"))
+ *horde3d-home-directory*))
:width 800
:height 600
:caption "Knight - Horde3D Sample"))
(defmethod app-init ((app knight-application))
-
+
;; Add resources
- (let ((env-res (h3d:add-resource :scene-graph "models/sphere/sphere.scene.xml" 0))
+ (let ((hdr-pipeline (h3d:add-resource :pipeline "pipelines/hdr.pipeline.xml" 0))
+ (env-res (h3d:add-resource :scene-graph "models/sphere/sphere.scene.xml" 0))
(knight-res (h3d:add-resource :scene-graph "models/knight/knight.scene.xml" 0))
(knight-anim-res-1 (h3d:add-resource :animation "animations/knight_order.anim" 0))
(knight-anim-res-2 (h3d:add-resource :animation "animations/knight_attack.anim" 0))
@@ -43,6 +45,8 @@
;; Load resources
(h3d:load-resources-from-disk (namestring (content-path app)))
+ (setf (hdr-pipeline app) hdr-pipeline)
+
;; add camera
(setf (camera-node app) (h3d:add-camera-node h3d:+root-node+ "Camera"
#+sbcl
@@ -53,13 +57,13 @@
(let ((env (h3d:add-nodes h3d:+root-node+ env-res))
(knight (h3d:add-nodes h3d:+root-node+ knight-res)))
(setf (knight-node app) knight)
-
+
(h3d:set-node-transform env 0 -20 0 0 0 0 20 20 20)
(h3d:set-node-transform knight 0 0 0 0 180 0 0.1 0.1 0.1)
-
+
(h3d:setup-model-animation-stage knight 0 knight-anim-res-1 0 "" nil)
(h3d:setup-model-animation-stage knight 1 knight-anim-res-2 0 "" nil)
-
+
;; add particles to hand
(h3d:find-nodes knight "Bip01_R_Hand" :joint)
(let ((particle-sys-node (h3d:add-nodes (h3d:get-node-find-result 0) particle-sys-res)))
@@ -80,7 +84,9 @@
;; Customize post processing effects
#-sbcl
(let ((mat-res (h3d:find-resource :material "pipelines/postHDR.material.xml")))
- (h3d:set-material-uniform mat-res "hdrParams" 2.5 0.5 0.08 0))
+ (h3d:set-material-uniform mat-res "hdrExposure" 2.5 0.0 0.0 0.0)
+ (h3d:set-material-uniform mat-res "hdrBrightThres" 0.5 0.0 0.0 0.0)
+ (h3d:set-material-uniform mat-res "hdrBrightOffset" 0.08 0.0 0.0 0.0))
;; Mark end of frame
(h3d:finalize-frame))
@@ -96,7 +102,7 @@
(decf (anim-weight app) (/ 2 (curr-fps app)))
(when (< (anim-weight app) 0.0)
(setf (anim-weight app) 0.0)))
-
+
(unless (freeze? app)
(let ((inv-fps (/ 1.0 (curr-fps app))))
(incf (anim-time app) inv-fps)
@@ -109,9 +115,9 @@
(h3d:do-nodes (node :start-node (particle-sys-node app) :node-type :emitter)
(h3d:advance-emitter-time node inv-fps))))
-
+
;; Set camera parameters
-
+
(with-accessors ((pos viewer-position)
(rot viewer-orientation)
(cam camera-node)
@@ -122,7 +128,7 @@
(when (> (stat-mode app) 0)
- (h3d:show-frame-statistics font panel (stat-mode app))
+ (h3d:show-frame-statistics font panel (stat-mode app))
;; Display weight
(h3d:show-text (format nil "Weight: ~a" (anim-weight app))
@@ -132,7 +138,7 @@
(h3d:show-overlay 0.75 0.8 0 1 0.75 1 0 0
1 1 1 0 1 0.8 1 1
1 1 1 1 (logo-resource app) 7)
-
+
;; Render scene
(h3d:render cam)))
View
6 horde3d-examples.asd
@@ -1,14 +1,14 @@
;;; -*- lisp -*-
(defsystem :horde3d-examples
- :description "The Horde3d examples ported to Common Lisp."
+ :description "The Horde3d examples ported to Common Lisp."
:long-description "The Horde3d examples ported to Common Lisp.
-Run (horde3d-examples:knight) and (horde3d-examples:chicago)."
+Run (horde3d-examples:knight) and (horde3d-examples:chicago)."
:version "0.1"
:author "Ole Arndt <ole@sugarshark.com>"
:maintainer "Ole Arndt <ole@sugarshark.com>"
:licence "EPL 1.0"
- :depends-on (:horde3d :lispbuilder-sdl)
+ :depends-on (:horde3d :lispbuilder-sdl :asdf)
:components ((:static-file "horde3d-examples.asd")
(:module "examples"
:components ((:file "package")
Please sign in to comment.
Something went wrong with that request. Please try again.