This commit is contained in:
InventorXtreme 2024-03-29 15:34:35 -04:00
parent 7f9cd7ef7c
commit cce6a90cbd
2 changed files with 16 additions and 15 deletions

14
c3d.c
View file

@ -124,7 +124,7 @@ void Tri2DSortByY(Tri2D *t) {
} }
void DrawScanline(Zee *zee, Tri2D *trianglepointer, double start, double end, int scanline) { void DrawScanline(Zee *zee, Tri2D *trianglepointer, double start, double end, int scanline) {
float depth = 0;
Vector3 f1baryatpoint = Tri2DBaryAtPoint(trianglepointer, (Vector2){Max(start, 0), scanline}); Vector3 f1baryatpoint = Tri2DBaryAtPoint(trianglepointer, (Vector2){Max(start, 0), scanline});
float f1depth = DepthAtBary(trianglepointer, f1baryatpoint); float f1depth = DepthAtBary(trianglepointer, f1baryatpoint);
@ -137,13 +137,15 @@ void DrawScanline(Zee *zee, Tri2D *trianglepointer, double start, double end, in
for (int i = (Max(start, 0)); i < (Min(end, RENDERWIDTH)); i++) { for (int i = (Max(start, 0)); i < (Min(end, RENDERWIDTH)); i++) {
/* zee[IndexOfZBuff(i, scanline)].triangle = tp; */ /* zee[IndexOfZBuff(i, scanline)].triangle = tp; */
/* Vector3 baryatpoint = Tri2DBaryAtPoint(tp, (Vector2){i, scanline}); */
/* float depth = DepthAtBary(tp, baryatpoint); */
float aproxdepth = f1depth + (dslope * ((float)i - (float)(Max(start, 0)))); //UNCOMMENT TO DO TRUE NON SLOPE BASED DEPTH CALC:
if (aproxdepth > zee[IndexOfZBuff(i, scanline)].depth) { /* Vector3 baryatpoint = Tri2DBaryAtPoint(trianglepointer, (Vector2){i, scanline}); */
/* depth = DepthAtBary(trianglepointer, baryatpoint); */
depth = f1depth + (dslope * ((float)i - (float)(Max(start, 0))));
if (depth > zee[IndexOfZBuff(i, scanline)].depth) {
zee[IndexOfZBuff(i, scanline)].c = trianglepointer->color; zee[IndexOfZBuff(i, scanline)].c = trianglepointer->color;
zee[IndexOfZBuff(i, scanline)].depth = aproxdepth; zee[IndexOfZBuff(i, scanline)].depth = depth;
//zee[IndexOfZBuff(i, scanline)].tri = trianglepointer; //zee[IndexOfZBuff(i, scanline)].tri = trianglepointer;
} }
} }

View file

@ -16,6 +16,12 @@ struct LocalCam {
}; };
typedef struct LocalCam LocalCam; typedef struct LocalCam LocalCam;
struct CMaterial {
char * name;
char * texturefile;
};
typedef struct CMaterial CMaterial;
struct Tri { struct Tri {
Vector3 a; Vector3 a;
Vector3 b; Vector3 b;
@ -23,17 +29,14 @@ struct Tri {
Color color; Color color;
Material material;
Vector2 auv; Vector2 auv;
Vector2 buv; Vector2 buv;
Vector2 cuv; Vector2 cuv;
}; };
struct Mat {
char * name;
char * file;
}
typedef struct Tri Tri; typedef struct Tri Tri;
@ -42,8 +45,6 @@ struct Tri2D {
Vector2 b; Vector2 b;
Vector2 c; Vector2 c;
float adepth; float adepth;
float bdepth; float bdepth;
float cdepth; float cdepth;
@ -76,8 +77,6 @@ struct Tri2DArray {
}; };
typedef struct Tri2DArray Tri2DArray; typedef struct Tri2DArray Tri2DArray;
struct Object3D { struct Object3D {
char name[100]; char name[100];
TriArray * triangles; TriArray * triangles;