Skip to content

Commit 6aee663

Browse files
committed
tweak light position
1 parent c9504fd commit 6aee663

File tree

3 files changed

+12
-57
lines changed

3 files changed

+12
-57
lines changed

examples/3d-cubes/src/components/DimensionsContext.tsx

Lines changed: 0 additions & 50 deletions
This file was deleted.

examples/3d-cubes/src/components/GlobalContext.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
1+
import { createContext, useContext, useEffect, useState } from 'react';
22
import { vec3 } from 'gl-matrix';
33
import 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+
1318
const 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

examples/3d-cubes/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const BaseApp = () => {
2222
[perspective],
2323
);
2424

25+
const [time, setTime] = useState(() => performance.now());
26+
2527
const [playing, setPlaying] = useState(true);
2628
const togglePlaying = useCallback(() => {
2729
setPlaying((isPlaying) => !isPlaying);
@@ -51,8 +53,6 @@ const BaseApp = () => {
5153
requestAnimationFrame(update);
5254
}, [playing]);
5355

54-
const [time, setTime] = useState(() => performance.now());
55-
5656
const translateToCentre = useFactoryRef<vec3>(() => vec3.create());
5757
const cubeGroup1Translate = useFactoryRef<vec3>(() => vec3.create());
5858
const cubeGroup2Translate = useFactoryRef<vec3>(() => vec3.create());

0 commit comments

Comments
 (0)