added new texture for box and clamped uv positioning

This commit is contained in:
Inventor Xtreme 2024-08-17 22:57:28 -04:00
parent 8ed29aa8d4
commit f8352c4581
3 changed files with 12 additions and 8 deletions

BIN
boxtex.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

18
c3d.c
View file

@ -2,6 +2,7 @@
#include "raylib.h" #include "raylib.h"
#include "raymath.h" #include "raymath.h"
#include "reader.h" #include "reader.h"
#include "float.h"
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
@ -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++) { for (int i = (Max(start, 0)); i < (Min(end, RENDERWIDTH)); i++) {
// UNCOMMENT TO DO TRUE NON SLOPE BASED DEPTH CALC: // UNCOMMENT TO DO TRUE NON SLOPE BASED DEPTH CALC:
//Vector3 baryatpoint = Tri2DBaryAtPoint(trianglepointer, ( (Vector2){i, scanline})); Vector3 baryatpoint = Tri2DBaryAtPoint(trianglepointer, ( (Vector2){i, scanline}));
depth = 1.0 / (f1invdepth + (dinvslope * ((float)i - (float)(Max(start, 0))))); //depth = 1.0 / (f1invdepth + (dinvslope * ((float)i - (float)(Max(start, 0)))));
//depth = 1.0 / InvDepthAtBary(trianglepointer, baryatpoint); depth = 1.0 / InvDepthAtBary(trianglepointer, baryatpoint);
//UNCOMMENT TO DO REAL UV CALC //UNCOMMENT TO DO REAL UV CALC
//UVpos = BaryAndTritoPoint(&UVRangeTri, baryatpoint); UVpos = BaryAndTritoPoint(&UVRangeTri, baryatpoint);
//UVpos = GetUVFromTriAndBary(baryatpoint, trianglepointer, depth); UVpos = GetUVFromTriAndBary(baryatpoint, trianglepointer, depth);
//V2Print(UVpos); //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) { if (depth < zee[IndexOfZBuff(i, scanline)].depth) {
CMaterial *mat = trianglepointer->material; CMaterial *mat = trianglepointer->material;
@ -640,7 +644,7 @@ int main() {
bool run3d = true; bool run3d = true;
Object3D t = ReadObjectFromFile("IronMan.obj"); Object3D t = ReadObjectFromFile("singletri.obj");
if (true) { if (true) {
for (int i = 0; i < t.triangles->length; i++) { for (int i = 0; i < t.triangles->length; i++) {
// printf("t: %f\n", t.triangles->arr[i].a.x); // printf("t: %f\n", t.triangles->arr[i].a.x);

View file

@ -9,4 +9,4 @@ Ke 0.000000 0.000000 0.000000
Ni 1.500000 Ni 1.500000
d 1.000000 d 1.000000
illum 2 illum 2
map_Kd /home/inventorx/Downloads/0.png map_Kd boxtex.png