aboutsummaryrefslogtreecommitdiff
path: root/cubie.js
diff options
context:
space:
mode:
Diffstat (limited to 'cubie.js')
-rwxr-xr-xcubie.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/cubie.js b/cubie.js
new file mode 100755
index 0000000..d76f43d
--- /dev/null
+++ b/cubie.js
@@ -0,0 +1,59 @@
1
2"use strict";
3
4Cubie.prototype.explosion = 0.55;
5
6Cubie.prototype.setPos = function(x,y,z)
7{
8 this.mesh.position.set(x * Cubie.prototype.explosion,
9 y * Cubie.prototype.explosion,
10 z * Cubie.prototype.explosion);
11};
12
13Cubie.prototype.updateExplosion = function()
14{
15 this.setPos(this.normPos[0],this.normPos[1],this.normPos[2]);
16};
17
18Cubie.prototype.updatePosition = function(pos)
19{
20 this.mesh.position.set((((Math.floor(pos/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion,
21 ((Math.floor(pos/4) * (-2)) + 1) * Cubie.prototype.explosion,
22 (((Math.floor((pos+1)/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion);
23};
24
25Cubie.prototype.getPos = function()
26{
27 return [this.mesh.position.x, this.mesh.position.y, this.mesh.position.z];
28};
29
30function Cubie(key,pos,colors)
31{
32 this.key = key;
33 this.pos = pos;
34 this.colors = colors;
35
36 var materials = new Array(6);
37 var us = new Array(6);
38 for(var i = 0; i < materials.length; i++)
39 {
40 materials[i] = new THREE.MeshBasicMaterial({ color: 0x000000, side: THREE.FrontSide });
41 }
42
43 for(var i = 0; i < colors.length; i++)
44 {
45 materials[colors[i].key] = new THREE.MeshBasicMaterial({ color: textures[colors[i].value], side: THREE.FrontSide });
46 }
47
48 this.normPos = [0.0,0.0,0.0];
49 this.geometry = new THREE.BoxGeometry(1.0,1.0,1.0);
50 this.material = new THREE.MeshFaceMaterial(materials);
51 this.mesh = new THREE.Mesh(this.geometry,this.material);
52
53 this.normPos = [(((Math.floor(this.pos/2) % 2) * (-2)) + 1),
54 ((Math.floor(this.pos/4) * (-2)) + 1),
55 (((Math.floor((this.pos+1)/2) % 2) * (-2)) + 1)];
56 this.mesh.position.set((((Math.floor(pos/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion,
57 ((Math.floor(pos/4) * (-2)) + 1) * Cubie.prototype.explosion,
58 (((Math.floor((pos+1)/2) % 2) * (-2)) + 1) * Cubie.prototype.explosion);
59}