Skip to content

Commit

Permalink
modified (point_in_view) function
Browse files Browse the repository at this point in the history
  • Loading branch information
Maphineth-UNG committed Nov 14, 2024
1 parent 575d662 commit a5b946e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions arcade/camera/camera_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,23 +477,23 @@ def aabb(self) -> Rect:
return LRBT(left=left, right=right, bottom=bottom, top=top)

def point_in_view(self, point: Point2) -> bool:
# TODO test
"""
Take a 2D point in the world, and return whether the point is inside the
visible area of the camera.
Check if a given 2D point in the world is within the camera's visible area.
"""
pos = self.position
diff = point[0] - pos[0], point[1] - pos[1]
pos = Vec2(*self.position)
diff = Vec2(point[0] - pos.x, point[1] - pos.y)

up = self._camera_data.up
up = Vec2(*self._camera_data.up[:2])
right = Vec2(up.y, -up.x) # Right is perpendicular to up

h_width = self.width / 2.0
h_height = self.height / 2.0

dot_x = up[1] * diff[0] - up[0] * diff[1]
dot_y = up[0] * diff[0] + up[1] * diff[1]
# Project the difference vector onto the camera's axes
proj_x = abs(right.dot(diff))
proj_y = abs(up.dot(diff))

return abs(dot_x) <= h_width and abs(dot_y) <= h_height
return proj_x <= h_width and proj_y <= h_height

@property
def view_data(self) -> CameraData:
Expand Down

0 comments on commit a5b946e

Please sign in to comment.