Cleanup sea triangles creation.
This commit is contained in:
parent
9e77e6680b
commit
f66c6ea6e9
@ -157,7 +157,7 @@ def main():
|
|||||||
|
|
||||||
sea_polar_textures = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png'))
|
sea_polar_textures = sea.load_polar_textures(('data/sea_bump1.png', 'data/sea_bump2.png'))
|
||||||
sea_detail_texture = sea.load_detail_texture('data/sea_bump.png')
|
sea_detail_texture = sea.load_detail_texture('data/sea_bump.png')
|
||||||
sea_triangles = sea.SeaTriangles(64, proj_far_z - 0.1, proj_ratio)
|
sea_triangles = sea.sea_triangles(64, proj_far_z - 0.1, proj_ratio)
|
||||||
|
|
||||||
scene = SceneNode(
|
scene = SceneNode(
|
||||||
FuncNode(update_camera, (mouse, camera, environment)),
|
FuncNode(update_camera, (mouse, camera, environment)),
|
||||||
|
63
game/sea.py
63
game/sea.py
@ -71,35 +71,34 @@ def load_detail_texture(path, scale = 0.5, waves_height = 0.002):
|
|||||||
data = array(_typecode, list(map(_conv, normals)))
|
data = array(_typecode, list(map(_conv, normals)))
|
||||||
return Texture(_format, width, height, 0, _flags, data)
|
return Texture(_format, width, height, 0, _flags, data)
|
||||||
|
|
||||||
class SeaTriangles(Triangles):
|
# TODO: with FOV
|
||||||
# TODO: with FOV
|
def sea_triangles(vsubdivs, distance, projection_ratio):
|
||||||
def __init__(self, vsubdivs, distance, projection_ratio):
|
assert vsubdivs > 0
|
||||||
assert vsubdivs > 0
|
vertices = []
|
||||||
vertices = []
|
hsubdivs = round(vsubdivs * projection_ratio)
|
||||||
hsubdivs = round(vsubdivs * projection_ratio)
|
z = -distance
|
||||||
z = -distance
|
width = distance * projection_ratio
|
||||||
width = distance * projection_ratio
|
height = distance
|
||||||
height = distance
|
startx = width * -0.5
|
||||||
startx = width * -0.5
|
starty = height * -0.5
|
||||||
starty = height * -0.5
|
stepx = width / hsubdivs
|
||||||
stepx = width / hsubdivs
|
stepy = height / vsubdivs
|
||||||
stepy = height / vsubdivs
|
y1 = starty
|
||||||
y1 = starty
|
y2 = y1 + stepy
|
||||||
y2 = y1 + stepy
|
for sy in range(vsubdivs):
|
||||||
for sy in range(vsubdivs):
|
x1 = startx
|
||||||
x1 = startx
|
x2 = x1 + stepx
|
||||||
x2 = x1 + stepx
|
for sx in range(hsubdivs):
|
||||||
for sx in range(hsubdivs):
|
a = (x1, y2, z)
|
||||||
a = (x1, y2, z)
|
b = (x2, y1, z)
|
||||||
b = (x2, y1, z)
|
vertices.append((x1, y1, z))
|
||||||
vertices.append((x1, y1, z))
|
vertices.append(b)
|
||||||
vertices.append(b)
|
vertices.append(a)
|
||||||
vertices.append(a)
|
vertices.append((x2, y2, z))
|
||||||
vertices.append((x2, y2, z))
|
vertices.append(a)
|
||||||
vertices.append(a)
|
vertices.append(b)
|
||||||
vertices.append(b)
|
x1 = x2
|
||||||
x1 = x2
|
x2 += stepx
|
||||||
x2 += stepx
|
y1 = y2
|
||||||
y1 = y2
|
y2 += stepy
|
||||||
y2 += stepy
|
return Triangles(array('f', chain.from_iterable(vertices)))
|
||||||
super().__init__(array('f', chain.from_iterable(vertices)))
|
|
||||||
|
Loading…
Reference in New Issue
Block a user