1
- import { createContext , useContext , useEffect , useMemo , useState } from 'react' ;
1
+ import { createContext , useContext , useEffect , useState } from 'react' ;
2
2
import { vec3 } from 'gl-matrix' ;
3
3
import type { ReactNode } from 'react' ;
4
4
@@ -10,11 +10,16 @@ type GlobalState = {
10
10
lightColor : string ;
11
11
} ;
12
12
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
+
13
18
const getDefaultState = ( width : number , height : number ) : GlobalState => ( {
14
19
width,
15
20
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 ( ) ) ,
18
23
lightColor : '#ffffff' ,
19
24
} ) ;
20
25
@@ -27,8 +32,8 @@ const updateGlobalStateDimensions = (
27
32
...state ,
28
33
width,
29
34
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 ) ,
32
37
} ;
33
38
} ;
34
39
0 commit comments