Adding turtle
[lambdamundo.git] / turtle.lisp
blobe6a9837addffb4296ff0950483630d9c2b73462a
2 (in-package :lambdamundo)
4 (defclass turtle (actor)
5 ((scale :initform (make-vector3d* 1.0 1.0 1.0) :accessor scale-of)))
7 (defmethod x-scale-of ((a turtle))
8 (aref (the (vector single-float 3) (scale-of a)) (the fixnum 0)))
10 (defmethod y-scale-of ((a turtle))
11 (the single-float
12 (aref (the (vector single-float 3) (scale-of a)) (the fixnum 1))))
14 (defmethod z-scale-of ((a turtle))
15 (the single-float
16 (aref (the (vector single-float 3) (scale-of a)) (the fixnum 2))))
18 (defmethod up ((a turtle) amount)
19 (setf (location-of a)
20 (vector3d-vertex3d
21 (vector3d-sum
22 (vertex3d-vector3d (location-of a))
23 (vector3d-scale (up-of a) amount)))))
25 (defmethod down ((a turtle) amount)
26 (up a (- amount)))
28 (defmethod left ((a turtle) amount)
29 (setf (location-of a)
30 (vector3d-vertex3d
31 (vector3d-sum
32 (vertex3d-vector3d (location-of a))
33 (vector3d-scale (cross-of a) amount)))))
35 (defmethod right ((a turtle) amount)
36 (left a (- amount)))
38 (defmethod forward ((a turtle) amount)
39 (setf (location-of a)
40 (vector3d-vertex3d
41 (vector3d-sum
42 (vertex3d-vector3d (location-of a))
43 (vector3d-scale (cross-of a) amount)))))
45 (defmethod backward ((a turtle) amount)
46 (forward a (- amount)))
49 ;; x= red, y =green, z = blue
50 (defmethod render ((a turtle))
51 (flet
52 ((render-x-axis ()
53 ;; x
54 (gl:color-3f 1.0 0.0 0.0)
55 (with-vertex3d
56 (location-of a)
57 (x y z w)
58 (gl:vertex-3f x y z))
59 (with-vector3d
60 (vector3d-sum
61 (vertex3d-vector3d
62 (location-of a))
63 (vector3d-scale
64 (cross-of a) (x-scale-of a)))
65 (x y z)
66 (gl:vertex-3f x y z)))
68 (render-y-axis ()
69 ;; y
70 (gl:color-3f 0.0 1.0 0.0)
71 (with-vertex3d
72 (location-of a)
73 (x y z w)
74 (gl:vertex-3f x y z))
75 (with-vector3d
76 (vector3d-sum
77 (vertex3d-vector3d
78 (location-of a))
79 (vector3d-scale
80 (up-of a) (y-scale-of a)))
81 (x y z)
82 (gl:vertex-3f x y z)))
85 (render-z-axis ()
86 ;; z
87 (gl:color-3f 0.0 0.0 1.0)
88 (with-vertex3d
89 (location-of a)
90 (x y z w)
91 (gl:vertex-3f x y z))
92 (with-vector3d
93 (vector3d-sum
94 (vertex3d-vector3d
95 (location-of a))
96 (vector3d-scale
97 (direction-of a)
98 (z-scale-of a)))
99 (x y z)
100 (gl:vertex-3f x y z))))
103 (gl:with-begin gl:+lines+
104 (render-x-axis)
105 (render-y-axis)
106 (render-z-axis))))