This commit is contained in:
InventorXtreme 2023-12-05 19:11:36 -05:00
parent 2190fd187e
commit 46678bd628
2 changed files with 44 additions and 25 deletions

View file

@ -1,6 +1,6 @@
CC = gcc CC = gcc
CFLAGS = -pg -O2 CFLAGS = -pg -g
LDFLAGS = -pg LDFLAGS = -pg -g
LDLIBS = -lraylib -lm LDLIBS = -lraylib -lm
objects = c3d.o objects = c3d.o

65
c3d.c
View file

@ -171,7 +171,7 @@ float Sign(Vector2* v1, Vector2* v2, Vector2* v3) {
return (v1->x - v3->x) * (v2->y - v3->y) - (v2->x - v3->x) * (v1->y - v3->y); return (v1->x - v3->x) * (v2->y - v3->y) - (v2->x - v3->x) * (v1->y - v3->y);
} }
inline bool IsInTri(Tri2D tri, Vector2 p) { bool IsInTri(Tri2D tri, Vector2 p) {
float d1, d2, d3; float d1, d2, d3;
bool has_neg, has_pos; bool has_neg, has_pos;
@ -418,16 +418,20 @@ int main() {
Tri2Darr.arr = internaltri2darray; Tri2Darr.arr = internaltri2darray;
static Zee ZBuff[1920][1080] = {{(Zee){10000,NULL}}}; //FIXME: Stupid static makes the file 32 Megs because pog static Zee ZBuff[1920][1080] = {{(Zee){10000,NULL}}}; //FIXME: Stupid static makes the file 32 Megs because pog
static Color display[1920*1080*4];
memset(display,0,sizeof(display));
Tri2D funners = (Tri2D){ (Vector2){50,50},(Vector2){500,50},(Vector2){500,500},GREEN};
Tri2D funners2 = (Tri2D){ (Vector2){600,0},(Vector2){600,500},(Vector2){1000,500},RED};
Tri2D blank = (Tri2D) { (Vector2){-10,-10},(Vector2){-10,-10}, (Vector2){-10,-10}};
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
float frametime = GetFrameTime(); float frametime = GetFrameTime();
CtrlLocalCam(&camera,frametime); CtrlLocalCam(&camera,frametime);
LocalCamApplyVelo(&camera,frametime); LocalCamApplyVelo(&camera,frametime);
BeginTextureMode(renderTexture); BeginTextureMode(renderTexture);
ClearBackground(BLACK); //ClearBackground(BLACK);
DrawText("Congrats! You created your first window!", 190, 200, 20, ;
BLACK);
/* Vector3 TransVector = TransformWithCam(point,&camera); */ /* Vector3 TransVector = TransformWithCam(point,&camera); */
/* if (TransVector.z < 0) { */ /* if (TransVector.z < 0) { */
/* Vector2 MPos = Conv3Dto2D(TransVector); */ /* Vector2 MPos = Conv3Dto2D(TransVector); */
@ -446,32 +450,45 @@ int main() {
for(int i = 0; i < TransformedTris.length; i++) { for(int i = 0; i < TransformedTris.length; i++) {
Tri2DArrayAppend(&Tri2Darr,ConvertTriToTri2D(&TransformedTris.arr[i])); Tri2DArrayAppend(&Tri2Darr,ConvertTriToTri2D(&TransformedTris.arr[i]));
} }
memset(ZBuff,0,sizeof(ZBuff));
for(int i = 0; i < Tri2Darr.length; i++) { //memset(ZBuff,0,sizeof(ZBuff));
for(int y = 0; y < RENDERHEIGHT; y++){ memset(display,0,sizeof(display));
for(int x = 0; x< RENDERWIDTH; x++) {
if (IsInTri(Tri2Darr.arr[i],(Vector2){x,y})) {
ZBuff[x][y].triangle = &Tri2Darr.arr[i];
} for (int y = 0; y < RENDERHEIGHT; y++){
} for (int x = 0; x<RENDERWIDTH; x++){
ZBuff[x][y].triangle = &blank;
} }
} }
/* for(int i = 0; i < Tri2Darr.length; i++) { */
/* for(int y = 0; y < RENDERHEIGHT; y++){ */
/* for(int x = 0; x< RENDERWIDTH; x++) { */
/* if (IsInTri(Tri2Darr.arr[i],(Vector2){x,y})) { */
/* ZBuff[x][y].triangle = &Tri2Darr.arr[i]; */
/* } */
/* } */
/* } */
/* } */
Tri2D funners = (Tri2D){ (Vector2){50,50},(Vector2){500,50},(Vector2){500,500},GREEN};
FillTopFlatZbuffer(ZBuff, &funners); FillTopFlatZbuffer(ZBuff, &funners);
Tri2D funners2 = (Tri2D){ (Vector2){600,0},(Vector2){600,500},(Vector2){1000,500},RED};
FillBottomFlatZbuffer(ZBuff,&funners2); FillBottomFlatZbuffer(ZBuff,&funners2);
int index = 0;
for(int y = 0; y < RENDERHEIGHT; y++) { for(int y = 0; y < RENDERHEIGHT; y++) {
for(int x = 0; x < RENDERWIDTH; x++) { for(int x = 0; x < RENDERWIDTH; x++) {
if (ZBuff[x][y].triangle != NULL){ //int index = (x+y*RENDERWIDTH);
DrawPixel(x,y,ZBuff[x][y].triangle->color); /* Color * c = &ZBuff[x][y].triangle->color;
} display[index] = c->r;
display[index+1] = c->g;
display[index+2] = c->b;
display[index+3] = c->a;
*/
display[index] = ZBuff[x][y].triangle->color;
index = index+1;
} }
@ -482,6 +499,8 @@ int main() {
//Copytexture to main display :0 //Copytexture to main display :0
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK);
UpdateTexture(renderTexture.texture, display);
DrawTexturePro(renderTexture.texture, (Rectangle){0,0,renderTexture.texture.width,-renderTexture.texture.height},(Rectangle){0,0,SCREENWIDTH,SCREENHEIGHT},(Vector2){0,0},0,WHITE); DrawTexturePro(renderTexture.texture, (Rectangle){0,0,renderTexture.texture.width,-renderTexture.texture.height},(Rectangle){0,0,SCREENWIDTH,SCREENHEIGHT},(Vector2){0,0},0,WHITE);
char fpstext[40]; char fpstext[40];