Skip to content

Commit bbab496

Browse files
committed
Completely fixed board
1 parent 28c7415 commit bbab496

File tree

8 files changed

+64
-39
lines changed

8 files changed

+64
-39
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var directions = new Array();
2-
directions.push({x: 0, y: 0.5});
3-
directions.push({x: 0.5, y: 0});
4-
directions.push({x: 0, y: -0.5});
5-
directions.push({x: -0.5, y: 0});
2+
directions.push({x: 0, y: 1});
3+
directions.push({x: 1, y: 0});
4+
directions.push({x: 0, y: -1});
5+
directions.push({x: -1, y: 0});
66

77
export {directions};

src/components/Algorithms/Maze/Generation/BinaryTreeCreation.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {directions} from '../Directions';
2-
import {_FindCellVisitState, _FindCellTypeState, _FindCell, _BoardReset} from '../Tools';
3-
import exit from 'exit';
1+
import {directions} from '../Directions';
2+
import {_FindCellVisitState, _FindCellTypeState, _FindCell, _BoardReset, _GetNeighbors} from '../Tools';
3+
import exit from 'exit';
4+
import {PATH_TYPE} from '../../../BoardCanvas/Cells';
45

56

67

@@ -9,7 +10,7 @@ export function BinaryTreeCreation(board) {
910
_BoardReset(board);
1011
const numPoints = board.length;
1112
const numCols = Math.ceil(Math.sqrt(numPoints));
12-
13+
const prev = null;
1314
for (var i = 0; i < numPoints; i++) {
1415
let node = board[i];
1516
// Needed to be percise to avoid floating point errors....
@@ -18,17 +19,26 @@ export function BinaryTreeCreation(board) {
1819
// console.log(direction);
1920
// console.log(directions[direction].x);
2021
// console.log(board[i].x + directions[direction].x);
21-
let xcord = node.x += directions[direction].x;
22-
let ycord = node.y += directions[direction].y;
22+
let xcord = node.x + directions[direction].x;
23+
let ycord = node.y + directions[direction].y;
2324
// console.log(xcord, ycord);
2425
// console.log(node.x + directions[direction].x, node.y + directions[direction].y);
25-
2626
const cell = _FindCell(board, xcord, ycord);
2727
// console.log(cell);
2828
// exit();
2929
if (cell) {
3030
// exit();
3131

32+
// const testNeighbor = _GetNeighbors(board, -6, -6);
33+
// if (testNeighbor) {
34+
// testNeighbor.forEach(neighbor => {
35+
// console.log('Neighbor: ', neighbor);
36+
// neighbor.type = PATH_TYPE;
37+
// });
38+
// }
39+
// return;
40+
41+
3242
if (!cell.visited) {
3343
// console.log(cell);
3444
cell.visited = true;
@@ -40,11 +50,6 @@ export function BinaryTreeCreation(board) {
4050
for (var x = 0; x < numPoints; x++) {
4151
let node = board[x];
4252

43-
// Tightly packed rows of cells.
44-
node.x = board[x].x = Math.floor(node.x);
45-
node.y = board[x].y = Math.floor(node.y);
46-
node.z = 0;
47-
4853
if (!node.visited) {
4954
node.type = '_wall_';
5055
}

src/components/Algorithms/Maze/Solving/RecursiveSolve.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export function RecursiveSolve(board, start, end, position) {
1616
}
1717

1818

19+
1920
}

src/components/Algorithms/Maze/Tools.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Quick selection test
33
*/
44
import {DEFAULT_TYPE} from '../../BoardCanvas/Cells';
5+
import {directions} from './Directions';
56

67

78

@@ -29,7 +30,7 @@ export function _FindCell(board, x, y) {
2930
// console.log(board[i].x, x, board[i].y, y);
3031

3132
if (board[i].x === x && board[i].y === y) {
32-
// console.log(board[i].x, x, board[i].y, y);
33+
console.log("Board x: " + board[i].x + "\nCelll x: " + x + "\nBoard y: "+ board[i].y + "\nCell y: " + y);
3334

3435
return board[i];
3536
}
@@ -38,6 +39,20 @@ export function _FindCell(board, x, y) {
3839
};
3940

4041

42+
export function _GetNeighbors(board, x, y) {
43+
let neighbors = [];
44+
for (let i = 0; i < 4; i++) {
45+
let xcoord = x + directions[i].x;
46+
let ycoord = y + directions[i].y;
47+
let neighbor = _FindCell(board, xcoord, ycoord);
48+
if (neighbor) {
49+
neighbors.push(neighbor);
50+
}
51+
}
52+
return neighbors;
53+
}
54+
55+
4156
export function _BoardReset(board) {
4257
for (let i = 0; i < board.length; i++) {
4358
board[i].visited = false;

src/components/BoardCanvas/Board.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const Board = ({board, layoutType, selectedPoint, onSelectPoint, mazeType
2121

2222

2323
return (
24-
<Canvas className = "board" camera = {{position: [0, 0, 80], far: 1000}}>
24+
<Canvas className = "board">
2525
<Controls ref = {controlsRef} selectedPoint = {selectedPoint}/>
2626
<mesh> {/* BorderBox */}
2727
{(layoutType === 'standard') ?

src/components/BoardCanvas/Cells.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {BinaryTreeCreation} from '../Algorithms/Maze/Generati
1212

1313

1414

15-
1615
export const TEST_COLOR = '#FF66CC';
1716
export const BURN_COLOR = '#fad6ee';
1817
export const PATH_COLOR = '#63caef';
@@ -201,7 +200,7 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
201200
<instancedMesh
202201
ref = {meshRef}
203202
args = {[null, null, numPoints]}
204-
frustumCulled = {true}
203+
frustumCulled = {false}
205204
onClick = {getClickTarget}
206205
onPointerDown = {setDownPointerCoord}
207206
>
@@ -214,16 +213,6 @@ const Cells = ({board, layoutType, mazeType, selectedPoint, onSelectPoint /*, u
214213
count = {numPoints}
215214
/>
216215
</boxBufferGeometry>
217-
{/* <boxBufferGeometry
218-
attach = "geometry"
219-
args = {[.9, .4, 0.9, 18]}
220-
color = "black"
221-
>
222-
<instancedBufferAttribute
223-
attachObject = {['attributes', 'color']}
224-
args = {[colorArray, 3]}
225-
/>
226-
</boxBufferGeometry> */}
227216
<meshStandardMaterial
228217
attach = "material"
229218
vertexColors = {THREE.VertexColors}

src/components/BoardCanvas/Layouts.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const useLayoutHook = ({board, layoutType}) => {
3737

3838

3939
export function useAnimationHook({board, layoutType}) {
40-
console.log('useAnimationHook used.');
40+
console.log('useAnimatio/* */nHook used.');
4141
useLayoutHook({board, layoutType}); // do the actual animation when layoutType changes
4242
console.log('useAnimationHook ended.');
4343

@@ -76,11 +76,14 @@ export function standardLayout(board) {
7676

7777
for (let i = 0; i < numPoints; ++i) {
7878
const node = board[i];
79+
80+
// const col = Math.abs((i % numCols) - numCols / 2);
81+
// const row = Math.abs(Math.floor(i / numCols) - numCols / 2);
7982
const col = (i % numCols) - numCols / 2;
8083
const row = Math.floor(i / numCols) - numCols / 2;
8184

82-
node.x = col * 1.05;
83-
node.y = row * 1.05;
85+
node.x = col;/* .05; */
86+
node.y = row;/* .05; */
8487
node.z = 0;
8588
}
8689
}

src/components/BoardCanvas/OrbitControls.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const DOWN_KEY = 40;
1717
const LEFT_KEY = 37;
1818
const 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

Comments
 (0)