forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc_controls_oculusrift.html
161 lines (123 loc) · 4.33 KB
/
misc_controls_oculusrift.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - controls - oculus rift</title>
<meta charset="utf-8">
<style>
body {
margin: 0px;
background-color: #000000;
overflow: hidden;
}
#info {
position: absolute;
top: 0px; width: 100%;
color: #ffffff;
padding: 5px;
font-family:Monospace;
font-size:13px;
font-weight: bold;
text-align:center;
}
a {
color: #ff8800;
}
</style>
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - headtracking demo for oculus rift. requires <a href="https://github.com/possan/oculus-rest/" target="_blank">oculus-rest</a> to get headtracking coordinates working.<br />
(left click: forward, a/s/w/d/r/f: move, h: hide text)
</div>
<script src="../build/three.min.js"></script>
<script src="js/ImprovedNoise.js"></script>
<script src="js/effects/OculusRiftEffect.js"></script>
<script src="js/controls/FirstPersonControls.js"></script>
<script src="js/controls/OculusControls.js"></script>
<script>
var camera, scene, renderer;
var realcamera;
var guiVisible = true;
var mesh, effect, controls, oculuscontrol;
var meshes = [];
var meshparent = [];
var meshparent2 = [];
var cols = 50;
var rows = 30;
var tot = cols * rows;
var clock = new THREE.Clock();
var perlin;
init();
animate();
function init() {
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
perlin = new ImprovedNoise();
camera = new THREE.PerspectiveCamera( 90, window.innerWidth / window.innerHeight, 1, 5000 );
camera.position.x = 200;
camera.position.y = 250;
camera.position.z = -200;
scene = new THREE.Scene();
effect = new THREE.OculusRiftEffect( renderer, { worldScale: 1 } );
effect.setSize( window.innerWidth, window.innerHeight );
controls = new THREE.FirstPersonControls( camera );
controls.movementSpeed = 4000;
controls.lookSpeed = 3.0;
controls.lookVertical = true;
oculuscontrol = new THREE.OculusControls( camera );
document.body.appendChild( renderer.domElement );
var hemiLight = new THREE.HemisphereLight( 0xffffff, 0xffffff, 0.6 );
hemiLight.color.setHSL( 0.6, 1, 0.6 );
hemiLight.groundColor.setHSL( 0.095, 1, 0.75 );
hemiLight.position.set( 0, 500, 0 );
scene.add( hemiLight );
var geometry = new THREE.BoxGeometry( 100, 100, 200 );
var texture = THREE.ImageUtils.loadTexture( 'textures/crate.gif' );
texture.anisotropy = renderer.getMaxAnisotropy();
var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0xffffff, shininess: 20, shading: THREE.FlatShading, map: texture } );
for (var i=0; i<tot; i++) {
meshparent2[i] = new THREE.Object3D();
scene.add( meshparent2[i] );
meshparent[i] = new THREE.Object3D();
meshparent[i].position.y = 50;
meshparent[i].position.x = -50;
meshparent2[i].add( meshparent[i] );
mesh = new THREE.Mesh( geometry, material );
meshparent[i].add( mesh );
meshes.push(mesh);
}
window.addEventListener( 'resize', onWindowResize, false );
document.addEventListener('keydown', keyPressed, false);
oculuscontrol.connect();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
realcamera.aspect = window.innerWidth / window.innerHeight;
realcamera.updateProjectionMatrix();
effect.setSize( window.innerWidth, window.innerHeight );
controls.handleResize();
}
function keyPressed(event) {
if (event.keyCode === 72) { // H
guiVisible = !guiVisible;
document.getElementById('info').style.display = guiVisible ? "block" : "none";
}
}
function animate() {
requestAnimationFrame( animate );
var t = clock.getElapsedTime();
for (var i=0; i<meshes.length; i++) {
var c = Math.floor(i % cols);
var r = Math.floor(i / cols);
meshparent2[i].rotation.y = (c * 3.142 * 2 / cols);
meshparent[i].rotation.x = ((r+10) * 3.142 * 2 / (rows+20));
meshes[i].position.z = 1400 - 1350 * perlin.noise(c*8/cols,r*8/rows,t/2);
}
controls.update( clock.getDelta() );
oculuscontrol.update( clock.getDelta() );
effect.render( scene, camera );
}
</script>
</body>
</html>