vec quaternionov pa stvari

rob
Jurij Podgoršek 2022-01-01 22:10:59 +01:00
parent 02ec213e1d
commit 775dde8482
3 changed files with 25 additions and 12 deletions

28
anim.js
View File

@ -54,6 +54,7 @@ var kameraZ = 0;
// Quaternioni za rotacijo in kalibracijo // Quaternioni za rotacijo in kalibracijo
var qWW = new THREE.Quaternion(-1, 0, 0, 0); var qWW = new THREE.Quaternion(-1, 0, 0, 0);
var qWWo = 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 qObj = new THREE.Quaternion(-1, 0, 0, 0);
var qOld = 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); var qStart = new THREE.Quaternion(-1, 0, 0, 0);
@ -119,8 +120,17 @@ function modulirajParametre() {
} }
// Rotiranje manualno (z rocnimi gibi "iz sredine") // 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]) { 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 // Karo
var vertices = new Float32Array([ 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 offset, 0, 0, 0, -offset, 0
]); ]);
// 3d objekt (3 komponente na vertex) // 3d objekt (3 komponente na vertex)
@ -231,13 +241,13 @@ oscCallbacks = {
], ],
'/quaternion/': [ '/quaternion/': [
function (args) { function (args) {
console.log(1);
// Popravimo osi (w x y z po defaultu HMM) // Popravimo osi (w x y z po defaultu HMM)
qWWo = qWW.clone(); qWWo = qWW.clone()
[qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal); [qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal)
// Dve sta obratno :) // Dve sta obratno :)
qWW.x *= -1; qWW.x *= -1
qWW.z *= -1; qWW.z *= -1
qWWd = qWWo.premultiply(qWW)
} }
], ],
/* /*

View File

@ -54,7 +54,9 @@ function openSerial() {
// Arduino OSC gre v web // Arduino OSC gre v web
scon.on('osc', msg => { scon.on('osc', msg => {
// Debug incoming osc // 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) sendAll(msg, null, null, osclients)
}) })

View File

@ -55,7 +55,7 @@ skupina.add(cube);
// Za pospeskomer - os X // Za pospeskomer - os X
var gAX = new THREE.CylinderGeometry(10, 10, 10, 16); 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); var AX = new THREE.Mesh(gAX, mAX);
skupina.add(AX); skupina.add(AX);
@ -90,7 +90,7 @@ function objAnim() {
qObj.multiply(qStart); qObj.multiply(qStart);
obj.setRotationFromQuaternion(qObj); obj.setRotationFromQuaternion(qObj);
AX.scale.x = accX; AX.scale.x = accX / 1000;
console.log(accX); console.log(accX);
}); });
@ -147,6 +147,7 @@ oscCallbacks = {
// Popravimo osi (w x y z po defaultu HMM) // Popravimo osi (w x y z po defaultu HMM)
[qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal); [qWW.w, qWW.z, qWW.x, qWW.y] = args.map(getVal);
// Dve sta obratno :) // Dve sta obratno :)
// Ali pac? Vcasih da, drugic ne. Zanimivo.
qWW.x *= -1; qWW.x *= -1;
qWW.z *= -1; qWW.z *= -1;
} }