Nekaj korakov naprej v smeri quaternionom
parent
8a2a9e412f
commit
bf287a5414
38
test.js
38
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 = quaternion.clone();
|
||||
//newq.multiplyQuaternions(quaternion, conjugation);
|
||||
//newq.multiply(conjugation);
|
||||
//quaternion.premultiply(conjugation);
|
||||
//quaternion.normalize();
|
||||
//console.log(quaternion);
|
||||
//obj.setRotationFromQuaternion(THREE.Quaternion.multiplyQuaternions(quaternion, conjugation));
|
||||
obj.setRotationFromQuaternion(newq);
|
||||
//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/': [
|
||||
|
|
Loading…
Reference in New Issue