kegel/web/osc_callbacks.js

129 lines
2.9 KiB
JavaScript

const oscCallbacks = {}
// Quaternioni za rotacijo in kalibracijo
var calibrate = true
const qWW = []
const qPrej = []
const qObj = []
const qStart = []
// Parametri rotacije (euler)
const rotacija = []
// Parametri pospeska
const acc = []
for (let i = 0; i < ST_KEGLOV; i++) {
qWW[i] = new THREE.Quaternion()
qPrej[i] = new THREE.Quaternion()
qObj[i] = new THREE.Quaternion()
qStart[i] = new THREE.Quaternion()
rotacija[i] = new THREE.Vector3()
acc[i] = new THREE.Vector3()
}
// rotacije in pospeski keglov
for (let i = 0; i < ST_KEGLOV; i++) {
oscCallbacks[`${PREPEND}${i}/quaternion`] = function (args) {
// Popravimo osi (w x y z po defaultu HMM)
qPrej[i].copy(qWW[i])
const vals = args.map(getVal)
qWW[i].set(vals[0], vals[1], vals[2], vals[3])
}
oscCallbacks[`${PREPEND}${i}/accel`] = function (args) {
[acc[i].x, acc[i].y, acc[i].z] = args.map(getVal)
}
oscCallbacks[`${PREPEND}${i}/gyro`] = function (args) {
[rotacija[i].x, rotacija[i].y, rotacija[i].z] = args.map(getVal)
}
}
// Parametri animacije
oscCallbacks['/ww/calibrate'] = function () {
calibrate = true
}
oscCallbacks['/ww/reload'] = function () {
window.location.reload()
}
oscCallbacks['/ww/zoom'] = args => {
const [kolicina] = args.map(getVal)
spremeniZoom(kolicina)
}
oscCallbacks['/ww/deformiraj'] = args => {
const [kolicina] = args.map(getVal)
spremeniDeformiraj(kolicina)
}
oscCallbacks['/ww/kegli'] = args => {
const [ali] = args.map(getVal)
kegli = ali
}
oscCallbacks['/ww/zogice'] = args => {
const [ali] = args.map(getVal)
zogice = ali
}
// Poslusaj OSC evente
const getVal = function (msg) {
return msg.value;
}
function spremeniDeformiraj (kolicina) {
const noviDeformiraj = deformiraj + (kolicina / 2)
//console.log('deform', noviDeformiraj)
if (noviDeformiraj > 0) {
deformiraj = noviDeformiraj
} else {
deformiraj = 0
}
}
function spremeniZoom (kolicina) {
const noviZum = camera.position.z * (1 + kolicina / 25)
console.log(noviZum)
if ((noviZum > 0.1) && (noviZum < 300)) {
camera.position.z = noviZum
}
}
// Zogice
function zogicaCB(args) {
console.log("MAMOMO MIDI!", args[0].value, args[1].value, args[2].value);
var minus = (IZBRAN == 1) ? -1 : 1;
// kegel.material.color.offsetHSL(minus * args[2].value / 1000, 0, 0);
barvaDodatni.offsetHSL(minus * args[2].value / 1000, 0, 0);
/*
if (Math.random() < 0.5) {
kegel.scale.x *= 2;
} else {
kegel.scale.z *= 2;
}
*/
//kegel.scale.y *= 1 + (args[2] / 100000);
//kegel.scale.z *= 1 + (args[2] / 100000);
if (zogice) {
novaKrogla();
var bId = IZBRAN == 0 ? 2 : 3
console.log('id barve:', bId)
barvnePaleteIdx[bId] = (barvnePaleteIdx[bId] + 1) % barvnePalete[bId].length;
}
napihni = 3
}
oscCallbacks['/midi-in/0'] = zogicaCB
oscCallbacks['/midi-in/1'] = zogicaCB
oscCallbacks['/midi-in/2'] = zogicaCB