-
Notifications
You must be signed in to change notification settings - Fork 1
/
clearer.js
123 lines (115 loc) · 3.88 KB
/
clearer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* clearer.js
*
* COMP 3490 Final Project
*
* Created by:
* Nicholas Josephson - 7791547
* Gershon Reydman - 7763541
* Eric Kulchycki - 7767961
*/
var clearer;
var setter;
var clearerPlane;
var droppingState = false;
var clearingState = false;
var movingUpState = false;
var moveBackState = false;
var setterDown = false;
var setterUp = false;
var cleanDone = false;
var downVector = new THREE.Vector3(0, -0.7, 0); // amount to move per frame
var backVector = new THREE.Vector3(0.7, 0, 0); // amount to move per frame
var upVector = new THREE.Vector3(0, 0.9, 0); // amount to move per frame
var forwardVector = new THREE.Vector3(-0.7, 0, 0); // amount to move per frame
var setDownVector = new THREE.Vector3(0, -0.6, 0); // amount to move per frame
var setUpVector = new THREE.Vector3(0, 0.6, 0); // amount to move per frame;
var startCleaner = false;
function animateCleaner() {
if (startCleaner) {
scene.remove(clearerPlane);
startCleaner = false;
cleanDone = false;
droppingState = true;
}
if (setterDown) {
setter.position.add(setDownVector); // add to position
setter.__dirtyPosition = true;
if (setter.position.y < 50) {
resetPins();
setterDown = false;
setterUp = true;
}
} else if (setterUp) {
setter.position.add(setUpVector); // add to position
setter.__dirtyPosition = true;
if (setter.position.y >= 90) {
setterUp = false;
cleanDone = true;
}
} else {
var direction;
if (droppingState) {
direction = downVector;
if (clearer.position.y <= 20) {
droppingState = false;
clearingState = true;
}
} else if (clearingState) {
direction = backVector;
if (clearer.position.x >= 30) {
clearingState = false;
movingUpState = true;
}
} else if (movingUpState) {
direction = upVector;
if (clearer.position.y >= 105) {
movingUpState = false;
moveBackState = true;
}
} else if (moveBackState) {
direction = forwardVector;
if (clearer.position.x <= -49) {
scene.add(clearerPlane);
moveBackState = false;
setterDown = true;
}
}
clearer.position.add(direction); // add to position
}
clearer.setLinearVelocity(new THREE.Vector3(0, 0, 0));
clearer.setAngularVelocity(new THREE.Vector3(0, 0, 0));
clearer.rotation.set(0, 0, 0);
clearer.__dirtyPosition = true;
clearer.__dirtyRotation = true;
}
function loadClearer() {
var clearerWidth = 8;
var clearerHeight = 30;
var clearerLength = 100;
var x = -50;
var z = 0;
var y = 105;
var clearerMaterial = new THREE.MeshPhongMaterial({color: 0x212428});
var clearerGeometry = new THREE.BoxGeometry(clearerWidth, clearerHeight, clearerLength);
clearer = new Physijs.ConvexMesh(clearerGeometry, clearerMaterial, 1000);
clearer.position.x = x;
clearer.position.y = y;
clearer.position.z = z;
clearer.setLinearVelocity(new THREE.Vector3(0, 0, 0));
clearer.setAngularVelocity(new THREE.Vector3(0, 0, 0));
scene.add(clearer);
var clearerPlaneGeometry = new THREE.BoxGeometry(clearerWidth, 0.5, clearerLength);
clearerPlane = new Physijs.ConvexMesh(clearerPlaneGeometry, clearerMaterial, 0);
clearerPlane.position.x = x;
clearerPlane.position.y = 90;
clearerPlane.position.z = z;
scene.add(clearerPlane);
}
function loadSetter() {
var setterMaterial = new THREE.MeshLambertMaterial({color: 0x212428});
setter = new THREE.Mesh(new THREE.BoxGeometry(60, 40, 70), setterMaterial);
setter.position.x = -15;
setter.position.y = 90;
setter.position.z = 0;
scene.add(setter);
}