also consider distance from plane in AudioArea volume

This commit is contained in:
Tomáš Mládek 2021-01-11 20:20:55 +01:00
parent 97b4aae360
commit eac0c6d8c7

View file

@ -22,6 +22,11 @@ export default defineComponent({
setup(props) {
const audio = ref<HTMLAudioElement | null>(null);
const MIN_SCALE = 0.02;
const MIN_VOLUME_MULTIPLIER = 0.25;
const vol_x = (1 - MIN_VOLUME_MULTIPLIER) / (1 - MIN_SCALE);
const vol_b = 1 - vol_x;
const onBBoxChange = () => {
const x = props.bbox.x + props.bbox.w / 2;
const y = props.bbox.y + props.bbox.h / 2;
@ -29,7 +34,8 @@ export default defineComponent({
if (distance < props.definition.radius) {
audio.value!.play();
audio.value!.volume = (props.definition.radius - distance) / props.definition.radius;
const volume = (props.definition.radius - distance) / props.definition.radius;
audio.value!.volume = volume * (props.bbox.z < 1 ? (props.bbox.z * vol_x + vol_b) : 1);
} else {
audio.value!.pause();
}