Referencna rotacija, kalibracija

kegel
Jurij Podgoršek 2022-11-28 14:28:45 +01:00
parent 726a7ededb
commit ec796bafab
1 changed files with 42 additions and 3 deletions

45
test.js
View File

@ -21,10 +21,12 @@ var accY = 0.000;
var accZ = 0.000;
// Scena, kamera in render
scene = new THREE.Scene;
var scene = new THREE.Scene;
window.scene = scene;
camera = new THREE.PerspectiveCamera(FOV, window.innerWidth / window.innerHeight, 0.1, 2000);
camera.position.z = odmik_kamere;
window.camera = camera;
renderer = new THREE.WebGLRenderer({
alpha: true
@ -160,6 +162,7 @@ window.mat = mat;
var kegel = new THREE.Mesh(geo, mat);
kegel.position.z += 64;
kegel.position.y += 32;
kegel.rotation.z = 180;
skupina.add(kegel);
@ -178,12 +181,16 @@ var qWW = new THREE.Quaternion();
var qObj = new THREE.Quaternion();
var qStart = new THREE.Quaternion();
var reset = false;
var calibrate = true;
var objekti = [kegel];
skupina.rotation.x = -90;
// Zacetna orientacija
camera.position.y = -100
scene.rotation.x = 90;
scene.rotation.z = -270;
skupina.position.z = 64;
skupina.position.y = -34;
@ -197,6 +204,11 @@ function render () {
// Funkcija za animacijo objektov
function objAnim() {
if (kbdPressed.c) {
calibrate = true;
}
// Rotacija kegla
objekti.map(function (obj) {
// Apliciramo rotacijo (po quaternionih - eulerji zajebavajo.)
qObj = qWW.clone();
@ -206,6 +218,15 @@ function objAnim() {
AX.scale.x = accX / 1000;
});
// Kalibracija rotacije kegla
if (calibrate) {
qStart = qWW.clone();
qStart.conjugate();
calibrate = false;
console.log("RESET!");
}
// rotiramo skupino da se vidi
//skupina.rotation.x += 0.003;
//skupina.rotation.y += 0.005;
@ -291,3 +312,21 @@ oscCallbacks['/midi'] = function (args) {
//kegel.scale.z *= 1 + (args[2] / 100000);
};
const kbdPressed = {
a: false,
s: false,
d: false,
f: false,
c: false
};
window.addEventListener('keydown', (e) => {
kbdPressed[e.key] = true;
});
window.addEventListener('keyup', (e) => {
if (e.key in kbdPressed) {
kbdPressed[e.key] = false;
}
});