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
CFLAGS = -pg -O2
LDFLAGS = -pg
CFLAGS = -pg -g
LDFLAGS = -pg -g
LDLIBS = -lraylib -lm
objects = c3d.o

53
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);
}
inline bool IsInTri(Tri2D tri, Vector2 p) {
bool IsInTri(Tri2D tri, Vector2 p) {
float d1, d2, d3;
bool has_neg, has_pos;
@ -419,15 +419,19 @@ int main() {
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()) {
float frametime = GetFrameTime();
CtrlLocalCam(&camera,frametime);
LocalCamApplyVelo(&camera,frametime);
BeginTextureMode(renderTexture);
ClearBackground(BLACK);
DrawText("Congrats! You created your first window!", 190, 200, 20,
BLACK);
//ClearBackground(BLACK);
;
/* Vector3 TransVector = TransformWithCam(point,&camera); */
/* if (TransVector.z < 0) { */
/* Vector2 MPos = Conv3Dto2D(TransVector); */
@ -447,31 +451,44 @@ int main() {
Tri2DArrayAppend(&Tri2Darr,ConvertTriToTri2D(&TransformedTris.arr[i]));
}
memset(ZBuff,0,sizeof(ZBuff));
//memset(ZBuff,0,sizeof(ZBuff));
memset(display,0,sizeof(display));
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];
}
}
ZBuff[x][y].triangle = &blank;
}
}
Tri2D funners = (Tri2D){ (Vector2){50,50},(Vector2){500,50},(Vector2){500,500},GREEN};
/* 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]; */
/* } */
/* } */
/* } */
/* } */
FillTopFlatZbuffer(ZBuff, &funners);
Tri2D funners2 = (Tri2D){ (Vector2){600,0},(Vector2){600,500},(Vector2){1000,500},RED};
FillBottomFlatZbuffer(ZBuff,&funners2);
int index = 0;
for(int y = 0; y < RENDERHEIGHT; y++) {
for(int x = 0; x < RENDERWIDTH; x++) {
if (ZBuff[x][y].triangle != NULL){
DrawPixel(x,y,ZBuff[x][y].triangle->color);
}
//int index = (x+y*RENDERWIDTH);
/* 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
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);
char fpstext[40];