...
This commit is contained in:
parent
d962951880
commit
7ddf2c5067
BIN
obj/base.o
BIN
obj/base.o
Binary file not shown.
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/triangles.o
BIN
obj/triangles.o
Binary file not shown.
32
src/base.c
32
src/base.c
|
@ -95,10 +95,30 @@ int convex_seg(int x1, int x2, double theta) {
|
||||||
return (int)(((1.0f - theta) * x1 + theta * x2));
|
return (int)(((1.0f - theta) * x1 + theta * x2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double convex_pt(double a, double b, double theta) {
|
||||||
|
return (a+(b-a)*theta) ;
|
||||||
|
}
|
||||||
|
|
||||||
double convex_tri(double a, double tha, double b, double thb, double c, double thc) {
|
double convex_tri(double a, double tha, double b, double thb, double c, double thc) {
|
||||||
return (a*tha + b*thb + c*thc);
|
return (a*tha + b*thb + c*thc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pt_2d convex_pt2d(pt_2d A, pt_2d B, double theta) {
|
||||||
|
pt_2d res;
|
||||||
|
res.x = convex_pt(A.x, B.x, theta);
|
||||||
|
res.y = convex_pt(A.y, B.y, theta);
|
||||||
|
res.z = convex_pt(A.z, B.z, theta);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
pt_2d convex_pt2d_tri(pt_2d A, double tha, pt_2d B, double thb, pt_2d C, double thc) {
|
||||||
|
pt_2d res;
|
||||||
|
res.x = convex_tri(A.x, tha, B.x, thb, C.x, thc);
|
||||||
|
res.y = convex_tri(A.y, tha, B.y, thb, C.y, thc);
|
||||||
|
res.z = convex_tri(A.z, tha, B.z, thb, C.z, thc);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_an_integer(char c) {
|
bool is_an_integer(char c) {
|
||||||
return ((int)c >= 48 && (int)c <= 57);
|
return ((int)c >= 48 && (int)c <= 57);
|
||||||
}
|
}
|
||||||
|
@ -188,14 +208,18 @@ teleporter create_teleporter(
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------ //
|
// ------------------------------------------------------------------------------------------------ //
|
||||||
|
|
||||||
double convex_pt(double a, double b, double theta) {
|
|
||||||
return (a+(b-a)*theta) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
double distance_pt_pt_3d(double x0, double y0, double z0, double x1, double y1, double z1) {
|
double distance_pt_pt_3d(double x0, double y0, double z0, double x1, double y1, double z1) {
|
||||||
return sqrt((x1 - x0)*(x1 - x0)+(y1 - y0)*(y1 - y0)+(z1 - z0)*(z1 - z0)) ;
|
return sqrt((x1 - x0)*(x1 - x0)+(y1 - y0)*(y1 - y0)+(z1 - z0)*(z1 - z0)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double proj_distance_to_camera(double x, double y, double z) {
|
||||||
|
return sqrt(x*x + y*y + z*z);
|
||||||
|
}
|
||||||
|
|
||||||
|
double proj_pt_distance_to_camera(pt_2d p) {
|
||||||
|
return proj_distance_to_camera(p.x, p.y, p.z);
|
||||||
|
}
|
||||||
|
|
||||||
double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, double sz, double ex, double ey, double ez) {
|
double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, double sz, double ex, double ey, double ez) {
|
||||||
double theta = -(
|
double theta = -(
|
||||||
((ex - sx) * (sx - x) + (ey - sy) * (sy - y) + (ez - sz) * (sz - z)) /
|
((ex - sx) * (sx - x) + (ey - sy) * (sy - y) + (ez - sz) * (sz - z)) /
|
||||||
|
|
|
@ -12,6 +12,8 @@ double maxd(double a, double b);
|
||||||
double absf(double n);
|
double absf(double n);
|
||||||
int convex_seg(int x1, int x2, double theta);
|
int convex_seg(int x1, int x2, double theta);
|
||||||
double convex_tri(double a, double tha, double b, double thb, double c, double thc);
|
double convex_tri(double a, double tha, double b, double thb, double c, double thc);
|
||||||
|
pt_2d convex_pt2d(pt_2d A, pt_2d B, double theta);
|
||||||
|
pt_2d convex_pt2d_tri(pt_2d A, double tha, pt_2d B, double thb, pt_2d C, double thc);
|
||||||
bool is_an_integer(char c);
|
bool is_an_integer(char c);
|
||||||
double to_double(int n);
|
double to_double(int n);
|
||||||
int to_int(double n);
|
int to_int(double n);
|
||||||
|
@ -33,6 +35,8 @@ teleporter create_teleporter(
|
||||||
|
|
||||||
double convex_pt(double a, double b, double theta);
|
double convex_pt(double a, double b, double theta);
|
||||||
double distance_pt_pt_3d(double x0, double y0, double z0, double x1, double y1, double z1);
|
double distance_pt_pt_3d(double x0, double y0, double z0, double x1, double y1, double z1);
|
||||||
|
double proj_distance_to_camera(double x, double y, double z);
|
||||||
|
double proj_pt_distance_to_camera(pt_2d p);
|
||||||
double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, double sz, double ex, double ey, double ez);
|
double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, double sz, double ex, double ey, double ez);
|
||||||
|
|
||||||
double convex_pt(double a, double b, double theta);
|
double convex_pt(double a, double b, double theta);
|
||||||
|
|
140
src/display.c
140
src/display.c
|
@ -20,16 +20,14 @@
|
||||||
#include "generation.h"
|
#include "generation.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
int flashlight = 20 ;
|
int flashlight = 0 ;
|
||||||
|
|
||||||
int* drawOrder;
|
int* drawOrder;
|
||||||
|
|
||||||
double draw_constant ;
|
double draw_constant ;
|
||||||
|
|
||||||
int* cubeDrawOrder;
|
|
||||||
bool* seen ;
|
|
||||||
|
|
||||||
pt_2d** triangles_to_render ;
|
pt_2d** triangles_to_render ;
|
||||||
|
pt_2d** triangles_og_coords ;
|
||||||
int triangles_i ;
|
int triangles_i ;
|
||||||
|
|
||||||
int* reds ;
|
int* reds ;
|
||||||
|
@ -42,14 +40,9 @@ int visited_i ;
|
||||||
|
|
||||||
void init_draworder() {
|
void init_draworder() {
|
||||||
drawOrder = malloc(sizeof(int)*6) ;
|
drawOrder = malloc(sizeof(int)*6) ;
|
||||||
cubeDrawOrder = malloc(sizeof(int)*2048);
|
|
||||||
seen = malloc(sizeof(bool)*2048);
|
|
||||||
for(int k = 0; k < 2048; k++) {
|
|
||||||
cubeDrawOrder[k] = 0;
|
|
||||||
seen[k] = false;
|
|
||||||
}
|
|
||||||
draw_constant = 0.4 ;
|
draw_constant = 0.4 ;
|
||||||
triangles_to_render = malloc(sizeof(pt_2d*)*8192) ;
|
triangles_to_render = malloc(sizeof(pt_2d*)*8192) ;
|
||||||
|
triangles_og_coords = malloc(sizeof(pt_2d*)*8192) ;
|
||||||
reds = malloc(sizeof(int)*8192) ;
|
reds = malloc(sizeof(int)*8192) ;
|
||||||
greens = malloc(sizeof(int)*8192) ;
|
greens = malloc(sizeof(int)*8192) ;
|
||||||
blues = malloc(sizeof(int)*8192) ;
|
blues = malloc(sizeof(int)*8192) ;
|
||||||
|
@ -57,6 +50,7 @@ void init_draworder() {
|
||||||
visited_tri = malloc(sizeof(bool)*8192) ;
|
visited_tri = malloc(sizeof(bool)*8192) ;
|
||||||
for(int k = 0; k < 8192; k++) {
|
for(int k = 0; k < 8192; k++) {
|
||||||
triangles_to_render[k] = malloc(sizeof(pt_2d)*3);
|
triangles_to_render[k] = malloc(sizeof(pt_2d)*3);
|
||||||
|
triangles_og_coords[k] = malloc(sizeof(pt_2d)*3);
|
||||||
triangles_order[k] = k;
|
triangles_order[k] = k;
|
||||||
}
|
}
|
||||||
triangles_i = 0;
|
triangles_i = 0;
|
||||||
|
@ -488,9 +482,10 @@ void renderTriangleNoProject(
|
||||||
|
|
||||||
double near = -1.0 ;
|
double near = -1.0 ;
|
||||||
double far = 1.0 ;
|
double far = 1.0 ;
|
||||||
double getZbuffer(double z) {
|
double getZbuffer(double x, double y, double z) {
|
||||||
|
return sqrt(x*x + y*y + z*z);
|
||||||
//return z;
|
//return z;
|
||||||
return (2.0*(z - near)/(far - near) -1.0);
|
//return (2.0*(z - near)/(far - near) -1.0);
|
||||||
//return ((far + near)/(far - near) + (1.0/z)*((-2.0*far*near)/(far - near)));
|
//return ((far + near)/(far - near) + (1.0/z)*((-2.0*far*near)/(far - near)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,13 +510,18 @@ void addTriangle(
|
||||||
double fpx1; double fpy1; double fpz1;
|
double fpx1; double fpy1; double fpz1;
|
||||||
double mpx0; double mpy0; double mpz0;
|
double mpx0; double mpy0; double mpz0;
|
||||||
double mpx1; double mpy1; double mpz1;
|
double mpx1; double mpy1; double mpz1;
|
||||||
|
double mx0, my0, mz0, mx1, my1, mz1;
|
||||||
|
double fx0, fy0, fz0, fx1, fy1, fz1;
|
||||||
project_to_camera(x0, y0, z0, &px0, &py0, &pz0);
|
project_to_camera(x0, y0, z0, &px0, &py0, &pz0);
|
||||||
project_to_camera(x1, y1, z1, &px1, &py1, &pz1);
|
project_to_camera(x1, y1, z1, &px1, &py1, &pz1);
|
||||||
project_to_camera(x2, y2, z2, &px2, &py2, &pz2);
|
project_to_camera(x2, y2, z2, &px2, &py2, &pz2);
|
||||||
if(pz0 >= draw_constant && pz1 >= draw_constant && pz2 >= draw_constant) {
|
if(pz0 >= draw_constant && pz1 >= draw_constant && pz2 >= draw_constant) {
|
||||||
triangles_to_render[triangles_i][0] = to_pt_2d(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, getZbuffer(pz0));
|
triangles_to_render[triangles_i][0] = to_pt_2d(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, getZbuffer(px0, py0, pz0));
|
||||||
triangles_to_render[triangles_i][1] = to_pt_2d(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, getZbuffer(pz1));
|
triangles_to_render[triangles_i][1] = to_pt_2d(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, getZbuffer(px1, py1, pz1));
|
||||||
triangles_to_render[triangles_i][2] = to_pt_2d(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, getZbuffer(pz2));
|
triangles_to_render[triangles_i][2] = to_pt_2d(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, getZbuffer(px2, py2, pz2));
|
||||||
|
triangles_og_coords[triangles_i][0] = to_pt_2d(px0, py0, pz0);
|
||||||
|
triangles_og_coords[triangles_i][1] = to_pt_2d(px1, py1, pz1);
|
||||||
|
triangles_og_coords[triangles_i][2] = to_pt_2d(px2, py2, pz2);
|
||||||
reds[triangles_i] = red ;
|
reds[triangles_i] = red ;
|
||||||
greens[triangles_i] = green ;
|
greens[triangles_i] = green ;
|
||||||
blues[triangles_i] = blue ;
|
blues[triangles_i] = blue ;
|
||||||
|
@ -529,63 +529,69 @@ void addTriangle(
|
||||||
} else if((pz0 >= draw_constant) + (pz1 >= draw_constant) + (pz2 >= draw_constant) == 2) {
|
} else if((pz0 >= draw_constant) + (pz1 >= draw_constant) + (pz2 >= draw_constant) == 2) {
|
||||||
if(pz0 < draw_constant) {
|
if(pz0 < draw_constant) {
|
||||||
// pz1 >= draw_constant and pz2 >+ draw_constant
|
// pz1 >= draw_constant and pz2 >+ draw_constant
|
||||||
|
fx0 = x1 ; fy0 = y1 ; fz0 = z1 ;
|
||||||
fpx0 = px1 ; fpy0 = py1 ; fpz0 = pz1 ;
|
fpx0 = px1 ; fpy0 = py1 ; fpz0 = pz1 ;
|
||||||
|
fx1 = x2 ; fy1 = y2 ; fz1 = z2 ;
|
||||||
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
||||||
|
mx0 = convex_pt(x1, x0, (pz1 - draw_constant)/(pz1 - pz0));
|
||||||
|
my0 = convex_pt(y1, y0, (pz1 - draw_constant)/(pz1 - pz0));
|
||||||
|
mz0 = convex_pt(z1, z0, (pz1 - draw_constant)/(pz1 - pz0));
|
||||||
|
mx1 = convex_pt(x2, x0, (pz2 - draw_constant)/(pz2 - pz0));
|
||||||
|
my1 = convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0));
|
||||||
|
mz1 = convex_pt(z2, z0, (pz2 - draw_constant)/(pz2 - pz0));
|
||||||
// 1-0 segment
|
// 1-0 segment
|
||||||
project_to_camera(
|
project_to_camera(mx0, my0, mz0, &mpx0, &mpy0, &mpz0) ;
|
||||||
convex_pt(x1, x0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
convex_pt(y1, y0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
convex_pt(z1, z0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
&mpx0, &mpy0, &mpz0) ;
|
|
||||||
|
|
||||||
// 0-2 segment
|
// 0-2 segment
|
||||||
project_to_camera(
|
project_to_camera(mx1, my1, mz1, &mpx1, &mpy1, &mpz1) ;
|
||||||
convex_pt(x2, x0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
convex_pt(z2, z0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
|
||||||
} else if(pz1 < draw_constant) {
|
} else if(pz1 < draw_constant) {
|
||||||
// pz0 >= draw_constant and pz2 >+ draw_constant
|
// pz0 >= draw_constant and pz2 >+ draw_constant
|
||||||
|
fx0 = x0 ; fy0 = y0 ; fz0 = z0 ;
|
||||||
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
||||||
|
fx1 = x2 ; fy1 = y2 ; fz1 = z2 ;
|
||||||
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
||||||
|
mx0 = convex_pt(x0, x1, (pz0 - draw_constant)/(pz0 - pz1));
|
||||||
|
my0 = convex_pt(y0, y1, (pz0 - draw_constant)/(pz0 - pz1));
|
||||||
|
mz0 = convex_pt(z0, z1, (pz0 - draw_constant)/(pz0 - pz1));
|
||||||
|
mx1 = convex_pt(x2, x1, (pz2 - draw_constant)/(pz2 - pz1));
|
||||||
|
my1 = convex_pt(y2, y1, (pz2 - draw_constant)/(pz2 - pz1));
|
||||||
|
mz1 = convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1));
|
||||||
// 0-1 segment
|
// 0-1 segment
|
||||||
project_to_camera(
|
project_to_camera(mx0, my0, mz0, &mpx0, &mpy0, &mpz0) ;
|
||||||
convex_pt(x0, x1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
convex_pt(y0, y1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
convex_pt(z0, z1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
&mpx0, &mpy0, &mpz0) ;
|
|
||||||
|
|
||||||
// 1-2 segment
|
// 1-2 segment
|
||||||
project_to_camera(
|
project_to_camera(mx1, my1, mz1, &mpx1, &mpy1, &mpz1) ;
|
||||||
convex_pt(x2, x1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
convex_pt(y2, y1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
|
||||||
} else /*if(pz2 < draw_constant)*/ {
|
} else /*if(pz2 < draw_constant)*/ {
|
||||||
// pz1 >= draw_constant and pz0 >+ draw_constant
|
// pz1 >= draw_constant and pz0 >+ draw_constant
|
||||||
|
fx0 = x0 ; fy0 = y0 ; fz0 = z0 ;
|
||||||
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
||||||
|
fx1 = x1 ; fy1 = y1 ; fz1 = z1 ;
|
||||||
fpx1 = px1 ; fpy1 = py1 ; fpz1 = pz1 ;
|
fpx1 = px1 ; fpy1 = py1 ; fpz1 = pz1 ;
|
||||||
|
mx0 = convex_pt(x0, x2, (pz0 - draw_constant)/(pz0 - pz2));
|
||||||
|
my0 = convex_pt(y0, y2, (pz0 - draw_constant)/(pz0 - pz2));
|
||||||
|
mz0 = convex_pt(z0, z2, (pz0 - draw_constant)/(pz0 - pz2));
|
||||||
|
mx1 = convex_pt(x1, x2, (pz1 - draw_constant)/(pz1 - pz2));
|
||||||
|
my1 = convex_pt(y1, y2, (pz1 - draw_constant)/(pz1 - pz2));
|
||||||
|
mz1 = convex_pt(z1, z2, (pz1 - draw_constant)/(pz1 - pz2));
|
||||||
// 0-2 segment
|
// 0-2 segment
|
||||||
project_to_camera(
|
project_to_camera(mx0, my0, mz0, &mpx0, &mpy0, &mpz0) ;
|
||||||
convex_pt(x0, x2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
convex_pt(y0, y2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
convex_pt(z0, z2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
&mpx0, &mpy0, &mpz0) ;
|
|
||||||
|
|
||||||
// 1-2 segment
|
// 1-2 segment
|
||||||
project_to_camera(
|
project_to_camera(mx1, my1, mz1, &mpx1, &mpy1, &mpz1) ;
|
||||||
convex_pt(x1, x2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
convex_pt(y1, y2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
convex_pt(z1, z2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
triangles_to_render[triangles_i][0] = to_pt_2d(1500.0 * (1.0 + (fpx0 / (1.5 * fpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy0 / (fpz0 * tan_fov))) / 2.0, getZbuffer(fpz0));
|
triangles_to_render[triangles_i][0] = to_pt_2d(1500.0 * (1.0 + (fpx0 / (1.5 * fpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy0 / (fpz0 * tan_fov))) / 2.0, getZbuffer(fpx0, fpy0, fpz0));
|
||||||
triangles_to_render[triangles_i][1] = to_pt_2d(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, getZbuffer(mpz0));
|
triangles_to_render[triangles_i][1] = to_pt_2d(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, getZbuffer(mpx0, mpy0, mpz0));
|
||||||
triangles_to_render[triangles_i][2] = to_pt_2d(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, getZbuffer(fpz1));
|
triangles_to_render[triangles_i][2] = to_pt_2d(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, getZbuffer(fpx1, fpy1, fpz1));
|
||||||
triangles_to_render[triangles_i+1][0] = to_pt_2d(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, getZbuffer(mpz0));
|
triangles_og_coords[triangles_i][0] = to_pt_2d(fpx0, fpy0, fpz0);
|
||||||
triangles_to_render[triangles_i+1][1] = to_pt_2d(1500.0 * (1.0 + (mpx1 / (1.5 * mpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy1 / (mpz1 * tan_fov))) / 2.0, getZbuffer(mpz1));
|
triangles_og_coords[triangles_i][1] = to_pt_2d(mpx0, mpy0, mpz0);
|
||||||
triangles_to_render[triangles_i+1][2] = to_pt_2d(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, getZbuffer(fpz1));
|
triangles_og_coords[triangles_i][2] = to_pt_2d(fpx1, fpy1, fpz1);
|
||||||
|
triangles_to_render[triangles_i+1][0] = to_pt_2d(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, getZbuffer(mpx0, mpy0, mpz0));
|
||||||
|
triangles_to_render[triangles_i+1][1] = to_pt_2d(1500.0 * (1.0 + (mpx1 / (1.5 * mpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy1 / (mpz1 * tan_fov))) / 2.0, getZbuffer(mpx1, mpy1, mpz1));
|
||||||
|
triangles_to_render[triangles_i+1][2] = to_pt_2d(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, getZbuffer(fpx1, fpy1, fpz1));
|
||||||
|
triangles_og_coords[triangles_i+1][0] = to_pt_2d(mpx0, mpy0, mpz0);
|
||||||
|
triangles_og_coords[triangles_i+1][1] = to_pt_2d(mpx1, mpy1, mpz1);
|
||||||
|
triangles_og_coords[triangles_i+1][2] = to_pt_2d(fpx1, fpy1, fpz1);
|
||||||
reds[triangles_i] = red ;
|
reds[triangles_i] = red ;
|
||||||
greens[triangles_i] = green ;
|
greens[triangles_i] = green ;
|
||||||
blues[triangles_i] = blue ;
|
blues[triangles_i] = blue ;
|
||||||
|
@ -629,9 +635,12 @@ void addTriangle(
|
||||||
&px1, &py1, &pz1);
|
&px1, &py1, &pz1);
|
||||||
}
|
}
|
||||||
|
|
||||||
triangles_to_render[triangles_i][0] = to_pt_2d(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, getZbuffer(pz0));
|
triangles_to_render[triangles_i][0] = to_pt_2d(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, getZbuffer(px0, py0, pz0));
|
||||||
triangles_to_render[triangles_i][1] = to_pt_2d(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, getZbuffer(pz1));
|
triangles_to_render[triangles_i][1] = to_pt_2d(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, getZbuffer(px1, py1, pz1));
|
||||||
triangles_to_render[triangles_i][2] = to_pt_2d(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, getZbuffer(pz2));
|
triangles_to_render[triangles_i][2] = to_pt_2d(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, getZbuffer(px2, py2, pz2));
|
||||||
|
triangles_og_coords[triangles_i][0] = to_pt_2d(px0, py0, pz0);
|
||||||
|
triangles_og_coords[triangles_i][1] = to_pt_2d(px1, py1, pz1);
|
||||||
|
triangles_og_coords[triangles_i][2] = to_pt_2d(px2, py2, pz2);
|
||||||
reds[triangles_i] = red ;
|
reds[triangles_i] = red ;
|
||||||
greens[triangles_i] = green ;
|
greens[triangles_i] = green ;
|
||||||
blues[triangles_i] = blue ;
|
blues[triangles_i] = blue ;
|
||||||
|
@ -663,7 +672,6 @@ void add_single(cube_0 c) { // x
|
||||||
int leng = surfaceDrawOrder(camx, camy, camz, c);
|
int leng = surfaceDrawOrder(camx, camy, camz, c);
|
||||||
for(int sf0 = 0; sf0 < leng; sf0++) {
|
for(int sf0 = 0; sf0 < leng; sf0++) {
|
||||||
int sf = drawOrder[sf0];
|
int sf = drawOrder[sf0];
|
||||||
//printf("%d\n", sf);
|
|
||||||
if(sf == 0 || sf == 1) {
|
if(sf == 0 || sf == 1) {
|
||||||
addTriangleRotated(
|
addTriangleRotated(
|
||||||
c.x + c.w*(sf==0), c.y , c.z,
|
c.x + c.w*(sf==0), c.y , c.z,
|
||||||
|
@ -738,10 +746,10 @@ double deltaz ;
|
||||||
void visiting(int k, bool vflag) {
|
void visiting(int k, bool vflag) {
|
||||||
if(visited_tri[k] != vflag) {
|
if(visited_tri[k] != vflag) {
|
||||||
visited_tri[k] = vflag;
|
visited_tri[k] = vflag;
|
||||||
for(int k2 = 0; k2 < triangles_i; k2++) {
|
for(int kk = 0; kk < triangles_i; kk++) {
|
||||||
if(k2 != k && visited_tri[k2] != vflag) {
|
if(visited_tri[kk] != vflag) {
|
||||||
if(delta_get(triangles_to_render[k], triangles_to_render[k2], &deltaz) && deltaz > 0.01) {
|
if(delta_get(triangles_to_render[k], triangles_og_coords[k], triangles_to_render[kk], triangles_og_coords[kk], &deltaz) && deltaz > 0.001) {
|
||||||
visiting(k2, vflag);
|
visiting(kk, vflag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,18 +771,28 @@ void drawCurrentRoom(SDL_Renderer* renderer) {
|
||||||
add_triangles_cb(current_room->map, current_room->map_size);
|
add_triangles_cb(current_room->map, current_room->map_size);
|
||||||
add_triangles_tp(current_room->tps, current_room->tps_size);
|
add_triangles_tp(current_room->tps, current_room->tps_size);
|
||||||
add_triangles_ent(current_room->ents, current_room->ent_len);
|
add_triangles_ent(current_room->ents, current_room->ent_len);
|
||||||
topological_sort();
|
//topological_sort();
|
||||||
for(int k = 0; k < triangles_i; k++) {
|
for(int k = 0; k < triangles_i; k++) {
|
||||||
renderTriangleFull(renderer, triangles_order[k]);
|
renderTriangleFull(renderer, triangles_order[k]);
|
||||||
}
|
}
|
||||||
/*for(int k = 0; k < triangles_i; k++) {
|
/*for(int k = 0; k < triangles_i; k++) {
|
||||||
drawNumberToRenderer(renderer, digits,
|
drawNumberToRenderer(renderer, digits,
|
||||||
(int)(0.33*(triangles_to_render[k][0].z+triangles_to_render[k][1].z+triangles_to_render[k][2].z)),
|
(int)(3.3*(proj_pt_distance_to_camera(triangles_og_coords[k][0])+proj_pt_distance_to_camera(triangles_og_coords[k][1])+proj_pt_distance_to_camera(triangles_og_coords[k][2]))),
|
||||||
(int)(0.33*(triangles_to_render[k][0].x+triangles_to_render[k][1].x+triangles_to_render[k][2].x)),
|
(int)(0.33*(triangles_to_render[k][0].x+triangles_to_render[k][1].x+triangles_to_render[k][2].x)),
|
||||||
(int)(0.33*(triangles_to_render[k][0].y+triangles_to_render[k][1].y+triangles_to_render[k][2].y)),
|
(int)(0.33*(triangles_to_render[k][0].y+triangles_to_render[k][1].y+triangles_to_render[k][2].y)),
|
||||||
75/4, 105/4, 0
|
75/4, 105/4, 0
|
||||||
);
|
);
|
||||||
}*/
|
}*/
|
||||||
|
for(int k = 0; k < triangles_i; k++) {
|
||||||
|
for(int l = 0; l < 3; l++) {
|
||||||
|
drawNumberToRenderer(renderer, digits,
|
||||||
|
(int)(proj_pt_distance_to_camera(triangles_og_coords[k][l])),
|
||||||
|
(int)(triangles_to_render[k][l].x),
|
||||||
|
(int)(triangles_to_render[k][l].y),
|
||||||
|
75/5, 105/5, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------------------------------------------------------------- //
|
||||||
|
|
|
@ -56,7 +56,7 @@ int main(int argc, char** argv) {
|
||||||
init_hashtbl() ;
|
init_hashtbl() ;
|
||||||
init_draworder() ;
|
init_draworder() ;
|
||||||
trInit();
|
trInit();
|
||||||
parse_rooms(4);
|
parse_rooms(5);
|
||||||
import_digits(rend) ;
|
import_digits(rend) ;
|
||||||
import_letters(rend) ;
|
import_letters(rend) ;
|
||||||
sim_time = 0.0 ;
|
sim_time = 0.0 ;
|
||||||
|
|
|
@ -116,6 +116,7 @@ extern int draw_type ;
|
||||||
extern double draw_constant ;
|
extern double draw_constant ;
|
||||||
|
|
||||||
extern pt_2d** triangles_to_render ;
|
extern pt_2d** triangles_to_render ;
|
||||||
|
extern pt_2d** triangles_og_coords ;
|
||||||
extern int triangles_i ;
|
extern int triangles_i ;
|
||||||
|
|
||||||
#endif
|
#endif
|
220
src/triangles.c
220
src/triangles.c
|
@ -153,195 +153,6 @@ bool multipleTrianglesIntersection(pt_2d* tri1, int len1, pt_2d* tri2, int len2,
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
pt_2d to_fpoint(double x0, double y0, double z0) {
|
|
||||||
pt_2d res;
|
|
||||||
res.x = x0;
|
|
||||||
res.y = y0;
|
|
||||||
res.z = z0;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int returnTriangle(
|
|
||||||
double x0, double y0, double z0,
|
|
||||||
double x1, double y1, double z1,
|
|
||||||
double x2, double y2, double z2,
|
|
||||||
pt_2d* retarr
|
|
||||||
) {
|
|
||||||
double px0; double py0; double pz0;
|
|
||||||
double px1; double py1; double pz1;
|
|
||||||
double px2; double py2; double pz2;
|
|
||||||
double fpx0; double fpy0; double fpz0;
|
|
||||||
double fpx1; double fpy1; double fpz1;
|
|
||||||
double mpx0; double mpy0; double mpz0;
|
|
||||||
double mpx1; double mpy1; double mpz1;
|
|
||||||
project_to_camera(x0, y0, z0, &px0, &py0, &pz0);
|
|
||||||
project_to_camera(x1, y1, z1, &px1, &py1, &pz1);
|
|
||||||
project_to_camera(x2, y2, z2, &px2, &py2, &pz2);
|
|
||||||
if(pz0 >= (draw_constant + draw_incr) && pz1 >= (draw_constant + draw_incr) && pz2 >= (draw_constant + draw_incr)) {
|
|
||||||
retarr[0] = to_fpoint(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, pz0);
|
|
||||||
retarr[1] = to_fpoint(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, pz1);
|
|
||||||
retarr[2] = to_fpoint(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, pz2);
|
|
||||||
return 3;
|
|
||||||
} else if((pz0 >= (draw_constant + draw_incr)) + (pz1 >= (draw_constant + draw_incr)) + (pz2 >= (draw_constant + draw_incr)) == 2) {
|
|
||||||
if(pz0 < (draw_constant + draw_incr)) {
|
|
||||||
// pz1 >= (draw_constant + draw_incr) and pz2 >+ (draw_constant + draw_incr)
|
|
||||||
fpx0 = px1 ; fpy0 = py1 ; fpz0 = pz1 ;
|
|
||||||
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
|
||||||
// 1-0 segment
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x1, x0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
convex_pt(y1, y0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
convex_pt(z1, z0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
&mpx0, &mpy0, &mpz0) ;
|
|
||||||
|
|
||||||
// 0-2 segment
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x2, x0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
convex_pt(z2, z0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
|
||||||
} else if(pz1 < (draw_constant + draw_incr)) {
|
|
||||||
// pz0 >= (draw_constant + draw_incr) and pz2 >+ (draw_constant + draw_incr)
|
|
||||||
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
|
||||||
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
|
||||||
// 0-1 segment
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x0, x1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
convex_pt(y0, y1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
convex_pt(z0, z1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
&mpx0, &mpy0, &mpz0) ;
|
|
||||||
|
|
||||||
// 1-2 segment
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x2, x1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
convex_pt(y2, y1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
|
||||||
} else /*if(pz2 < (draw_constant + draw_incr))*/ {
|
|
||||||
// pz1 >= (draw_constant + draw_incr) and pz0 >+ (draw_constant + draw_incr)
|
|
||||||
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
|
||||||
fpx1 = px1 ; fpy1 = py1 ; fpz1 = pz1 ;
|
|
||||||
// 0-2 segment
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x0, x2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
convex_pt(y0, y2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
convex_pt(z0, z2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
&mpx0, &mpy0, &mpz0) ;
|
|
||||||
|
|
||||||
// 1-2 segment
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x1, x2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
convex_pt(y1, y2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
convex_pt(z1, z2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
retarr[0] = to_fpoint(1500.0 * (1.0 + (fpx0 / (1.5 * fpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy0 / (fpz0 * tan_fov))) / 2.0, fpz0);
|
|
||||||
retarr[1] = to_fpoint(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, mpz0);
|
|
||||||
retarr[2] = to_fpoint(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, fpz1);
|
|
||||||
retarr[3] = to_fpoint(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, mpz0);
|
|
||||||
retarr[4] = to_fpoint(1500.0 * (1.0 + (mpx1 / (1.5 * mpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy1 / (mpz1 * tan_fov))) / 2.0, mpz1);
|
|
||||||
retarr[5] = to_fpoint(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, fpz1);
|
|
||||||
return 6;
|
|
||||||
} else if((pz0 >= (draw_constant + draw_incr)) + (pz1 >= (draw_constant + draw_incr)) + (pz2 >= (draw_constant + draw_incr)) == 1) {
|
|
||||||
if(pz0 >= (draw_constant + draw_incr)) {
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x0, x1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
convex_pt(y0, y1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
convex_pt(z0, z1, (pz0 - draw_constant)/(pz0 - pz1)),
|
|
||||||
&px1, &py1, &pz1);
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x0, x2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
convex_pt(y0, y2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
convex_pt(z0, z2, (pz0 - draw_constant)/(pz0 - pz2)),
|
|
||||||
&px2, &py2, &pz2);
|
|
||||||
} else if(pz1 >= (draw_constant + draw_incr)) {
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x1, x0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
convex_pt(y1, y0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
convex_pt(z1, z0, (pz1 - draw_constant)/(pz1 - pz0)),
|
|
||||||
&px0, &py0, &pz0);
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x1, x2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
convex_pt(y1, y2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
convex_pt(z1, z2, (pz1 - draw_constant)/(pz1 - pz2)),
|
|
||||||
&px2, &py2, &pz2);
|
|
||||||
} else if(pz2 >= (draw_constant + draw_incr)) {
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x2, x0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
convex_pt(z2, z0, (pz2 - draw_constant)/(pz2 - pz0)),
|
|
||||||
&px0, &py0, &pz0);
|
|
||||||
project_to_camera(
|
|
||||||
convex_pt(x2, x1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
convex_pt(y2, y1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
|
|
||||||
&px1, &py1, &pz1);
|
|
||||||
}
|
|
||||||
|
|
||||||
retarr[0] = to_fpoint(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, pz0);
|
|
||||||
retarr[1] = to_fpoint(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, pz1);
|
|
||||||
retarr[2] = to_fpoint(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, pz2);
|
|
||||||
return 3;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int fillPolygon(int sf, cube_0 c, int trig, pt_2d* ret) {
|
|
||||||
// trig is either 0 or 1
|
|
||||||
// returns the length of the result
|
|
||||||
if(sf == 0 || sf == 1) { // x
|
|
||||||
if(trig == 0) {
|
|
||||||
return returnTriangle(
|
|
||||||
c.x + c.w*(sf==0), c.y, c.z,
|
|
||||||
c.x + c.w*(sf==0), c.y + c.h, c.z,
|
|
||||||
c.x + c.w*(sf==0), c.y + c.h, c.z + c.d,
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return returnTriangle(
|
|
||||||
c.x + c.w*(sf==0), c.y, c.z,
|
|
||||||
c.x + c.w*(sf==0), c.y, c.z + c.d,
|
|
||||||
c.x + c.w*(sf==0), c.y + c.h, c.z + c.d,
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if(sf == 2 || sf == 3) { // y
|
|
||||||
if(trig == 0) {
|
|
||||||
return returnTriangle(
|
|
||||||
c.x, c.y + c.h*(sf==2), c.z,
|
|
||||||
c.x + c.w, c.y + c.h*(sf==2), c.z,
|
|
||||||
c.x + c.w, c.y + c.h*(sf==2), c.z + c.d,
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return returnTriangle(
|
|
||||||
c.x, c.y + c.h*(sf==2), c.z,
|
|
||||||
c.x, c.y + c.h*(sf==2), c.z + c.d,
|
|
||||||
c.x + c.w, c.y + c.h*(sf==2), c.z + c.d,
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else { // z
|
|
||||||
if(trig == 0) {
|
|
||||||
return returnTriangle(
|
|
||||||
c.x, c.y, c.z + c.d*(sf==4),
|
|
||||||
c.x + c.w, c.y, c.z + c.d*(sf==4),
|
|
||||||
c.x + c.w, c.y + c.h, c.z + c.d*(sf==4),
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return returnTriangle(
|
|
||||||
c.x, c.y, c.z + c.d*(sf==4),
|
|
||||||
c.x, c.y + c.h, c.z + c.d*(sf==4),
|
|
||||||
c.x + c.w, c.y + c.h, c.z + c.d*(sf==4),
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int visibleSurfaces(double x0, double y0, double z0, cube_0 cb, int* dOrd) {
|
int visibleSurfaces(double x0, double y0, double z0, cube_0 cb, int* dOrd) {
|
||||||
// returns the number of surfaces that should be drawn, as well as filling dOrd for said surfaces :
|
// returns the number of surfaces that should be drawn, as well as filling dOrd for said surfaces :
|
||||||
// 0 = +x ; 1 = -x
|
// 0 = +x ; 1 = -x
|
||||||
|
@ -490,29 +301,48 @@ bool delta_get2(pt_2d* tri1, pt_2d* tri2, double* ret) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool delta_get(pt_2d* tri1, pt_2d* tri2, double* ret) {
|
bool delta_get(pt_2d* tri1, pt_2d* og1, pt_2d* tri2, pt_2d* og2, double* ret) {
|
||||||
double th1 = 0.0;
|
double th1 = 0.0;
|
||||||
double th2 = 0.0;
|
double th2 = 0.0;
|
||||||
double th3 = 0.0;
|
double th3 = 0.0;
|
||||||
for(int k = 0; k < 3; k++) { // pt
|
/*for(int k = 0; k < 3; k++) { // pt
|
||||||
if(point_in_triangle(tri1[k], tri2[0], tri2[1], tri2[2], &th1, &th2, &th3)) {
|
if(point_in_triangle(tri1[k], tri2[0], tri2[1], tri2[2], &th1, &th2, &th3)) {
|
||||||
//printf("%lf, %lf, %lf\n", th1, th2, th3);
|
//printf("%lf, %lf, %lf\n", th1, th2, th3);
|
||||||
if(ret != NULL) {*ret = convex_tri(tri2[0].z, th1, tri2[1].z, th2, tri2[2].z, th3) - tri1[k].z;}
|
if(ret != NULL) {
|
||||||
|
pt_2d* trio2 = og2;
|
||||||
|
pt_2d proj = convex_pt2d_tri(trio2[0], th1, trio2[1], th2, trio2[2], th3);
|
||||||
|
pt_2d* trio1 = og1;
|
||||||
|
printf("[1 in 2] %lf, %lf, %lf\n", proj.x/trio1[k].x, proj.y/trio1[k].y, proj.z/trio1[k].z);
|
||||||
|
*ret = sqrt(proj.z*proj.z + proj.y*proj.y + proj.x*proj.x) - sqrt(trio1[k].z*trio1[k].z + trio1[k].y*trio1[k].y + trio1[k].x*trio1[k].x);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(point_in_triangle(tri2[k], tri1[0], tri1[1], tri1[2], &th1, &th2, &th3)) {
|
if(point_in_triangle(tri2[k], tri1[0], tri1[1], tri1[2], &th1, &th2, &th3)) {
|
||||||
//printf("%lf, %lf, %lf\n", th1, th2, th3);
|
//printf("%lf, %lf, %lf\n", th1, th2, th3);
|
||||||
if(ret != NULL) {*ret = tri2[k].z - convex_tri(tri1[0].z, th1, tri1[1].z, th2, tri1[2].z, th3);}
|
if(ret != NULL) {
|
||||||
|
pt_2d* trio1 = og1;
|
||||||
|
pt_2d proj = convex_pt2d_tri(trio1[0], th1, trio1[1], th2, trio1[2], th3);
|
||||||
|
pt_2d* trio2 = og2;
|
||||||
|
printf("[2 in 1] %lf, %lf, %lf\n", proj.x/trio2[k].x, proj.y/trio2[k].y, proj.z/trio2[k].z);
|
||||||
|
*ret = sqrt(trio2[k].z*trio2[k].z + trio2[k].y*trio2[k].y + trio2[k].x*trio2[k].x) - sqrt(proj.z*proj.z + proj.y*proj.y + proj.x*proj.x);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
for(int k1 = 0; k1 < 3; k1++) { // seg
|
for(int k1 = 0; k1 < 3; k1++) { // seg
|
||||||
for(int k2 = 0; k2 < 3; k2++) {
|
for(int k2 = 0; k2 < 3; k2++) {
|
||||||
if(seg_seg_inter(tri1[k1], tri1[(k1+1)%3], tri2[k2], tri2[(k2+1)%3], &th1, &th2)) {
|
if(seg_seg_inter(tri1[k1], tri1[(k1+1)%3], tri2[k2], tri2[(k2+1)%3], &th1, &th2)) {
|
||||||
//print_tri(tri1);
|
//print_tri(tri1);
|
||||||
//print_tri(tri2);
|
//print_tri(tri2);
|
||||||
//printf("%lf, %lf\n\n", th1, th2);
|
//printf("%lf, %lf\n\n", th1, th2);
|
||||||
if(ret != NULL) {*ret = convex_pt(tri2[k2].z, tri2[(k2+1)%3].z, th2) - convex_pt(tri1[k1].z, tri1[(k1+1)%3].z, th1);}
|
if(ret != NULL) {
|
||||||
|
pt_2d proj1 = convex_pt2d(og1[k1], og1[(k1+1)%3], th1);
|
||||||
|
pt_2d proj2 = convex_pt2d(og2[k2], og2[(k2+1)%3], th2);
|
||||||
|
printf("[Seg Seg] %lf, %lf, %lf - ", proj1.x/proj2.x, proj1.y/proj2.y, proj1.z/proj2.z);
|
||||||
|
printf("{%lf}\n", maxd(absf(proj1.x/proj2.x-1), maxd(absf(proj1.y/proj2.y-1), absf(proj1.z/proj2.z-1))));
|
||||||
|
*ret = distance_pt_pt_3d(proj2.x, proj2.y, proj2.z, 0.0, 0.0, 0.0);
|
||||||
|
*ret -= distance_pt_pt_3d(proj1.x, proj1.y, proj1.z, 0.0, 0.0, 0.0);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,6 @@ bool triangleIntersection(pt_2d* tri1, pt_2d* tri2);
|
||||||
bool triangleIntersectionDec(pt_2d t1_1, pt_2d t1_2, pt_2d t1_3, pt_2d t2_1, pt_2d t2_2, pt_2d t2_3);
|
bool triangleIntersectionDec(pt_2d t1_1, pt_2d t1_2, pt_2d t1_3, pt_2d t2_1, pt_2d t2_2, pt_2d t2_3);
|
||||||
bool multipleTrianglesIntersection(pt_2d* tri1, int len1, pt_2d* tri2, int len2, int* ret1, int* ret2);
|
bool multipleTrianglesIntersection(pt_2d* tri1, int len1, pt_2d* tri2, int len2, int* ret1, int* ret2);
|
||||||
|
|
||||||
int returnTriangle(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, pt_2d* retarr);
|
bool delta_get(pt_2d* tri1, pt_2d* og1, pt_2d* tri2, pt_2d* og2, double* ret) ;
|
||||||
int fillPolygon(int sf, cube_0 c, int trig, pt_2d* ret);
|
|
||||||
|
|
||||||
bool delta_get(pt_2d* tri1, pt_2d* tri2, double* ret);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,14 @@
|
||||||
|
Blocks :
|
||||||
|
[-10.0, 0.0, -10.0, 20.0, 0.9, 20.0, 0.0, 0.0, 192, 192, 192]
|
||||||
|
[-10.0, 7.1, -10.0, 20.0, 0.9, 20.0, 0.0, 0.0, 192, 192, 192]
|
||||||
|
|
||||||
|
Teleporters :
|
||||||
|
[-10.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 255, 0, 0; 0, -1]
|
||||||
|
[-5.0, 1.0, -10.0, 10.0, 2.0, 1.0, 0.0, 0.0, 255, 255, 0; -1, 0]
|
||||||
|
[9.0, 1.0, -5.0, 1.0, 2.0, 10.0, 0.0, 0.0, 0, 255, 0; 0, 1]
|
||||||
|
[-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0]
|
||||||
|
|
||||||
|
Weight :
|
||||||
|
100
|
||||||
|
|
||||||
|
$
|
Loading…
Reference in New Issue