Skip to content
Snippets Groups Projects
Commit c86e0041 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Radial view cone, if angle is 360 it is just a circle

parent fe21742f
No related branches found
No related tags found
1 merge request!56Resolve "More FOV"
Pipeline #45987 passed
......@@ -87,8 +87,8 @@ player_config:
radius: 0.4
player_speed_units_per_seconds: 6
interaction_range: 1.6
restricted_view: False
view_angle: 60
restricted_view: True
view_angle: 90
view_range: 3 # in grid units, can be "null"
effect_manager:
......
......@@ -45,11 +45,12 @@ def grayscale(img):
return surface
def create_polygon(n, length):
def create_polygon(n, start_vec):
if n == 1:
return np.array([0, 0])
vector = np.array([length, 0])
vector = start_vec.copy()
angle = (2 * np.pi) / n
rot_matrix = np.array(
......@@ -155,51 +156,64 @@ class Visualizer:
angle = state["view_restriction"]["angle"] / 2
range = state["view_restriction"]["range"]
angle = min(angle, 180)
pos = pos * grid_size + pygame.math.Vector2([grid_size / 2, grid_size / 2])
rect_scale = max(width, height)
rect_scale = max(width, height) * 2
# rect_scale = 2 * grid_size
left_beam = pos + (direction.rotate(angle) * rect_scale * 2)
right_beam = pos + (direction.rotate(-angle) * rect_scale * 2)
offset_front = direction * grid_size * 0.2
pygame.draw.polygon(
screen,
colors["black"],
(
pos - offset_front,
left_beam - offset_front,
left_beam + (direction.rotate(90) * rect_scale),
pos
- (direction * rect_scale * 2)
+ (direction.rotate(90) * rect_scale),
pos
- (direction * rect_scale * 2)
+ (direction.rotate(-90) * rect_scale),
right_beam + (direction.rotate(-90) * rect_scale),
right_beam - offset_front,
),
)
if range:
offset_front = direction * grid_size * 0.0
if angle != 180:
pygame.draw.polygon(
screen,
colors["black"],
(
pos - offset_front,
left_beam - offset_front,
left_beam + (direction.rotate(90) * rect_scale),
pos
+ (direction.rotate(90) * rect_scale)
+ (direction * range * grid_size),
pos
+ (direction.rotate(-90) * rect_scale)
+ (direction * range * grid_size),
pos
+ (direction.rotate(-90) * rect_scale)
+ (direction * rect_scale),
- (direction * rect_scale * 2)
+ (direction.rotate(90) * rect_scale),
pos
+ (direction.rotate(90) * rect_scale)
+ (direction * rect_scale),
- (direction * rect_scale * 2)
+ (direction.rotate(-90) * rect_scale),
right_beam + (direction.rotate(-90) * rect_scale),
right_beam - offset_front,
),
)
if range:
n_circle_points = 40
start_vec = np.array(-direction * range)
points = (
np.array(create_polygon(n_circle_points, start_vec)) * grid_size
) + pos
circle_closed = np.concatenate([points, points[0:1]], axis=0)
corners = [
pos - (direction * rect_scale),
*circle_closed,
pos - (direction * rect_scale),
pos
- (direction * rect_scale)
+ (direction.rotate(90) * rect_scale),
pos
+ (direction * rect_scale)
+ (direction.rotate(90) * rect_scale),
pos
+ (direction * rect_scale)
+ (direction.rotate(-90) * rect_scale),
pos
- (direction * rect_scale)
+ (direction.rotate(-90) * rect_scale),
]
pygame.draw.polygon(screen, colors["black"], [*corners])
def draw_background(
self, surface: pygame.Surface, width: int, height: int, grid_size: int
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment