From imattsson at common-lisp.net Tue Oct 10 06:19:35 2006 From: imattsson at common-lisp.net (Ingvar Mattsson) Date: Tue, 10 Oct 2006 06:19:35 +0000 Subject: [gamelib-cvs] coords.lisp Message-ID: <20061010061935.9A41434058@common-lisp.net> Update of /project/gamelib/cvsroot/source In directory clnet:/tmp/cvs-serv16563 Modified Files: coords.lisp packages-3d.lisp shapes.lisp Log Message: Added 3D camera (with movement and turning). Index: packages-3d.lisp =================================================================== RCS file: /project/gamelib/cvsroot/source/packages-3d.lisp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** packages-3d.lisp 5 Sep 2006 06:04:32 -0000 1.4 --- packages-3d.lisp 10 Oct 2006 06:19:33 -0000 1.5 *************** *** 5,9 **** #:*score-table* #:+screen-side+ #:box #:camera #:camera-to-screen #:collide-p #:collide-action #:coord #:draw-all-shapes #:draw-grid ! #:draw-shape #:defvolume #:flat #:get-centre #:move #:octaeder #:score-from-object #:shape #:tetraeder #:tetragon --- 5,9 ---- #:*score-table* #:+screen-side+ #:box #:camera #:camera-to-screen #:collide-p #:collide-action #:coord #:draw-all-shapes #:draw-grid ! #:draw-shape #:defvolume #:flat #:full-move #:3d-camera #:get-centre #:move #:octaeder #:score-from-object #:shape #:tetraeder #:tetragon Index: shapes.lisp =================================================================== RCS file: /project/gamelib/cvsroot/source/shapes.lisp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** shapes.lisp 29 Sep 2006 06:30:38 -0000 1.6 --- shapes.lisp 10 Oct 2006 06:19:33 -0000 1.7 *************** *** 11,15 **** (defgeneric get-centre (shape &optional camera )) (defgeneric move (object &optional distance)) ! (defgeneric turn (object angle)) (defvar *skip-zapping-cam-state* nil) --- 11,16 ---- (defgeneric get-centre (shape &optional camera )) (defgeneric move (object &optional distance)) ! (defgeneric full-move (object displacement)) ! (defgeneric turn (object angle &optional axis)) (defvar *skip-zapping-cam-state* nil) *************** *** 50,60 **** (incf (y cam) (y move-to)) (incf (z cam) (z move-to))))) - ! (defmethod turn ((cam camera) angle) (let ((tmp (angle cam))) (declare (double-float tmp angle)) (setf (angle cam) (mod (+ angle tmp) (* pi 2.0d0))))) (defmethod get-centre ((shape sphere) &optional camera) (update-cam-vertexes shape) --- 51,89 ---- (incf (y cam) (y move-to)) (incf (z cam) (z move-to))))) ! (defmethod full-move ((cam 3d-camera) displacement) ! (let ((move-to (vector (the-x displacement) ! (the-y displacement) ! (the-z displacement)))) ! (let ((move-to (base-transform move-to (transform cam) move-to))) ! (incf (x cam) (x move-to)) ! (incf (y cam) (y move-to)) ! (incf (z cam) (z move-to))))) ! ! (defmethod turn ((cam camera) angle &optional axis) ! (declare (ignore axis)) (let ((tmp (angle cam))) (declare (double-float tmp angle)) (setf (angle cam) (mod (+ angle tmp) (* pi 2.0d0))))) + (defmethod turn ((cam 3d-camera) angle &optional (axis :z)) + (multiple-value-bind (xbase ybase zbase) + (let ((angle-2 (+ angle (* 2.0d0 pi)))) + (case axis + (:z (values (vector (cos angle) (sin angle) 0.0d0) + (vector (cos angle-2) (sin angle-2) 0.0d0) + (vector 0.0d0 0.0d0 1.0d0))) + (:y (values (vector (cos angle-2) (sin angle-2) 0.0d0) + (vector 0.0d0 0.0d0 1.0d0) + (vector (cos angle) (sin angle) 0.0d0))) + (:x (values (vector 0.0d0 0.0d0 1.0d0) + (vector (cos angle) (sin angle) 0.0d0) + (vector (cos angle-2) (sin angle-2) 0.0d0))))) + (let ((invert (invert-transform (transform cam)))) + (let ((xb2 (base-transform xbase invert xbase)) + (yb2 (base-transform xbase invert ybase)) + (zb2 (base-transform xbase invert zbase))) + (setf (transform cam (build-transform (list xbase ybase zbase)))))))) + (defmethod get-centre ((shape sphere) &optional camera) (update-cam-vertexes shape) Index: coords.lisp =================================================================== RCS file: /project/gamelib/cvsroot/source/coords.lisp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** coords.lisp 29 Sep 2006 06:30:38 -0000 1.4 --- coords.lisp 10 Oct 2006 06:19:33 -0000 1.5 *************** *** 25,32 **** (defmethod x ((ar array)) (aref ar 0)) - (defmethod y ((ar array)) (aref ar 1)) - (defmethod z ((ar array)) (aref ar 2)) --- 25,30 ---- *************** *** 35,42 **** (defmethod (setf x) (new (ar array)) (setf (aref ar 0) new)) - (defmethod (setf y) (new (ar array)) (setf (aref ar 1) new)) - (defmethod (setf z) (new (ar array)) (setf (aref ar 2) new)) --- 33,38 ---- *************** *** 97,102 **** (setf ybase (base-transform (vector 0.0d0 1.0d0 0.0d0) transform ybase)) (setf zbase (base-transform (vector 0.0d0 0.0d0 1.0d0) transform zbase)) ! (build-transform (list xbase ybase zbase)))) ! (defmethod world-to-camera (w c &optional result) --- 93,97 ---- (setf ybase (base-transform (vector 0.0d0 1.0d0 0.0d0) transform ybase)) (setf zbase (base-transform (vector 0.0d0 0.0d0 1.0d0) transform zbase)) ! (build-transform (list xbase ybase zbase)))) (defmethod world-to-camera (w c &optional result) From imattsson at common-lisp.net Tue Oct 10 06:24:08 2006 From: imattsson at common-lisp.net (Ingvar Mattsson) Date: Tue, 10 Oct 2006 06:24:08 +0000 Subject: [gamelib-cvs] shapes.lisp Message-ID: <20061010062408.187723901F@common-lisp.net> Update of /project/gamelib/cvsroot/source In directory clnet:/tmp/cvs-serv18473 Modified Files: shapes.lisp Log Message: Minor bugfixes. Index: shapes.lisp =================================================================== RCS file: /project/gamelib/cvsroot/source/shapes.lisp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** shapes.lisp 10 Oct 2006 06:19:33 -0000 1.7 --- shapes.lisp 10 Oct 2006 06:24:06 -0000 1.8 *************** *** 84,88 **** (yb2 (base-transform xbase invert ybase)) (zb2 (base-transform xbase invert zbase))) ! (setf (transform cam (build-transform (list xbase ybase zbase)))))))) (defmethod get-centre ((shape sphere) &optional camera) --- 84,88 ---- (yb2 (base-transform xbase invert ybase)) (zb2 (base-transform xbase invert zbase))) ! (setf (transform cam) (build-transform (list xb2 yb2 zb2))))))) (defmethod get-centre ((shape sphere) &optional camera) From imattsson at common-lisp.net Tue Oct 10 06:24:32 2006 From: imattsson at common-lisp.net (Ingvar Mattsson) Date: Tue, 10 Oct 2006 06:24:32 +0000 Subject: [gamelib-cvs] 3d.html Message-ID: <20061010062432.8E2EB39020@common-lisp.net> Update of /project/gamelib/cvsroot/source/doc In directory clnet:/tmp/cvs-serv18554 Modified Files: 3d.html Log Message: Documentation changes (mostly concerning the 3d camera). Index: 3d.html =================================================================== RCS file: /project/gamelib/cvsroot/source/doc/3d.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** 3d.html 4 Sep 2006 06:27:16 -0000 1.3 --- 3d.html 10 Oct 2006 06:24:30 -0000 1.4 *************** *** 23,29 **** as up/down.

!

The built-in camera class is geared towards a camera that slides ! around and doesn't turn other than around the Z axis, but that might ! be changed in future releases.

Defining volumes

--- 23,29 ---- as up/down.

!

Starting with version 0.3, there are two cameras available. The "old" ! camera, capable of moving in X, Y and Z, always turning in the XY ! plane and the "new" (or 3D) camera, having 6 degrees of freedom.

Defining volumes

*************** *** 50,53 **** --- 50,66 ---- count or what-have-you).

+

Base and transform designators

+ +

Starting from version 0.3, there is a "fully 3D" camera available, + necessitating some new concepts and accessors (hopefully seamlessly + integrated into the whole). The most developer-visible of these are + "base designators" and "transform designators".

+ +

A "base designator" is either 3-element vector, array or list.

+ + A "transform designator" is a 3-element sequence of "base + designators", specifying the (world coordinate) vectors from the + camera origo to [ 1, 0, 0 ], [ 0, 1, 0 ] and [ 0, 0, 1 ]. +

What will be shown and how?

*************** *** 98,101 **** --- 111,120 ---- 3d-rendering is made on. Also guides the size of the X window it will be displayed in. +
3d-camera +
(3d-camera x y z &optional + transform)
+ Return a newly constructed 3d-camera object, at position [ X, Y, Z ]. + If an optional transform designator is passed it, the camera will + use this as its transform, otherwise it will use a unit transform.
box
Shape class. 8 corners, 6 sides. *************** *** 137,140 **** --- 156,165 ----
flat
Shape class, superclass for all flat surfaces. +
full-move +
(full-move camera displacement)
+ Displace the camera by displacement, a 3D coordinate (using the + camera's position as origo, expressed in the camera coordinate + system). The displacement will be transformed into world coordinates + before being applied.
get-centre
(get-centre shape &optional *************** *** 161,166 ****
Shape class (flat)
turn !
(turn object angle)
! Generic function. Turn object through angle around the Z axis.
volume
Shape class, superclass for all volumes. --- 186,195 ----
Shape class (flat)
turn !
(turn object angle &optional angle)
! Generic function. Turn object through angle. If the ! object is "the standard camera" it will be turned around the Z axis. A ! 3D camera will default to turn around teh Z axis unless otherwise ! specified. Axes are designated by the :x :y or :z keywords. The angle ! is specified in radians.
volume
Shape class, superclass for all volumes.