diff --git a/anim.js b/anim.js index b1cf295..439cfb6 100644 --- a/anim.js +++ b/anim.js @@ -54,6 +54,7 @@ var kameraZ = 0; // Quaternioni za rotacijo in kalibracijo var qWW = new THREE.Quaternion(-1, 0, 0, 0); var qWWo = new THREE.Quaternion(-1, 0, 0, 0); +var qWWd = new THREE.Quaternion(-1, 0, 0, 0); var qObj = new THREE.Quaternion(-1, 0, 0, 0); var qOld = new THREE.Quaternion(-1, 0, 0, 0); var qStart = new THREE.Quaternion(-1, 0, 0, 0); @@ -119,8 +120,17 @@ function modulirajParametre() { } // Rotiranje manualno (z rocnimi gibi "iz sredine") + if (keysPressed[3]) { + var k = objekti.slice(-1)[0]; + k.rotation.x += qWWd.x; + k.rotation.y += qWWd.y; + k.rotation.z += qWWd.z; + } if (keysPressed[2]) { - objekti[0].rotation.apply + console.log(qWWd.x, qWWd.y, qWWd.z); + drotacijaX += qWWd.x; + drotacijaY += qWWd.y; + drotacijaZ += qWWd.z; } } @@ -154,10 +164,10 @@ function addObj(w, h) { // Karo var vertices = new Float32Array([ - -offset, 0, 0, 0, offset, 0, + -offset, 0, 0, 0, offset, 0, -offset, 0, 0, 0, -offset, 0, - offset, 0, 0, 0, offset, 0, - offset, 0, 0, 0, -offset, 0 + offset, 0, 0, 0, offset, 0, + offset, 0, 0, 0, -offset, 0 ]); // 3d objekt (3 komponente na vertex) @@ -231,13 +241,13 @@ oscCallbacks = { ], '/quaternion/': [ function (args) { - console.log(1); // Popravimo osi (w x y z po defaultu HMM) - qWWo = qWW.clone(); - [qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal); + qWWo = qWW.clone() + [qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal) // Dve sta obratno :) - qWW.x *= -1; - qWW.z *= -1; + qWW.x *= -1 + qWW.z *= -1 + qWWd = qWWo.premultiply(qWW) } ], /* diff --git a/server.js b/server.js index 3a540ac..ba8d638 100644 --- a/server.js +++ b/server.js @@ -54,7 +54,9 @@ function openSerial() { // Arduino OSC gre v web scon.on('osc', msg => { // Debug incoming osc - //console.log('tty osc', msg.address, ...msg.args.map(val => Math.round(val * 1000) / 1000)) + if (msg.address.indexOf('quaternion') > -1) { + console.log('tty osc', msg.address, ...msg.args.map(val => Math.round(val * 1000) / 1000)) + } sendAll(msg, null, null, osclients) }) diff --git a/test.js b/test.js index f0fff80..fe36e9c 100644 --- a/test.js +++ b/test.js @@ -55,7 +55,7 @@ skupina.add(cube); // Za pospeskomer - os X var gAX = new THREE.CylinderGeometry(10, 10, 10, 16); -var mAX = new THREE.MeshBasicMaterial({ color: 0xff0000 }); +var mAX = new THREE.MeshBasicMaterial({ color: 0xff000055 }); var AX = new THREE.Mesh(gAX, mAX); skupina.add(AX); @@ -90,7 +90,7 @@ function objAnim() { qObj.multiply(qStart); obj.setRotationFromQuaternion(qObj); - AX.scale.x = accX; + AX.scale.x = accX / 1000; console.log(accX); }); @@ -147,6 +147,7 @@ oscCallbacks = { // Popravimo osi (w x y z po defaultu HMM) [qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal); // Dve sta obratno :) + // Ali pac? Vcasih da, drugic ne. Zanimivo. qWW.x *= -1; qWW.z *= -1; }