@@ -17,7 +17,7 @@ const DOWN_KEY = 40;
1717const LEFT_KEY = 37 ;
1818const RIGHT_KEY = 39 ;
1919
20- const OrbitControls = ( { selectedPoint, onSelectedPoint} , ref ) => {
20+ const OrbitControls = ( { board , selectedPoint, onSelectedPoint} , ref ) => {
2121 const controls = useRef ( ) ;
2222 const [ target , setTarget ] = useState ( null ) ;
2323 const { camera, gl} = useThree ( ) ;
@@ -26,7 +26,7 @@ const OrbitControls = ({selectedPoint, onSelectedPoint}, ref) => {
2626 // Set up the camera on mount.
2727 useEffect ( ( ) => {
2828 camera . position . set ( 0 , - 10 , 50 ) ; // Initial camera position
29- camera . lookAt ( 0 , 0 , 0 ) ;
29+ camera . lookAt ( 0 , - 10 , 50 ) ;
3030 } , [ camera ] ) ;
3131
3232 // Set up the initial target.
@@ -42,7 +42,7 @@ const OrbitControls = ({selectedPoint, onSelectedPoint}, ref) => {
4242 * {useImperativeHandle} React requirement in order to use refs, and
4343 * to pass the ref to the component altering functionality.
4444 */
45- useImperativeHandle ( ref , ( state ) => ( {
45+ useImperativeHandle ( ref , ( ) => ( {
4646 setTarget : ( target ) => {
4747 setTarget ( target ) ;
4848 console . log ( 'setTarget' , target ) ;
@@ -57,10 +57,22 @@ const OrbitControls = ({selectedPoint, onSelectedPoint}, ref) => {
5757 * Function to reset the camera to the default position.
5858 */
5959 resetCamera : ( ) => {
60- camera . position . set ( 0 , - 10 , 50 ) ; // reset position
61- camera . lookAt ( 0 , 0 , 0 ) ; // reset rotation
62- this . setTarget ( null ) ; // reset target
60+ // reset look-at (target) and camera position
61+ controls . current . target . set ( 0 , 0 , 0 ) ;
62+ camera . position . set ( 0 , 0 , 80 ) ;
63+
64+ // needed for trackball controls, reset the up vector
65+ camera . up . set (
66+ controls . current . up0 . x ,
67+ controls . current . up0 . y ,
68+ controls . current . up0 . z
69+ ) ;
6370 } ,
71+ // resetCamera: () => {
72+ // camera.position.set(0, -10, 50); // reset position
73+ // camera.lookAt(0, 0, 0); // reset rotation
74+ // this.setTarget(null); // reset target
75+ // },
6476
6577
6678 /*
0 commit comments