-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved CardinalDirection to World folder.
- Loading branch information
Showing
15 changed files
with
140 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 85 additions & 85 deletions
170
OpenTESArena/src/Game/CardinalDirection.cpp → OpenTESArena/src/World/CardinalDirection.cpp
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,85 @@ | ||
#include <unordered_map> | ||
|
||
#include "CardinalDirection.h" | ||
#include "CardinalDirectionName.h" | ||
|
||
#include "components/debug/Debug.h" | ||
|
||
// Wikipedia says the intermediate directions don't have a space, so that's the | ||
// convention I'll use here. | ||
const std::unordered_map<CardinalDirectionName, std::string> CardinalDirectionDisplayNames = | ||
{ | ||
{ CardinalDirectionName::North, "North" }, | ||
{ CardinalDirectionName::NorthEast, "Northeast" }, | ||
{ CardinalDirectionName::East, "East" }, | ||
{ CardinalDirectionName::SouthEast, "Southeast" }, | ||
{ CardinalDirectionName::South, "South" }, | ||
{ CardinalDirectionName::SouthWest, "Southwest" }, | ||
{ CardinalDirectionName::West, "West" }, | ||
{ CardinalDirectionName::NorthWest, "Northwest" } | ||
}; | ||
|
||
CardinalDirectionName CardinalDirection::getDirectionName(const WorldDouble2 &direction) | ||
{ | ||
const WorldDouble2 northEast = CardinalDirection::North.slerp(CardinalDirection::East, 0.5); | ||
const WorldDouble2 southEast = CardinalDirection::South.slerp(CardinalDirection::East, 0.5); | ||
const WorldDouble2 southWest = CardinalDirection::South.slerp(CardinalDirection::West, 0.5); | ||
const WorldDouble2 northWest = CardinalDirection::North.slerp(CardinalDirection::West, 0.5); | ||
|
||
// Each direction gets an equal slice of the circle's area. | ||
// (I'm not sure why the deviation is 1/12th; at a glance it should be 1/8th). | ||
const double deviation = 1.0 / 12.0; | ||
auto isCloseEnoughTo = [deviation, &direction](const Double2 &cardinalDirection) | ||
{ | ||
return direction.dot(cardinalDirection) >= (1.0 - deviation); | ||
}; | ||
|
||
// Find the cardinal direction closest to the given direction. Start with | ||
// a default name and figure out the true one from there. | ||
auto name = CardinalDirectionName::North; | ||
if (isCloseEnoughTo(CardinalDirection::North)) | ||
{ | ||
name = CardinalDirectionName::North; | ||
} | ||
else if (isCloseEnoughTo(northEast)) | ||
{ | ||
name = CardinalDirectionName::NorthEast; | ||
} | ||
else if (isCloseEnoughTo(CardinalDirection::East)) | ||
{ | ||
name = CardinalDirectionName::East; | ||
} | ||
else if (isCloseEnoughTo(southEast)) | ||
{ | ||
name = CardinalDirectionName::SouthEast; | ||
} | ||
else if (isCloseEnoughTo(CardinalDirection::South)) | ||
{ | ||
name = CardinalDirectionName::South; | ||
} | ||
else if (isCloseEnoughTo(southWest)) | ||
{ | ||
name = CardinalDirectionName::SouthWest; | ||
} | ||
else if (isCloseEnoughTo(CardinalDirection::West)) | ||
{ | ||
name = CardinalDirectionName::West; | ||
} | ||
else if (isCloseEnoughTo(northWest)) | ||
{ | ||
name = CardinalDirectionName::NorthWest; | ||
} | ||
else | ||
{ | ||
DebugCrash("Invalid CardinalDirection (" + std::to_string(direction.x) + ", " + | ||
std::to_string(direction.y) + ")."); | ||
} | ||
|
||
return name; | ||
} | ||
|
||
const std::string &CardinalDirection::toString(CardinalDirectionName directionName) | ||
{ | ||
const std::string &displayName = CardinalDirectionDisplayNames.at(directionName); | ||
return displayName; | ||
} | ||
#include <unordered_map> | ||
|
||
#include "CardinalDirection.h" | ||
#include "CardinalDirectionName.h" | ||
|
||
#include "components/debug/Debug.h" | ||
|
||
// Wikipedia says the intermediate directions don't have a space, so that's the | ||
// convention I'll use here. | ||
const std::unordered_map<CardinalDirectionName, std::string> CardinalDirectionDisplayNames = | ||
{ | ||
{ CardinalDirectionName::North, "North" }, | ||
{ CardinalDirectionName::NorthEast, "Northeast" }, | ||
{ CardinalDirectionName::East, "East" }, | ||
{ CardinalDirectionName::SouthEast, "Southeast" }, | ||
{ CardinalDirectionName::South, "South" }, | ||
{ CardinalDirectionName::SouthWest, "Southwest" }, | ||
{ CardinalDirectionName::West, "West" }, | ||
{ CardinalDirectionName::NorthWest, "Northwest" } | ||
}; | ||
|
||
CardinalDirectionName CardinalDirection::getDirectionName(const WorldDouble2 &direction) | ||
{ | ||
const WorldDouble2 northEast = CardinalDirection::North.slerp(CardinalDirection::East, 0.5); | ||
const WorldDouble2 southEast = CardinalDirection::South.slerp(CardinalDirection::East, 0.5); | ||
const WorldDouble2 southWest = CardinalDirection::South.slerp(CardinalDirection::West, 0.5); | ||
const WorldDouble2 northWest = CardinalDirection::North.slerp(CardinalDirection::West, 0.5); | ||
|
||
// Each direction gets an equal slice of the circle's area. | ||
// (I'm not sure why the deviation is 1/12th; at a glance it should be 1/8th). | ||
const double deviation = 1.0 / 12.0; | ||
auto isCloseEnoughTo = [deviation, &direction](const Double2 &cardinalDirection) | ||
{ | ||
return direction.dot(cardinalDirection) >= (1.0 - deviation); | ||
}; | ||
|
||
// Find the cardinal direction closest to the given direction. Start with | ||
// a default name and figure out the true one from there. | ||
auto name = CardinalDirectionName::North; | ||
if (isCloseEnoughTo(CardinalDirection::North)) | ||
{ | ||
name = CardinalDirectionName::North; | ||
} | ||
else if (isCloseEnoughTo(northEast)) | ||
{ | ||
name = CardinalDirectionName::NorthEast; | ||
} | ||
else if (isCloseEnoughTo(CardinalDirection::East)) | ||
{ | ||
name = CardinalDirectionName::East; | ||
} | ||
else if (isCloseEnoughTo(southEast)) | ||
{ | ||
name = CardinalDirectionName::SouthEast; | ||
} | ||
else if (isCloseEnoughTo(CardinalDirection::South)) | ||
{ | ||
name = CardinalDirectionName::South; | ||
} | ||
else if (isCloseEnoughTo(southWest)) | ||
{ | ||
name = CardinalDirectionName::SouthWest; | ||
} | ||
else if (isCloseEnoughTo(CardinalDirection::West)) | ||
{ | ||
name = CardinalDirectionName::West; | ||
} | ||
else if (isCloseEnoughTo(northWest)) | ||
{ | ||
name = CardinalDirectionName::NorthWest; | ||
} | ||
else | ||
{ | ||
DebugCrash("Invalid CardinalDirection (" + std::to_string(direction.x) + ", " + | ||
std::to_string(direction.y) + ")."); | ||
} | ||
|
||
return name; | ||
} | ||
|
||
const std::string &CardinalDirection::toString(CardinalDirectionName directionName) | ||
{ | ||
const std::string &displayName = CardinalDirectionDisplayNames.at(directionName); | ||
return displayName; | ||
} |
50 changes: 25 additions & 25 deletions
50
OpenTESArena/src/Game/CardinalDirection.h → OpenTESArena/src/World/CardinalDirection.h
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
#ifndef CARDINAL_DIRECTION_H | ||
#define CARDINAL_DIRECTION_H | ||
|
||
#include <string> | ||
|
||
#include "../Math/Vector2.h" | ||
#include "../World/Coord.h" | ||
|
||
enum class CardinalDirectionName; | ||
|
||
// North, northeast, southwest, etc.. | ||
namespace CardinalDirection | ||
{ | ||
// Cardinal directions in the XZ plane (bird's eye view). | ||
// CANNOT INITIALIZE FROM VOXELUTILS due to global initialization order uncertainty. | ||
const WorldDouble2 North(-1.0, 0.0); | ||
const WorldDouble2 South(1.0, 0.0); | ||
const WorldDouble2 East(0.0, -1.0); | ||
const WorldDouble2 West(0.0, 1.0); | ||
|
||
CardinalDirectionName getDirectionName(const WorldDouble2 &direction); | ||
const std::string &toString(CardinalDirectionName directionName); | ||
} | ||
|
||
#endif | ||
#ifndef CARDINAL_DIRECTION_H | ||
#define CARDINAL_DIRECTION_H | ||
|
||
#include <string> | ||
|
||
#include "Coord.h" | ||
#include "../Math/Vector2.h" | ||
|
||
enum class CardinalDirectionName; | ||
|
||
// North, northeast, southwest, etc.. | ||
namespace CardinalDirection | ||
{ | ||
// Cardinal directions in the XZ plane (bird's eye view). | ||
// CANNOT INITIALIZE FROM VOXELUTILS due to global initialization order uncertainty. | ||
const WorldDouble2 North(-1.0, 0.0); | ||
const WorldDouble2 South(1.0, 0.0); | ||
const WorldDouble2 East(0.0, -1.0); | ||
const WorldDouble2 West(0.0, 1.0); | ||
|
||
CardinalDirectionName getDirectionName(const WorldDouble2 &direction); | ||
const std::string &toString(CardinalDirectionName directionName); | ||
} | ||
|
||
#endif |
Oops, something went wrong.