Passed test again
[tuple-trace.git] / ray.lisp
blob8d80983efd4a1c39ab19fd05a997d19daa4c737e
3 (in-package :tuple-trace)
5 ;; this is a small enough thing it might be a primitive in cl-tuples..
6 (def-tuple-class ray
7 (:tuples
8 ((origin :type vector3d)
9 (direction :type vector3d))))
12 (defun make-ray (xo yo zo xr yr zr)
13 (let ((result
14 (make-instance 'ray
15 :origin (make-vector3d* xo yo zo)
16 :direction (make-vector3d* xr yr zr))))
17 result))
19 (defmethod distance-of ((self ray))
20 (vector3d-length (direction-of self)))
22 (defmethod direction-normal-of ((self ray))
23 (vector3d-normal (direction-of self)))
25 (def-tuple-op extrapolate
26 ((origin vector3d (xo yo zo))
27 (direction vector3d (xd yd zd))
28 (alpha single-float))
29 (:return vector3d
30 (vector3d*
31 (+ xo (* xd alpha))
32 (+ yo (* yd alpha))
33 (+ zo (* zd alpha)))))
35 (defmethod point-on ((self ray) interval)
36 (extrapolate
37 (origin-of self)
38 (direction-of self)
39 interval))
41 ;; test code
42 ;; (defparameter *ray* (make-ray 0.0 1.0 0.0 0.0 -1.0 0.0))
43 ;; (direction-of *ray*)
44 ;; (distance-of *ray*)
45 ;; (direction-normal-of *ray*)
46 ;; (setf (direction-of *ray*) #{ 0.0 -2.0 0.0 })
47 ;; (direction-normal-of *ray*)
48 ;; (point-on *ray* 4.0)