-
Notifications
You must be signed in to change notification settings - Fork 29
attempting to implement orthographic camera #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9523324
a6e1c26
1eaf6f6
4d00855
9a0235f
9453b59
38305ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { | |
| WebGLRenderer, | ||
| Scene, | ||
| PerspectiveCamera, | ||
| OrthographicCamera, | ||
| Raycaster, | ||
| TextureLoader, | ||
| Vector2, | ||
|
|
@@ -26,6 +27,7 @@ const three = window.THREE | |
| WebGLRenderer, | ||
| Scene, | ||
| PerspectiveCamera, | ||
| OrthographicCamera, | ||
| Raycaster, | ||
| TextureLoader, | ||
| Vector2, | ||
|
|
@@ -183,10 +185,12 @@ export default Kapsule({ | |
| tbControls: state => state.controls // to be deprecated | ||
| }, | ||
|
|
||
| stateInit: () => ({ | ||
| stateInit: ({ cameraType = 'perspective' }) => ({ | ||
| scene: new three.Scene(), | ||
| camera: new three.PerspectiveCamera(), | ||
| clock: new three.Clock() | ||
| clock: new three.Clock(), | ||
| camera: cameraType === 'perspective' ? | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this logic if the user specifies anything else other than camera: new three[cameraType === 'orthographic' ? 'OrthographicCamera' : 'PerspectiveCamera'](); |
||
| new three.PerspectiveCamera() : | ||
| new three.OrthographicCamera() | ||
| }), | ||
|
|
||
| init(domNode, state, { controlType = 'trackball', rendererConfig = {}, waitForLoadComplete = true }) { | ||
|
|
@@ -298,10 +302,10 @@ export default Kapsule({ | |
| } | ||
|
|
||
| state.renderer.setSize(state.width, state.height); | ||
| state.camera.aspect = state.width/state.height; | ||
| state.camera.updateProjectionMatrix(); | ||
|
|
||
| // initialize camera | ||
| state.camera.position.z = 1000; | ||
| updateCamera(state.camera, state.width, state.height, state.camera.position.z); | ||
|
|
||
| // add sky | ||
| state.scene.add(state.skysphere = new three.Mesh()); | ||
|
|
@@ -317,8 +321,8 @@ export default Kapsule({ | |
| state.container.style.width = state.width; | ||
| state.container.style.height = state.height; | ||
| state.renderer.setSize(state.width, state.height); | ||
| state.camera.aspect = state.width/state.height; | ||
| state.camera.updateProjectionMatrix(); | ||
|
|
||
| updateCamera(state.camera, state.width, state.height, state.camera.position.z); | ||
| } | ||
|
|
||
| if (changedProps.hasOwnProperty('skyRadius') && state.skyRadius) { | ||
|
|
@@ -361,10 +365,28 @@ export default Kapsule({ | |
| state.objects.forEach(obj => state.scene.add(obj)); // Add to scene | ||
| } | ||
|
|
||
| // | ||
|
|
||
| function finishLoad() { | ||
| state.loadComplete = state.scene.visible = true; | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| const THREE_JS_PERSPECTIVE_CAMERA_FOV_Y_DEFAULT = 50; | ||
|
|
||
| function updateCamera(camera, width, height, depth) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small nit, |
||
| if (camera.type === 'PerspectiveCamera') { | ||
| camera.aspect = width / height; | ||
| } else { | ||
| const aspect = width / height; | ||
| const height_ortho = depth * 2 * Math.atan( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| THREE_JS_PERSPECTIVE_CAMERA_FOV_Y_DEFAULT * (Math.PI / 180) / 2 | ||
| ); | ||
| const width_ortho = height_ortho * aspect; | ||
|
|
||
| camera.left = width_ortho / -2; | ||
| camera.right = width_ortho / 2; | ||
| camera.top = height_ortho / 2; | ||
| camera.bottom = height_ortho / -2; | ||
| } | ||
| camera.updateProjectionMatrix(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The camera declaration should remain in
stateInit. Otherwise you may run into situations where you try to use it before it's declared, for example by invokingcameraPositionbefore initialization.If you need one of the config options you can always get it as input to
stateInit:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done