Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
cube Class Reference

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)
 

Detailed Description

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.

+z
| /+x
| /
|/___+y
______
/. /|
/ . 5 / |
/__.__/ |
| ...|3./
| .0 | /
|. |/
.-----/
______
/| .|
/ | 1. |
/..|... |
|2 |-----/
| / . /
|/ 4./
.-----/

The integer indices of the 8 children are shown below.

^ +z
|
__________
/ 4 / 5 /
/____/____/.
/ 6 / 7 / .
/____/____/ .
. _____.___.
. / 0 /. 1 / +x
. /____/_.__/ ->
. / 2 / 3. /
./____/___./
/ +y
|/

The integer indices of the 12 edges are shown below.

^ +z
|
|
_____2____
/ /
5 /.8 7/.
/ . / .
/_____3___/ .9
. . ._____.___.
10. / 0 . / +x
. 4/ 11. / ->
. / . /6
./________./
1
/ +y
|/

Member Function Documentation

◆ calcmerges()

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.

◆ discardchildren()

void cube::discardchildren ( bool fixtex = false,
int depth = 0 )

discards children

Parameters
fixtextoggles fixing the texture of the resulting cube
depthat which to stop discarding

◆ isempty()

bool cube::isempty ( ) const
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)

◆ isvalidcube()

bool cube::isvalidcube ( ) const

Returns whether the cube is valid.

If the cube is not convex, this function returns true, otherwise it returns false.

◆ setmat()

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.

Parameters
cthe cube object to use
matmaterial index to apply
matmaskmaterial mask
filtermatif nonzero, determines what existing mats to apply to
filtermaskfilter material mask
filtergeomtype of geometry inside the cube (empty, solid, partially solid)

Member Data Documentation

◆ children

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.

◆ edges

uchar cube::edges[12]

edges of the cube, each uchar is 2 4bit values denoting the range. see documentation jpgs for more info.

◆ escaped

uchar cube::escaped

mask of which children have escaped merges

◆ ext

cubeext* cube::ext

extended info for the cube

◆ faces

uint cube::faces[3]

4 edges of each dimension together representing 2 perpendicular faces

◆ material

ushort cube::material

empty-space material, bitmask created from available mats

◆ merged

uchar cube::merged

merged faces of the cube

◆ texture

ushort cube::texture[6]

one for each face. same order as orient.

◆ valid

bool cube::valid

status of the cube:

◆ visible

uchar cube::visible

visibility info for faces


The documentation for this class was generated from the following file: