1- import { createContext , useContext , useEffect , useMemo , useState } from 'react' ;
1+ import { createContext , useContext , useEffect , useState } from 'react' ;
22import { vec3 } from 'gl-matrix' ;
33import type { ReactNode } from 'react' ;
44
@@ -10,11 +10,16 @@ type GlobalState = {
1010 lightColor : string ;
1111} ;
1212
13+ const updatePerspective = ( height : number ) => ( 500 / 750 ) * height ;
14+
15+ const updateLightPosition = ( width : number , height : number , v : vec3 ) =>
16+ vec3 . set ( v , width / 4 , height / 4 , 100 ) ;
17+
1318const getDefaultState = ( width : number , height : number ) : GlobalState => ( {
1419 width,
1520 height,
16- perspective : ( 500 / 750 ) * height ,
17- lightPosition : vec3 . fromValues ( width / 3 , height / 3 , 0 ) ,
21+ perspective : updatePerspective ( height ) ,
22+ lightPosition : updateLightPosition ( width , height , vec3 . create ( ) ) ,
1823 lightColor : '#ffffff' ,
1924} ) ;
2025
@@ -27,8 +32,8 @@ const updateGlobalStateDimensions = (
2732 ...state ,
2833 width,
2934 height,
30- perspective : ( 500 / 750 ) * height ,
31- lightPosition : vec3 . set ( state . lightPosition , width / 3 , height / 3 , 0 ) ,
35+ perspective : updatePerspective ( height ) ,
36+ lightPosition : updateLightPosition ( width , height , state . lightPosition ) ,
3237 } ;
3338} ;
3439
0 commit comments