Start block shapes
This commit is contained in:
parent
84163d0d3c
commit
9e3bf000cf
8 changed files with 217 additions and 67 deletions
57
map.h
57
map.h
|
@ -76,8 +76,8 @@
|
|||
#define LCR_BLOCK_LEFT_FRONT 0x03 ///< filled left front quarter of block
|
||||
#define LCR_BLOCK_BOTTOM_LEFT 0x04 ///< filled bottom left quarter of block
|
||||
|
||||
#define LCR_BLOCK_CHECKPOINT_NOT 0x10 ///< checkpoint, not taken
|
||||
#define LCR_BLOCK_CHECKPOINT_YES 0x11 ///< checkpoint, taken
|
||||
#define LCR_BLOCK_CHECKPOINT_0 0x10 ///< checkpoint, not taken
|
||||
#define LCR_BLOCK_CHECKPOINT_1 0x11 ///< checkpoint, taken
|
||||
#define LCR_BLOCK_FINISH 0x12 ///< finish
|
||||
|
||||
// special blocks:
|
||||
|
@ -274,18 +274,57 @@ const uint8_t *LCR_mapGetBlockAt(uint8_t x, uint8_t y, uint8_t z)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void _LCR_addBlockShapeByte(uint8_t *bytes, uint8_t *byteCount,
|
||||
int x, int y, int z)
|
||||
{
|
||||
if (*byteCount >= LCR_MAP_BLOCK_SHAPE_MAX_BYTES)
|
||||
return;
|
||||
|
||||
bytes[*byteCount] = (5 * 7) * z + 7 * y + x;
|
||||
*byteCount += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
Gets a shape of given map block type as a 3D model composed of triangles. The
|
||||
model is returned as an array of 16 bit ints, each of which represents
|
||||
X with lowest 5 bits, Y with next 5 bits and Z with next 5 bits (the
|
||||
directions of axes are same as map X, Y, Z directions). Each coordinate can
|
||||
go from 0 to 16; WATCH OUT, THIS IS 17 VALUES, NOT 16, so as to allow having
|
||||
a mid coord (8), mid-mid coords (4, 12) and mid-mid-mid coords.
|
||||
model is returned as an array of byte triplets (triangles), with each byte
|
||||
representing one coordinate. These coordinates can be decoded with
|
||||
LCR_decodeMapBlockCoords function.
|
||||
*/
|
||||
void LCR_mapGetBlockShape(uint8_t blockType, uint8_t transform,
|
||||
uint16_t triangles[LCR_MAP_BLOCK_SHAPE_MAX_TRIANGLES * 3],
|
||||
uint8_t *triangleCount)
|
||||
uint8_t bytes[LCR_MAP_BLOCK_SHAPE_MAX_BYTES], uint8_t *byteCount)
|
||||
{
|
||||
/*
|
||||
The coordinate format is following: byte B specifies coordinates X (0 to 6)
|
||||
= B % 7, Y (vertical, 0 to 4) = (B / 7) % 5, Z (0 to 6) = B % 35.
|
||||
*/
|
||||
|
||||
*byteCount = 0;
|
||||
|
||||
switch (blockType)
|
||||
{
|
||||
case LCR_BLOCK_FULL:
|
||||
default:
|
||||
_LCR_addBlockShapeByte(bytes,byteCount,0,0,1);
|
||||
_LCR_addBlockShapeByte(bytes,byteCount,5,0,1);
|
||||
_LCR_addBlockShapeByte(bytes,byteCount,0,1,3);
|
||||
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Decodes XYZ coordinates encoded in a byte returned by LCR_mapGetBlockShape.
|
||||
Each coordinate will be in range 0 to 12 (including both). This unusual range
|
||||
is intentional as it for example has an exact mid value.
|
||||
*/
|
||||
void LCR_decodeMapBlockCoords(uint8_t byte, uint8_t *x, uint8_t *y, uint8_t *z)
|
||||
{
|
||||
*x = (byte % 7) * 2;
|
||||
*y = ((byte / 7) % 5) * 3;
|
||||
*z = (byte % 35) * 2;
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue