diff options
| author | Loki Rautio <lokirautio@gmail.com> | 2026-03-04 03:56:03 -0600 |
|---|---|---|
| committer | Loki Rautio <lokirautio@gmail.com> | 2026-03-04 03:56:03 -0600 |
| commit | 42aec6dac53dffa6afe072560a7e1d4986112538 (patch) | |
| tree | 0836426857391df1b6a83f6368a183f83ec9b104 /Minecraft.World/Direction.cpp | |
| parent | c9d58eeac7c72f0b3038e084667b4d89a6249fce (diff) | |
| parent | ef9b6fd500dfabd9463267b0dd9e29577eea8a2b (diff) | |
Merge branch 'main' into pr/win64-world-saves
# Conflicts:
# Minecraft.Client/MinecraftServer.cpp
# README.md
Diffstat (limited to 'Minecraft.World/Direction.cpp')
| -rw-r--r-- | Minecraft.World/Direction.cpp | 80 |
1 files changed, 58 insertions, 22 deletions
diff --git a/Minecraft.World/Direction.cpp b/Minecraft.World/Direction.cpp index 408bbab5..f758798b 100644 --- a/Minecraft.World/Direction.cpp +++ b/Minecraft.World/Direction.cpp @@ -4,18 +4,20 @@ const int Direction::STEP_X[] = { - 0, -1, 0, 1 + 0, -1, 0, 1 }; const int Direction::STEP_Z[] = { - 1, 0, -1, 0 + 1, 0, -1, 0 }; +const wstring Direction::NAMES[] = {L"SOUTH", L"WEST", L"NORTH", L"EAST" }; + // for [direction] it gives [tile-face] int Direction::DIRECTION_FACING[4] = { - Facing::SOUTH, Facing::WEST, Facing::NORTH, Facing::EAST + Facing::SOUTH, Facing::WEST, Facing::NORTH, Facing::EAST }; // for [facing] it gives [direction] @@ -26,37 +28,71 @@ int Direction::FACING_DIRECTION[] = int Direction::DIRECTION_OPPOSITE[4] = { - Direction::NORTH, Direction::EAST, Direction::SOUTH, Direction::WEST + NORTH, EAST, SOUTH, WEST }; // for [direction] it gives [90 degrees clockwise direction] int Direction::DIRECTION_CLOCKWISE[] = { - Direction::WEST, Direction::NORTH, Direction::EAST, Direction::SOUTH + WEST, NORTH, EAST, SOUTH }; // for [direction] it gives [90 degrees counter clockwise direction] int Direction::DIRECTION_COUNTER_CLOCKWISE[] = { - Direction::EAST, Direction::SOUTH, Direction::WEST, Direction::NORTH + EAST, SOUTH, WEST, NORTH }; int Direction::RELATIVE_DIRECTION_FACING[4][6] = { - // south - { - Facing::UP, Facing::DOWN, Facing::SOUTH, Facing::NORTH, Facing::EAST, Facing::WEST - }, - // west - { - Facing::UP, Facing::DOWN, Facing::EAST, Facing::WEST, Facing::NORTH, Facing::SOUTH - }, - // north - { - Facing::UP, Facing::DOWN, Facing::NORTH, Facing::SOUTH, Facing::WEST, Facing::EAST - }, - // east - { - Facing::UP, Facing::DOWN, Facing::WEST, Facing::EAST, Facing::SOUTH, Facing::NORTH - } + // south + { + Facing::UP, Facing::DOWN, Facing::SOUTH, Facing::NORTH, Facing::EAST, Facing::WEST + }, + // west + { + Facing::UP, Facing::DOWN, Facing::EAST, Facing::WEST, Facing::NORTH, Facing::SOUTH + }, + // north + { + Facing::UP, Facing::DOWN, Facing::NORTH, Facing::SOUTH, Facing::WEST, Facing::EAST + }, + // east + { + Facing::UP, Facing::DOWN, Facing::WEST, Facing::EAST, Facing::SOUTH, Facing::NORTH + } }; + +int Direction::getDirection(double xd, double zd) +{ + if (Mth::abs((float) xd) > Mth::abs((float) zd)) + { + if (xd > 0) + { + return WEST; + } + else + { + return EAST; + } + } + else + { + if (zd > 0) + { + return NORTH; + } + else + { + return SOUTH; + } + } +} + +int Direction::getDirection(int x0, int z0, int x1, int z1) +{ + int xd = x0 - x1; + int zd = z0 - z1; + + return getDirection(xd, zd); +}
\ No newline at end of file |
