Libprimis
Imprimis' 3D destroyable world engine
|
The fundemental building block of the octree world, representing a 3D cube. More...
#include <octa.h>
Public Member Functions | |
bool | isempty () const |
returns if the cube is empty (face 0 does not exist) | |
bool | issolid () const |
returns if the cube passed is entirely solid (no distortions) | |
void | setmat (ushort mat, ushort matmask, ushort filtermat, ushort filtermask, int filtergeom) |
Sets a cube's materials, given a material & filter to use. | |
void | discardchildren (bool fixtex=false, int depth=0) |
discards children | |
void | calcmerges () |
Merges adjacent faces that can be losslessly merged. | |
bool | isvalidcube () const |
Returns whether the cube is valid. | |
Public Attributes | ||
std::array< cube, 8 > * | children | |
cubeext * | ext | |
union { | ||
uchar edges [12] | ||
uint faces [3] | ||
}; | ||
ushort | texture [6] | |
ushort | material | |
uchar | merged | |
union { | ||
uchar escaped | ||
uchar visible | ||
}; | ||
bool | valid | |
Friends | |
bool | operator== (const cfkey &x, const cfkey &y) |
The fundemental building block of the octree world, representing a 3D cube.
The main rendered object in the world is an octree (8-leaf tree) comprising of objects of this type. Each cube object has its own deformation information, texture information, and a handful of utility functions as well as pointing to up to eight children in a fractal manner.
Cube objects are the game-facing abstraction which the renderer itself does not use; they are converted to vertex arrays
by the engine which requires calculation by itself. However, the octree structure is capable of a relatively simple and effective representation of detail over several orders of magnitude.
The integer indices for the textures are shown below.
The integer indices of the 8 children are shown below.
The integer indices of the 12 edges are shown below.
void cube::calcmerges | ( | ) |
Merges adjacent faces that can be losslessly merged.
Merges adjacent faces, provided that the resulting cube created is no larger than the maxmerge
gridpower size. Faces resulting from the merge process are always lossless; therefore the previously existing cubes must be coplanar prior to the merge request.
Applies to all children of this cube, and also all adjacent cubes at the same level as this cube. This function is assumed to be called from the first element of an octree (eight element) array and will fail ungracefully if this condition is not satisfied.
void cube::discardchildren | ( | bool | fixtex = false, |
int | depth = 0 ) |
discards children
fixtex | toggles fixing the texture of the resulting cube |
depth | at which to stop discarding |
|
inline |
returns if the cube is empty (face 0 does not exist)
note that a non-empty (but distorted) cube missing faces for an axis is impossible unless there are no faces at all (impossible to construct a 3d cube otherwise)
bool cube::isvalidcube | ( | ) | const |
Returns whether the cube is valid.
If the cube is not convex, this function returns true, otherwise it returns false.
void cube::setmat | ( | ushort | mat, |
ushort | matmask, | ||
ushort | filtermat, | ||
ushort | filtermask, | ||
int | filtergeom ) |
Sets a cube's materials, given a material & filter to use.
Modifies the material properties of a cube object, given the various filtering parameters.
c | the cube object to use |
mat | material index to apply |
matmask | material mask |
filtermat | if nonzero, determines what existing mats to apply to |
filtermask | filter material mask |
filtergeom | type of geometry inside the cube (empty, solid, partially solid) |
std::array<cube, 8>* cube::children |
points to 8 cube structures which are its children, or nullptr. -Z first, then -Y, -X. If children[0] == nullptr, assume there are no children.
uchar cube::edges[12] |
edges of the cube, each uchar is 2 4bit values denoting the range. see documentation jpgs for more info.
uchar cube::escaped |
mask of which children have escaped merges
cubeext* cube::ext |
extended info for the cube
uint cube::faces[3] |
4 edges of each dimension together representing 2 perpendicular faces
ushort cube::material |
empty-space material, bitmask created from available mats
uchar cube::merged |
merged faces of the cube
ushort cube::texture[6] |
one for each face. same order as orient.
bool cube::valid |
status of the cube:
uchar cube::visible |
visibility info for faces