Ready for performance testing
[lambdamundo.git] / turtle.lisp
blobb5d2896f7f3443632e4ec25b42a05f2e6964195d
2 (in-package :lambdamundo)
4 (defparameter *turtle* nil)
6 (defclass turtle (actor)
7 ((scale :initform (make-vector3d* 1.0 1.0 1.0) :accessor scale-of)))
9 (defmethod x-scale-of ((a turtle))
10 (aref (the (vector single-float 3) (scale-of a)) (the fixnum 0)))
12 (defmethod y-scale-of ((a turtle))
13 (the single-float
14 (aref (the (vector single-float 3) (scale-of a)) (the fixnum 1))))
16 (defmethod z-scale-of ((a turtle))
17 (the single-float
18 (aref (the (vector single-float 3) (scale-of a)) (the fixnum 2))))
20 (defmethod up ((a turtle) amount)
21 (setf (location-of a)
22 (vector3d-vertex3d
23 (vector3d-sum
24 (vertex3d-vector3d (location-of a))
25 (vector3d-scale (up-of a) amount)))))
27 (defmethod down ((a turtle) amount)
28 (up a (- amount)))
30 (defmethod left ((a turtle) amount)
31 (setf (location-of a)
32 (vector3d-vertex3d
33 (vector3d-sum
34 (vertex3d-vector3d (location-of a))
35 (vector3d-scale (cross-of a) amount)))))
37 (defmethod right ((a turtle) amount)
38 (left a (- amount)))
40 (defmethod forward ((a turtle) amount)
41 (setf (location-of a)
42 (vector3d-vertex3d
43 (vector3d-sum
44 (vertex3d-vector3d (location-of a))
45 (vector3d-scale (cross-of a) amount)))))
47 (defmethod backward ((a turtle) amount)
48 (forward a (- amount)))
51 ;; x= red, y =green, z = blue
52 (defmethod render ((a turtle))
53 ;; (break)
54 (flet
55 ((render-x-axis ()
56 ;; x
57 (gl:color-3f 1.0 0.0 0.0)
58 (with-vertex3d
59 (location-of a)
60 (x y z w)
61 (gl:vertex-3f x y z))
62 (with-vector3d
63 (vector3d-sum
64 (vertex3d-vector3d
65 (location-of a))
66 (vector3d-scale
67 (cross-of a) (x-scale-of a)))
68 (x y z)
69 (gl:vertex-3f x y z)))
71 (render-y-axis ()
72 ;; y
73 (gl:color-3f 0.0 1.0 0.0)
74 (with-vertex3d
75 (location-of a)
76 (x y z w)
77 (gl:vertex-3f x y z))
78 (with-vector3d
79 (vector3d-sum
80 (vertex3d-vector3d
81 (location-of a))
82 (vector3d-scale
83 (up-of a) (y-scale-of a)))
84 (x y z)
85 (gl:vertex-3f x y z)))
88 (render-z-axis ()
89 ;; z
90 (gl:color-3f 0.0 0.0 1.0)
91 (with-vertex3d
92 (location-of a)
93 (x y z w)
94 (gl:vertex-3f x y z))
95 (with-vector3d
96 (vector3d-sum
97 (vertex3d-vector3d
98 (location-of a))
99 (vector3d-scale
100 (direction-of a)
101 (z-scale-of a)))
102 (x y z)
103 (gl:vertex-3f x y z))))
106 (gl:with-begin gl:+lines+
107 (render-x-axis)
108 (render-y-axis)
109 (render-z-axis))))