From bf287a5414dd1b30465e0a421f014371ef661635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Podgor=C5=A1ek?= Date: Sat, 9 Oct 2021 06:39:14 +0200 Subject: [PATCH] Nekaj korakov naprej v smeri quaternionom --- test.js | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/test.js b/test.js index 7a9a75b..f09678c 100644 --- a/test.js +++ b/test.js @@ -42,9 +42,11 @@ var mat = new THREE.MeshBasicMaterial({ color: 0xff00ff, wireframe: true }); -// quaternion = new THREE.Quaternion(); -var quaternion = null; -var conjugation = null; + +var start = false; +var qWW = new THREE.Quaternion(); +var qObj = new THREE.Quaternion(-1, 0, 0, 0); +var qStart = null; var cube = new THREE.Mesh(geo, mat); scene.add(cube); // @@ -54,21 +56,35 @@ var objekti = [cube]; function render () { requestAnimationFrame(render); renderer.render(scene, camera); + + if (start) { objAnim(); + } else { + if (qWW) { + qStart = qWW.clone(); + qStart.inverse(); + start = true; + } + } }; // Funkcija za animacijo objektov function objAnim() { objekti.map(function (obj) { - if (conjugation) { - //obj.setRotationFromEuler(new THREE.Euler(rotacijaY, -rotacijaX, rotacijaZ, 'XYZ')); - newq = quaternion.clone(); - //newq.multiplyQuaternions(quaternion, conjugation); - //newq.multiply(conjugation); - //obj.setRotationFromQuaternion(THREE.Quaternion.multiplyQuaternions(quaternion, conjugation)); - obj.setRotationFromQuaternion(newq); - console.log(obj.rotation.x); - } + //obj.setRotationFromEuler(new THREE.Euler(rotacijaY, -rotacijaX, rotacijaZ, 'XYZ')); + //newq = quaternion.clone(); + //newq.multiplyQuaternions(quaternion, conjugation); + //newq.multiply(conjugation); + //quaternion.premultiply(conjugation); + //quaternion.normalize(); + //console.log(quaternion); + //obj.setRotationFromQuaternion(THREE.Quaternion.multiplyQuaternions(quaternion, conjugation)); + //quaterion = new THREE.Quaternion(-1, 0, 0, 0); + //qObj = qWW.clone(); + //qObj.multiply(qStart); + obj.setRotationFromQuaternion(qWW); + //obj.setRotationFromQuaternion(conjugation); + console.log(obj.rotation.x); }); }; @@ -106,13 +122,7 @@ oscCallbacks = { ], '/quaternion/': [ function (args) { - if (quaternion) { - [quaternion.w, quaternion.x, quaternion.y, quaternion.z] = args.map(getVal); - } else { - quaternion = new THREE.Quaternion(args[0], args[1], args[2], args[3]); - conjugation = quaternion.clone(); - conjugation.conjugate(); - } + [qWW.w, qWW.x, qWW.y, qWW.z] = args.map(getVal); } ], '/gyro/': [