-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.js
154 lines (139 loc) · 3.02 KB
/
control.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Interaktivnost
var socket = new WebSocket(location.origin.replace(/https?/, 'ws'));
function throttle (cb, limit) {
var w = false;
return function () {
if (!w) {
cb.apply(this, arguments);
w = true;
setTimeout(function () {
w = false;
}, limit);
}
}
}
inputi = {
"fov": {
val: 120,
min: 30,
max: 179
},
"sirina": {
val: 2,
min: 1,
max: 6,
step: 0.1
},
"visina": {
val: 2,
min: 1,
max: 6,
step: 0.1
},
"obj_limit": {
val: 1000,
min: 1,
max: 10000
},
"rotx": {
val: 0,
min: -0.1,
max: 0.1,
step: 0.001
},
"roty": {
val: 0,
min: -0.1,
max: 0.1,
step: 0.001
},
"rotz": {
val: 0,
min: -0.1,
max: 0.1,
step: 0.001
},
"barva_mod": {
val: 0.001,
min: 0.001,
max: 0.18,
step: 0.001
},
"cam_rot_offset": {
val: 0,
min: -10,
max: 10,
step: 0.1
}
};
Object.keys(inputi).map(function (name) {
var valEl = document.getElementById(name + "Val");
if (!valEl) { return; }
var ctlEl = document.getElementById(name + "Ctl");
var params = inputi[name];
var step = params.step;
if (!step) step = 1;
noUiSlider.create(ctlEl, {
start: [params.val],
range: {
min: [params.min],
max: [params.max]
},
step: step
});
ctlEl.noUiSlider.on('slide', throttle(function(val) {
console.log("update!");
var value = val[0];
valEl.innerHTML = value;
socket.send(['adjust', name, value].join(':'));
}, 125));
valEl.innerHTML = ctlEl.noUiSlider.get();
});
callbacks = {
fov: function(val) {
if (typeof camera === 'undefined') return;
FOV = val;
camera.fov = val;
camera.updateProjectionMatrix();
},
sirina: function(val) {
width = parseFloat(val);
},
visina: function (val) {
height = parseFloat(val);
},
rotx: function(val) {
rotacijaX = parseFloat(val);
},
roty: function(val) {
rotacijaY = parseFloat(val);
},
rotz: function(val) {
rotacijaZ = parseFloat(val);
},
obj_limit: function(val) {
obj_limit = parseInt(val);
},
default: function(name, val) {
window[name] = parseFloat(val);
}
};
socket.onmessage = function (msg) {
var parts = msg.data.split(":");
var cmd = parts[0];
switch (cmd) {
case 'adjust':
var name = parts[1];
var val = parts[2];
if (name in callbacks) {
callbacks[name].call(this, val);
} else {
callbacks["default"].call(this, name, val);
}
var valEl = document.getElementById(name + "Val");
if (!valEl) { return; }
var ctlEl = document.getElementById(name + "Ctl");
ctlEl.noUiSlider.set(val, false);
valEl.innerHTML = ctlEl.noUiSlider.get();
}
};