ree
This commit is contained in:
parent
2190fd187e
commit
46678bd628
4
Makefile
4
Makefile
|
@ -1,6 +1,6 @@
|
|||
CC = gcc
|
||||
CFLAGS = -pg -O2
|
||||
LDFLAGS = -pg
|
||||
CFLAGS = -pg -g
|
||||
LDFLAGS = -pg -g
|
||||
LDLIBS = -lraylib -lm
|
||||
objects = c3d.o
|
||||
|
||||
|
|
65
c3d.c
65
c3d.c
|
@ -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;
|
||||
|
||||
|
@ -418,16 +418,20 @@ int main() {
|
|||
Tri2Darr.arr = internaltri2darray;
|
||||
|
||||
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); */
|
||||
|
@ -446,32 +450,45 @@ int main() {
|
|||
for(int i = 0; i < TransformedTris.length; i++) {
|
||||
Tri2DArrayAppend(&Tri2Darr,ConvertTriToTri2D(&TransformedTris.arr[i]));
|
||||
}
|
||||
|
||||
memset(ZBuff,0,sizeof(ZBuff));
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
//memset(ZBuff,0,sizeof(ZBuff));
|
||||
memset(display,0,sizeof(display));
|
||||
|
||||
|
||||
|
||||
for (int y = 0; y < RENDERHEIGHT; y++){
|
||||
for (int x = 0; x<RENDERWIDTH; x++){
|
||||
ZBuff[x][y].triangle = ␣
|
||||
}
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
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];
|
||||
|
|
Loading…
Reference in a new issue