-
Notifications
You must be signed in to change notification settings - Fork 3
/
visualizer.html
112 lines (86 loc) · 2.98 KB
/
visualizer.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
<!doctype html>
<html lang="en">
<head>
<title>Seeing Sounds</title>
<meta charset="utf-8">
</head>
<body style="margin:0px;">
<script src="libs/three.js"></script>
<!-- Physics -->
<script src="libs/physics/physi.js"></script>
<script>
Physijs.scripts.worker = "libs/physics/physijs_worker.js";
Physijs.scripts.ammo = 'ammo.js';
</script>
<!-- load libs -->
<script src="libs/perlin.js"></script>
<script src="libs/THREEx.KeyboardState.js"></script>
<script src="libs/tween.min.js"></script>
<!-- load objects -->
<script src="objects/starfield.js"></script>
<script src="objects/terrainMatrix.js"></script>
<script src="objects/light.js"></script>
<script src="objects/ball.js"></script>
<script src="objects/cameraControls.js"></script>
<script src ="objects/audio/audioAnalyser.js"></script>
<!-- main script-->
<script>
/**
* Main Visualizer
*/
function Visualizer(){
this.audioAnalyser = new AudioAnalyser('objects/audio/sierra.ogg');
this.keyboard = new THREEx.KeyboardState();
this.clock = new THREE.Clock();
this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
this.scene = new Physijs.Scene();
this.renderer = new THREE.WebGLRenderer();;
this.starField = new StarField;
this.light = new Light();
this.terrain;
this.balls = new BallTerrain(this.audioAnalyser);
this.cameraControls = new CameraControls();
}
/**
* Visualizer functions
*/
Visualizer.prototype = {
constructor: Visualizer,
init:function(){
this.camera.position.z = 5;
//set the size of the renderer
this.renderer.setSize( window.innerWidth, window.innerHeight );
//add the renderer to the html document body
document.body.appendChild( this.renderer.domElement );
this.starField.addStars(this.scene);
this.light.addLight(this.scene);
this.terrain = new TerrainMatrix(this.scene);
this.terrain.createTerrainMatrix();
this.balls.addBalls(this.scene);
this.audioAnalyser.play();
this.scene.setGravity(new THREE.Vector3( 0, -80, 0 ));
},
render:function(){
this.scene.simulate();
var localRenderer = this;
//get the frame
requestAnimationFrame( function(){localRenderer.render();} );
//render the scene
this.renderer.setClearColor( 0x000646, 1);
this.renderer.render( this.scene, this.camera );
this.starField.animateStars(this.camera, this.scene);
//uncomment below to animate the terrain
//this.balls.animateBalls();
//this.terrain.animateFloor();
this.terrain.moveWithCamera(this.camera);
this.balls.moveWithCamera(this.camera);
this.terrain.respondToAudio(this.audioAnalyser.boost, this.camera);
this.cameraControls.update(this.camera, this.keyboard, this.clock);
}
};
var viz = new Visualizer;
viz.init();
viz.render();
</script>
</body>
</html>