-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
196 lines (183 loc) · 6.42 KB
/
index.html
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<html>
<head>
<style>
div {
display: none;
}
body {
background: #161616;
width: 100%;
position: absolute;
padding: 0;
margin: 0;
}
h1 {
text-align: center;
margin-right: auto;
margin-left: auto;
top: 100px;
left: 45%;
position: absolute;
color: rgba(255, 255, 255, .25);
z-index: 10;
font-family: 'Roboto', sans-serif;
font-weight: 100;
font-size: 3em;
}
canvas {
position: relative;
-webkit-filter: contrast(2) brightness(1.5) blur(.5px);
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>hologram</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,100' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="./oflow.js"></script>
<script type="text/javascript" src="./colors.js"></script>
<script type="text/javascript" src="./bower_components/three.js/three.js"></script>
<script type="text/javascript" src="./OrbitControls.js"></script>
<script type="text/javascript" src="./bower_components/tracking.js/build/tracking.js"></script>
<script type="text/javascript" src="./bower_components/tracking.js/build/data/face-min.js"></script>
<script type="text/javascript" src="./headtrackr.js"></script>
<script type="text/javascript">
if ( window.innerWidth === 0 ) { window.innerWidth = parent.innerWidth; window.innerHeight = parent.innerHeight; }
function main() {
var zoneSize = 8,
videoElement = document.getElementById('videoOut'),
videoWidth = videoElement.videoWidth,
videoHeight = videoElement.videoHeight;
webCamFlow = new oflow.WebCamFlow(videoElement, zoneSize),
canvas = document.getElementById('scene'),
sceneCtx = canvas.getContext('2d'),
sceneWidth = canvas.width,
sceneHeight = canvas.height,
energy_field = [];
var scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 95, window.innerWidth / window.innerHeight, 0.1, 1000 );
renderer = new THREE.WebGLRenderer({antialias: true});
hydrogen_spectrum = [0x2EFAEE, 0x567794, 0x01E7E1, 0xFBED7E, 0xC71911];
h_mats = [];
for (var i = 0; i < hydrogen_spectrum.length; i++) {
h_mats.push(new THREE.PointCloudMaterial({color: hydrogen_spectrum[i], size: 2, transparent: true}))
}
camera.position.z = 550;
renderer.setSize( window.innerWidth, window.innerHeight );
x = document.body.appendChild( renderer.domElement );
mag_field = [];
for (var row = 0; row < 480; ++row) {
energy_field.push([]);
mag_field.push([]);
for (var col = 0; col < 640; ++col) {
energy_field[row].push([0, 0]);
mag_field.push(0);
}
}
pMat = new THREE.MeshNormalMaterial();
vertex = 0;
// create the particles
geometries = [new THREE.Geometry(),new THREE.Geometry(),new THREE.Geometry(),new THREE.Geometry(),new THREE.Geometry()];
tot = [0,0,0];
k = .95;
webCamFlow.onCalculated(function(direction) {
//tot = [0,0,0];
tot[1] *= k;
tot[0] *= k;
tot[2] *= k;
// render zones
//sceneCtx.clearRect(0, 0, sceneWidth, sceneHeight);
for (var i = 0; i < direction.zones.length; ++i) {
var zone = direction.zones[i];
energy_field[zone.y][zone.x][0] += zone.u;
energy_field[zone.y][zone.x][1] += zone.v;
mag = (energy_field[zone.y][zone.x][0] * energy_field[zone.y][zone.x][0] + energy_field[zone.y][zone.x][1] * energy_field[zone.y][zone.x][1]) - 1;
mag_field[zone.y][zone.x] += mag;
tot[0] += zone.u;
tot[1] += zone.v;
tot[2] += mag;
//sceneCtx.strokeStyle = getColor(zone.u, zone.v);
//sceneCtx.beginPath();
//sceneCtx.moveTo(zone.x, zone.y);
//sceneCtx.lineTo((zone.x - energy_field[zone.y][zone.x][0]), (zone.y + energy_field[zone.y][zone.x][1]));
//sceneCtx.stroke();
energy_field[zone.y][zone.x][0] *= k;
energy_field[zone.y][zone.x][1] *= k;
mag_field[zone.y][zone.x] *= k;
if (mag > 50) {
ind = 0;
if (mag < 100) {
ind = 1;
}
else if (mag < 150) {
ind = 2;
}
else if (mag < 200) {
ind = 3;
}
else if (mag >= 250) {
ind = 4;
}
vertex = new THREE.Vector3();
vertex.v_z = mag;
vertex.v_x = energy_field[zone.y][zone.x][0] * .25;
vertex.v_y = energy_field[zone.y][zone.x][1] * .25;
vertex.x = zone.x + vertex.v_x;
vertex.y = zone.y + vertex.v_y;
vertex.z = 20 * Math.log(mag);
geometries[ind].vertices.push(vertex);
}
}
for (var i = 0; i < h_mats.length; ++i) {
particles = new THREE.PointCloud(geometries[i], h_mats[i]);
particles.sortParticles = true;
particles.age = 0;
scene.add(particles);
}
geometries = [new THREE.Geometry(),new THREE.Geometry(),new THREE.Geometry(),new THREE.Geometry(),new THREE.Geometry()];
});
t = 0;
//controls = new THREE.OrbitControls(camera, renderer.domElement);
MAX_AGE = 8.0;
function render() {
//headtrackr.controllers.three.realisticAbsoluteCameraControl(camera, 10, [320,240, 450], new THREE.Vector3(320, 240, 0), {damping : 0.5});
//console.log(camera.position)
requestAnimationFrame( render );
renderer.render(scene, camera);
t += .01;
lt2 = Math.log(tot[2]);
camera.fov = 110
camera.fov -= 3 * lt2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
camera.position.x = 320 + 0.0001 * tot[0];
camera.position.y = 240 + 0.0001 * tot[1];
camera.position.z = 400 + 10 * (lt2);
camera.rotation.x = .000001 * tot[0] + Math.PI;
camera.rotation.y = .000001 * tot[1] + Math.PI;
//camera.rotation.z = Math.PI;
for (var i = 0; i < scene.children.length; i++) {
object = scene.children[i];
if (object instanceof THREE.PointCloud) {
if (object.age > MAX_AGE) scene.remove(object);
object.material.opacity = 1 - object.age++ / MAX_AGE;// * //Math.cos(object.age++/MAX_AGE * Math.PI);
}
//else if (object.geometry instanceof THREE.PlaneGeometry) {
// object.position = new THREE.Vector3(maxRect.x, maxRect.y, 0);
//}
}
}
render();
webCamFlow.startCapture();
//trackerTask.stop();
};
</script>
</head>
<body onload="main()">
<div style="float:left">
<video id="videoOut" width="640px" height="480px" autoplay></video>
<canvas id="scene" width="640px" height="480px"></canvas>
<br>
</div>
<!-- <h1>hologram</h1>
--> <!-- <footer>built using oflow.js</footer> -->
</body>
</html>