Nekaj korakov naprej v smeri quaternionom
parent
8a2a9e412f
commit
bf287a5414
48
test.js
48
test.js
|
@ -42,9 +42,11 @@ var mat = new THREE.MeshBasicMaterial({
|
||||||
color: 0xff00ff,
|
color: 0xff00ff,
|
||||||
wireframe: true
|
wireframe: true
|
||||||
});
|
});
|
||||||
// quaternion = new THREE.Quaternion();
|
|
||||||
var quaternion = null;
|
var start = false;
|
||||||
var conjugation = null;
|
var qWW = new THREE.Quaternion();
|
||||||
|
var qObj = new THREE.Quaternion(-1, 0, 0, 0);
|
||||||
|
var qStart = null;
|
||||||
|
|
||||||
var cube = new THREE.Mesh(geo, mat);
|
var cube = new THREE.Mesh(geo, mat);
|
||||||
scene.add(cube); //
|
scene.add(cube); //
|
||||||
|
@ -54,21 +56,35 @@ var objekti = [cube];
|
||||||
function render () {
|
function render () {
|
||||||
requestAnimationFrame(render);
|
requestAnimationFrame(render);
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
|
|
||||||
|
if (start) {
|
||||||
objAnim();
|
objAnim();
|
||||||
|
} else {
|
||||||
|
if (qWW) {
|
||||||
|
qStart = qWW.clone();
|
||||||
|
qStart.inverse();
|
||||||
|
start = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Funkcija za animacijo objektov
|
// Funkcija za animacijo objektov
|
||||||
function objAnim() {
|
function objAnim() {
|
||||||
objekti.map(function (obj) {
|
objekti.map(function (obj) {
|
||||||
if (conjugation) {
|
//obj.setRotationFromEuler(new THREE.Euler(rotacijaY, -rotacijaX, rotacijaZ, 'XYZ'));
|
||||||
//obj.setRotationFromEuler(new THREE.Euler(rotacijaY, -rotacijaX, rotacijaZ, 'XYZ'));
|
//newq = quaternion.clone();
|
||||||
newq = quaternion.clone();
|
//newq.multiplyQuaternions(quaternion, conjugation);
|
||||||
//newq.multiplyQuaternions(quaternion, conjugation);
|
//newq.multiply(conjugation);
|
||||||
//newq.multiply(conjugation);
|
//quaternion.premultiply(conjugation);
|
||||||
//obj.setRotationFromQuaternion(THREE.Quaternion.multiplyQuaternions(quaternion, conjugation));
|
//quaternion.normalize();
|
||||||
obj.setRotationFromQuaternion(newq);
|
//console.log(quaternion);
|
||||||
console.log(obj.rotation.x);
|
//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/': [
|
'/quaternion/': [
|
||||||
function (args) {
|
function (args) {
|
||||||
if (quaternion) {
|
[qWW.w, qWW.x, qWW.y, qWW.z] = args.map(getVal);
|
||||||
[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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'/gyro/': [
|
'/gyro/': [
|
||||||
|
|
Loading…
Reference in New Issue