Start block shapes
This commit is contained in:
parent
84163d0d3c
commit
9e3bf000cf
8 changed files with 217 additions and 67 deletions
121
renderer.h
121
renderer.h
|
@ -23,45 +23,116 @@ struct LCR_Renderer
|
|||
S3L_Scene LCR_scene3D;
|
||||
S3L_Model3D LCR_models3D[3]; // TODO
|
||||
|
||||
S3L_Unit LCR_vertices3D[LCR_SETTING_MAX_VERTICES * 3];
|
||||
S3L_Index LCR_triangles3D[LCR_SETTING_MAX_TRIANGLES * 3];
|
||||
S3L_Model3D *LCR_mapModel;
|
||||
S3L_Unit LCR_mapVertices[LCR_SETTING_MAX_MAP_VERTICES * 3];
|
||||
S3L_Index LCR_mapTriangles[LCR_SETTING_MAX_MAP_TRIANGLES * 3];
|
||||
|
||||
void LCR_pixelFunc3D(S3L_PixelInfo *pixel)
|
||||
{
|
||||
LCR_drawPixelSafe(pixel->x,pixel->y,0xff00);
|
||||
LCR_drawPixelXYSafe(pixel->x,pixel->y,0xff00);
|
||||
}
|
||||
|
||||
S3L_Index _LCR_addMapVertex(S3L_Unit x, S3L_Unit y, S3L_Unit z)
|
||||
{
|
||||
S3L_Index index = 0;
|
||||
S3L_Unit *vertices = LCR_mapVertices;
|
||||
|
||||
while (index < LCR_mapModel->vertexCount) // if exists, return vertex index
|
||||
{
|
||||
if (vertices[0] == x && vertices[1] == y && vertices[2] == z)
|
||||
return index;
|
||||
|
||||
vertices += 3;
|
||||
index++;
|
||||
}
|
||||
|
||||
// if it doesn't exist, add it
|
||||
|
||||
if (LCR_mapModel->vertexCount < LCR_SETTING_MAX_MAP_VERTICES)
|
||||
{
|
||||
*vertices = x;
|
||||
vertices++;
|
||||
*vertices = y;
|
||||
vertices++;
|
||||
*vertices = z;
|
||||
LCR_mapModel->vertexCount++;
|
||||
return LCR_mapModel->vertexCount - 1;
|
||||
}
|
||||
|
||||
// TODO: error print
|
||||
return 0;
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
*t = a;
|
||||
t++;
|
||||
*t = b;
|
||||
t++;
|
||||
*t = c;
|
||||
|
||||
LCR_mapModel->triangleCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/** Builds an internal 3D model of the currently loaded map. Returns 1 on
|
||||
success, otherwise 0 (e.g. not enough space). */
|
||||
uint8_t LCR_buildMapModel(void)
|
||||
uint8_t _LCR_rendererBuildMapModel(void)
|
||||
{
|
||||
// TODO
|
||||
uint8_t blockShapeBytes[LCR_MAP_BLOCK_SHAPE_MAX_BYTES];
|
||||
uint8_t blockShapeByteCount;
|
||||
|
||||
LCR_vertices3D[0] = -2000;
|
||||
LCR_vertices3D[1] = -100;
|
||||
LCR_vertices3D[2] = 1000;
|
||||
S3L_model3DInit(LCR_mapVertices,0,LCR_mapTriangles,0,LCR_mapModel);
|
||||
|
||||
LCR_vertices3D[3] = 400;
|
||||
LCR_vertices3D[4] = -100;
|
||||
LCR_vertices3D[5] = 2000;
|
||||
LCR_mapGetBlockShape(0,0,blockShapeBytes,&blockShapeByteCount);
|
||||
|
||||
LCR_vertices3D[6] = 0;
|
||||
LCR_vertices3D[7] = 400;
|
||||
LCR_vertices3D[8] = 2000;
|
||||
uint8_t vx, vy, vz, vi = 0;
|
||||
uint8_t *bytes = blockShapeBytes;
|
||||
S3L_Index triangleIndices[3];
|
||||
|
||||
LCR_triangles3D[0] = 0;
|
||||
LCR_triangles3D[1] = 1;
|
||||
LCR_triangles3D[2] = 2;
|
||||
for (int i = 0; i < blockShapeByteCount; ++i)
|
||||
{
|
||||
LCR_decodeMapBlockCoords(blockShapeBytes[i],&vx,&vy,&vz);
|
||||
|
||||
printf("%d: %d %d %d\n",blockShapeBytes[i],vx,vy,vz);
|
||||
|
||||
triangleIndices[vi] = _LCR_addMapVertex(
|
||||
(LCR_SQUARE_SIDE_LEN * ((LCR_SpaceUnit) vx)) / 12,
|
||||
(LCR_SQUARE_SIDE_LEN / 2 * ((LCR_SpaceUnit) vy)) / 12,
|
||||
(LCR_SQUARE_SIDE_LEN * ((LCR_SpaceUnit) 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;
|
||||
}
|
||||
|
||||
uint8_t LCR_rendererInit(void)
|
||||
{
|
||||
if (!LCR_buildMapModel())
|
||||
LCR_mapModel = LCR_models3D;
|
||||
|
||||
if (!_LCR_rendererBuildMapModel())
|
||||
return 0;
|
||||
|
||||
S3L_model3DInit(LCR_vertices3D,3,LCR_triangles3D,1,LCR_models3D);
|
||||
S3L_sceneInit(LCR_models3D,1,&LCR_scene3D);
|
||||
|
||||
return 1;
|
||||
|
@ -108,6 +179,14 @@ void LCR_rendererDraw(void)
|
|||
|
||||
void LCR_drawBackground(int verticalOffset)
|
||||
{
|
||||
|
||||
// TODO
|
||||
|
||||
for (int y = 0; y < LCR_EFFECTIVE_RESOLUTION_Y; ++y)
|
||||
for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x)
|
||||
LCR_drawPixelXYUnsafe(x,y,0xffff);
|
||||
|
||||
/*
|
||||
uint16_t color = LCR_skyImages[LCR_skyImages[256] & 0x00ff] ; // TODO
|
||||
int limit = verticalOffset - LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE / 2;
|
||||
|
||||
|
@ -128,11 +207,13 @@ void LCR_drawBackground(int verticalOffset)
|
|||
for (int y = LCR_EFFECTIVE_RESOLUTION_Y - 1; y >= limit; --y)
|
||||
for (int x = 0; x < LCR_EFFECTIVE_RESOLUTION_X; ++x)
|
||||
LCR_drawPixelUnsafe(x,y,color);
|
||||
*/
|
||||
}
|
||||
|
||||
void LCR_drawSkyStrip(int verticalOffset, uint8_t horizontalOffset)
|
||||
{
|
||||
#if LCR_SETTING_SKY_SIZE != 0
|
||||
/*
|
||||
verticalOffset -= (LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE) / 2;
|
||||
|
||||
int finalY = verticalOffset + LCR_SETTING_SKY_SIZE * LCR_SKY_IMAGE_SIZE;
|
||||
|
@ -173,7 +254,7 @@ void LCR_drawSkyStrip(int verticalOffset, uint8_t horizontalOffset)
|
|||
if (verticalOffset % LCR_SETTING_SKY_SIZE == 0)
|
||||
skyLine += LCR_SKY_IMAGE_SIZE / 2;
|
||||
}
|
||||
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue