-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshape.lisp
47 lines (39 loc) · 1.34 KB
/
shape.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;;;; -*- Mode: Lisp -*-
(in-package :raytracer)
(defclass shape ()
((position
:initarg :position
:initform '(0 0 0))
;; ambient, diffuse, specular, shininess, refractionIdx
(material
:initarg :material
:initform '((.2 .2 .2 1) (.8 .8 .8 1) (.5 .5 .5 1) 0 0))))
(defgeneric draw (shape))
(defgeneric intersect (shape direction eye))
(defgeneric normal (shape direction eye vecscale))
(defgeneric texture (shape direction eye vecscale))
(defgeneric specular (shape))
(defgeneric ambient (shape))
(defgeneric diffuse (shape))
(defgeneric refractiveIdx (shape))
(defmethod draw :around (shape)
(with-slots (position material) shape
(cl-opengl:with-pushed-matrix
(cl-opengl:translate (nth 0 position) (nth 1 position) (nth 2 position))
(cl-opengl:material :front :ambient (nth 0 material))
(cl-opengl:material :front :diffuse (nth 1 material))
(cl-opengl:material :front :specular (nth 2 material))
(cl-opengl:material :front :shininess (nth 3 material))
(call-next-method))))
(defmethod ambient (shape)
(with-slots (material) shape
(nth 0 material)))
(defmethod diffuse (shape)
(with-slots (material) shape
(nth 1 material)))
(defmethod specular (shape)
(with-slots (material) shape
(nth 2 material)))
(defmethod refractiveIdx (shape)
(with-slots (material) shape
(nth 4 material)))