Class AABB
Defined in File AABB.h
Class Documentation
-
class AABB
This file defines the members and methods implemented as part of the AABB class.
This class represents an Axis Aligned Bounding Box as seen from the top-view of the Minecraft X-Z plane.
Public Functions
-
Pos getTopLeft()
Returns a copy of the Pos object used to represent the top left of the AABB from the top view of the X-Z plane.
- Returns:
Pos The copy of the top left coordinate.
-
Pos getBottomRight()
Returns a copy of the Pos object used to represent the bottom right of the AABB from the top view of the X-Z plane.
- Returns:
Pos The copy of the bottom right coordinate.
-
std::vector<std::unique_ptr<Block>> &getBlockList()
Get the block list specific to this AABB. Do not transfer ownership of any unique_ptr as it may cause scope issues.
- Returns:
The reference to the block list.
-
std::vector<std::unique_ptr<Entity>> &getEntityList()
Get the entity list specific to this AABB. Do not transfer ownership of any unique_ptr as it may cause scope issues.
- Returns:
The reference to the entity list.
-
std::vector<std::unique_ptr<Object>> &getObjectList()
Get the object list specific to this AABB. Do not transfer ownership of any unique_ptr as it may cause scope issues.
- Returns:
The reference to the object list.
-
std::vector<std::unique_ptr<AABB>> &getAABBList()
Gets the list of AABBs this AABB is the parent of. Do not transfer ownership of any unique_ptr as it may cause scope issues.
- Returns:
std::vector<AABB*>& Reference to the list of children AABBs.
-
std::vector<std::unique_ptr<Connection>> &getConnectionList()
Returns the Connection vector for this AABB. Do not transfer ownership of any unique_ptr as it may cause scope issues.
- Returns:
std::vector<Connection*>& The connection list.
-
int getMidpointX()
Get the midpoint X value calculated between the top left and bottom right x values.
- Returns:
int The midpoint X coordinate.
-
int getMidpointY()
Get the midpoint Y value calculated between the top left and bottom right y values.
- Returns:
int The midpoint Y coordinate
-
int getMidpointZ()
Get the midpoint Z value calculated between the top left and bottom right z values.
- Returns:
int The midpoint Z coordinate
-
int getSizeX()
Get the difference of the extreme x coordinates for this AABB.
- Returns:
int The difference
-
int getSizeY()
Get the difference of the extreme y coordinates for this AABB.
- Returns:
int The difference
-
int getSizeZ()
Get the difference of the extreme z coordinates for this AABB.
- Returns:
int The difference
-
virtual Pos getRandomPos(std::mt19937_64 &gen, int offsetPosX = 0, int offsetNegX = 0, int offsetPosY = 0, int offsetNegY = 0, int offsetPosZ = 0, int offsetNegZ = 0)
Get a random position in the AABB within the given offsets.
- Parameters:
gen – THe boost generation object to generate distributions from
offsetPosX – How far away from the left wall should the position be. Defaults to 0
offsetNegX – How far away from the right wall should the position be. Defaults to 0
offsetPosY – How far away from the left wall should the position be. Defaults to 0
offsetNegY – How far away from the right wall should the position be. Defaults to 0
offsetPosZ – How far away from the bottom wall should the position be. Defaults to 0
offsetNegZ – How far away from the top wall should the position be. Defaults to 0
- Returns:
Pos The random position
-
virtual std::vector<Pos> getEdgeMidpointAtBase()
Get a list of the positions of the edge midpoints for this AABB. The Y value for all these Pos objects is equal to the Y value of the AABB’s top left field which is considered the base.
- Returns:
vector<Pos> The list of coordinates as: top, right, bottom and left edge midpoints.
-
AABB *getSubAABB(std::string id)
Get a particular AABB contained by this AABB. The AABB can be identified by its ID. A unique pointer already owns this, so do not assign new ownership.
-
void setTopLeft(Pos &topLeft)
Set the top left coordinate of the AABB.
- Parameters:
topLeft – Pos object top left is to be set to
-
void setBottomRight(Pos &bottomRight)
Set the bottom right coordinate of the AABB.
- Parameters:
bottomRight – Pos object bottom right is to be set to
-
void setMaterial(std::string material)
Set the base building material.
- Parameters:
material – The base material
-
void addBlock(std::unique_ptr<Block> block)
Add a specific block for this AABB to keep track of. Ideally this should be related to the AABB. No checks are implicitly performed within this method.
- Parameters:
block – Block to be added
-
void addEntity(std::unique_ptr<Entity> entity)
Add a specific entity for this AABB to keep track of. Ideally this should be related to the AABB. No checks are implicitly performed within this method.
- Parameters:
entity – Entity to be added
-
void addObject(std::unique_ptr<Object> object)
Add a specific object for this AABB to keep track of. Ideally this should be related to the AABB. No checks are implicitly performed within this method.
- Parameters:
object – Object to be added
-
void addAABB(std::unique_ptr<AABB> aabb)
Adds an AABB that will be part of this AABB’s child list.
- Parameters:
aabb – The AABB to add.
-
void addConnection(std::unique_ptr<Connection> connection)
Add an connection to the vector of connection held inside the aabb.
- Parameters:
connection – The connection to add.
-
virtual bool intersects(AABB &other)
Checks to see if two AABBs overlap with each other (including the case where one AABB is fully contained within the other.
- Parameters:
other – The AABB to compare to
- Returns:
true When the AABBs do overlap
- Returns:
false When the AABBs don’t overlap
-
virtual void generateBox(std::string material, int offsetPosX = 0, int offsetNegX = 0, int offsetPosY = 0, int offsetNegY = 0, int offsetPosZ = 0, int offsetNegZ = 0)
Generate a box made of a specific material inside the AABB with the ability to specify offsets.
- Parameters:
material – The material to make this box out of
offsetPosX – How far away from the left wall should the position be. Defaults to 0
offsetNegX – How far away from the right wall should the position be. Defaults to 0
offsetPosY – How far away from the left wall should the position be. Defaults to 0
offsetNegY – How far away from the right wall should the position be. Defaults to 0
offsetPosZ – How far away from the bottom wall should the position be. Defaults to 0
offsetNegZ – How far away from the top wall should the position be. Defaults to 0
-
virtual void addRandomBlocks(int n, std::string material, std::mt19937_64 &gen, int offsetPosX = 0, int offsetNegX = 0, int offsetPosY = 0, int offsetNegY = 0, int offsetPosZ = 0, int offsetNegZ = 0)
Add n random blocks of the given type and material inside the AABB within the offset parameters.
- Parameters:
n – The number of blocks to add
material – The block’s material type
gen – THe boost generation object to generate distributions from
offsetPosX – How far away from the left wall should the position be. Defaults to 0
offsetNegX – How far away from the right wall should the position be. Defaults to 0
offsetPosY – How far away from the left wall should the position be. Defaults to 0
offsetNegY – How far away from the right wall should the position be. Defaults to 0
offsetPosZ – How far away from the bottom wall should the position be. Defaults to 0
offsetNegZ – How far away from the top wall should the position be. Defaults to 0
-
void shiftX(int shift)
Translate the AABB by the given amount in the X axis.
- Parameters:
shift – The amount to shift by which may be positive or negative
-
void shiftY(int shift)
Translate the AABB by the given amount in the Y axis.
- Parameters:
shift – The amount to shift by which may be positive or negative
-
void shiftZ(int shift)
Translate the AABB by the given amount in the Z axis.
- Parameters:
shift – The amount to shift by which may be positive or negative
-
void shift(int shiftX, int shiftY, int shiftZ)
Translates the AABB by the given amounts in the X, Y and Z axes.
- Parameters:
shiftX – The amount to shift by in X which may be positive or negative
shiftY – The amount to shift by in Y which may be positive or negative
shiftZ – The amount to shift by in Z which may be positive or negative
-
virtual void toSemanticMapJSON(nlohmann::json &json_base)
Adds the JSON representation of this object to the “locations” list of the base json.
- Returns:
nlohmann::json The base json
-
virtual void toLowLevelMapJSON(nlohmann::json &json_base)
Adds the alternate block by block JSON representation of this object to the “blocks” list of the base json.
- Returns:
nlohmann::json The base json
-
AABB(std::string id, std::string type, std::string material, Pos &topLeft, Pos &bottomRight, bool isHollow = true, bool hasRoof = false, bool autoAdjust = true)
Construct a new AABB object.
- Parameters:
id – The id associated with this AABB
type – A semantic name describing the type and/or purpose of the AABB
material – The material this AABB is built out of
topLeft – The coordinates of the top left of the AABB from the top view of the X-Z plane. Y coordinate should be lowest here.
bottomRight – The coordinates of the bottom right of the AABB from the top view of the X-Z plane. Y coordinate should be maximum here.
isHollow – Specify whether the AABB should be hollow or not. Defaults to true.
hasRoof – specify whether the AABB should have a roof or not. Defaults to false.
autoAdjust – Whether or not you want the boundary to auto adjust to its children. Defaults to true.
-
AABB(std::string id)
Construct a new AABB object. Use this contructor when you know the top left and bottom right positions will change in the future. Here, since the autoAdjust defaults to true and the base material is “blank”, it is effectively a blank canvas. It will resize when children AABB are added to it, and since it’s base material is blank, the WorldBuilder java class won’t place anything at locations marked with a material of type “blank.” All of this can of course be achieved with the other constructor, but this one makes the process more convenient.
- Parameters:
id – The id associated with this AABB
Protected Functions
-
void recalculateOverallBoundary()
-
Pos getTopLeft()