mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-23 20:59:58 +01:00
Fix index overflows
This commit is contained in:
parent
010f5b3e59
commit
41caa6030d
2 changed files with 11 additions and 9 deletions
|
@ -82,19 +82,21 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
|
||||
S3L_normalizeVec3(&normal);
|
||||
|
||||
uint8_t shading =
|
||||
S3L_clamp((S3L_dotProductVec3(normal,toLight) + S3L_FRACTIONS_PER_UNIT) / 4,0,255);
|
||||
S3L_Unit shading =
|
||||
(S3L_dotProductVec3(normal,toLight) + S3L_FRACTIONS_PER_UNIT) / 2;
|
||||
|
||||
shading = S3L_interpolate(shading,0,p->depth,32 * S3L_FRACTIONS_PER_UNIT);
|
||||
|
||||
int index = (p->y * S3L_RESOLUTION_X + p->x) * 3;
|
||||
|
||||
frameBuffer[index] = shading;
|
||||
frameBuffer[index + 1] = shading;
|
||||
frameBuffer[index + 2] = shading;
|
||||
frameBuffer[index] = S3L_clamp(S3L_interpolateByUnitFrom0(200,shading),0,255);
|
||||
frameBuffer[index + 1] = S3L_clamp(S3L_interpolateByUnitFrom0(255,shading),0,255);
|
||||
frameBuffer[index + 2] = S3L_clamp(S3L_interpolateByUnitFrom0(150,shading),0,255);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
S3L_setVec4(&toLight,10,10,10,0);
|
||||
S3L_setVec4(&toLight,10,-10,-10,0);
|
||||
|
||||
S3L_normalizeVec3(&toLight);
|
||||
|
||||
|
|
|
@ -982,7 +982,7 @@ void S3L_getIndexedTriangleValues(
|
|||
S3L_Vec4 *v1,
|
||||
S3L_Vec4 *v2)
|
||||
{
|
||||
S3L_Index i0, i1;
|
||||
uint32_t i0, i1;
|
||||
S3L_Unit *value;
|
||||
|
||||
i0 = triangleIndex * 3;
|
||||
|
@ -1046,7 +1046,7 @@ void S3L_computeModelNormals(S3L_Model3D model, S3L_Unit *dst,
|
|||
(model.triangles[j + 2] == i))
|
||||
{
|
||||
S3L_Vec4 t0, t1, t2;
|
||||
S3L_Index vIndex;
|
||||
uint32_t vIndex;
|
||||
|
||||
#define getVertex(n)\
|
||||
vIndex = model.triangles[j + n] * 3;\
|
||||
|
@ -2437,7 +2437,7 @@ void _S3L_projectVertex(
|
|||
S3L_Vec4 *result,
|
||||
S3L_Unit focalLength)
|
||||
{
|
||||
S3L_Index vertexIndex = model->triangles[triangleIndex * 3 + vertex] * 3;
|
||||
uint32_t vertexIndex = model->triangles[triangleIndex * 3 + vertex] * 3;
|
||||
|
||||
result->x = model->vertices[vertexIndex];
|
||||
result->y = model->vertices[vertexIndex + 1];
|
||||
|
|
Loading…
Reference in a new issue