Continue blocks shapes
This commit is contained in:
parent
c4d56de0d4
commit
5567863745
4 changed files with 112 additions and 75 deletions
81
renderer.h
81
renderer.h
|
@ -13,16 +13,12 @@
|
|||
|
||||
#include "small3dlib.h"
|
||||
|
||||
/**
|
||||
Renderer specific unit, length of one map square.
|
||||
*/
|
||||
/// Renderer specific unit, length of one map square.
|
||||
#define LCR_RENDERER_UNIT S3L_FRACTIONS_PER_UNIT
|
||||
|
||||
struct LCR_Renderer
|
||||
{
|
||||
// TODO
|
||||
|
||||
|
||||
};
|
||||
|
||||
S3L_Scene LCR_scene3D;
|
||||
|
@ -34,7 +30,7 @@ S3L_Index LCR_mapTriangles[LCR_SETTING_MAX_MAP_TRIANGLES * 3];
|
|||
|
||||
void LCR_pixelFunc3D(S3L_PixelInfo *pixel)
|
||||
{
|
||||
LCR_drawPixelXYSafe(pixel->x,pixel->y, 0xff00 + (pixel->triangleID % 16) * 16 );
|
||||
LCR_drawPixelXYSafe(pixel->x,pixel->y,0xff00 + (pixel->triangleID % 16) * 16 );
|
||||
}
|
||||
|
||||
S3L_Index _LCR_addMapVertex(S3L_Unit x, S3L_Unit y, S3L_Unit z)
|
||||
|
@ -52,7 +48,6 @@ S3L_Index _LCR_addMapVertex(S3L_Unit x, S3L_Unit y, S3L_Unit z)
|
|||
}
|
||||
|
||||
// if it doesn't exist, add it
|
||||
|
||||
if (LCR_mapModel->vertexCount < LCR_SETTING_MAX_MAP_VERTICES)
|
||||
{
|
||||
*vertices = x;
|
||||
|
@ -72,7 +67,7 @@ void _LCR_addMapTriangle(S3L_Index a, S3L_Index b, S3L_Index c)
|
|||
{
|
||||
if (LCR_mapModel->triangleCount < LCR_SETTING_MAX_MAP_TRIANGLES)
|
||||
{
|
||||
S3L_Index *t = &(LCR_mapModel->triangles[LCR_mapModel->triangleCount * 3]);
|
||||
S3L_Index *t = &(LCR_mapTriangles[LCR_mapModel->triangleCount * 3]);
|
||||
|
||||
*t = a;
|
||||
t++;
|
||||
|
@ -84,8 +79,10 @@ void _LCR_addMapTriangle(S3L_Index a, S3L_Index b, S3L_Index c)
|
|||
}
|
||||
}
|
||||
|
||||
/** Builds an internal 3D model of the currently loaded map. Returns 1 on
|
||||
success, otherwise 0 (e.g. not enough space). */
|
||||
/**
|
||||
Builds an internal 3D model of the currently loaded map. Returns 1 on success,
|
||||
otherwise 0 (e.g. not enough space).
|
||||
*/
|
||||
uint8_t _LCR_rendererBuildMapModel(void)
|
||||
{
|
||||
uint8_t blockShapeBytes[LCR_MAP_BLOCK_SHAPE_MAX_BYTES];
|
||||
|
@ -93,41 +90,39 @@ uint8_t _LCR_rendererBuildMapModel(void)
|
|||
|
||||
S3L_model3DInit(LCR_mapVertices,0,LCR_mapTriangles,0,LCR_mapModel);
|
||||
|
||||
LCR_mapGetBlockShape(0,
|
||||
|
||||
LCR_BLOCK_TRANSFORM_ROT_270
|
||||
,blockShapeBytes,&blockShapeByteCount);
|
||||
|
||||
uint8_t vx, vy, vz, vi = 0;
|
||||
uint8_t *bytes = blockShapeBytes;
|
||||
S3L_Index triangleIndices[3];
|
||||
|
||||
for (int i = 0; i < blockShapeByteCount; ++i)
|
||||
{
|
||||
LCR_decodeMapBlockCoords(blockShapeBytes[i],&vx,&vy,&vz);
|
||||
|
||||
triangleIndices[vi] = _LCR_addMapVertex(
|
||||
(LCR_RENDERER_UNIT * ((S3L_Unit) vx)) / 12,
|
||||
(LCR_RENDERER_UNIT / 2 * ((S3L_Unit) vy)) / 12,
|
||||
(LCR_RENDERER_UNIT * ((S3L_Unit) vz)) / 12);
|
||||
|
||||
if (vi < 2)
|
||||
vi++;
|
||||
else
|
||||
for (int j = 0; j < LCR_currentMap.blockCount; ++j)
|
||||
{
|
||||
_LCR_addMapTriangle(
|
||||
triangleIndices[0],triangleIndices[1],triangleIndices[2]);
|
||||
vi = 0;
|
||||
uint8_t bx, by, bz;
|
||||
LCR_mapBlockGetCoords(LCR_currentMap.blocks + j * LCR_BLOCK_SIZE,&bx,&by,&bz);
|
||||
|
||||
LCR_mapGetBlockShape(LCR_currentMap.blocks[j * LCR_BLOCK_SIZE],0,
|
||||
blockShapeBytes,&blockShapeByteCount);
|
||||
|
||||
uint8_t vx, vy, vz, vi = 0;
|
||||
uint8_t *bytes = blockShapeBytes;
|
||||
S3L_Index triangleIndices[3];
|
||||
|
||||
S3L_Unit originOffset = -1 * LCR_MAP_SIZE_BLOCKS / 2 * LCR_RENDERER_UNIT;
|
||||
|
||||
for (int i = 0; i < blockShapeByteCount; ++i)
|
||||
{
|
||||
LCR_decodeMapBlockCoords(blockShapeBytes[i],&vx,&vy,&vz);
|
||||
|
||||
triangleIndices[vi] = _LCR_addMapVertex(
|
||||
originOffset + (((S3L_Unit) bx) * LCR_RENDERER_UNIT) + (LCR_RENDERER_UNIT * ((S3L_Unit) vx)) / 12,
|
||||
(originOffset + (((S3L_Unit) by) * LCR_RENDERER_UNIT)) / 2 + (LCR_RENDERER_UNIT / 2 * ((S3L_Unit) vy)) / 12,
|
||||
originOffset + (((S3L_Unit) bz) * LCR_RENDERER_UNIT) + (LCR_RENDERER_UNIT * ((S3L_Unit) vz)) / 12);
|
||||
|
||||
if (vi < 2)
|
||||
vi++;
|
||||
else
|
||||
{
|
||||
_LCR_addMapTriangle(
|
||||
triangleIndices[0],triangleIndices[1],triangleIndices[2]);
|
||||
vi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
a = _LCR_addMapVertex(-2000,-100,1000);
|
||||
b = _LCR_addMapVertex(400,-100,2000);
|
||||
c = _LCR_addMapVertex(0,400,2000);
|
||||
|
||||
_LCR_addMapTriangle(a,b,c);
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue