3 (in-package :lambdamundo
)
5 (defparameter *actors
* (make-hash-table :test
'eql
))
9 ((location :type vertex3d
)
10 (velocity :type vector3d
)
11 (orientation :type quaternion
)
12 (w-velocity :type vector3d
))
14 ((id :allocation
:class
:reader id-of
:initform
(get-universal-time))
15 (dv :type single-float
:intiarg
:dv
:initform
0.0 :accessor dv-of
)
16 (dw :type single-float
:initarg
:dw
:initform
0.0 :accessor dw-of
))))
19 (defmethod initialize-instance :after
((self actor
) &rest args
)
20 (declare (ignore args
))
21 (setf (gethash (id-of self
) *actors
*) self
))
23 (defun make-actor (actor-type &rest args
)
25 (apply #'make-instance actor-type args
))
26 (result (id-of actor
)))
27 (incf (slot-value actor
'id
))
31 (def-tuple-op angular-velocity
32 ((vector vector3d
(vx vy vz
))
33 (quat quaternion
(qx qy qz qw
)))
34 "Calculate dq/dt as a quat from an angular velocity"
38 (vector3d-quaternion vector
)
41 (defmethod update-position ((a actor
))
46 (vertex3d-vector3d (location-of a
))
49 (defmethod update-dv ((a actor
))
56 (defmethod update-dw ((a actor
))
57 ;; update angluar velocity
58 (setf (w-velocity-of a
)
59 (vector3d-scale (w-velocity-of a
) (dw-of a
))))
61 (defmethod update-orientation ((a actor
))
63 (setf (orientation-of a
)
69 (orientation-of a
))))))
73 (defmethod update ((a actor
))
77 (update-orientation a
))
80 (defmethod up-of ((a actor
))
81 "Return a tuple vector representing the up axis of the camera."
82 (quaternion-transform-vector3d
83 (vector3d* 0.0 1.0 0.0)
86 (defmethod direction-of ((a actor
))
87 "Return a tuple vector representing the z axis of the camera."
88 (quaternion-transform-vector3d
89 (vector3d* 0.0 0.0 1.0)
92 (defmethod cross-of ((a actor
))
93 "Return a tuple vector representing the x axis of the camera."
94 (quaternion-transform-vector3d
95 (vector3d* 1.0 0.0 0.0)
98 (defun destroy-actor (actor)
99 (format *debug-io
* "Goodbye ~A@%" actor
)
100 (let ((destructee (gethash actor
*actors
*)))
105 (defmethod destroy ((a actor
))