Adding forgotten file
[lambdamundo.git] / actor.lisp
blob44ae953d31d8cc3dd96f72467ac734ce4d8bcaa8
3 (in-package :lambdamundo)
5 (defparameter *actors* (make-array 0 :adjustable t :fill-pointer 0))
7 (def-tuple-class actor
8 (:tuples
9 ((location :type vertex3d)
10 (velocity :type vector3d)
11 (orientation :type quaternion)
12 (w-velocity :type vector3d))
13 :slots
14 ((dv :type single-float :initform 0.0 :accessor dv-of)
15 (dw :type single-float :initform 0.0 :accessor dw-of))))
18 (defmethod initialize-instance :after ((self actor) &rest args)
19 (declare (ignore args))
20 (setf (aref (orientation-of% self) 3) 1.0)
21 (vector-push-extend self *actors*))
23 (def-tuple-op angular-velocity
24 ((vector vector3d (vx vy vz))
25 (quat quaternion (qx qy qz qw)))
26 "Calculate dq/dt as a quat from an angular velocity"
27 (:return quaternion
28 (quaternion-scale
29 (quaternion-product
30 (vector3d-quaternion vector)
31 quat) 0.5)))
33 (defmethod update-position ((a actor))
34 ;; update position
35 (setf (location-of a)
36 (vector3d-vertex3d
37 (vector3d-sum
38 (vertex3d-vector3d (location-of a))
39 (velocity-of a)))))
41 (defmethod update-dv ((a actor))
42 ;; update velocity
43 (setf (velocity-of a)
44 (vector3d-scale
45 (velocity-of a)
46 (dv-of a))))
48 (defmethod update-dw ((a actor))
49 ;; update angluar velocity
50 (setf (w-velocity-of a)
51 (vector3d-scale (w-velocity-of a) (dw-of a))))
53 (defmethod update-orientation ((a actor))
54 ;; update orientation
55 (setf (orientation-of a)
56 (quaternion-unitize
57 (quaternion-sum
58 (orientation-of a)
59 (angular-velocity
60 (w-velocity-of a)
61 (orientation-of a))))))
65 (defmethod update ((a actor))
66 (update-dv a)
67 (update-dw a)
68 (update-position a)
69 (update-orientation a))
72 (defmethod up-of ((a actor))
73 "Return a tuple vector representing the up axis of the camera."
74 (quaternion-transform-vector3d
75 (vector3d* 0.0 1.0 0.0)
76 (orientation-of a)))
78 (defmethod direction-of ((a actor))
79 "Return a tuple vector representing the z axis of the camera."
80 (quaternion-transform-vector3d
81 (vector3d* 0.0 0.0 1.0)
82 (orientation-of a)))
84 (defmethod cross-of ((a actor))
85 "Return a tuple vector representing the x axis of the camera."
86 (quaternion-transform-vector3d
87 (vector3d* 1.0 0.0 0.0)
88 (orientation-of a)))