2017-09-08 09:24:16 -07:00
|
|
|
//
|
|
|
|
// soundMaker.js
|
|
|
|
//--------------------
|
|
|
|
// Provides env sound object, such as crowd for figure 8
|
|
|
|
// by RHY3756547
|
|
|
|
//
|
|
|
|
|
|
|
|
//0008
|
|
|
|
|
|
|
|
window.ObjSoundMaker = function(obji, scene) {
|
|
|
|
var obji = obji;
|
|
|
|
|
|
|
|
var t = this;
|
|
|
|
|
|
|
|
t.pos = vec3.clone(obji.pos);
|
|
|
|
|
|
|
|
t.soundProps = {};
|
|
|
|
t.sndUpdate = sndUpdate;
|
|
|
|
t.requireRes = requireRes;
|
|
|
|
t.provideRes = provideRes;
|
|
|
|
t.update = update;
|
|
|
|
t.draw = draw;
|
|
|
|
|
|
|
|
var mat = mat4.create();
|
|
|
|
var frame = 0;
|
|
|
|
|
|
|
|
var sound = null;
|
|
|
|
var sN = 0;
|
|
|
|
var threshold = 0.2;
|
|
|
|
var gain = 1;
|
|
|
|
switch (obji.ID) {
|
|
|
|
case 0x0008:
|
|
|
|
sN = 259;
|
|
|
|
gain = 2;
|
|
|
|
threshold = 0.2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
function draw(view, pMatrix) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function sndUpdate(view) {
|
2019-06-09 15:50:55 -07:00
|
|
|
//t.soundProps.pos = vec3.transformMat4([], t.pos, view);
|
|
|
|
//t.soundProps.pos = [0, 0, Math.sqrt(vec3.dot(t.soundProps.pos, t.soundProps.pos))]
|
2017-09-08 09:24:16 -07:00
|
|
|
//if (t.soundProps.lastPos != null) t.soundProps.vel = vec3.sub([], t.soundProps.pos, t.soundProps.lastPos);
|
|
|
|
//else t.soundProps.vel = [0, 0, 0];
|
|
|
|
//t.soundProps.lastPos = t.soundProps.pos;
|
|
|
|
|
2019-06-09 15:50:55 -07:00
|
|
|
t.soundProps.pos = t.pos; //todo: when reintroducing doppler, disable it on this source
|
|
|
|
|
|
|
|
t.soundProps.refDistance = 1024;
|
2017-09-08 09:24:16 -07:00
|
|
|
//t.soundProps.rolloffFactor = 1;
|
|
|
|
|
2019-06-09 15:50:55 -07:00
|
|
|
var relPos = vec3.transformMat4([], t.pos, view);
|
|
|
|
|
|
|
|
var calcVol = (t.soundProps.refDistance / (t.soundProps.refDistance + t.soundProps.rolloffFactor * (relPos[2] - t.soundProps.refDistance)));
|
2017-09-08 09:24:16 -07:00
|
|
|
|
|
|
|
if (calcVol<threshold) {
|
|
|
|
if (sound != null) {
|
|
|
|
nitroAudio.instaKill(sound);
|
|
|
|
sound = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sound == null) {
|
|
|
|
sound = nitroAudio.playSound(sN, {}, 0, t);
|
|
|
|
sound.gainN.gain.value = gain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function requireRes() {
|
|
|
|
return {mdl: []};
|
|
|
|
}
|
|
|
|
|
|
|
|
function provideRes(r) { }
|
|
|
|
|
|
|
|
}
|