summaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-09-26 15:22:02 +0000
committerrodri <rgl@antares-labs.eu>2024-09-26 15:22:02 +0000
commit3155c6737832c54310c70ecaaf8667d0362de5e8 (patch)
tree5046974fdbaef855fb29d19671a9b80a9deb41f2 /render.c
parenta8c789be9ab0fec65004118b7df373e84900cb1a (diff)
downloadlibgraphics-3155c6737832c54310c70ecaaf8667d0362de5e8.tar.gz
libgraphics-3155c6737832c54310c70ecaaf8667d0362de5e8.tar.bz2
libgraphics-3155c6737832c54310c70ecaaf8667d0362de5e8.zip
implement a parser for a model(6). get rid of the libobj dependency.
Diffstat (limited to 'render.c')
-rw-r--r--render.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/render.c b/render.c
index 5a4f5b6..cc5a201 100644
--- a/render.c
+++ b/render.c
@@ -4,7 +4,6 @@
#include <draw.h>
#include <memdraw.h>
#include <geometry.h>
-#include "libobj/obj.h"
#include "graphics.h"
#include "internal.h"
@@ -155,7 +154,7 @@ _barycoords(Triangle2 t, Point2 p)
Point3 v = crossvec3(Vec3(p0p2.x, p0p1.x, pp0.x), Vec3(p0p2.y, p0p1.y, pp0.y));
/* handle degenerate triangles—i.e. the ones where every point lies on the same line */
- if(fabs(v.z) < 1e-5)
+ if(fabs(v.z) < ε1)
return Pt3(-1,-1,-1,1);
return Pt3(1 - (v.x + v.y)/v.z, v.y/v.z, v.x/v.z, 1);
}
@@ -262,7 +261,7 @@ rasterize(Rastertask *task)
/* interpolate z⁻¹ and get actual z */
pcz = flerp(prim->v[0].p.w, prim->v[1].p.w, perc);
- pcz = 1.0/(pcz < 1e-5? 1e-5: pcz);
+ pcz = 1.0/(pcz < ε1? ε1: pcz);
/* perspective-correct attribute interpolation */
perc *= prim->v[0].p.w * pcz;
@@ -314,7 +313,7 @@ discard:
/* interpolate z⁻¹ and get actual z */
pcz = fberp(prim->v[0].p.w, prim->v[1].p.w, prim->v[2].p.w, bc);
- pcz = 1.0/(pcz < 1e-5? 1e-5: pcz);
+ pcz = 1.0/(pcz < ε1? ε1: pcz);
/* perspective-correct attribute interpolation */
bc = modulapt3(bc, Vec3(prim->v[0].p.w*pcz,