Compare commits
3 Commits
727d097f45
...
d962951880
Author | SHA1 | Date |
---|---|---|
|
d962951880 | |
|
fc1c266b49 | |
|
7ae206b6c4 |
|
@ -8,6 +8,9 @@
|
||||||
"generation.h": "c",
|
"generation.h": "c",
|
||||||
"time.h": "c",
|
"time.h": "c",
|
||||||
"limits": "c",
|
"limits": "c",
|
||||||
"sdl.h": "c"
|
"sdl.h": "c",
|
||||||
|
"triangles.h": "c",
|
||||||
|
"base.h": "c",
|
||||||
|
"move.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
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/entities.o
BIN
obj/entities.o
Binary file not shown.
BIN
obj/generation.o
BIN
obj/generation.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/move.o
BIN
obj/move.o
Binary file not shown.
BIN
obj/triangles.o
BIN
obj/triangles.o
Binary file not shown.
27
src/base.c
27
src/base.c
|
@ -95,6 +95,10 @@ 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_tri(double a, double tha, double b, double thb, double c, double thc) {
|
||||||
|
return (a*tha + b*thb + c*thc);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -339,6 +343,29 @@ void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, do
|
||||||
if(rz != NULL) {*rz = zry*cos(c.vt_angle) + yry*sin(c.vt_angle);}
|
if(rz != NULL) {*rz = zry*cos(c.vt_angle) + yry*sin(c.vt_angle);}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double dist_to_cam_cube(double x0, double y0, double z0, cube_0 c) {
|
||||||
|
double px0, py0, pz0;
|
||||||
|
project_to_cube(x0, y0, z0, &px0, &py0, &pz0, c);
|
||||||
|
return distance_pt_pt_3d(px0 + c.x + c.w/2.0, py0 + c.y + c.h/2.0, pz0 + c.z + c.d/2.0, camx, camy, camz);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pt_equal_3D(pt_2d p1, pt_2d p2) {
|
||||||
|
return (p1.x == p2.x && p1.y == p2.y && p1.z == p2.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pt_equal_2D(pt_2d p1, pt_2d p2) {
|
||||||
|
return (p1.x == p2.x && p1.y == p2.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pt_equal_3D_eps(pt_2d p1, pt_2d p2, double epsilon) {
|
||||||
|
return (absf(p1.x - p2.x) <= epsilon && absf(p1.y - p2.y) <= epsilon && absf(p1.z - p2.z) <= epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pt_equal_2D_eps(pt_2d p1, pt_2d p2, double epsilon, bool debug0) {
|
||||||
|
if(debug0) {printf("(%lf, %lf)\n", absf(p1.x - p2.x), absf(p1.y - p2.y));}
|
||||||
|
return (absf(p1.x - p2.x) <= epsilon && absf(p1.y - p2.y) <= epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------ //
|
// ------------------------------------------------------------------------------------------------ //
|
||||||
|
|
||||||
void remove_entity(entity** arr, int* memlen, int* len, int index) {
|
void remove_entity(entity** arr, int* memlen, int* len, int index) {
|
||||||
|
|
|
@ -11,12 +11,17 @@ double mind(double a, double b);
|
||||||
double maxd(double a, double b);
|
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);
|
||||||
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);
|
||||||
int line_count(char* filename);
|
int line_count(char* filename);
|
||||||
int str_to_int(char* s);
|
int str_to_int(char* s);
|
||||||
bool str_equal(char* s1, char* s2);
|
bool str_equal(char* s1, char* s2);
|
||||||
|
bool pt_equal_3D(pt_2d p1, pt_2d p2);
|
||||||
|
bool pt_equal_2D(pt_2d p1, pt_2d p2);
|
||||||
|
bool pt_equal_3D_eps(pt_2d p1, pt_2d p2, double epsilon);
|
||||||
|
bool pt_equal_2D_eps(pt_2d p1, pt_2d p2, double epsilon, bool debug0);
|
||||||
|
|
||||||
cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b);
|
cube_0 create_cube_0(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b);
|
||||||
cube create_cube(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b);
|
cube create_cube(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b);
|
||||||
|
@ -51,6 +56,7 @@ void add_entity(entity** arr, int* memlen, int* len, entity ent);
|
||||||
double distance_pt_cube_3d(double x0, double y0, double z0, cube cb);
|
double distance_pt_cube_3d(double x0, double y0, double z0, cube cb);
|
||||||
void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz);
|
void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz);
|
||||||
void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, double* rz, cube_0 c);
|
void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, double* rz, cube_0 c);
|
||||||
|
double dist_to_cam_cube(double x0, double y0, double z0, cube_0 c);
|
||||||
|
|
||||||
void import_digits(SDL_Renderer* renderer);
|
void import_digits(SDL_Renderer* renderer);
|
||||||
void import_letters(SDL_Renderer* renderer);
|
void import_letters(SDL_Renderer* renderer);
|
||||||
|
|
392
src/display.c
392
src/display.c
|
@ -20,13 +20,47 @@
|
||||||
#include "generation.h"
|
#include "generation.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
int flashlight = 20 ;
|
||||||
|
|
||||||
int* drawOrder;
|
int* drawOrder;
|
||||||
|
|
||||||
double draw_constant ;
|
double draw_constant ;
|
||||||
|
|
||||||
|
int* cubeDrawOrder;
|
||||||
|
bool* seen ;
|
||||||
|
|
||||||
|
pt_2d** triangles_to_render ;
|
||||||
|
int triangles_i ;
|
||||||
|
|
||||||
|
int* reds ;
|
||||||
|
int* greens ;
|
||||||
|
int* blues ;
|
||||||
|
|
||||||
|
int* triangles_order ;
|
||||||
|
bool* visited_tri ;
|
||||||
|
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) ;
|
||||||
|
reds = malloc(sizeof(int)*8192) ;
|
||||||
|
greens = malloc(sizeof(int)*8192) ;
|
||||||
|
blues = malloc(sizeof(int)*8192) ;
|
||||||
|
triangles_order = malloc(sizeof(int)*8192) ;
|
||||||
|
visited_tri = malloc(sizeof(bool)*8192) ;
|
||||||
|
for(int k = 0; k < 8192; k++) {
|
||||||
|
triangles_to_render[k] = malloc(sizeof(pt_2d)*3);
|
||||||
|
triangles_order[k] = k;
|
||||||
|
}
|
||||||
|
triangles_i = 0;
|
||||||
|
visited_i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRenderer(SDL_Renderer* renderer) {
|
void updateRenderer(SDL_Renderer* renderer) {
|
||||||
|
@ -420,12 +454,12 @@ int surfaceDrawOrder(double x0, double y0, double z0, cube_0 cb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Vertex construct_vertex(double px, double py, int r, int g, int b) {
|
SDL_Vertex construct_vertex(double px, double py, int r, int g, int b, int a) {
|
||||||
SDL_Vertex vtx ;
|
SDL_Vertex vtx ;
|
||||||
vtx.color.r = r ;
|
vtx.color.r = r ;
|
||||||
vtx.color.g = g ;
|
vtx.color.g = g ;
|
||||||
vtx.color.b = b ;
|
vtx.color.b = b ;
|
||||||
vtx.color.a = SDL_ALPHA_OPAQUE;
|
vtx.color.a = a ;
|
||||||
vtx.position.x = (float)px ;
|
vtx.position.x = (float)px ;
|
||||||
vtx.position.y = (float)py ;
|
vtx.position.y = (float)py ;
|
||||||
vtx.tex_coord.x = 0.0f;
|
vtx.tex_coord.x = 0.0f;
|
||||||
|
@ -433,23 +467,65 @@ SDL_Vertex construct_vertex(double px, double py, int r, int g, int b) {
|
||||||
return vtx ;
|
return vtx ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderTriangle(
|
void renderTriangleNoProject(
|
||||||
SDL_Renderer* renderer,
|
SDL_Renderer* renderer,
|
||||||
|
double px0, double py0, double pz0,
|
||||||
|
double px1, double py1, double pz1,
|
||||||
|
double px2, double py2, double pz2,
|
||||||
|
int red, int green, int blue, bool debug
|
||||||
|
) {
|
||||||
|
|
||||||
|
const SDL_Vertex vtxs[3] = {
|
||||||
|
construct_vertex(px0, py0, max(red - (int)(flashlight*pz0), 0), max(green - (int)(flashlight*pz0), 0), max(blue - (int)(flashlight*pz0), 0), 255),
|
||||||
|
construct_vertex(px1, py1, max(red - (int)(flashlight*pz1), 0), max(green - (int)(flashlight*pz1), 0), max(blue - (int)(flashlight*pz1), 0), 255),
|
||||||
|
construct_vertex(px2, py2, max(red - (int)(flashlight*pz2), 0), max(green - (int)(flashlight*pz2), 0), max(blue - (int)(flashlight*pz2), 0), 255),
|
||||||
|
};
|
||||||
|
if(debug) {
|
||||||
|
printf("P[*] : (%f, %f), (%f, %f), (%f, %f)\n", vtxs[0].position.x, vtxs[0].position.y, vtxs[1].position.x, vtxs[1].position.y, vtxs[2].position.x, vtxs[2].position.y);
|
||||||
|
}
|
||||||
|
SDL_RenderGeometry(renderer, NULL, vtxs, 3, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
double near = -1.0 ;
|
||||||
|
double far = 1.0 ;
|
||||||
|
double getZbuffer(double z) {
|
||||||
|
//return z;
|
||||||
|
return (2.0*(z - near)/(far - near) -1.0);
|
||||||
|
//return ((far + near)/(far - near) + (1.0/z)*((-2.0*far*near)/(far - near)));
|
||||||
|
}
|
||||||
|
|
||||||
|
pt_2d to_pt_2d(double x0, double y0, double z0) {
|
||||||
|
pt_2d res;
|
||||||
|
res.x = x0;
|
||||||
|
res.y = y0;
|
||||||
|
res.z = z0;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addTriangle(
|
||||||
double x0, double y0, double z0,
|
double x0, double y0, double z0,
|
||||||
double x1, double y1, double z1,
|
double x1, double y1, double z1,
|
||||||
double x2, double y2, double z2,
|
double x2, double y2, double z2,
|
||||||
int red, int green, int blue
|
int red, int green, int blue
|
||||||
) {
|
) {
|
||||||
|
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(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) {
|
||||||
const SDL_Vertex vtxs[3] = {
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, red, green, blue),
|
reds[triangles_i] = red ;
|
||||||
};
|
greens[triangles_i] = green ;
|
||||||
SDL_RenderGeometry(renderer, NULL, vtxs, 3, NULL, 0);
|
blues[triangles_i] = blue ;
|
||||||
|
triangles_i += 1;
|
||||||
} 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
|
||||||
|
@ -504,15 +580,19 @@ void renderTriangle(
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
&mpx1, &mpy1, &mpz1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SDL_Vertex vtxs[6] = {
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (fpx0 / (1.5 * fpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy0 / (fpz0 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (mpx0 / (1.5 * mpz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy0 / (mpz0 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (mpx1 / (1.5 * mpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (mpy1 / (mpz1 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (fpx1 / (1.5 * fpz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (fpy1 / (fpz1 * tan_fov))) / 2.0, red, green, blue),
|
reds[triangles_i] = red ;
|
||||||
};
|
greens[triangles_i] = green ;
|
||||||
SDL_RenderGeometry(renderer, NULL, vtxs, 6, NULL, 0);
|
blues[triangles_i] = blue ;
|
||||||
|
reds[triangles_i+1] = red ;
|
||||||
|
greens[triangles_i+1] = green ;
|
||||||
|
blues[triangles_i+1] = blue ;
|
||||||
|
triangles_i += 2 ;
|
||||||
} else if((pz0 >= draw_constant) + (pz1 >= draw_constant) + (pz2 >= draw_constant) == 1) {
|
} else if((pz0 >= draw_constant) + (pz1 >= draw_constant) + (pz2 >= draw_constant) == 1) {
|
||||||
if(pz0 >= draw_constant) {
|
if(pz0 >= draw_constant) {
|
||||||
project_to_camera(
|
project_to_camera(
|
||||||
|
@ -548,253 +628,153 @@ void renderTriangle(
|
||||||
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
|
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
|
||||||
&px1, &py1, &pz1);
|
&px1, &py1, &pz1);
|
||||||
}
|
}
|
||||||
const SDL_Vertex vtxs[3] = {
|
|
||||||
construct_vertex(1500.0 * (1.0 + (px0 / (1.5 * pz0 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py0 / (pz0 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (px1 / (1.5 * pz1 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py1 / (pz1 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
construct_vertex(1500.0 * (1.0 + (px2 / (1.5 * pz2 * tan_fov))) / 2.0, 1000.0 * (1.0 + (py2 / (pz2 * tan_fov))) / 2.0, red, green, blue),
|
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));
|
||||||
};
|
reds[triangles_i] = red ;
|
||||||
SDL_RenderGeometry(renderer, NULL, vtxs, 3, NULL, 0);
|
greens[triangles_i] = green ;
|
||||||
|
blues[triangles_i] = blue ;
|
||||||
|
triangles_i += 1;
|
||||||
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderTriangleRotated(
|
void addTriangleRotated(
|
||||||
SDL_Renderer* renderer,
|
|
||||||
double x0, double y0, double z0,
|
double x0, double y0, double z0,
|
||||||
double x1, double y1, double z1,
|
double x1, double y1, double z1,
|
||||||
double x2, double y2, double z2,
|
double x2, double y2, double z2,
|
||||||
int red, int green, int blue,
|
int red, int green, int blue,
|
||||||
cube_0 cb
|
cube_0 cb
|
||||||
) {
|
) {
|
||||||
/*double px0; double py0; double pz0;
|
double px0; double py0; double pz0;
|
||||||
double px1; double py1; double pz1;
|
double px1; double py1; double pz1;
|
||||||
double px2; double py2; double pz2;*/
|
double px2; double py2; double pz2;
|
||||||
rotate_cube(x0, y0, z0, &px0, &py0, &pz0, cb);
|
rotate_cube(x0, y0, z0, &px0, &py0, &pz0, cb);
|
||||||
rotate_cube(x1, y1, z1, &px1, &py1, &pz1, cb);
|
rotate_cube(x1, y1, z1, &px1, &py1, &pz1, cb);
|
||||||
rotate_cube(x2, y2, z2, &px2, &py2, &pz2, cb);
|
rotate_cube(x2, y2, z2, &px2, &py2, &pz2, cb);
|
||||||
renderTriangle(renderer, px0, py0, pz0, px1, py1, pz1, px2, py2, pz2, red, green, blue);
|
addTriangle(px0, py0, pz0, px1, py1, pz1, px2, py2, pz2, red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawSfOfCube(SDL_Renderer* renderer, int sf, cube_0 c) {
|
// -------------------------------------------------------------------------------------------------------------------------------- //
|
||||||
if(sf == 0 || sf == 1) { // x
|
|
||||||
renderTriangleRotated(renderer,
|
void add_single(cube_0 c) { // x
|
||||||
c.x + c.w*(sf==0), c.y, c.z,
|
int leng = surfaceDrawOrder(camx, camy, camz, c);
|
||||||
|
for(int sf0 = 0; sf0 < leng; sf0++) {
|
||||||
|
int sf = drawOrder[sf0];
|
||||||
|
//printf("%d\n", sf);
|
||||||
|
if(sf == 0 || sf == 1) {
|
||||||
|
addTriangleRotated(
|
||||||
|
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.x + c.w*(sf==0), c.y + c.h, c.z + c.d,
|
c.x + c.w*(sf==0), c.y + c.h, c.z + c.d,
|
||||||
c.red, c.green, c.blue, c
|
c.red, c.green, c.blue, c
|
||||||
);
|
);
|
||||||
renderTriangleRotated(renderer,
|
addTriangleRotated(
|
||||||
c.x + c.w*(sf==0), c.y, c.z,
|
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.z + c.d,
|
||||||
c.x + c.w*(sf==0), c.y + c.h, c.z + c.d,
|
c.x + c.w*(sf==0), c.y + c.h, c.z + c.d,
|
||||||
c.red, c.green, c.blue, c
|
c.red, c.green, c.blue, c
|
||||||
);
|
);
|
||||||
} else if(sf == 2 || sf == 3) { // y
|
} else if(sf == 2 || sf == 3) {
|
||||||
renderTriangleRotated(renderer,
|
addTriangleRotated(
|
||||||
c.x, c.y + c.h*(sf==2), c.z,
|
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.x + c.w, c.y + c.h*(sf==2), c.z + c.d,
|
c.x + c.w, c.y + c.h*(sf==2), c.z + c.d,
|
||||||
c.red, c.green, c.blue, c
|
c.red, c.green, c.blue, c
|
||||||
);
|
);
|
||||||
renderTriangleRotated(renderer,
|
addTriangleRotated(
|
||||||
c.x, c.y + c.h*(sf==2), c.z,
|
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.y + c.h*(sf==2), c.z + c.d,
|
||||||
c.x + c.w, c.y + c.h*(sf==2), c.z + c.d,
|
c.x + c.w, c.y + c.h*(sf==2), c.z + c.d,
|
||||||
c.red, c.green, c.blue, c
|
c.red, c.green, c.blue, c
|
||||||
);
|
);
|
||||||
} else { // z
|
} else { // z
|
||||||
renderTriangleRotated(renderer,
|
addTriangleRotated(
|
||||||
c.x, c.y, c.z + c.d*(sf==4),
|
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.z + c.d*(sf==4),
|
||||||
c.x + c.w, c.y + c.h, c.z + c.d*(sf==4),
|
c.x + c.w, c.y + c.h, c.z + c.d*(sf==4),
|
||||||
c.red, c.green, c.blue, c
|
c.red, c.green, c.blue, c
|
||||||
);
|
);
|
||||||
renderTriangleRotated(renderer,
|
addTriangleRotated(
|
||||||
c.x, c.y, c.z + c.d*(sf==4),
|
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.y + c.h, c.z + c.d*(sf==4),
|
||||||
c.x + c.w, c.y + c.h, c.z + c.d*(sf==4),
|
c.x + c.w, c.y + c.h, c.z + c.d*(sf==4),
|
||||||
c.red, c.green, c.blue, c
|
c.red, c.green, c.blue, c
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void drawFullCube(SDL_Renderer* renderer, cube_0 cb) {
|
|
||||||
int sfToDraw = surfaceDrawOrder(camx, camy, camz, cb);
|
|
||||||
for(int k = 0; k < sfToDraw; k++) {
|
|
||||||
drawSfOfCube(renderer, drawOrder[k], cb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------------- //
|
void add_triangles_cb(cube_0* arr, int len) {
|
||||||
|
|
||||||
void swap_cb(cube_0* arr, int i, int j) {
|
|
||||||
cube_0 temp = arr[i];
|
|
||||||
arr[i] = arr[j];
|
|
||||||
arr[j] = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap_tp(teleporter* arr, int i, int j) {
|
|
||||||
teleporter temp = arr[i];
|
|
||||||
arr[i] = arr[j];
|
|
||||||
arr[j] = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void swap_ent(entity* arr, int i, int j) {
|
|
||||||
entity temp = arr[i];
|
|
||||||
arr[i] = arr[j];
|
|
||||||
arr[j] = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
double mult_x = 1.0 ;
|
|
||||||
double mult_y = 1.0 ;
|
|
||||||
double mult_z = 1.0 ;
|
|
||||||
|
|
||||||
void insertionSort_cb(cube_0* arr, int len) {
|
|
||||||
for(int k = 0; k < len; k++) {
|
for(int k = 0; k < len; k++) {
|
||||||
int j = k-1 ;
|
add_single(arr[k]);
|
||||||
while(j >= 0) {
|
|
||||||
//if(distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j]) < distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j+1])) {
|
|
||||||
//if(distance_pt_cube_0_3d_max(camx, camy, camz, arr[j]) < distance_pt_cube_0_3d_max(camx, camy, camz, arr[j+1])) {
|
|
||||||
if(
|
|
||||||
distance_pt_cube_0_3d_max(camx, camy, camz, arr[j]) + distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j]) <
|
|
||||||
distance_pt_cube_0_3d_max(camx, camy, camz, arr[j+1]) + distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j+1])) {
|
|
||||||
//if(cube_z_distance_to_camera(arr[j]) < cube_z_distance_to_camera(arr[j+1])) {
|
|
||||||
swap_cb(arr, j, j+1);
|
|
||||||
j -= 1;
|
|
||||||
} else {
|
|
||||||
j = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertionSort_tp(teleporter* arr, int len) {
|
void add_triangles_tp(teleporter* arr, int len) {
|
||||||
for(int k = 0; k < len; k++) {
|
for(int k = 0; k < len; k++) {
|
||||||
int j = k-1 ;
|
add_single(arr[k].hitbox);
|
||||||
while(j >= 0) {
|
|
||||||
//if(distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j].hitbox) < distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j+1].hitbox)) {
|
|
||||||
//if(distance_pt_cube_0_3d_max(camx, camy, camz, arr[j].hitbox) < distance_pt_cube_0_3d_max(camx, camy, camz, arr[j+1].hitbox)) {
|
|
||||||
if(distance_pt_cube_0_3d_max(camx, camy, camz, arr[j].hitbox) + distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j].hitbox) <
|
|
||||||
distance_pt_cube_0_3d_max(camx, camy, camz, arr[j+1].hitbox) + distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, arr[j+1].hitbox)) {
|
|
||||||
//if(cube_z_distance_to_camera(arr[j].hitbox) < cube_z_distance_to_camera(arr[j+1].hitbox)) {
|
|
||||||
swap_tp(arr, j, j+1);
|
|
||||||
j -= 1;
|
|
||||||
} else {
|
|
||||||
j = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertionSort_ent(entity* arr, int len) {
|
void add_triangles_ent(entity* arr, int len) {
|
||||||
for(int k = 0; k < len; k++) {
|
for(int k = 0; k < len; k++) {
|
||||||
int j = k-1 ;
|
add_single(*(arr[k].pos));
|
||||||
while(j >= 0) {
|
}
|
||||||
//if(distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, *(arr[j].pos)) < distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, *(arr[j+1].pos))) {
|
}
|
||||||
//if(distance_pt_cube_0_3d_max(camx, camy, camz, *(arr[j].pos)) < distance_pt_cube_0_3d_max(camx, camy, camz, *(arr[j+1].pos))) {
|
|
||||||
if(distance_pt_cube_0_3d_max(camx, camy, camz, *(arr[j].pos)) + distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, *(arr[j].pos)) <
|
void renderTriangleFull(SDL_Renderer* renderer, int k) {
|
||||||
distance_pt_cube_0_3d_max(camx, camy, camz, *(arr[j+1].pos)) + distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, *(arr[j+1].pos))) {
|
renderTriangleNoProject(renderer,
|
||||||
//if(cube_z_distance_to_camera(*(arr[j].pos)) < cube_z_distance_to_camera(*(arr[j+1].pos))) {
|
triangles_to_render[k][0].x, triangles_to_render[k][0].y, triangles_to_render[k][0].z,
|
||||||
swap_ent(arr, j, j+1);
|
triangles_to_render[k][1].x, triangles_to_render[k][1].y, triangles_to_render[k][1].z,
|
||||||
j -= 1;
|
triangles_to_render[k][2].x, triangles_to_render[k][2].y, triangles_to_render[k][2].z,
|
||||||
} else {
|
reds[k], greens[k], blues[k], false
|
||||||
j = -1;
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
double deltaz ;
|
||||||
|
void visiting(int k, bool vflag) {
|
||||||
|
if(visited_tri[k] != vflag) {
|
||||||
|
visited_tri[k] = vflag;
|
||||||
|
for(int k2 = 0; k2 < triangles_i; k2++) {
|
||||||
|
if(k2 != k && visited_tri[k2] != vflag) {
|
||||||
|
if(delta_get(triangles_to_render[k], triangles_to_render[k2], &deltaz) && deltaz > 0.01) {
|
||||||
|
visiting(k2, vflag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
triangles_order[visited_i] = k;
|
||||||
|
visited_i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void topological_sort() {
|
||||||
|
bool vflag = !visited_tri[0];
|
||||||
|
for(int k = 0; k < triangles_i; k++) {
|
||||||
|
visiting(k, vflag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawCurrentRoom(SDL_Renderer* renderer) {
|
void drawCurrentRoom(SDL_Renderer* renderer) {
|
||||||
insertionSort_cb(current_room->map, current_room->map_size);
|
triangles_i = 0;
|
||||||
insertionSort_tp(current_room->tps, current_room->tps_size);
|
visited_i = 0;
|
||||||
insertionSort_ent(current_room->ents, current_room->ent_len);
|
add_triangles_cb(current_room->map, current_room->map_size);
|
||||||
|
add_triangles_tp(current_room->tps, current_room->tps_size);
|
||||||
/*for(int k1 = 0; k1 < current_room->map_size; k1++) {
|
add_triangles_ent(current_room->ents, current_room->ent_len);
|
||||||
current_room->map[k1].red = 188 ;
|
topological_sort();
|
||||||
current_room->map[k1].green = 0 ;
|
for(int k = 0; k < triangles_i; k++) {
|
||||||
current_room->map[k1].blue = 0 ;
|
renderTriangleFull(renderer, triangles_order[k]);
|
||||||
}
|
|
||||||
|
|
||||||
int front ;
|
|
||||||
for(int k1 = 0; k1 < current_room->map_size; k1++) {
|
|
||||||
for(int k2 = k1+1; k2 < current_room->map_size; k2++) {
|
|
||||||
if(cubeOverlap(current_room->map[k1], current_room->map[k2], &front)) {
|
|
||||||
current_room->map[k1].red = 188*(front==1) ;
|
|
||||||
current_room->map[k1].green = 188 ;
|
|
||||||
current_room->map[k2].red = 188*(front==-1) ;
|
|
||||||
current_room->map[k2].green = 188 ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/*for(int k = 0; k < triangles_i; k++) {
|
||||||
|
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)(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)),
|
||||||
|
75/4, 105/4, 0
|
||||||
|
);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if(true || draw_type == 0) {
|
|
||||||
for(int k = 0; k < current_room->map_size; k++) {
|
|
||||||
drawFullCube(renderer, current_room->map[k]);
|
|
||||||
}
|
|
||||||
for(int k = 0; k < current_room->ent_len; k++) {
|
|
||||||
drawFullCube(renderer, *(current_room->ents[k].pos));
|
|
||||||
}
|
|
||||||
for(int k = 0; k < current_room->tps_size; k++) {
|
|
||||||
drawFullCube(renderer, current_room->tps[k].hitbox);
|
|
||||||
}
|
|
||||||
} else if(draw_type == 1) {
|
|
||||||
int k_cb = 0 ;
|
|
||||||
int k_tp = 0 ;
|
|
||||||
int k_et = 0 ;
|
|
||||||
|
|
||||||
int updated = 1+2+4 ;
|
|
||||||
|
|
||||||
double dcb = -1.0 ;
|
|
||||||
double dtp = -1.0 ;
|
|
||||||
double det = -1.0 ;
|
|
||||||
while(k_cb < current_room->map_size || k_tp < current_room->tps_size || k_et < current_room->ent_len) {
|
|
||||||
if(updated == 7) {
|
|
||||||
if(k_et < current_room->ent_len) {
|
|
||||||
det = distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, *(current_room->ents[k_et].pos));
|
|
||||||
}
|
|
||||||
if(k_tp < current_room->tps_size) {
|
|
||||||
dtp = distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, current_room->tps[k_tp].hitbox);
|
|
||||||
}
|
|
||||||
if(k_cb < current_room->map_size) {
|
|
||||||
dcb = distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, current_room->map[k_cb]);
|
|
||||||
}
|
|
||||||
} else if((updated/4)%2 == 1) {
|
|
||||||
if(k_et < current_room->ent_len) {
|
|
||||||
det = distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, *(current_room->ents[k_et].pos));
|
|
||||||
} else {
|
|
||||||
det = -1.0 ;
|
|
||||||
}
|
|
||||||
} else if((updated/2)%2 == 1) {
|
|
||||||
if(k_tp < current_room->tps_size) {
|
|
||||||
dtp = distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, current_room->tps[k_tp].hitbox);
|
|
||||||
} else {
|
|
||||||
dtp = -1.0 ;
|
|
||||||
}
|
|
||||||
} else if(updated%2 == 1) {
|
|
||||||
if(k_cb < current_room->map_size) {
|
|
||||||
dcb = distance_pt_cube_0_3d_weighted(camx, camy, camz, mult_x, mult_y, mult_z, current_room->map[k_cb]);
|
|
||||||
} else {
|
|
||||||
dcb = -1.0 ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updated = 0 ;
|
|
||||||
double mn = maxd(maxd(dcb, dtp), det);
|
|
||||||
if(mn == dcb) {
|
|
||||||
drawFullCube(renderer, current_room->map[k_cb]);
|
|
||||||
updated += 1 ;
|
|
||||||
k_cb += 1;
|
|
||||||
}
|
|
||||||
if(mn == dtp) {
|
|
||||||
drawFullCube(renderer, current_room->tps[k_tp].hitbox);
|
|
||||||
updated += 2 ;
|
|
||||||
k_tp += 1;
|
|
||||||
}
|
|
||||||
if(mn == det) {
|
|
||||||
drawFullCube(renderer, *(current_room->ents[k_et].pos));
|
|
||||||
updated += 4;
|
|
||||||
k_et += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------------------------------------------------------------- //
|
||||||
|
|
|
@ -44,22 +44,12 @@ void drawCurrentRoom(SDL_Renderer* renderer);
|
||||||
|
|
||||||
void drawData(SDL_Renderer* renderer);
|
void drawData(SDL_Renderer* renderer);
|
||||||
|
|
||||||
void renderTriangle(
|
void renderTriangleNoProject(
|
||||||
SDL_Renderer* renderer,
|
SDL_Renderer* renderer,
|
||||||
double x0, double y0, double z0,
|
double x0, double y0, double z0,
|
||||||
double x1, double y1, double z1,
|
double x1, double y1, double z1,
|
||||||
double x2, double y2, double z2,
|
double x2, double y2, double z2,
|
||||||
int red, int green, int blue
|
int red, int green, int blue, bool debug
|
||||||
);
|
);
|
||||||
void renderTriangleRotated(
|
|
||||||
SDL_Renderer* renderer,
|
|
||||||
double x0, double y0, double z0,
|
|
||||||
double x1, double y1, double z1,
|
|
||||||
double x2, double y2, double z2,
|
|
||||||
int red, int green, int blue,
|
|
||||||
cube_0 cb
|
|
||||||
);
|
|
||||||
void drawSfOfCube(SDL_Renderer* renderer, int sf, cube_0 cb);
|
|
||||||
void drawFullCube(SDL_Renderer* renderer, cube_0 cb);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -15,6 +15,7 @@
|
||||||
#include "structure.h"
|
#include "structure.h"
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "triangles.h"
|
||||||
#include "entities.h"
|
#include "entities.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "generation.h"
|
#include "generation.h"
|
||||||
|
@ -55,7 +56,7 @@ int main(int argc, char** argv) {
|
||||||
init_hashtbl() ;
|
init_hashtbl() ;
|
||||||
init_draworder() ;
|
init_draworder() ;
|
||||||
trInit();
|
trInit();
|
||||||
parse_rooms(3);
|
parse_rooms(4);
|
||||||
import_digits(rend) ;
|
import_digits(rend) ;
|
||||||
import_letters(rend) ;
|
import_letters(rend) ;
|
||||||
sim_time = 0.0 ;
|
sim_time = 0.0 ;
|
||||||
|
|
|
@ -115,12 +115,7 @@ extern int draw_type ;
|
||||||
|
|
||||||
extern double draw_constant ;
|
extern double draw_constant ;
|
||||||
|
|
||||||
extern double px0; extern double py0; extern double pz0;
|
extern pt_2d** triangles_to_render ;
|
||||||
extern double px1; extern double py1; extern double pz1;
|
extern int triangles_i ;
|
||||||
extern double px2; extern double py2; extern double pz2;
|
|
||||||
extern double fpx0; extern double fpy0; extern double fpz0;
|
|
||||||
extern double fpx1; extern double fpy1; extern double fpz1;
|
|
||||||
extern double mpx0; extern double mpy0; extern double mpz0;
|
|
||||||
extern double mpx1; extern double mpy1; extern double mpz1;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
205
src/triangles.c
205
src/triangles.c
|
@ -14,15 +14,10 @@
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "structure.h"
|
#include "structure.h"
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
#include "display.h"
|
||||||
#include "triangles.h"
|
#include "triangles.h"
|
||||||
|
|
||||||
double px0; double py0; double pz0;
|
double draw_incr = 0.0 ;
|
||||||
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;
|
|
||||||
|
|
||||||
int errno = 0;
|
int errno = 0;
|
||||||
pt_2d* triangle_1 ;
|
pt_2d* triangle_1 ;
|
||||||
|
@ -132,7 +127,7 @@ bool triTri2D(pt_2d* t1, pt_2d* t2, double eps, bool allowReversed, bool onBound
|
||||||
}
|
}
|
||||||
|
|
||||||
bool triangleIntersection(pt_2d* tri1, pt_2d* tri2) {
|
bool triangleIntersection(pt_2d* tri1, pt_2d* tri2) {
|
||||||
return triTri2D(tri1, tri2, 0.0, false, true);
|
return triTri2D(tri1, tri2, 0.0, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -145,10 +140,12 @@ bool triangleIntersectionDec(pt_2d t1_1, pt_2d t1_2, pt_2d t1_3, pt_2d t2_1, pt_
|
||||||
return triangleIntersection(triangle_1, triangle_2);
|
return triangleIntersection(triangle_1, triangle_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool multipleTrianglesIntersection(pt_2d* tri1, int len1, pt_2d* tri2, int len2) {
|
bool multipleTrianglesIntersection(pt_2d* tri1, int len1, pt_2d* tri2, int len2, int* ret1, int* ret2) {
|
||||||
for(int k1 = 0; k1 < len1; k1+=3) {
|
for(int k1 = 0; k1 < len1; k1+=3) {
|
||||||
for(int k2 = 0; k2 < len2; k2+=3) {
|
for(int k2 = 0; k2 < len2; k2+=3) {
|
||||||
if(triangleIntersection(&tri1[k1], &tri2[k2])) {
|
if(triangleIntersection(&tri1[k1], &tri2[k2])) {
|
||||||
|
if(ret1 != NULL) {*ret1 = k1;}
|
||||||
|
if(ret2 != NULL) {*ret2 = k2;}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,17 +167,24 @@ int returnTriangle(
|
||||||
double x2, double y2, double z2,
|
double x2, double y2, double z2,
|
||||||
pt_2d* retarr
|
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(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 + 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[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[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);
|
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;
|
return 3;
|
||||||
} else if((pz0 >= draw_constant) + (pz1 >= draw_constant) + (pz2 >= draw_constant) == 2) {
|
} else if((pz0 >= (draw_constant + draw_incr)) + (pz1 >= (draw_constant + draw_incr)) + (pz2 >= (draw_constant + draw_incr)) == 2) {
|
||||||
if(pz0 < draw_constant) {
|
if(pz0 < (draw_constant + draw_incr)) {
|
||||||
// pz1 >= draw_constant and pz2 >+ draw_constant
|
// pz1 >= (draw_constant + draw_incr) and pz2 >+ (draw_constant + draw_incr)
|
||||||
fpx0 = px1 ; fpy0 = py1 ; fpz0 = pz1 ;
|
fpx0 = px1 ; fpy0 = py1 ; fpz0 = pz1 ;
|
||||||
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
||||||
// 1-0 segment
|
// 1-0 segment
|
||||||
|
@ -196,8 +200,8 @@ int returnTriangle(
|
||||||
convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0)),
|
convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0)),
|
||||||
convex_pt(z2, z0, (pz2 - draw_constant)/(pz2 - pz0)),
|
convex_pt(z2, z0, (pz2 - draw_constant)/(pz2 - pz0)),
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
&mpx1, &mpy1, &mpz1) ;
|
||||||
} else if(pz1 < draw_constant) {
|
} else if(pz1 < (draw_constant + draw_incr)) {
|
||||||
// pz0 >= draw_constant and pz2 >+ draw_constant
|
// pz0 >= (draw_constant + draw_incr) and pz2 >+ (draw_constant + draw_incr)
|
||||||
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
||||||
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
fpx1 = px2 ; fpy1 = py2 ; fpz1 = pz2 ;
|
||||||
// 0-1 segment
|
// 0-1 segment
|
||||||
|
@ -213,8 +217,8 @@ int returnTriangle(
|
||||||
convex_pt(y2, y1, (pz2 - draw_constant)/(pz2 - pz1)),
|
convex_pt(y2, y1, (pz2 - draw_constant)/(pz2 - pz1)),
|
||||||
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
|
convex_pt(z2, z1, (pz2 - draw_constant)/(pz2 - pz1)),
|
||||||
&mpx1, &mpy1, &mpz1) ;
|
&mpx1, &mpy1, &mpz1) ;
|
||||||
} else /*if(pz2 < draw_constant)*/ {
|
} else /*if(pz2 < (draw_constant + draw_incr))*/ {
|
||||||
// pz1 >= draw_constant and pz0 >+ draw_constant
|
// pz1 >= (draw_constant + draw_incr) and pz0 >+ (draw_constant + draw_incr)
|
||||||
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
fpx0 = px0 ; fpy0 = py0 ; fpz0 = pz0 ;
|
||||||
fpx1 = px1 ; fpy1 = py1 ; fpz1 = pz1 ;
|
fpx1 = px1 ; fpy1 = py1 ; fpz1 = pz1 ;
|
||||||
// 0-2 segment
|
// 0-2 segment
|
||||||
|
@ -239,8 +243,8 @@ int returnTriangle(
|
||||||
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[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);
|
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;
|
return 6;
|
||||||
} else if((pz0 >= draw_constant) + (pz1 >= draw_constant) + (pz2 >= draw_constant) == 1) {
|
} else if((pz0 >= (draw_constant + draw_incr)) + (pz1 >= (draw_constant + draw_incr)) + (pz2 >= (draw_constant + draw_incr)) == 1) {
|
||||||
if(pz0 >= draw_constant) {
|
if(pz0 >= (draw_constant + draw_incr)) {
|
||||||
project_to_camera(
|
project_to_camera(
|
||||||
convex_pt(x0, x1, (pz0 - draw_constant)/(pz0 - pz1)),
|
convex_pt(x0, x1, (pz0 - draw_constant)/(pz0 - pz1)),
|
||||||
convex_pt(y0, y1, (pz0 - draw_constant)/(pz0 - pz1)),
|
convex_pt(y0, y1, (pz0 - draw_constant)/(pz0 - pz1)),
|
||||||
|
@ -251,7 +255,7 @@ int returnTriangle(
|
||||||
convex_pt(y0, y2, (pz0 - draw_constant)/(pz0 - pz2)),
|
convex_pt(y0, y2, (pz0 - draw_constant)/(pz0 - pz2)),
|
||||||
convex_pt(z0, z2, (pz0 - draw_constant)/(pz0 - pz2)),
|
convex_pt(z0, z2, (pz0 - draw_constant)/(pz0 - pz2)),
|
||||||
&px2, &py2, &pz2);
|
&px2, &py2, &pz2);
|
||||||
} else if(pz1 >= draw_constant) {
|
} else if(pz1 >= (draw_constant + draw_incr)) {
|
||||||
project_to_camera(
|
project_to_camera(
|
||||||
convex_pt(x1, x0, (pz1 - draw_constant)/(pz1 - pz0)),
|
convex_pt(x1, x0, (pz1 - draw_constant)/(pz1 - pz0)),
|
||||||
convex_pt(y1, y0, (pz1 - draw_constant)/(pz1 - pz0)),
|
convex_pt(y1, y0, (pz1 - draw_constant)/(pz1 - pz0)),
|
||||||
|
@ -262,7 +266,7 @@ int returnTriangle(
|
||||||
convex_pt(y1, y2, (pz1 - draw_constant)/(pz1 - pz2)),
|
convex_pt(y1, y2, (pz1 - draw_constant)/(pz1 - pz2)),
|
||||||
convex_pt(z1, z2, (pz1 - draw_constant)/(pz1 - pz2)),
|
convex_pt(z1, z2, (pz1 - draw_constant)/(pz1 - pz2)),
|
||||||
&px2, &py2, &pz2);
|
&px2, &py2, &pz2);
|
||||||
} else if(pz2 >= draw_constant) {
|
} else if(pz2 >= (draw_constant + draw_incr)) {
|
||||||
project_to_camera(
|
project_to_camera(
|
||||||
convex_pt(x2, x0, (pz2 - draw_constant)/(pz2 - pz0)),
|
convex_pt(x2, x0, (pz2 - draw_constant)/(pz2 - pz0)),
|
||||||
convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0)),
|
convex_pt(y2, y0, (pz2 - draw_constant)/(pz2 - pz0)),
|
||||||
|
@ -389,64 +393,127 @@ int visibleSurfaces(double x0, double y0, double z0, cube_0 cb, int* dOrd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_zdepths(cube_0 c, int sf, double* ret) {
|
bool noWT;
|
||||||
pt_2d campt = to_fpoint(camx, camy, camz);
|
double sign_triangle(pt_2d p1, pt_2d p2, pt_2d p3) {
|
||||||
if(sf == 0 || sf == 1) { // x
|
return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
|
||||||
ret[0] = zdepth_of_pt(c.x + c.w*(sf==0), c.y, c.z );
|
|
||||||
ret[1] = zdepth_of_pt(c.x + c.w*(sf==0), c.y + c.h, c.z );
|
|
||||||
ret[2] = zdepth_of_pt(c.x + c.w*(sf==0), c.y , c.z + c.d);
|
|
||||||
ret[3] = zdepth_of_pt(c.x + c.w*(sf==0), c.y + c.h, c.z + c.d);
|
|
||||||
} else if(sf == 2 || sf == 3) { // y
|
|
||||||
ret[0] = zdepth_of_pt(c.x, c.y + c.h*(sf==2), c.z );
|
|
||||||
ret[1] = zdepth_of_pt(c.x + c.w, c.y + c.h*(sf==2), c.z );
|
|
||||||
ret[2] = zdepth_of_pt(c.x , c.y + c.h*(sf==2), c.z + c.d);
|
|
||||||
ret[3] = zdepth_of_pt(c.x + c.w, c.y + c.h*(sf==2), c.z + c.d);
|
|
||||||
} else { // z
|
|
||||||
ret[0] = zdepth_of_pt(c.x, c.y, c.z + c.d*(sf==4));
|
|
||||||
ret[1] = zdepth_of_pt(c.x + c.w, c.y, c.z + c.d*(sf==4));
|
|
||||||
ret[2] = zdepth_of_pt(c.x , c.y + c.h, c.z + c.d*(sf==4));
|
|
||||||
ret[3] = zdepth_of_pt(c.x + c.w, c.y + c.h, c.z + c.d*(sf==4));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_all_behind(double* back, double* front) {
|
pt_2d to_pt2d(double x0, double y0, double z0) {
|
||||||
for(int k = 0; k < 3; k++) {
|
pt_2d res;
|
||||||
if(back[k] > front[k]) {
|
res.x = x0;
|
||||||
|
res.y = y0;
|
||||||
|
res.z = z0;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
double dot_product_3D(pt_2d p1, pt_2d p2) {
|
||||||
|
return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z ;
|
||||||
|
}
|
||||||
|
|
||||||
|
double dot_product_2D(pt_2d p1, pt_2d p2) {
|
||||||
|
return p1.x*p2.x + p1.y*p2.y ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void return_barycentric(pt_2d p, pt_2d a, pt_2d b, pt_2d c, double* u, double* v, double* w) {
|
||||||
|
// get barycentric coords of p inside ABC triangle
|
||||||
|
pt_2d v0 = to_pt2d(b.x - a.x, b.y - a.y, b.z - a.z);
|
||||||
|
pt_2d v1 = to_pt2d(c.x - a.x, c.y - a.y, c.z - a.z);
|
||||||
|
pt_2d v2 = to_pt2d(p.x - a.x, p.y - a.y, p.z - a.z);
|
||||||
|
double d00 = dot_product_2D(v0, v0);
|
||||||
|
double d01 = dot_product_2D(v0, v1);
|
||||||
|
double d11 = dot_product_2D(v1, v1);
|
||||||
|
double d20 = dot_product_2D(v2, v0);
|
||||||
|
double d21 = dot_product_2D(v2, v1);
|
||||||
|
double denom = d00 * d11 - d01 * d01;
|
||||||
|
if(v != NULL) {*v = (d11 * d20 - d01 * d21) / denom;}
|
||||||
|
if(w != NULL) {*w = (d00 * d21 - d01 * d20) / denom;}
|
||||||
|
if(u != NULL && v != NULL && w != NULL) {*u = 1.0 - *v - *w;}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool point_in_triangle(pt_2d pt, pt_2d v1, pt_2d v2, pt_2d v3, double* thetaA, double* thetaB, double* thetaC) {
|
||||||
|
double d1, d2, d3;
|
||||||
|
bool has_neg, has_pos;
|
||||||
|
|
||||||
|
d1 = sign_triangle(pt, v1, v2);
|
||||||
|
d2 = sign_triangle(pt, v2, v3);
|
||||||
|
d3 = sign_triangle(pt, v3, v1);
|
||||||
|
|
||||||
|
has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
|
||||||
|
has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
|
||||||
|
|
||||||
|
if(!(has_neg && has_pos)) {
|
||||||
|
return_barycentric(pt, v1, v2, v3, thetaA, thetaB, thetaC);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int which_is_in_front(cube_0 c1, int sfc1, cube_0 c2, int sfc2) {
|
bool seg_seg_inter(pt_2d p1, pt_2d p2, pt_2d p3, pt_2d p4, double* ret0, double* ret1) {
|
||||||
int nVis1 = visibleSurfaces(camx, camy, camz, c1, dOrder1);
|
double deno = (p4.x - p3.x)*(p2.y - p1.y) - (p4.y - p3.y)*(p2.x - p1.x);
|
||||||
int nVis2 = visibleSurfaces(camx, camy, camz, c2, dOrder2);
|
if(0.0 <= deno && deno <= 0.001) {
|
||||||
for(int k1 = 0; k1 < nVis1; k1++) {
|
//printf("%lf -->", deno);
|
||||||
for(int k2 = 0; k2 < nVis2; k2++) {
|
deno = 0.001 ;
|
||||||
get_zdepths(c1, dOrder1[k1], zdepths1);
|
} else if(-0.001 <= deno && deno <= 0.0) {
|
||||||
get_zdepths(c2, dOrder2[k2], zdepths2);
|
//printf("%lf -->", deno);
|
||||||
if(is_all_behind(zdepths1, zdepths2)) {
|
deno = -0.001 ;
|
||||||
return 1;
|
|
||||||
} else if(is_all_behind(zdepths2, zdepths1)) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
//printf("%lf\n", deno);
|
||||||
}
|
double alpha =
|
||||||
return 0;
|
((p4.x - p3.x)*(p3.y - p1.y) - (p4.y - p3.y)*(p3.x - p1.x))/
|
||||||
|
(deno) ;
|
||||||
|
|
||||||
|
double beta =
|
||||||
|
((p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x))/
|
||||||
|
(deno) ;
|
||||||
|
|
||||||
|
if(ret0 != NULL) {*ret0 = alpha;}
|
||||||
|
if(ret1 != NULL) {*ret1 = beta;}
|
||||||
|
return (alpha >= 0.0 && alpha <= 1.0 && beta >= 0.0 && beta <= 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cubeOverlap(cube_0 c1, cube_0 c2, int* retval) {
|
void print_tri(pt_2d* t) {
|
||||||
int len1 = 0;
|
printf("T :\n (%lf, %lf, %lf)\n (%lf, %lf, %lf)\n (%lf, %lf, %lf)\n", t[0].x, t[0].y, t[0].z, t[1].x, t[1].y, t[1].z, t[2].x, t[2].y, t[2].z);
|
||||||
int len2 = 0;
|
}
|
||||||
for(int i1 = 0; i1 < 6; i1++) {
|
|
||||||
for(int i2 = i1+1; i2 < 6; i2++) {
|
double triangle_dist(pt_2d* tri) {
|
||||||
for(int n = 0; n < 4; n++) {
|
return (tri[0].z + tri[1].z + tri[2].z);
|
||||||
len1 = fillPolygon(i1, c1, n%2, cube_t1);
|
}
|
||||||
len2 = fillPolygon(i2, c2, n/2, cube_t2);
|
|
||||||
if(multipleTrianglesIntersection(cube_t1, len1, cube_t2, len2)) {
|
bool delta_get2(pt_2d* tri1, pt_2d* tri2, double* ret) {
|
||||||
if(retval != NULL) {*retval = which_is_in_front(c1, i1, c2, i2);}
|
if(triangleIntersection(tri1, tri2)) {
|
||||||
|
if(ret != NULL) {
|
||||||
|
*ret = triangle_dist(tri2) - triangle_dist(tri1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool delta_get(pt_2d* tri1, pt_2d* tri2, double* ret) {
|
||||||
|
double th1 = 0.0;
|
||||||
|
double th2 = 0.0;
|
||||||
|
double th3 = 0.0;
|
||||||
|
for(int k = 0; k < 3; k++) { // pt
|
||||||
|
if(point_in_triangle(tri1[k], tri2[0], tri2[1], tri2[2], &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;}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if(point_in_triangle(tri2[k], tri1[0], tri1[1], tri1[2], &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);}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int k1 = 0; k1 < 3; k1++) { // seg
|
||||||
|
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)) {
|
||||||
|
//print_tri(tri1);
|
||||||
|
//print_tri(tri2);
|
||||||
|
//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);}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,11 @@ bool boundaryDoesntCollideChk(pt_2d *p1, pt_2d *p2, pt_2d *p3, double eps) ;
|
||||||
bool triTri2D(pt_2d* t1, pt_2d* t2, double eps, bool allowReversed, bool onBoundary) ;
|
bool triTri2D(pt_2d* t1, pt_2d* t2, double eps, bool allowReversed, bool onBoundary) ;
|
||||||
bool triangleIntersection(pt_2d* tri1, pt_2d* tri2);
|
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);
|
||||||
|
|
||||||
int returnTriangle(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, pt_2d* retarr);
|
int returnTriangle(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, pt_2d* retarr);
|
||||||
int fillPolygon(int sf, cube_0 c, int trig, pt_2d* ret);
|
int fillPolygon(int sf, cube_0 c, int trig, pt_2d* ret);
|
||||||
|
|
||||||
bool cubeOverlap(cube_0 c1, cube_0 c2, int* retval);
|
bool delta_get(pt_2d* tri1, pt_2d* tri2, double* ret);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,16 @@
|
||||||
|
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]
|
||||||
|
[-10.0, 1.0, -10.0, 5.0, 6.0, 5.0, 0.0, 0.0, 92, 92, 92]
|
||||||
|
[5.0, 1.0, 5.0, 5.0, 6.0, 5.0, 0.0, 0.0, 92, 92, 93]
|
||||||
|
|
||||||
|
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 :
|
||||||
|
50
|
||||||
|
|
||||||
|
$
|
Loading…
Reference in New Issue