-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #826 from vorth/orthographic
Added orthographic camera
- Loading branch information
Showing
11 changed files
with
153 additions
and
30 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
|
||
import { Switch } from "@kobalte/core"; | ||
|
||
import { useCamera } from "./context/camera"; | ||
|
||
export const CameraMode = () => | ||
{ | ||
const { togglePerspective, state } = useCamera(); | ||
|
||
return ( | ||
<div style={ { position: 'absolute', top: '1em', right: '1em' } }> | ||
<Switch.Root checked={state.camera.perspective} onChange={togglePerspective}> | ||
<Switch.Label class="switch__label">perspective</Switch.Label> | ||
<Switch.Input class="switch__input" /> | ||
<Switch.Control class="switch__control"> | ||
<Switch.Thumb class="switch__thumb" /> | ||
</Switch.Control> | ||
</Switch.Root> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
// Adapted from https://github.com/nksaraf/react-three-fiber/commit/581d02376d4304fb3bab5445435a61c53cc5cdc2 | ||
|
||
import { createEffect, untrack, onCleanup } from 'solid-js'; | ||
import { useThree } from 'solid-three'; | ||
|
||
export const OrthographicCamera = (props) => | ||
{ | ||
const set = useThree(({ set }) => set); | ||
const scene = useThree(({ scene }) => scene); | ||
const camera = useThree(({ camera }) => camera); | ||
|
||
let cam; | ||
|
||
createEffect(() => { | ||
cam.near = props.near; | ||
cam.far = props.far; | ||
cam.left = -props.halfWidth; | ||
cam.right = props.halfWidth; | ||
const halfHeight = props.halfWidth / props.aspect; | ||
cam.top = halfHeight; | ||
cam.bottom = -halfHeight; | ||
cam.updateProjectionMatrix(); | ||
}); | ||
|
||
createEffect( () => { | ||
const [ x, y, z ] = props.target; | ||
cam .lookAt( x, y, z ); | ||
}); | ||
|
||
createEffect(() => { | ||
const oldCam = untrack(() => camera()); | ||
set()({ camera: cam }); | ||
scene() .add( cam ); // The camera will work without this, but the *lights* won't! | ||
onCleanup(() => { | ||
set()({ camera: oldCam }); | ||
scene() .remove( cam ); | ||
}); | ||
}); | ||
|
||
return <orthographicCamera ref={cam} position={props.position} {...props} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters