Skip to content

Commit

Permalink
[camera-position] add camera position debugging and memoize functions…
Browse files Browse the repository at this point in the history
… that are affected
  • Loading branch information
Tryferos committed Dec 14, 2024
1 parent 9faafbc commit fa7be90
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
8 changes: 3 additions & 5 deletions resources/js/Game/Board/Board.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useGameDimensions } from "@/Store/game_dimensions";
import { DragControls, Grid } from "@react-three/drei";
import { PieceCode } from "@/types/piece";
import * as THREE from "three";
import { useBoardState } from "@/Store/board_state";
import { memo } from "react";

export const Board = () => {
const blockSize = useGameDimensions(state => state.blockSize);
export const Board = memo(() => {
const gridSize = useGameDimensions(state => state.getGridSize());
const setBoardRef = useBoardState(state => state.setBoardRef);
return (
Expand All @@ -17,4 +15,4 @@ export const Board = () => {
</mesh>
</>
);
}
});
29 changes: 29 additions & 0 deletions resources/js/Game/Board/GameMap.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
import { useThree } from "@react-three/fiber";
import { Lights } from "../Ligths";
import { Board } from "./Board";
import Hand from "./Hand";
import { useEffect } from "react";
import { useControls } from "leva";

const GameMap = () => {

const {y,z} = useControls({
y: {
label: 'Camera Y',
value: 9.5,
min: 0,
max: 30,
step: 0.1,
},
z: {
label: 'Camera Z',
value: 8.3,
min: 0,
max: 30,
step: 0.1,
},
})

const {camera} = useThree();

useEffect(() => {

camera.position.set(0, y, z);
camera.updateProjectionMatrix()

}, [y,z])

return (
<>
<Lights/>
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Game/Board/Hand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as THREE from "three";
import { Piece } from "./Piece/Piece";
import { PieceCode } from "@/types/piece";
import { useGameDimensions } from "@/Store/game_dimensions";
import { memo } from "react";

const Hand = () => {

const Hand = memo(() => {
const blockSize = useGameDimensions(state => state.blockSize);
const handPosition = new THREE.Vector3(10, 0, 0);
return (
Expand All @@ -24,6 +24,6 @@ const Hand = () => {
}
</>
)
}
})

export default Hand

0 comments on commit fa7be90

Please sign in to comment.