adds labyrinth and subjects as well as performance increases
This commit is contained in:
parent
6c5cae958b
commit
0638d5e666
10 changed files with 1591 additions and 234 deletions
Client
146
Client/Client.py
146
Client/Client.py
|
@ -41,10 +41,30 @@ def value_to_color(v, min_value, max_value):
|
|||
|
||||
|
||||
class Client:
|
||||
def __init__(self, test=False, pos=[0, 0, 0]):
|
||||
def __init__(self, test=False, pos=[0, 0, 0], world_class=WorldProvider):
|
||||
self.state = 0
|
||||
with open('./config.json', 'r') as f:
|
||||
self.config = json.load(f)
|
||||
self.init_shaders()
|
||||
|
||||
self.world_provider = world_class(self.normal_program)
|
||||
self.draw_world()
|
||||
|
||||
self.pos = pos
|
||||
self.time = time.time()
|
||||
|
||||
glutReshapeFunc(self.resize)
|
||||
glutDisplayFunc(self.display)
|
||||
glutKeyboardFunc(self.keyboardHandler)
|
||||
glutSpecialFunc(self.funcKeydHandler)
|
||||
|
||||
if not test:
|
||||
glutMainLoop()
|
||||
else:
|
||||
self.display()
|
||||
self.resize(100, 100)
|
||||
|
||||
def init_shaders(self):
|
||||
glutInit(sys.argv)
|
||||
self.width = 1920
|
||||
self.height = 1080
|
||||
|
@ -96,7 +116,7 @@ class Client:
|
|||
self.depth_program[self.normal_program[key]] = Spotlight.getDepthProgram(self.vertex_shader_id,
|
||||
key.GeometryShaderId)
|
||||
|
||||
self.world_provider = WorldProvider(self.normal_program)
|
||||
def draw_world(self):
|
||||
for x_pos in range(0, 100):
|
||||
for y_pos in range(0, 100):
|
||||
for z_pos in range(0, 1):
|
||||
|
@ -118,97 +138,11 @@ class Client:
|
|||
r, g, b = colors[int(self.world_provider.world.plates[x_pos, y_pos])]
|
||||
self.world_provider.world.set_color(x_pos, y_pos, z_pos, r, g, b)
|
||||
|
||||
# total_x = self.world_provider.world.chunk_n_x * self.world_provider.world.chunk_size_x
|
||||
# total_y = self.world_provider.world.chunk_n_y * self.world_provider.world.chunk_size_y
|
||||
# for x_pos in range(0, 100):
|
||||
# for y_pos in range(0, 100):
|
||||
# if self.world_provider.world.faults[x_pos, y_pos] == -2:
|
||||
# self.world_provider.world.set_color(x_pos, y_pos, 0, 0, 0, 0)
|
||||
#
|
||||
# for line_index, line in enumerate(self.world_provider.world.fault_lines):
|
||||
# for x_pos in range(0, 100):
|
||||
# for y_pos in range(0, 100):
|
||||
# if self.world_provider.world.faults[x_pos, y_pos] == line_index:
|
||||
# if line_index != 9:
|
||||
# self.world_provider.world.set_color(x_pos, y_pos, 0, 0, 0, 1)
|
||||
# else:
|
||||
# self.world_provider.world.set_color(x_pos, y_pos, 0, 1, 1, 1)
|
||||
#
|
||||
# for x_pos in range(0, 100):
|
||||
# for y_pos in range(0, 100):
|
||||
# for z_pos in range(0, 1):
|
||||
# if [x_pos, y_pos] in self.world_provider.world.fault_nodes:
|
||||
# r, g, b = 1, 0, 0
|
||||
# self.world_provider.world.set_color(x_pos, y_pos, z_pos, r, g, b)
|
||||
|
||||
# # visualize direction lengths
|
||||
# lengths = np.sqrt(np.sum(np.square(self.world_provider.world.directions), axis=2))
|
||||
# lengths = lengths / np.max(lengths)
|
||||
# for x_pos in range(0, 100):
|
||||
# for y_pos in range(0, 100):
|
||||
# for z_pos in range(0, 1):
|
||||
# r, g, b = lengths[x_pos, y_pos], lengths[x_pos, y_pos], lengths[x_pos, y_pos]
|
||||
# self.world_provider.world.set_color(x_pos, y_pos, z_pos, r, g, b)
|
||||
|
||||
self.projMatrix = perspectiveMatrix(45.0, 400 / 400, 0.01, MAX_DISTANCE)
|
||||
|
||||
self.rx = self.cx = self.cy = 0
|
||||
self.opening = 45
|
||||
|
||||
glutReshapeFunc(self.resize)
|
||||
glutDisplayFunc(self.display)
|
||||
glutKeyboardFunc(self.keyboardHandler)
|
||||
glutSpecialFunc(self.funcKeydHandler)
|
||||
|
||||
self.pos = pos
|
||||
|
||||
self.time = time.time()
|
||||
|
||||
self.field = (100, 100, 1)
|
||||
self.e_a = np.array([
|
||||
[0, 0, 0],
|
||||
[1, 0, 0],
|
||||
[1, 1, 0],
|
||||
[0, 1, 0],
|
||||
[-1, 1, 0],
|
||||
[-1, 0, 0],
|
||||
[-1, -1, 0],
|
||||
[0, -1, 0],
|
||||
[1, -1, 0],
|
||||
])
|
||||
|
||||
self.relaxation_time = 0.55 # 0.55
|
||||
self.w_a = [
|
||||
4.0 / 9.0,
|
||||
1.0 / 9.0,
|
||||
1.0 / 36.0,
|
||||
1.0 / 9.0,
|
||||
1.0 / 36.0,
|
||||
1.0 / 9.0,
|
||||
1.0 / 36.0,
|
||||
1.0 / 9.0,
|
||||
1.0 / 36.0
|
||||
]
|
||||
|
||||
self.n_a = np.zeros((len(self.e_a),) + self.field)
|
||||
self.n_a_eq = np.zeros(self.n_a.shape)
|
||||
self.n = np.zeros(self.field)
|
||||
self.n[:, :, :] += 1.0
|
||||
self.gravity_applies = np.zeros(self.field)
|
||||
# self.n /= np.sum(self.n)
|
||||
self.n_a[0] = np.array(self.n)
|
||||
self.u = np.zeros(self.field + (self.e_a.shape[1],))
|
||||
|
||||
self.compressible = True
|
||||
self.max_n = self.w_a[0]
|
||||
|
||||
self.test_pixel = [40, 50, 0]
|
||||
|
||||
if not test:
|
||||
glutMainLoop()
|
||||
else:
|
||||
self.display()
|
||||
self.resize(100, 100)
|
||||
|
||||
def display(self):
|
||||
glClearColor(0, 0, 0, 0)
|
||||
|
@ -261,41 +195,7 @@ class Client:
|
|||
|
||||
glutSwapBuffers()
|
||||
|
||||
min_value = 0
|
||||
max_value_n = np.max(self.n)
|
||||
# max_value_n = 1.0
|
||||
|
||||
vel = np.sqrt(np.sum(np.square(self.u), axis=3)) *self.n
|
||||
max_value_vel = np.max(vel)
|
||||
# max_value_vel = np.sqrt(3)
|
||||
|
||||
# print('round')
|
||||
# print('sum n: %f' % np.sum(self.n))
|
||||
# print('max n: %f' % np.max(self.n))
|
||||
# print('min n: %f' % np.min(self.n))
|
||||
# print('sum vel: %f' % np.sum(vel))
|
||||
# print('max vel: %f' % np.max(vel))
|
||||
# print('min vel: %f' % np.min(vel))
|
||||
|
||||
# for x_pos in range(0, 100):
|
||||
# for y_pos in range(0, 100):
|
||||
# for z_pos in range(0, 1):
|
||||
# # if self.state == 2:
|
||||
# # r, g, b = value_to_color(int(self.gravity_applies[x_pos, y_pos, z_pos]), 0, 1)
|
||||
# # if self.state == 1:
|
||||
# # r, g, b = value_to_color(vel[x_pos, y_pos, z_pos], min_value, max_value_vel)
|
||||
# # if self.state == 0:
|
||||
# # r, g, b = value_to_color(self.n[x_pos, y_pos, z_pos], min_value, max_value_n)
|
||||
# r, g, b, = 128, 128, 128
|
||||
# if [x_pos, y_pos] in self.world_provider.world.fault_nodes:
|
||||
# r, g, b = 128, 0, 0
|
||||
#
|
||||
# self.world_provider.world.set_color(x_pos, y_pos, z_pos, r, g, b)
|
||||
# self.world_provider.world.set_color(int(round(self.test_pixel[0])),
|
||||
# int(round(self.test_pixel[1])),
|
||||
# int(round(self.test_pixel[2])), 1.0, 1.0, 1.0)
|
||||
|
||||
print(1.0 / (time.time() - self.time))
|
||||
print('fps', 1.0 / (time.time() - self.time))
|
||||
self.time = time.time()
|
||||
glutPostRedisplay()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue