Compiled meshes work
[lambdamundo.git] / turtle.lisp
blob450e680e685594a484026a976ee040ebfd3d9dc4
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 (flet
54 ((render-x-axis ()
55 ;; x
56 (gl:color-3f 1.0 0.0 0.0)
57 (with-vertex3d
58 (location-of a)
59 (x y z w)
60 (gl:vertex-3f x y z))
61 (with-vector3d
62 (vector3d-sum
63 (vertex3d-vector3d
64 (location-of a))
65 (vector3d-scale
66 (cross-of a) (x-scale-of a)))
67 (x y z)
68 (gl:vertex-3f x y z)))
70 (render-y-axis ()
71 ;; y
72 (gl:color-3f 0.0 1.0 0.0)
73 (with-vertex3d
74 (location-of a)
75 (x y z w)
76 (gl:vertex-3f x y z))
77 (with-vector3d
78 (vector3d-sum
79 (vertex3d-vector3d
80 (location-of a))
81 (vector3d-scale
82 (up-of a) (y-scale-of a)))
83 (x y z)
84 (gl:vertex-3f x y z)))
87 (render-z-axis ()
88 ;; z
89 (gl:color-3f 0.0 0.0 1.0)
90 (with-vertex3d
91 (location-of a)
92 (x y z w)
93 (gl:vertex-3f x y z))
94 (with-vector3d
95 (vector3d-sum
96 (vertex3d-vector3d
97 (location-of a))
98 (vector3d-scale
99 (direction-of a)
100 (z-scale-of a)))
101 (x y z)
102 (gl:vertex-3f x y z))))
105 (gl:with-begin gl:+lines+
106 (render-x-axis)
107 (render-y-axis)
108 (render-z-axis))))
111 (defun make-turtle (x y z)
112 (if *turtle*
113 *turtle*
114 (let ((result
115 (make-instance 'turtle)))
116 (setf (location-of result) (vertex3d* x y z 1.0))
117 (setf *turtle* result)
118 result)))