diff --git a/boxtex.png b/boxtex.png new file mode 100644 index 0000000..c7615da Binary files /dev/null and b/boxtex.png differ diff --git a/c3d.c b/c3d.c index 4717ad4..035601e 100644 --- a/c3d.c +++ b/c3d.c @@ -2,6 +2,7 @@ #include "raylib.h" #include "raymath.h" #include "reader.h" +#include "float.h" #include #include #include @@ -220,17 +221,20 @@ void DrawScanline(Zee *zee, Tri2D *trianglepointer, double start, double end, in for (int i = (Max(start, 0)); i < (Min(end, RENDERWIDTH)); i++) { // UNCOMMENT TO DO TRUE NON SLOPE BASED DEPTH CALC: - //Vector3 baryatpoint = Tri2DBaryAtPoint(trianglepointer, ( (Vector2){i, scanline})); - depth = 1.0 / (f1invdepth + (dinvslope * ((float)i - (float)(Max(start, 0))))); - //depth = 1.0 / InvDepthAtBary(trianglepointer, baryatpoint); + Vector3 baryatpoint = Tri2DBaryAtPoint(trianglepointer, ( (Vector2){i, scanline})); + //depth = 1.0 / (f1invdepth + (dinvslope * ((float)i - (float)(Max(start, 0))))); + depth = 1.0 / InvDepthAtBary(trianglepointer, baryatpoint); //UNCOMMENT TO DO REAL UV CALC - //UVpos = BaryAndTritoPoint(&UVRangeTri, baryatpoint); - //UVpos = GetUVFromTriAndBary(baryatpoint, trianglepointer, depth); + UVpos = BaryAndTritoPoint(&UVRangeTri, baryatpoint); + UVpos = GetUVFromTriAndBary(baryatpoint, trianglepointer, depth); + //V2Print(UVpos); - UVpos = Vector2Add(tex1point, Vector2Scale(UVSlope, ((float)i - (float)(Max(start, 0))))); + //UVpos = Vector2Add(tex1point, Vector2Scale(UVSlope, ((float)i - (float)(Max(start, 0))))); + Vector2 MAX_VEC2 = (Vector2) {FLT_MAX, FLT_MAX}; + UVpos = Vector2Clamp(UVpos, Vector2Zero(), MAX_VEC2); if (depth < zee[IndexOfZBuff(i, scanline)].depth) { CMaterial *mat = trianglepointer->material; @@ -640,7 +644,7 @@ int main() { bool run3d = true; - Object3D t = ReadObjectFromFile("IronMan.obj"); + Object3D t = ReadObjectFromFile("singletri.obj"); if (true) { for (int i = 0; i < t.triangles->length; i++) { // printf("t: %f\n", t.triangles->arr[i].a.x); diff --git a/singletri.mtl b/singletri.mtl index ce56451..6c720a9 100644 --- a/singletri.mtl +++ b/singletri.mtl @@ -9,4 +9,4 @@ Ke 0.000000 0.000000 0.000000 Ni 1.500000 d 1.000000 illum 2 -map_Kd /home/inventorx/Downloads/0.png +map_Kd boxtex.png