-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convert.py
59 lines (50 loc) · 1.76 KB
/
Convert.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
class Convert:
def __init__(self, height_map, texture, gl, map_size):
#Tuples for each axis's scale
self.height_map_scale = height_map
self.texture_scale = texture
self.open_gl_scale = gl
self.sea_level = self.open_gl_scale[1]/float(15)
self.size = map_size
#print self.size
self.gl_x = self.size * self.open_gl_scale[0]
self.gl_y = self.open_gl_scale[1]
self.gl_z = self.size * self.open_gl_scale[2]
def set_dimensions(self, x, z):
self.heightmap_x = x
self.heightmap_z = z
self.texture_x = x * self.texture_scale[0]
self.texture_z = z * self.texture_scale[2]
self.gl_x = x * self.open_gl_scale[0]
self.gl_y = 1 * self.open_gl_scale[1]
self.gl_z = z * self.open_gl_scale[2]
def convert(self, from_system, to_system, axis, amt):
initial_system = self._find_coord_system(from_system)
final_system = self._find_coord_system(to_system)
system_axis = self._find_axis(axis)
converted_amt = amt * final_system[system_axis] / initial_system[system_axis]
return converted_amt
def convert_for_triangle(self, axis, hm_num):
if axis == 'x':
return hm_num
else:
new_num = hm_num - self.size
return new_num
def _find_coord_system(self, name):
if name == 'h':
return self.height_map_scale
elif name == 't':
return self.texture_scale
elif name == 'g':
return self.open_gl_scale
else:
return None
def _find_axis(self, name):
if name == 'x':
return 0
elif name == 'y':
return 1
elif name == 'z':
return 2
else:
return None