writeRay method
void
writeRay(
- Ray out, {
- required Vector3 origin,
- required Vector3 forward,
- required Vector3 screenRight,
- required Vector3 up,
Writes the active controller ray, falling back to head gaze on release. A touch pad uses a head-relative frontal hemisphere; IMU/driver poses supply a world-space direction. The origin is a 3DoF estimate, not 6DoF.
Implementation
void writeRay(
Ray out, {
required Vector3 origin,
required Vector3 forward,
required Vector3 screenRight,
required Vector3 up,
}) {
out.origin.setFrom(origin);
if (!_pointerActive) {
out.direction.setFrom(forward);
} else if (!_relativePointer) {
out.direction.setFrom(_pointerForward);
} else {
final yaw = _laserX * math.pi / 2;
final pitch = _laserY * 1.25;
final f = math.cos(yaw) * math.cos(pitch);
final r = math.sin(yaw) * math.cos(pitch);
final u = math.sin(pitch);
out.direction.setValues(
forward.x * f + screenRight.x * r + up.x * u,
forward.y * f + screenRight.y * r + up.y * u,
forward.z * f + screenRight.z * r + up.z * u,
);
}
if (_validDirection(out.direction)) out.direction.normalize();
}