"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; }