aboutsummaryrefslogtreecommitdiff
path: root/anim.js
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2022-08-13 11:33:30 +0100
committerFederico Igne <git@federicoigne.com>2022-08-13 11:33:30 +0100
commit2fd9cc46ff2428bb2fa891f47002e9d3e7585583 (patch)
tree81b8b0122a00e9cd06d5f55091a3b087e430ddb0 /anim.js
downloadrubik-2fd9cc46ff2428bb2fa891f47002e9d3e7585583.tar.gz
rubik-2fd9cc46ff2428bb2fa891f47002e9d3e7585583.zip
init: import project
Diffstat (limited to 'anim.js')
-rwxr-xr-xanim.js122
1 files changed, 122 insertions, 0 deletions
diff --git a/anim.js b/anim.js
new file mode 100755
index 0000000..341c654
--- /dev/null
+++ b/anim.js
@@ -0,0 +1,122 @@
1
2"use strict";
3
4var animations = new Map();
5
6animations.set("pitchA",
7 {
8 name: "pitch",
9 cubies: [4,5,1,0],
10 vec: new THREE.Vector3(1.0,0.0,0.0),
11 dir: 1,
12 func: function(x){ return Math.sin(x); },
13 max_rotation: Math.PI/2,
14 });
15
16animations.set("pitchB",
17 {
18 name: "pitch",
19 cubies: [7,6,2,3],
20 vec: new THREE.Vector3(1.0,0.0,0.0),
21 dir: 1,
22 func: function(x){ return Math.sin(x); },
23 max_rotation: Math.PI/2,
24 });
25
26animations.set("rollA",
27 {
28 name: "roll",
29 cubies: [3,7,4,0],
30 vec: new THREE.Vector3(0.0,0.0,1.0),
31 dir: 1,
32 func: function(x){ return Math.sin(x); },
33 max_rotation: Math.PI/2,
34 });
35
36animations.set("rollB",
37 {
38 name: "roll",
39 cubies: [6,5,1,2],
40 vec: new THREE.Vector3(0.0,0.0,1.0),
41 dir: 1,
42 func: function(x){ return Math.sin(x); },
43 max_rotation: Math.PI/2,
44 });
45
46animations.set("yawA",
47 {
48 name: "yaw",
49 cubies: [0,1,2,3],
50 vec: new THREE.Vector3(0.0,1.0,0.0),
51 dir: 1,
52 func: function(x){ return Math.sin(x); },
53 max_rotation: Math.PI/2,
54 });
55
56animations.set("yawB",
57 {
58 name: "yaw",
59 cubies: [4,5,6,7],
60 vec: new THREE.Vector3(0.0,1.0,0.0),
61 dir: 1,
62 func: function(x){ return Math.sin(x); },
63 max_rotation: Math.PI/2,
64 });
65
66function startAnimation(a,d)
67{
68 if(!animation)
69 {
70 current_animation = animations.get(a);
71 current_animation.dir = d;
72
73 x = 0.0;
74 animation = true;
75 face = new THREE.Object3D();
76
77 var temp = new THREE.Vector3();
78
79 q = new THREE.Quaternion();
80 q_init = new THREE.Quaternion();
81 temp.copy(current_animation.vec);
82 q_init.setFromAxisAngle(temp.multiplyScalar(current_animation.dir).normalize(),0.0);
83 q_end = new THREE.Quaternion();
84 temp.copy(current_animation.vec);
85 q_end.setFromAxisAngle(temp.multiplyScalar(current_animation.dir).normalize(),current_animation.dir*current_animation.max_rotation);
86
87 for(var i = 0; i < 4; i++)
88 {
89 scene.remove(cubies.get(current_animation.cubies[i]).mesh);
90 face.add(cubies.get(current_animation.cubies[i]).mesh);
91 }
92
93 scene.add(face);
94 }
95}
96
97Animator.prototype.goOn = function()
98{
99 startAnimation(this.moves[this.index].move, this.moves[this.index].dir);
100 if(! scramb)
101 {
102 info.innerHTML = "N. of moves: " + (this.index+1);
103 }
104 if(++this.index == this.moves.length)
105 {
106 animator = null;
107 removeCounter = 5.0;
108 if(scramb)
109 {
110 scramb = false;
111 }
112 }
113};
114
115function Animator(moves)
116{
117 this.index = 0;
118 this.moves = moves;
119}
120
121
122