Nekaj korakov naprej v smeri quaternionom

rob
Jurij Podgoršek 2021-10-09 06:39:14 +02:00
parent 8a2a9e412f
commit bf287a5414
1 changed files with 29 additions and 19 deletions

48
test.js
View File

@ -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/': [