"""Operator camera only. No reference to the sensor, articulation or policy. Cumulative inputs survive coalesced Core/Worker polls. Duplicate sequences have no effect; switching views starts a new gesture session. All motion is bounded. """ import math def axes(yaw, pitch): c, s, cp, sp = math.cos(yaw), math.sin(yaw), math.cos(pitch), math.sin(pitch) return (c * cp, s * cp, sp), (s, -c, 0), (-c * sp, -s * sp, cp) class ObserverCamera: def __init__(self): self.mode = None self.session = None self.sequence = -1 self.totals = [0.0] * 6 self.yaw = 0.0 self.pitch = -0.4 self.distance = 3.0 self.offset = [0.0, 0.0, 0.0] self.eye = [0.0, 0.0, 0.0] self.target = [1.0, 0.0, 0.0] def update(self, mode, body, heading, sensor_eye, navigation=None): if mode != self.mode: # Free flight starts exactly where the operator was looking. if self.mode is None or mode != "overview": self.yaw = 0.0 if mode != "overview" else heading self.pitch = 0.0 if mode == "camera" else -0.4 self.offset = [0.0, 0.0, 0.0] self.distance = 3.0 else: d = [b - a for a, b in zip(self.eye, self.target, strict=True)] self.yaw = math.atan2(d[1], d[0]) self.pitch = math.atan2(d[2], math.hypot(d[0], d[1])) self.mode = mode self.session, self.sequence, self.totals = None, -1, [0.0] * 6 if navigation: if self.session != navigation["session"]: self.session, self.sequence, self.totals = navigation["session"], -1, [0.0] * 6 if navigation["sequence"] > self.sequence: values = [*navigation["orbit"], *navigation["move"], navigation["zoom"]] dyaw, dpitch, right, forward, up, zoom = [ a - b for a, b in zip(values, self.totals, strict=True) ] self.totals, self.sequence = values, navigation["sequence"] self.yaw += dyaw self.pitch = max(-1.5, min(1.5, self.pitch + dpitch)) f, r, u = axes(self.yaw + (heading if mode != "overview" else 0), self.pitch) if mode == "overview": self.eye = [ max( -10000, min( 10000, v + right * r[i] + forward * f[i] + up * u[i] - zoom * f[i] * max(1, self.distance), ), ) for i, v in enumerate(self.eye) ] elif mode == "follow": self.distance = max( 0.5, min(200, self.distance * math.exp(max(-3, min(3, zoom)))) ) self.offset = [ max(-100, min(100, v + right * r[i] + up * u[i])) for i, v in enumerate(self.offset) ] f, _, up = axes(self.yaw + (heading if mode != "overview" else 0), self.pitch) if mode == "follow": self.target = [body[i] + self.offset[i] + (0.25 if i == 2 else 0) for i in range(3)] self.eye = [self.target[i] - f[i] * self.distance for i in range(3)] else: if mode == "camera": self.eye = list(sensor_eye) self.target = [self.eye[i] + f[i] for i in range(3)] return self.eye, self.target, up class SmoothView: """Render-rate easing for coalesced operator input; never used by sensors.""" def __init__(self): self.mode = self.pose = self.last = None def update(self, mode, pose, now): if self.pose is None or mode != self.mode: self.pose = [list(v) for v in pose] else: alpha = 1 - math.exp(-max(0, now - self.last) / 0.08) self.pose = [ [a + (b - a) * alpha for a, b in zip(old, new, strict=True)] for old, new in zip(self.pose, pose, strict=True) ] self.mode, self.last = mode, now return self.pose