From 2fd9cc46ff2428bb2fa891f47002e9d3e7585583 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sat, 13 Aug 2022 11:33:30 +0100 Subject: init: import project --- anim.js | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 anim.js (limited to 'anim.js') diff --git a/anim.js b/anim.js new file mode 100755 index 0000000..341c654 --- /dev/null +++ b/anim.js @@ -0,0 +1,122 @@ + +"use strict"; + +var animations = new Map(); + +animations.set("pitchA", + { + name: "pitch", + cubies: [4,5,1,0], + vec: new THREE.Vector3(1.0,0.0,0.0), + dir: 1, + func: function(x){ return Math.sin(x); }, + max_rotation: Math.PI/2, + }); + +animations.set("pitchB", + { + name: "pitch", + cubies: [7,6,2,3], + vec: new THREE.Vector3(1.0,0.0,0.0), + dir: 1, + func: function(x){ return Math.sin(x); }, + max_rotation: Math.PI/2, + }); + +animations.set("rollA", + { + name: "roll", + cubies: [3,7,4,0], + vec: new THREE.Vector3(0.0,0.0,1.0), + dir: 1, + func: function(x){ return Math.sin(x); }, + max_rotation: Math.PI/2, + }); + +animations.set("rollB", + { + name: "roll", + cubies: [6,5,1,2], + vec: new THREE.Vector3(0.0,0.0,1.0), + dir: 1, + func: function(x){ return Math.sin(x); }, + max_rotation: Math.PI/2, + }); + +animations.set("yawA", + { + name: "yaw", + cubies: [0,1,2,3], + vec: new THREE.Vector3(0.0,1.0,0.0), + dir: 1, + func: function(x){ return Math.sin(x); }, + max_rotation: Math.PI/2, + }); + +animations.set("yawB", + { + name: "yaw", + cubies: [4,5,6,7], + vec: new THREE.Vector3(0.0,1.0,0.0), + dir: 1, + func: function(x){ return Math.sin(x); }, + max_rotation: Math.PI/2, + }); + +function startAnimation(a,d) +{ + if(!animation) + { + current_animation = animations.get(a); + current_animation.dir = d; + + x = 0.0; + animation = true; + face = new THREE.Object3D(); + + var temp = new THREE.Vector3(); + + q = new THREE.Quaternion(); + q_init = new THREE.Quaternion(); + temp.copy(current_animation.vec); + q_init.setFromAxisAngle(temp.multiplyScalar(current_animation.dir).normalize(),0.0); + q_end = new THREE.Quaternion(); + temp.copy(current_animation.vec); + q_end.setFromAxisAngle(temp.multiplyScalar(current_animation.dir).normalize(),current_animation.dir*current_animation.max_rotation); + + for(var i = 0; i < 4; i++) + { + scene.remove(cubies.get(current_animation.cubies[i]).mesh); + face.add(cubies.get(current_animation.cubies[i]).mesh); + } + + scene.add(face); + } +} + +Animator.prototype.goOn = function() +{ + startAnimation(this.moves[this.index].move, this.moves[this.index].dir); + if(! scramb) + { + info.innerHTML = "N. of moves: " + (this.index+1); + } + if(++this.index == this.moves.length) + { + animator = null; + removeCounter = 5.0; + if(scramb) + { + scramb = false; + } + } +}; + +function Animator(moves) +{ + this.index = 0; + this.moves = moves; +} + + + -- cgit v1.2.3