-
Notifications
You must be signed in to change notification settings - Fork 1
/
space.py
40 lines (36 loc) · 1.49 KB
/
space.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import math
import random
from vector import Vector2d, DirectionalVector
from bezier import make_bezier
class Space:
LISTENER_POSITION = Vector2d(0, 0)
ROOM_RADIUS = 30
NEAREST_DISTANCE_TO_LISTENER = 0.1
MIN_CURVATURE = 50.0 / 360 * 2*math.pi
MAX_CURVATURE = 80.0 / 360 * 2*math.pi
TRAJECTORY_PRECISION = 300
def new_peer(self):
return Peer(self)
def parabolic_trajectory_to_listener(self, remote_angle):
remote = DirectionalVector(remote_angle, self.ROOM_RADIUS)
midpoint_angle = remote_angle + random.choice([1,-1]) * \
random.uniform(self.MIN_CURVATURE, self.MAX_CURVATURE)
midpoint = DirectionalVector(midpoint_angle, self.ROOM_RADIUS/2)
local = self.LISTENER_POSITION + \
DirectionalVector(remote_angle, self.NEAREST_DISTANCE_TO_LISTENER)
control_points = [(remote.x, remote.y),
(midpoint.x, midpoint.y),
(local.x, local.y)]
bezier = make_bezier(control_points)
return bezier(self.TRAJECTORY_PRECISION)
# to test simplier movement along one dimension:
# control_points = [(0, -20),
# (0, 2)]
# bezier = make_bezier(control_points)
# return bezier(self.TRAJECTORY_PRECISION)
class Peer:
def __init__(self, space):
self.space = space
self.bearing = random.uniform(0.0, 2*math.pi)
#self.pan = math.cos(self.bearing)
self.pan = random.choice([-1.0, 1.0])