def __init__(
self, colour, position, intensity=1.0, radius_limits=None,
- angle_limits=None):
+ direction=None, spread=None):
self.colour = colour
self.on = True
self.intensity = intensity
self.body.light = self
self.ray_manager = self.RAY_MANAGER(
self.body, position, ray_filter=LIGHT_FILTER,
- radius_limits=radius_limits, angle_limits=angle_limits)
+ radius_limits=radius_limits, direction=direction, spread=spread)
self.fitting = pymunk.Circle(
self.body, self.FITTING_RADIUS, self.ray_manager.position)
self.fitting.filter = FITTINGS_FILTER
class RayPolyManager(object):
def __init__(
- self, body, position, ray_filter, radius_limits, angle_limits):
+ self, body, position, ray_filter, radius_limits, direction,
+ spread):
self._body = body # light's body
self._position = pymunk.Vec2d(position) # light's position
self._ray_filter = ray_filter # light filter
self._rays = [] # list of RayPolys
self._start = None # normal vector in direction of start angle limit
self._end = None # normal vector in direction of end angle limit
- self._set_angle_limits(angle_limits)
+ self._set_angle_limits(direction, spread)
self._max_radius = None # maximum radius in pixels
self._min_radius = None # minimum radius in pixels
self._set_radius_limits(radius_limits)
else:
self._max_radius = radius_limits[1]
+ def rotatable(self):
+ return self._start is not None
+
def rotate_degrees(self, degrees):
self._start.rotate_degrees(degrees)
self._end.rotate_degrees(degrees)
self._poly_cache = None
- def _set_angle_limits(self, angle_limits):
- if angle_limits is None:
+ def _set_angle_limits(self, direction, spread):
+ if direction is None or spread is None:
self._start = None
self._end = None
else:
- self._start = pymunk.Vec2d(1, 0).rotated(
- to_pymunk_radians(angle_limits[0]))
- self._end = pymunk.Vec2d(1, 0).rotated(
- to_pymunk_radians(angle_limits[1]))
+ n = pymunk.Vec2d(1, 0)
+ self._start = n.rotated_degrees(-spread/2.)
+ self._end = n.rotated_degrees(spread/2.)
self._poly_cache = None
def polys(self):