/
orthographic-view.js
58 lines (50 loc) · 1.34 KB
/
orthographic-view.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
import View from './view';
import Viewport from '../viewports/viewport';
import {Matrix4} from 'math.gl';
import OrthographicController from '../controllers/orthographic-controller';
const viewMatrix = new Matrix4().lookAt({eye: [0, 0, 1]});
function getProjectionMatrix({width, height, near, far}) {
// Make sure Matrix4.ortho doesn't crash on 0 width/height
width = width || 1;
height = height || 1;
return new Matrix4().ortho({
left: -width / 2,
right: width / 2,
bottom: height / 2,
top: -height / 2,
near,
far
});
}
class OrthographicViewport extends Viewport {
constructor({id, x, y, width, height, near = 0.1, far = 1000, zoom = 0, target = [0, 0, 0]}) {
const scale = Math.pow(2, zoom);
return new Viewport({
id,
x,
y,
width,
height,
position: target,
viewMatrix: viewMatrix.clone().scale(scale),
projectionMatrix: getProjectionMatrix({width, height, near, far}),
zoom
});
}
}
export default class OrthographicView extends View {
constructor(props) {
super(
Object.assign({}, props, {
type: OrthographicViewport
})
);
}
get controller() {
return this._getControllerProps({
type: OrthographicController,
ViewportType: OrthographicViewport
});
}
}
OrthographicView.displayName = 'OrthographicView';