#include <voxel_3.h>
Public Member Functions | |
voxel_3_c (unsigned int x, unsigned int y, unsigned int z, const gridType_c *gt, voxel_type init=0) | |
voxel_3_c (xmlParser_c &pars, const gridType_c *gt) | |
voxel_3_c (const voxel_c &orig) | |
voxel_3_c (const voxel_c *orig) | |
virtual bool | transform (unsigned int nr) |
the transformation function for cubic grids | |
bool | getNeighbor (unsigned int idx, unsigned int typ, int x, int y, int z, int *xn, int *yn, int *zn) const |
returns the coordinates for a neighbour to the given voxel | |
void | scale (unsigned int amount, bool grid) |
scale the space, making x by x by x cubes out of single cubes | |
bool | scaleDown (unsigned char by, bool action) |
Scale down voxel space by a certain amount. | |
void | resizeInclude (int &px, int &py, int &pz) |
resizes and translates the space so that the the given voxel can be included the function returns the new coordinate of the point. | |
void | minimizePiece (void) |
changes the size of the voxel space to the smallest size so that all voxels whose value is not 0 can be contained. | |
virtual bool | validCoordinate (int x, int y, int z) const |
Return if a given coordinate is valid to use. | |
bool | identicalInBB (const voxel_c *op, bool includeColors=true) const |
Comparison of two voxel spaces. | |
bool | onGrid (int x, int y, int z) const |
this function is used to find out if the given position is of the same voxel type as the voxel at position 0. | |
virtual bool | meshParamsValid (double bevel, double offset) const |
void | getConnectionFace (int x, int y, int z, int n, double bevel, double offset, std::vector< float > &faceCorners) const |
this function must return a polygon that is the connecting face to the neighbor n for the voxel at position x, y, z The function is used by the default implementation of getMesh to generate the default basis mesh it is also used by the 3D cursor drawing code | |
void | calculateSize (float *x, float *y, float *z) const |
calculate the size, that the returned mesh has | |
void | recalcSpaceCoordinates (float *x, float *y, float *z) const |
Private Member Functions | |
void | operator= (const voxel_3_c &) |
This grid builds on top of the cube grid. The rhombic grid is emulated using cubes. So this class uses many functions from the cubes voxel space.
This class mainly adds alignment functionality for transformations and the neighbor functionality.
The rhombic grid emulation is explained in the user guide with some graphics, here I can place only a textual description which might be hard to understand.
It is possible to halve a cube in such a way that you get 2 prisms with a triangle as base face. This triangle has a shape of an rectangular triangle with sides of length 1, 1 and sqrt(2). There are 2*3 = 6 such cuts possible. If you do all those 6 cuts on a cube you get 24 little irregular but identical tetrahedras. Those are the building blocks of the rhombic grid.
The cube with its 24 tetrahedras is emulated in a 5x5x5 sized cube within the cubic grid. The 24 tetrahedras are located as little diamonds on each of the six faces of the 5x5x5 cube. That makes 6 faces with 4 cubes each = 24 voxels.
Have a look at the user guide to see this and play with BurrTools to understand the grid.
With this grid it is possible to build rhombic dodecahedrons. The grid needs alignment of 5 in each direction to ensure voxels don't change parity when the shape is rotated. Also translations can only be done in multiples of 5 and so on...
voxel_3_c::voxel_3_c | ( | unsigned int | x, | |
unsigned int | y, | |||
unsigned int | z, | |||
const gridType_c * | gt, | |||
voxel_type | init = 0 | |||
) | [inline] |
voxel_3_c::voxel_3_c | ( | xmlParser_c & | pars, | |
const gridType_c * | gt | |||
) | [inline] |
voxel_3_c::voxel_3_c | ( | const voxel_c & | orig | ) | [inline] |
voxel_3_c::voxel_3_c | ( | const voxel_c * | orig | ) | [inline] |
void voxel_3_c::calculateSize | ( | float * | x, | |
float * | y, | |||
float * | z | |||
) | const [virtual] |
calculate the size, that the returned mesh has
Reimplemented from voxel_0_c.
References voxel_c::getX(), voxel_c::getY(), and voxel_c::getZ().
void voxel_3_c::getConnectionFace | ( | int | , | |
int | , | |||
int | , | |||
int | , | |||
double | , | |||
double | , | |||
std::vector< float > & | ||||
) | const [virtual] |
this function must return a polygon that is the connecting face to the neighbor n for the voxel at position x, y, z The function is used by the default implementation of getMesh to generate the default basis mesh it is also used by the 3D cursor drawing code
Reimplemented from voxel_0_c.
References bt_assert, intdiv_inf(), and voxel_c::voxels.
bool voxel_3_c::getNeighbor | ( | unsigned int | idx, | |
unsigned int | typ, | |||
int | x, | |||
int | y, | |||
int | z, | |||
int * | xn, | |||
int * | yn, | |||
int * | zn | |||
) | const [virtual] |
returns the coordinates for a neighbour to the given voxel
idx is the index if the neighbour, if you want the next neighbour, give the next number typ is what kind of neighbour you want, face (0), edge (1) or corner (2) x, y, z coordinate for the source xn, yn, zn, coordinate for the neighbour return true, when a valid neighbour with that index exists
This function is different for different grids. There is no default implementation, so each grid has to define its own version of this function
Reimplemented from voxel_0_c.
References coordinateToggling(), and intdiv_inf().
bool voxel_3_c::identicalInBB | ( | const voxel_c * | op, | |
bool | includeColors = true | |||
) | const [virtual] |
Comparison of two voxel spaces.
2 voxel spaces are identical, if their bounding boxes have the same size and the voxels within there boxes is identical
if includeColors is true, the colours are included in the comparison, meaning when the colours differ the shapes are not equal, otherwise only the states are compared
There are special conditions to take care in different grid (e.g alignment along a bigger grid) so this function can be overloaded. The default implementation simply treats all voxels equal
Reimplemented from voxel_c.
References voxel_c::boundX1(), voxel_c::boundY1(), voxel_c::boundZ1(), voxel_c::bx1, voxel_c::by1, and voxel_c::bz1.
bool voxel_3_c::meshParamsValid | ( | double | bevel, | |
double | offset | |||
) | const [virtual] |
Reimplemented from voxel_0_c.
void voxel_3_c::minimizePiece | ( | void | ) | [virtual] |
changes the size of the voxel space to the smallest size so that all voxels whose value is not 0 can be contained.
as in some grids there are special conditions to consider when doing this operation the function can be overloaded. This default implementation will minimize to the bounding box.
Reimplemented from voxel_c.
References voxel_c::bx1, voxel_c::by1, voxel_c::bz1, voxel_c::resize(), voxel_c::sx, voxel_c::sy, voxel_c::sz, and voxel_c::translate().
bool voxel_3_c::onGrid | ( | int | x, | |
int | y, | |||
int | z | |||
) | const [virtual] |
this function is used to find out if the given position is of the same voxel type as the voxel at position 0.
This is used to find out if a piece can be placed at a certain position in a voxel grid
Reimplemented from voxel_0_c.
void voxel_3_c::operator= | ( | const voxel_3_c & | ) | [private] |
void voxel_3_c::recalcSpaceCoordinates | ( | float * | x, | |
float * | y, | |||
float * | z | |||
) | const [virtual] |
Reimplemented from voxel_c.
void voxel_3_c::resizeInclude | ( | int & | px, | |
int & | py, | |||
int & | pz | |||
) | [virtual] |
resizes and translates the space so that the the given voxel can be included the function returns the new coordinate of the point.
Each grid has to implement it's own version because there are different kinds of supergrids that are imposed on the normal grid
Reimplemented from voxel_0_c.
References voxel_c::getX(), voxel_c::getY(), voxel_c::getZ(), voxel_c::resize(), and voxel_c::translate().
void voxel_3_c::scale | ( | unsigned int | amount, | |
bool | grid | |||
) | [virtual] |
scale the space, making x by x by x cubes out of single cubes
This must be done differently by all grids. The default implementation doesn't do anything. It's just there to allow grids without scaling as not all grid have such a possibility (e.g. spheres can't be scaled) if grid is true (not all functions need to support this) the result it not filled, but rather a grid with only the outer edges filled
Reimplemented from voxel_0_c.
References voxel_c::count(), voxel_c::hx, voxel_c::hy, voxel_c::hz, voxel_c::isEmpty2(), voxel_c::recalcBoundingBox(), voxel_c::space, voxel_c::sx, voxel_c::sy, voxel_c::sz, voxel_c::voxels, and voxel_c::VX_EMPTY.
bool voxel_3_c::scaleDown | ( | unsigned char | by, | |
bool | action | |||
) | [virtual] |
Scale down voxel space by a certain amount.
for the minimize scale function applied to all shapes we need to first check, if all shapes can be scaled down by a certain factor and then do it. If action is true, then the shape is really scaled, otherwise you only get the fact if it is scalable by the given amount
This must be done differently by all grids. The default implementation doesn't do anything. It's just there to allow grids without scaling as not all grid have such a possibility (e.g. spheres can't be scaled)
Reimplemented from voxel_0_c.
bool voxel_3_c::transform | ( | unsigned int | nr | ) | [virtual] |
the transformation function for cubic grids
The nice thing about the cubic grid is that we can easily calculate how big the grid will be after the transformation, we can also easily calculate the new bounding box and the now position for the hotspot.
This makes this transformation function faster than the other 2 variations for spheres and triangles
Reimplemented from voxel_0_c.
References voxel_c::getX(), voxel_c::getY(), voxel_c::getZ(), voxel_c::resize(), voxel_c::sx, voxel_c::sy, and voxel_c::sz.
bool voxel_3_c::validCoordinate | ( | int | x, | |
int | y, | |||
int | z | |||
) | const [virtual] |
Return if a given coordinate is valid to use.
In some voxel spaces not all possible coordinates are valid. For example in the sphere grid only the coordinates with (x+y+z) % 2 == 0 are valid This function does that calculation
Reimplemented from voxel_0_c.