-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
58 lines (43 loc) · 1.18 KB
/
test.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
var createApp = require('canvas-testbed')
var THREE = require('three')
var ScreenQuad = require('./')(THREE)
createApp(render, start, {
context: 'webgl',
onResize: resize
});
var renderer,
scene,
camera,
controls,
screenQuad
function start(gl, width, height) {
renderer = new THREE.WebGLRenderer({
canvas: gl.canvas
});
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, width/height, 1, 1000);
camera.position.set(0, 0 , -10);
camera.lookAt(new THREE.Vector3());
//make a quad thats 50% width and 50% height of the canvas
//but offset in pixels
screenQuad = new ScreenQuad({
width: .5,
height: .5,
top:'25px',
left: '25px',
debug: true
});
screenQuad.setScreenSize( renderer.getSize().width , renderer.getSize().height );
scene.add(screenQuad)
}
function render(gl, width, height) {
renderer.render(scene, camera);
}
function resize(width, height) {
if (!renderer)
return
renderer.setViewport(0, 0, width, height);
camera.aspect = width/height;
camera.updateProjectionMatrix();
screenQuad.setScreenSize( width , height );
}