diff --git a/game/game.py b/game/game.py index c99477b..e77834d 100644 --- a/game/game.py +++ b/game/game.py @@ -157,7 +157,7 @@ def main(): 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_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( FuncNode(update_camera, (mouse, camera, environment)), diff --git a/game/sea.py b/game/sea.py index f6eed95..6e96a46 100644 --- a/game/sea.py +++ b/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))) return Texture(_format, width, height, 0, _flags, data) -class SeaTriangles(Triangles): - # TODO: with FOV - def __init__(self, vsubdivs, distance, projection_ratio): - assert vsubdivs > 0 - vertices = [] - hsubdivs = round(vsubdivs * projection_ratio) - z = -distance - width = distance * projection_ratio - height = distance - startx = width * -0.5 - starty = height * -0.5 - stepx = width / hsubdivs - stepy = height / vsubdivs - y1 = starty - y2 = y1 + stepy - for sy in range(vsubdivs): - x1 = startx - x2 = x1 + stepx - for sx in range(hsubdivs): - a = (x1, y2, z) - b = (x2, y1, z) - vertices.append((x1, y1, z)) - vertices.append(b) - vertices.append(a) - vertices.append((x2, y2, z)) - vertices.append(a) - vertices.append(b) - x1 = x2 - x2 += stepx - y1 = y2 - y2 += stepy - super().__init__(array('f', chain.from_iterable(vertices))) +# TODO: with FOV +def sea_triangles(vsubdivs, distance, projection_ratio): + assert vsubdivs > 0 + vertices = [] + hsubdivs = round(vsubdivs * projection_ratio) + z = -distance + width = distance * projection_ratio + height = distance + startx = width * -0.5 + starty = height * -0.5 + stepx = width / hsubdivs + stepy = height / vsubdivs + y1 = starty + y2 = y1 + stepy + for sy in range(vsubdivs): + x1 = startx + x2 = x1 + stepx + for sx in range(hsubdivs): + a = (x1, y2, z) + b = (x2, y1, z) + vertices.append((x1, y1, z)) + vertices.append(b) + vertices.append(a) + vertices.append((x2, y2, z)) + vertices.append(a) + vertices.append(b) + x1 = x2 + x2 += stepx + y1 = y2 + y2 += stepy + return Triangles(array('f', chain.from_iterable(vertices)))