-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathperspective.js
More file actions
78 lines (55 loc) · 1.55 KB
/
perspective.js
File metadata and controls
78 lines (55 loc) · 1.55 KB
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
import Ember from 'ember';
import BaseCameraMixin from './base';
import { PerspectiveCamera } from 'three';
const { computed, get, getProperties, isEmpty, observer, set } = Ember;
export default BaseCameraMixin.extend({
viewAngle: 75,
near: 1,
far: 10000,
setAspectDynamically: true,
position: {
x: 0,
y: 0,
z: 1000
},
aspect: computed('width', 'height', function() {
const { width, height } = getProperties(this, 'width', 'height');
if (isEmpty(width) || isEmpty(height)) { return; }
// Set aspect
return width / height;
}),
// @function setCamera
//
// Adds a Three.js Camera and sets on the component.
setCamera() {
const {
aspect,
far,
near,
viewAngle
} = getProperties(this, 'aspect', 'far', 'near', 'viewAngle');
let camera = new PerspectiveCamera(
viewAngle, aspect, near, far
);
set(this, 'camera', camera);
this.setCameraPosition();
},
// @function setCameraPosition
//
// Sets the Three.js camera position.
setCameraPosition() {
let { camera, position } = getProperties(this, 'camera', 'position');
Object.keys(get(this, 'position')).forEach((key) => {
camera.position[key] = position[key];
});
},
// @observer aspectChanged
//
// Updates Three.js camera when the aspect is changed.
aspectChanged: observer('aspect', function() {
if (isEmpty(get(this, 'camera'))) { return; }
const camera = get(this, 'camera');
camera.aspect = get(this, 'aspect');
camera.updateProjectionMatrix();
})
});