-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapes.py
98 lines (80 loc) · 2.96 KB
/
shapes.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import pyglet
import ctypes
from material import *
class Hitable_list:
hitables = []
def update(self, pn):
#pass all objects to the shader
for i in range(len(self.hitables)):
self.hitables[i].update(i, pn)
pyglet.gl.glUniform1i(pyglet.gl.glGetUniformLocation(pn, ctypes.create_string_buffer("NUM_OBJECTS".encode('ascii'))), int(len(self.hitables)))
def add(self, shape):
self.hitables.append(shape)
class Hitable:
position = []
size = 0
rotation = []
shape = 0
material = None
volume = 0
def __init__(self, *args):
#for now take three arrays for args
if len(args) >= 1:
self.position = args[0]
else:
print("not enough arguments supplied to Hitable")
if len(args) >=2:
self.size = args[1]
else:
self.size = 0.5
if len(args) >= 3:
self.rotation = args[2]
else:
self.rotation = [0.0, 1.0, 0.0]
if len(args) >= 4:
self.material = args[3]
else:
self.material = Lambertian((1.0, 0.5, 0.5))
def get_locations(self, i, pn):
pass
def update(self, i, pn):
##update position
name = "hitables["+str(i)+"].pos"
pyglet.gl.glUniform3f(pyglet.gl.glGetUniformLocation(pn, ctypes.create_string_buffer(name.encode('ascii'))), self.position[0], self.position[1], self.position[2])
#update size
name = "hitables["+str(i)+"].size"
pyglet.gl.glUniform1f(pyglet.gl.glGetUniformLocation(pn, ctypes.create_string_buffer(name.encode('ascii'))), self.size)
##update rotation
name = "hitables["+str(i)+"].dir"
pyglet.gl.glUniform3f(pyglet.gl.glGetUniformLocation(pn, ctypes.create_string_buffer(name.encode('ascii'))), self.rotation[0], self.rotation[1], self.rotation[2])
##update type
name = "hitables["+str(i)+"].type"
pyglet.gl.glUniform1i(pyglet.gl.glGetUniformLocation(pn, ctypes.create_string_buffer(name.encode('ascii'))), int(self.shape))
self.material.update(i, pn)
## update volume flag
name = "hitables["+str(i)+"].volume"
pyglet.gl.glUniform1i(pyglet.gl.glGetUniformLocation(pn, ctypes.create_string_buffer(name.encode('ascii'))), self.volume)
class Sphere(Hitable):
def __init__(self, *args):
super(Sphere, self).__init__(*args)
self.shape = 1
class Cube(Hitable):
def __init__(self, *args):
super(Cube, self).__init__(*args)
self.shape = 2
class Plane(Hitable):
def __init__(self, *args):
super(Plane, self).__init__(*args)
self.shape = 3
class Triangle(Hitable):
def __init__(self, *args):
super(Triangle, self).__init__(*args)
self.shape = 4
class Disk(Hitable):
def __init__(self, *args):
super(Disk, self).__init__(*args)
self.shape = 5
def ConstantMedium(s):
shape = s
shape.volume = 1
return shape