diff --git a/c3d.c b/c3d.c index e6825bc..80c7a61 100644 --- a/c3d.c +++ b/c3d.c @@ -124,7 +124,7 @@ void Tri2DSortByY(Tri2D *t) { } void DrawScanline(Zee *zee, Tri2D *trianglepointer, double start, double end, int scanline) { - + float depth = 0; Vector3 f1baryatpoint = Tri2DBaryAtPoint(trianglepointer, (Vector2){Max(start, 0), scanline}); 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++) { /* 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)))); - if (aproxdepth > zee[IndexOfZBuff(i, scanline)].depth) { + //UNCOMMENT TO DO TRUE NON SLOPE BASED DEPTH CALC: + /* 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)].depth = aproxdepth; + zee[IndexOfZBuff(i, scanline)].depth = depth; //zee[IndexOfZBuff(i, scanline)].tri = trianglepointer; } } diff --git a/c3dtypes.h b/c3dtypes.h index 19601df..e2bb10c 100644 --- a/c3dtypes.h +++ b/c3dtypes.h @@ -16,6 +16,12 @@ struct LocalCam { }; typedef struct LocalCam LocalCam; +struct CMaterial { + char * name; + char * texturefile; +}; +typedef struct CMaterial CMaterial; + struct Tri { Vector3 a; Vector3 b; @@ -23,17 +29,14 @@ struct Tri { Color color; - + Material material; + Vector2 auv; Vector2 buv; Vector2 cuv; }; -struct Mat { - char * name; - char * file; -} typedef struct Tri Tri; @@ -42,8 +45,6 @@ struct Tri2D { Vector2 b; Vector2 c; - - float adepth; float bdepth; float cdepth; @@ -76,8 +77,6 @@ struct Tri2DArray { }; typedef struct Tri2DArray Tri2DArray; - - struct Object3D { char name[100]; TriArray * triangles;