|
|
|
@ -6,12 +6,15 @@
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
int NNNN = 0;
|
|
|
|
|
typedef struct {
|
|
|
|
|
double x;
|
|
|
|
|
double y;
|
|
|
|
|
double z;
|
|
|
|
|
double slope1;
|
|
|
|
|
double slope2;
|
|
|
|
|
int vertex;
|
|
|
|
|
int index;
|
|
|
|
|
} cord;
|
|
|
|
|
int point_on_line(double x,double y,double lx1,double ly1, double lx2,double ly2){
|
|
|
|
|
double crossproduct = (y-ly1)*(lx2-lx1) - (x-lx1)*(ly2-ly1);
|
|
|
|
@ -35,7 +38,7 @@ cord poi_d(double x1,double y1,double x2, double y2,int len,GLfloat* pixels,int
|
|
|
|
|
aa.z = -1;
|
|
|
|
|
|
|
|
|
|
for(int yyu = 0; yyu!=len-1; yyu++){
|
|
|
|
|
//if(yyu==ign)continue;
|
|
|
|
|
if(yyu==ign)continue;
|
|
|
|
|
double x3 = pixels[yyu*2];
|
|
|
|
|
double x4 = pixels[(yyu+1)*2];
|
|
|
|
|
double y3 = pixels[yyu*2+1];
|
|
|
|
@ -54,6 +57,7 @@ cord poi_d(double x1,double y1,double x2, double y2,int len,GLfloat* pixels,int
|
|
|
|
|
if(isnan(nsx)||isnan(nsy)||!(0<=s&&1>=s&&0<=t&&1>=t))
|
|
|
|
|
continue;
|
|
|
|
|
//printf("%f %f, %f %f | (%f,%f),(%f,%f)\n",nsx,nsy,nsx2,nsy2,x1,y1,x2,y2);
|
|
|
|
|
//printf("%f %f\n",s,t);
|
|
|
|
|
if(!(nsx>=lesser(x1,x2)&&nsx<=greater(x2,x1)&&nsy>=lesser(y1,y2)&&nsy<=greater(y2,y1))||(diff(nsx,x1)<FL_DIS&&diff(nsy,y1)<FL_DIS))
|
|
|
|
|
continue;
|
|
|
|
|
//printf("aaa\n");
|
|
|
|
@ -61,6 +65,9 @@ cord poi_d(double x1,double y1,double x2, double y2,int len,GLfloat* pixels,int
|
|
|
|
|
if(aa.z==-1||pow(nsx-x1,2)+pow(nsy-y1,2)<pow(aa.x-x1,2)+pow(aa.y-y1,2)){
|
|
|
|
|
aa.x = nsx;
|
|
|
|
|
aa.y = nsy;
|
|
|
|
|
aa.slope1 = s;
|
|
|
|
|
aa.slope2 = t;
|
|
|
|
|
aa.index = yyu;
|
|
|
|
|
}
|
|
|
|
|
aa.z++;
|
|
|
|
|
if(!shortest)
|
|
|
|
@ -101,19 +108,15 @@ GLuint prog;
|
|
|
|
|
static const char* vshader_src =
|
|
|
|
|
"#version 330\n"
|
|
|
|
|
"layout (location = 0) in vec3 pos;\n"
|
|
|
|
|
"layout (location = 1) in vec3 color;\n"
|
|
|
|
|
"layout (location = 2) in float trans;\n"
|
|
|
|
|
"layout (location = 1) in vec3 color;\n"
|
|
|
|
|
"out vec3 ncolor;\n"
|
|
|
|
|
"out float ntrans;\n"
|
|
|
|
|
"void main(){\n"
|
|
|
|
|
"ncolor = color;\n"
|
|
|
|
|
"ntrans = trans;\n"
|
|
|
|
|
"gl_Position = vec4(pos,1.0);\n"
|
|
|
|
|
"};";
|
|
|
|
|
static const char* fshader_src =
|
|
|
|
|
"#version 330\n"
|
|
|
|
|
"in vec3 ncolor;\n"
|
|
|
|
|
"in float ntrans;\n"
|
|
|
|
|
"out vec4 color;\n"
|
|
|
|
|
"void main(){\n"
|
|
|
|
|
//"gl_FragColor = vec4(1.0,0.0,1.0,1.0);\n"
|
|
|
|
@ -179,26 +182,19 @@ typedef struct {
|
|
|
|
|
//double depth;
|
|
|
|
|
cord max;
|
|
|
|
|
cord min;
|
|
|
|
|
int lin;
|
|
|
|
|
} glfl_ar;
|
|
|
|
|
void render_p(glfl_ar* bba){
|
|
|
|
|
void render_p(glfl_ar* bba,int tri){
|
|
|
|
|
//glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC1_ALPHA);
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
//glEnable(GL_BLEND);
|
|
|
|
|
//glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
GLuint verta;
|
|
|
|
|
glGenVertexArrays(1,&verta);
|
|
|
|
|
glBindVertexArray(verta);
|
|
|
|
|
/*
|
|
|
|
|
GLuint vetb;
|
|
|
|
|
glGenBuffers(1,&vetb);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,vetb);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER,sizeof(*bba->pix)*(bba->len*3),bba->pix,GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,vetb);
|
|
|
|
|
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,(void*)0);
|
|
|
|
|
*/
|
|
|
|
|
GLuint vetb;
|
|
|
|
|
int triang = tri;
|
|
|
|
|
if(triang){
|
|
|
|
|
GLuint vetb;
|
|
|
|
|
glGenBuffers(1,&vetb);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,vetb);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER,sizeof(*bba->tri)*(bba->tlen*12),bba->tri,GL_STATIC_DRAW);
|
|
|
|
@ -206,17 +202,7 @@ void render_p(glfl_ar* bba){
|
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,vetb);
|
|
|
|
|
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,(void*)0);
|
|
|
|
|
/*
|
|
|
|
|
GLuint colb;
|
|
|
|
|
glGenBuffers(1,&colb);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,colb);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER,sizeof(*bba->col)*(bba->len*4),bba->col,GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,colb);
|
|
|
|
|
glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,0,(void*)0);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLuint colb;
|
|
|
|
|
glGenBuffers(1,&colb);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,colb);
|
|
|
|
@ -226,134 +212,47 @@ void render_p(glfl_ar* bba){
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,colb);
|
|
|
|
|
glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,0,(void*)0);
|
|
|
|
|
|
|
|
|
|
GLuint trab;
|
|
|
|
|
glGenBuffers(1,&trab);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,trab);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER,sizeof(*bba->trans)*(bba->len*2),bba->trans,GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(2);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,trab);
|
|
|
|
|
glVertexAttribPointer(2,1,GL_FLOAT,GL_FALSE,0,(void*)0);
|
|
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLES,0,bba->tlen*3);
|
|
|
|
|
glDeleteBuffers(1,&trab);
|
|
|
|
|
|
|
|
|
|
glDeleteBuffers(1,&vetb);
|
|
|
|
|
glDeleteBuffers(1,&colb);
|
|
|
|
|
} else {
|
|
|
|
|
GLuint vetb;
|
|
|
|
|
glGenBuffers(1,&vetb);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,vetb);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER,sizeof(*bba->pix)*(bba->len*3),bba->pix,GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,vetb);
|
|
|
|
|
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,(void*)0);
|
|
|
|
|
|
|
|
|
|
GLuint colb;
|
|
|
|
|
glGenBuffers(1,&colb);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,colb);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER,sizeof(*bba->col)*(bba->len*5),bba->col,GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER,colb);
|
|
|
|
|
glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,0,(void*)0);
|
|
|
|
|
|
|
|
|
|
glDrawArrays(GL_POINTS,0,bba->len);
|
|
|
|
|
|
|
|
|
|
glDeleteBuffers(1,&vetb);
|
|
|
|
|
glDeleteBuffers(1,&colb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
glfl_ar* perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,double ctz,double cx, double cy, double cz){
|
|
|
|
|
|
|
|
|
|
GLfloat* pixels = malloc(sizeof(*pixels)*((1+c->len)*3));
|
|
|
|
|
GLfloat* colors = malloc(sizeof(*colors)*((1+c->len)*4));
|
|
|
|
|
GLfloat* trans = malloc(sizeof(*trans)*((1+c->len)*2));
|
|
|
|
|
if(pixels==NULL||colors==NULL||trans==NULL)
|
|
|
|
|
err("failed to allocate perspective array:(",pexit);
|
|
|
|
|
double dep = 0.0;
|
|
|
|
|
double depy = 0.0;
|
|
|
|
|
double coy = cos(cty);
|
|
|
|
|
double sinz = sin(ctz);
|
|
|
|
|
double coz = cos(ctz);
|
|
|
|
|
double six = sin(ctx);
|
|
|
|
|
double siy = sin(cty);
|
|
|
|
|
double cox = cos(ctx);
|
|
|
|
|
double fov = 0.002;
|
|
|
|
|
double ex = cx;
|
|
|
|
|
double ey = cy;
|
|
|
|
|
refresh_size(b);
|
|
|
|
|
GLuint fb = 0;
|
|
|
|
|
int c_len = 0;
|
|
|
|
|
//double ez=1/tan(fov/2); //i dont get this at all
|
|
|
|
|
double ez=get_w();
|
|
|
|
|
//printf("---\n");
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
cord maxf;
|
|
|
|
|
cord minf;
|
|
|
|
|
maxf.x = -INFINITY;
|
|
|
|
|
maxf.y = -INFINITY;
|
|
|
|
|
maxf.z = -INFINITY;
|
|
|
|
|
|
|
|
|
|
minf.x = INFINITY;
|
|
|
|
|
minf.y = INFINITY;
|
|
|
|
|
minf.z = INFINITY;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i!=c->len; i++){
|
|
|
|
|
double ax = c->c[i].at.x;
|
|
|
|
|
double ay = c->c[i].at.y;
|
|
|
|
|
double az = c->c[i].at.z;
|
|
|
|
|
|
|
|
|
|
double eyz = (coz*(ay-cy)-sinz*ax-cx);
|
|
|
|
|
double yzm = (coy*(az-cz) + siy*(sinz*(ay-cy) + coz*(ax-cx)));
|
|
|
|
|
double dx = coy * (sinz*(ay-cy) + coz*(ax-cx)) - (siy*(az-cz));
|
|
|
|
|
double dy = six * yzm + cox*eyz;
|
|
|
|
|
double dz = cox * yzm - six*eyz;
|
|
|
|
|
|
|
|
|
|
double bx = ez/dz*dx+dx;
|
|
|
|
|
double by = ez/dz*dy+dy;
|
|
|
|
|
maxf.z = greater(maxf.z,dz);
|
|
|
|
|
minf.z = lesser(minf.z,dz);
|
|
|
|
|
|
|
|
|
|
maxf.x = greater(maxf.x,bx);
|
|
|
|
|
minf.x = lesser(minf.x,bx);
|
|
|
|
|
|
|
|
|
|
maxf.y = greater(maxf.y,by);
|
|
|
|
|
minf.y = lesser(minf.y,by);
|
|
|
|
|
if(dz>=0){
|
|
|
|
|
//printf("-- %f\n",dz);
|
|
|
|
|
//if(dz>dep) dep = dz;
|
|
|
|
|
ab_to_vp(xa,ya,get_w(),get_h(),bx,by);
|
|
|
|
|
pixels[c_len*2] = xa+1;
|
|
|
|
|
pixels[c_len*2+1] = ya;
|
|
|
|
|
colors[c_len*3] = c->c[i].color.r;
|
|
|
|
|
colors[c_len*3+1] = c->c[i].color.g;
|
|
|
|
|
colors[c_len*3+2] = c->c[i].color.b;
|
|
|
|
|
trans[c_len] = 0.5;
|
|
|
|
|
c_len++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//printf("%f\n",dep);
|
|
|
|
|
int fc_len = c_len;
|
|
|
|
|
/*
|
|
|
|
|
for(int i = 0; 0&&i<=fc_len-1; i++){
|
|
|
|
|
//printf("%f %f | %f %f\n",pixels[i*2],pixels[i*2+1],pixels[(i+1)*2],pixels[(i+1)*2+1]);
|
|
|
|
|
if(isinf(pixels[i*2])||isinf(pixels[i*2+1])||
|
|
|
|
|
isinf(pixels[(i+1)*2])||isinf(pixels[(i+1)*2+1]))
|
|
|
|
|
continue;
|
|
|
|
|
double x22[3] = {pixels[i*2],pixels[(i+1)*2]};
|
|
|
|
|
double y22[3] = {pixels[i*2+1],pixels[(i+1)*2+1]};
|
|
|
|
|
point_arr* bas = basier2d(x22,y22,2,0.1f,0.1f,0.1f);
|
|
|
|
|
|
|
|
|
|
pixels = realloc(pixels,sizeof(*pixels) *((c_len+2+bas->len)*3));
|
|
|
|
|
|
|
|
|
|
colors = realloc(colors,sizeof(*colors) *((c_len+2+bas->len)*4));
|
|
|
|
|
|
|
|
|
|
trans = realloc(trans,sizeof(*trans) *((c_len+2+bas->len)*2));
|
|
|
|
|
if(pixels==NULL||colors==NULL||trans==NULL)
|
|
|
|
|
err("can't reallocate AAA",pexit);
|
|
|
|
|
for(int zaa=0; zaa<=bas->len; zaa++){
|
|
|
|
|
|
|
|
|
|
pixels[c_len*2] = bas->c[zaa].at.x;
|
|
|
|
|
pixels[c_len*2+1] = bas->c[zaa].at.y;
|
|
|
|
|
colors[c_len*3] = colors[i*3];
|
|
|
|
|
colors[c_len*3+1] = colors[i*3+1];
|
|
|
|
|
colors[c_len*3+2] = colors[i*3+2];
|
|
|
|
|
trans[c_len] = 0.5;
|
|
|
|
|
c_len++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(bas->c);
|
|
|
|
|
free(bas->vert);
|
|
|
|
|
free(bas);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
//double dclen = c_len;
|
|
|
|
|
int vvi = 0;
|
|
|
|
|
|
|
|
|
|
glfl_ar* poly_to_tri(GLfloat* pixels,GLfloat* colors,int fc_len){
|
|
|
|
|
int vvi = 0;
|
|
|
|
|
int c_len = fc_len;
|
|
|
|
|
glfl_m* trline = malloc(sizeof(*trline));
|
|
|
|
|
trline->len = 0;
|
|
|
|
|
trline->at = malloc(sizeof(*trline->at)*fc_len);
|
|
|
|
|
if(trline==NULL||trline->at==NULL)
|
|
|
|
|
pexit(54);
|
|
|
|
|
for(int i = 0; i<=fc_len-1; i++){
|
|
|
|
|
if(c->c[i].at.vertex==1||1){
|
|
|
|
|
if(/*c->c[i].at.vertex==1||*/1){
|
|
|
|
|
if(pixels==NULL||colors==NULL)
|
|
|
|
|
pexit(55);
|
|
|
|
|
if(isinf(pixels[i*2]))
|
|
|
|
@ -389,7 +288,7 @@ glfl_ar* perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,doubl
|
|
|
|
|
{double aax[] = {pixels[i*2],aab.x};
|
|
|
|
|
double aay[] = {pixels[i*2+1],aab.y};
|
|
|
|
|
point_arr* frl = basier2d(aax,aay,2,0.1,0.1,0.1);
|
|
|
|
|
if(trans==NULL||pixels==NULL||colors==NULL)
|
|
|
|
|
if(pixels==NULL||colors==NULL)
|
|
|
|
|
pexit(55);
|
|
|
|
|
for(int cci = 0; cci<=frl->len; cci++){
|
|
|
|
|
trline->at[trline->len].at[trline->at[trline->len].len*2] = frl->c[cci].at.x;
|
|
|
|
@ -420,7 +319,7 @@ glfl_ar* perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,doubl
|
|
|
|
|
double aay[] = {pixels[i*2+1],aaa.y};
|
|
|
|
|
//printf("a %f %f | %f %f\n",pixels[i*2],aab.x,pixels[i*2+1],aab.y);
|
|
|
|
|
point_arr* frl = basier2d(aax,aay,2,0.1,0.1,0.1);
|
|
|
|
|
if(trans==NULL||pixels==NULL||colors==NULL)
|
|
|
|
|
if(pixels==NULL||colors==NULL)
|
|
|
|
|
pexit(55);
|
|
|
|
|
for(int cci = 0; cci<=frl->len; cci++){
|
|
|
|
|
trline->at[trline->len].at[trline->at[trline->len].len*2] = frl->c[cci].at.x;
|
|
|
|
@ -659,19 +558,440 @@ glfl_ar* perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,doubl
|
|
|
|
|
}
|
|
|
|
|
free(trline->at);
|
|
|
|
|
free(trline);
|
|
|
|
|
glfl_ar* rr = malloc(sizeof(*rr));
|
|
|
|
|
rr->tlen = tric;
|
|
|
|
|
rr->tri = tria;
|
|
|
|
|
rr->tricol =tricol;
|
|
|
|
|
rr->len = c_len;
|
|
|
|
|
return rr;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
glfl_ar** transp(glfl_ar** con,int lle){
|
|
|
|
|
int o_a_len = lle;
|
|
|
|
|
int aal[o_a_len];
|
|
|
|
|
glfl_ar** neww = malloc(sizeof ** neww * lle * 80);
|
|
|
|
|
int neww_l = 0;
|
|
|
|
|
for(int i = 0; i<=o_a_len-1; i++)
|
|
|
|
|
aal[i] = con[i]->len;
|
|
|
|
|
float b_r = 0.0f;
|
|
|
|
|
float b_g = 0.0f;
|
|
|
|
|
float b_b = 0.0f;
|
|
|
|
|
for(int i = 0; 0&&i<=o_a_len-1; i++){
|
|
|
|
|
for(int ii = 0; ii<=con[i]->len; ii++){
|
|
|
|
|
con[i]->col[ii*3] = (con[i]->col[ii*3] + b_r)/2;
|
|
|
|
|
con[i]->col[ii*3+1] = (con[i]->col[ii*3+1] + b_g)/2;
|
|
|
|
|
con[i]->col[ii*3+2] = (con[i]->col[ii*3+2] + b_b)/2;
|
|
|
|
|
}
|
|
|
|
|
for(int ii = 0; ii<=con[i]->tlen*4; ii++){
|
|
|
|
|
con[i]->tricol[ii*3] = (con[i]->tricol[ii*3] + b_r)/2;
|
|
|
|
|
con[i]->tricol[ii*3+1] = (con[i]->tricol[ii*3+1] + b_g)/2;
|
|
|
|
|
con[i]->tricol[ii*3+2] = (con[i]->tricol[ii*3+2] + b_b)/2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//for(int i = o_a_len-1; i>=0; i--)
|
|
|
|
|
// for(int z = o_a_len-1; z>=0; z--)
|
|
|
|
|
// printf(" %f %f %f\n",con[z]->col[3],con[z]->col[4],con[z]->col[5]);
|
|
|
|
|
//printf("s\n");
|
|
|
|
|
//printf("---\n");
|
|
|
|
|
for(int i = o_a_len-1; i>=0; i--){
|
|
|
|
|
|
|
|
|
|
for(int z = o_a_len-1; z>=0; z--){
|
|
|
|
|
if(i!=z){
|
|
|
|
|
//printf("a\n");
|
|
|
|
|
float c_r = (con[i]->col[3] + con[z]->col[3])/2;
|
|
|
|
|
float c_g = (con[i]->col[4] + con[z]->col[4])/2;
|
|
|
|
|
float c_b = (con[i]->col[5] + con[z]->col[5])/2;
|
|
|
|
|
//printf("b\n");
|
|
|
|
|
if(con[i]->max.x>=con[z]->max.x&&con[i]->min.x<=con[z]->min.x&&
|
|
|
|
|
con[i]->max.y>=con[z]->max.y&&con[i]->min.y<=con[z]->min.y){
|
|
|
|
|
//continue;
|
|
|
|
|
//printf("c\n");
|
|
|
|
|
//neww = realloc(neww,sizeof ** neww * (neww_l + 2));
|
|
|
|
|
neww[neww_l] = malloc(sizeof * neww[neww_l] * (1 + con[i]->len + con[z]->len) * 40);
|
|
|
|
|
neww[neww_l]->pix = malloc(sizeof * neww[neww_l]->pix * (1 + con[i]->len + con[z]->len) * 4);
|
|
|
|
|
neww[neww_l]->col = malloc(sizeof * neww[neww_l]->col * (1 + con[i]->len + con[z]->len) * 4);
|
|
|
|
|
for(int zz = 0; zz<=aal[z]; zz++){
|
|
|
|
|
neww[neww_l]->pix[zz*2] = con[z]->pix[zz*2];
|
|
|
|
|
neww[neww_l]->pix[zz*2+1] = con[z]->pix[zz*2+1];
|
|
|
|
|
//printf("%f %f\n",con[z]->pix[zz*2+1],con[z]->pix[zz*2]);
|
|
|
|
|
neww[neww_l]->col[zz*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[zz*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[zz*3+2] = c_b;
|
|
|
|
|
/*con[z]->col[zz*3] = 1.0f;
|
|
|
|
|
con[z]->col[zz*3+1] = 0.0f;
|
|
|
|
|
con[z]->col[zz*3+2] = 0.0f;*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
neww[neww_l]->len = aal[z];
|
|
|
|
|
neww_l++;
|
|
|
|
|
|
|
|
|
|
//err("haven't tested this yet",pexit);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//printf("c2\n");
|
|
|
|
|
int o_c = aal[i];
|
|
|
|
|
cord last;
|
|
|
|
|
//printf("-\n");
|
|
|
|
|
last.z = -2;
|
|
|
|
|
int lali = -2;
|
|
|
|
|
//neww = realloc(neww,sizeof ** neww * (neww_l + 2));
|
|
|
|
|
neww[neww_l] = malloc(sizeof * neww[neww_l]* 90);
|
|
|
|
|
neww[neww_l]->pix = malloc(sizeof * neww[neww_l]->pix* 8);
|
|
|
|
|
neww[neww_l]->col = malloc(sizeof * neww[neww_l]->col* 8);
|
|
|
|
|
neww[neww_l]->len = 0;
|
|
|
|
|
neww[neww_l]->tlen = 0;
|
|
|
|
|
//neww[neww_l]->max = con[i]->max;
|
|
|
|
|
//neww[neww_l]->min = con[i]->min;
|
|
|
|
|
neww[neww_l]->max.index = -INFINITY;
|
|
|
|
|
neww[neww_l]->max.vertex = -INFINITY;
|
|
|
|
|
neww[neww_l]->max.x = -INFINITY;
|
|
|
|
|
neww[neww_l]->max.y = -INFINITY;
|
|
|
|
|
|
|
|
|
|
neww[neww_l]->min.index = INFINITY;
|
|
|
|
|
neww[neww_l]->min.vertex = INFINITY;
|
|
|
|
|
neww[neww_l]->min.x = INFINITY;
|
|
|
|
|
neww[neww_l]->min.y = INFINITY;
|
|
|
|
|
//printf("d\n");
|
|
|
|
|
for(int ii = 0; ii<=o_c-2; ii++){
|
|
|
|
|
|
|
|
|
|
//printf("e\n");
|
|
|
|
|
//printf("%f %f -> %f %f | %i\n",con[i]->pix[ii*2],con[i]->pix[ii*2+1]
|
|
|
|
|
// ,con[i]->pix[(ii+1)*2],con[i]->pix[(ii+1)*2+1],aal[z]);
|
|
|
|
|
if(aal[z]==0)
|
|
|
|
|
continue;
|
|
|
|
|
cord ny = poi_d(con[i]->pix[ii*2],con[i]->pix[ii*2+1]
|
|
|
|
|
,con[i]->pix[(ii+1)*2],con[i]->pix[(ii+1)*2+1],aal[z],con[z]->pix,1,-1);
|
|
|
|
|
//if(ii==ny.index)
|
|
|
|
|
//continue;
|
|
|
|
|
//printf("f\n");
|
|
|
|
|
if(ny.z!=-1){
|
|
|
|
|
if(ny.z==1){
|
|
|
|
|
//debug("multiple intersections");
|
|
|
|
|
cord tesm = poi_d(con[i]->pix[ii*2],con[i]->pix[ii*2+1]
|
|
|
|
|
,con[i]->pix[(ii+1)*2],con[i]->pix[(ii+1)*2+1],aal[z],con[z]->pix,0,ny.index);
|
|
|
|
|
//printf("%i %f\n",tesm.index,tesm.z);
|
|
|
|
|
last = tesm;
|
|
|
|
|
//ny = tesm;
|
|
|
|
|
lali=ii;
|
|
|
|
|
//continue;
|
|
|
|
|
}
|
|
|
|
|
else if(ny.z>1){
|
|
|
|
|
//ny = poi_d(con[i]->pix[ii*2],con[i]->pix[ii*2+1]
|
|
|
|
|
//,con[i]->pix[(ii+1)*2],con[i]->pix[(ii+1)*2+1],aal[z],con[z]->pix,0,-1);
|
|
|
|
|
//printf("%f %f, %f %f, %f %f\n",ny.x,ny.y,con[i]->pix[ii*2],con[i]->pix[ii*2+1]
|
|
|
|
|
//,con[i]->pix[(ii+1)*2],con[i]->pix[(ii+1)*2+1]);
|
|
|
|
|
//warn("too many intersections:( (not convex?)");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(last.z!=-2){
|
|
|
|
|
/*
|
|
|
|
|
if(last.y>ny.y&&last.x>ny.x&&0){
|
|
|
|
|
cord tem = ny;
|
|
|
|
|
ny = last;
|
|
|
|
|
last = tem;
|
|
|
|
|
//printf("sw\n");
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
//int zzz = 0;
|
|
|
|
|
//printf("g\n");
|
|
|
|
|
//printf("%i,%i | %i %i\n",lali,ii,last.index,ny.index);
|
|
|
|
|
double zzzz = 77777.0;
|
|
|
|
|
cord aa = poi_d(con[i]->pix[(lali+1)*2],con[i]->pix[(lali+1)*2+1],zzzz,con[i]->pix[(lali+1)*2+1],con[z]->len,con[z]->pix,0,-1);
|
|
|
|
|
cord bb = poi_d(con[i]->pix[(lali+1)*2],con[i]->pix[(lali+1)*2+1],-zzzz,con[i]->pix[(lali+1)*2+1],con[z]->len,con[z]->pix,0,-1);
|
|
|
|
|
//if(aa.z==-1||bb.z==-1)
|
|
|
|
|
// printf("AAA\n");
|
|
|
|
|
int tes = aa.z==-1||bb.z==-1;
|
|
|
|
|
int iii1 = z;
|
|
|
|
|
int iii2 = i;
|
|
|
|
|
cord iiii5 = last;
|
|
|
|
|
cord aa2 = poi_d(con[iii1]->pix[(iiii5.index+1)*2],con[iii1]->pix[(iiii5.index+1)*2+1],zzzz,con[iii1]->pix[(iiii5.index+1)*2+1],con[iii2]->len,con[iii2]->pix,0,-1);
|
|
|
|
|
cord bb2 = poi_d(con[iii1]->pix[(iiii5.index+1)*2],con[iii1]->pix[(iiii5.index+1)*2+1],-zzzz,con[iii1]->pix[(iiii5.index+1)*2+1],con[iii2]->len,con[iii2]->pix,0,-1);
|
|
|
|
|
//if(aa.z==-1||bb.z==-1)
|
|
|
|
|
// printf("AAA\n");
|
|
|
|
|
|
|
|
|
|
int tes2 = aa2.z==-1||bb2.z==-1;
|
|
|
|
|
|
|
|
|
|
//printf("%i %i\n",tes,tes2);
|
|
|
|
|
neww[neww_l]->pix = realloc(neww[neww_l]->pix,
|
|
|
|
|
sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->col = realloc(neww[neww_l]->col,
|
|
|
|
|
sizeof * neww[neww_l]->col* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2] = last.x;
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2+1] = last.y;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+2] = c_b;
|
|
|
|
|
neww[neww_l]->len++;
|
|
|
|
|
|
|
|
|
|
//printf("%i %i | %i %i, %i %i\n",neww_l,tes,lali,ii,last.index,ny.index);
|
|
|
|
|
|
|
|
|
|
if(!tes2){
|
|
|
|
|
//printf("%i %i %i\n",neww_l,last.index,ny.index);
|
|
|
|
|
for(int zz = last.index+1; zz<=ny.index;
|
|
|
|
|
zz++){
|
|
|
|
|
|
|
|
|
|
//printf("aa\n");
|
|
|
|
|
//printf("zzz %lu\n",sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix = realloc(neww[neww_l]->pix,
|
|
|
|
|
sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->col = realloc(neww[neww_l]->col,
|
|
|
|
|
sizeof * neww[neww_l]->col* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2] = con[z]->pix[zz*2];
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2+1] = con[z]->pix[zz*2+1];
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+2] = c_b;
|
|
|
|
|
neww[neww_l]->len++;
|
|
|
|
|
|
|
|
|
|
//zzz++;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
con[z]->col[zz*3] = 1.0f;
|
|
|
|
|
con[z]->col[zz*3+1] = 0.0f;
|
|
|
|
|
con[z]->col[zz*3+2] = 0.0f;
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//if(neww_l==3)printf("T\n");
|
|
|
|
|
//printf("%i | %i %i\n",o_c,last.index,ny.index);
|
|
|
|
|
//if(ny.index<o_c)
|
|
|
|
|
for(int zz = last.index; zz!=ny.index;
|
|
|
|
|
zz--){
|
|
|
|
|
//printf("%i, %i / %i / %i\n",neww_l,zz,ny.index,o_c);
|
|
|
|
|
//printf("aa\n");
|
|
|
|
|
//printf("zzz %lu\n",sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix = realloc(neww[neww_l]->pix,
|
|
|
|
|
sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->col = realloc(neww[neww_l]->col,
|
|
|
|
|
sizeof * neww[neww_l]->col* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2] = con[z]->pix[zz*2];
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2+1] = con[z]->pix[zz*2+1];
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+2] = c_b;
|
|
|
|
|
neww[neww_l]->len++;
|
|
|
|
|
//printf("%i\n",zz);
|
|
|
|
|
//break;
|
|
|
|
|
if(zz<=0){
|
|
|
|
|
if(o_c<=ny.index)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
zz=o_c;
|
|
|
|
|
}
|
|
|
|
|
//zzz++;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
con[z]->col[zz*3] = 1.0f;
|
|
|
|
|
con[z]->col[zz*3+1] = 0.0f;
|
|
|
|
|
con[z]->col[zz*3+2] = 0.0f;
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//printf("hhhh\n");
|
|
|
|
|
neww[neww_l]->pix = realloc(neww[neww_l]->pix,
|
|
|
|
|
sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->col = realloc(neww[neww_l]->col,
|
|
|
|
|
sizeof * neww[neww_l]->col* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2] = ny.x;
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2+1] = ny.y;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+2] = c_b;
|
|
|
|
|
neww[neww_l]->len++;
|
|
|
|
|
|
|
|
|
|
//printf("%f %f\n",aa.z,bb.z);
|
|
|
|
|
|
|
|
|
|
if(tes){
|
|
|
|
|
//printf("%i %i %i\n",neww_l,lali,ii);
|
|
|
|
|
|
|
|
|
|
for(int zz = ii+1; zz!=lali+1;
|
|
|
|
|
zz++){
|
|
|
|
|
|
|
|
|
|
neww[neww_l]->pix = realloc(neww[neww_l]->pix,
|
|
|
|
|
sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->col = realloc(neww[neww_l]->col,
|
|
|
|
|
sizeof * neww[neww_l]->col* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2] = con[i]->pix[zz*2];
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2+1] = con[i]->pix[zz*2+1];
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+2] = c_b;
|
|
|
|
|
neww[neww_l]->len++;
|
|
|
|
|
//break;
|
|
|
|
|
if(zz>=o_c-1)
|
|
|
|
|
zz=-1;
|
|
|
|
|
//zzz++;
|
|
|
|
|
//break;
|
|
|
|
|
/*
|
|
|
|
|
con[i]->col[zz*3] = 1.0f;
|
|
|
|
|
con[i]->col[zz*3+1] = 0.0f;
|
|
|
|
|
con[i]->col[zz*3+2] = 0.0f;
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//printf("%i %i %i\n",neww_l,ii,lali);
|
|
|
|
|
for(int zz = ii; zz>=lali+1;
|
|
|
|
|
zz--){
|
|
|
|
|
|
|
|
|
|
neww[neww_l]->pix = realloc(neww[neww_l]->pix,
|
|
|
|
|
sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->col = realloc(neww[neww_l]->col,
|
|
|
|
|
sizeof * neww[neww_l]->col* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2] = con[i]->pix[zz*2];
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2+1] = con[i]->pix[zz*2+1];
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+2] = c_b;
|
|
|
|
|
neww[neww_l]->len++;
|
|
|
|
|
//break;
|
|
|
|
|
//zzz++;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
con[i]->col[zz*3] = 1.0f;
|
|
|
|
|
con[i]->col[zz*3+1] = 0.0f;
|
|
|
|
|
con[i]->col[zz*3+2] = 0.0f;
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//zzz++;
|
|
|
|
|
|
|
|
|
|
neww[neww_l]->pix = realloc(neww[neww_l]->pix,
|
|
|
|
|
sizeof * neww[neww_l]->pix* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->col = realloc(neww[neww_l]->col,
|
|
|
|
|
sizeof * neww[neww_l]->col* 4 * (neww[neww_l]->len+1));
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2] = neww[neww_l]->pix[0];
|
|
|
|
|
neww[neww_l]->pix[neww[neww_l]->len*2+1] = neww[neww_l]->pix[1];
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3] = c_r;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+1] = c_g;
|
|
|
|
|
neww[neww_l]->col[neww[neww_l]->len*3+2] = c_b;
|
|
|
|
|
neww[neww_l]->len++;
|
|
|
|
|
|
|
|
|
|
//last.z = -2;
|
|
|
|
|
//lali = -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lali = ii;
|
|
|
|
|
last = ny;
|
|
|
|
|
}
|
|
|
|
|
//printf("oo\n");
|
|
|
|
|
}
|
|
|
|
|
neww_l++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//printf("ee ---\n");
|
|
|
|
|
for(int i = 0; i<=neww_l-1;i++){
|
|
|
|
|
//neww[i]->max.x = neww[i]->pix[2];
|
|
|
|
|
//neww[i]->max.y = neww[i]->pix[3];
|
|
|
|
|
|
|
|
|
|
//neww[i]->min.x = neww[i]->pix[2];
|
|
|
|
|
//neww[i]->min.y = neww[i]->pix[3];
|
|
|
|
|
for(int z = 0; z<=neww[i]->len-1; z++){
|
|
|
|
|
//printf("%i %i, %f %f\n",i,z,neww[i]->pix[z*2],neww[i]->pix[z*2+1]);
|
|
|
|
|
neww[i]->max.x = greater(neww[i]->max.x,neww[i]->pix[z*2]);
|
|
|
|
|
neww[i]->max.y = greater(neww[i]->max.y,neww[i]->pix[z*2+1]);
|
|
|
|
|
|
|
|
|
|
neww[i]->min.x = lesser(neww[i]->min.x,neww[i]->pix[z*2]);
|
|
|
|
|
neww[i]->min.y = lesser(neww[i]->min.y,neww[i]->pix[z*2+1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//printf(" -- %f %f\n",neww[i]->max.x,neww[i]->min.x);
|
|
|
|
|
neww[i]->lin = neww_l;
|
|
|
|
|
}
|
|
|
|
|
return neww;
|
|
|
|
|
}
|
|
|
|
|
glfl_ar* perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,double ctz,double cx, double cy, double cz){
|
|
|
|
|
|
|
|
|
|
GLfloat* pixels = malloc(sizeof(*pixels)*((1+c->len)*3));
|
|
|
|
|
GLfloat* colors = malloc(sizeof(*colors)*((1+c->len)*4));
|
|
|
|
|
GLfloat* trans = malloc(sizeof(*trans)*((1+c->len)*2));
|
|
|
|
|
if(pixels==NULL||colors==NULL||trans==NULL)
|
|
|
|
|
err("failed to allocate perspective array:(",pexit);
|
|
|
|
|
double dep = 0.0;
|
|
|
|
|
double depy = 0.0;
|
|
|
|
|
double coy = cos(cty);
|
|
|
|
|
double sinz = sin(ctz);
|
|
|
|
|
double coz = cos(ctz);
|
|
|
|
|
double six = sin(ctx);
|
|
|
|
|
double siy = sin(cty);
|
|
|
|
|
double cox = cos(ctx);
|
|
|
|
|
double fov = 0.002;
|
|
|
|
|
double ex = cx;
|
|
|
|
|
double ey = cy;
|
|
|
|
|
refresh_size(b);
|
|
|
|
|
GLuint fb = 0;
|
|
|
|
|
int c_len = 0;
|
|
|
|
|
//double ez=1/tan(fov/2); //i dont get this at all
|
|
|
|
|
double ez=get_w();
|
|
|
|
|
//printf("---\n");
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
cord maxf;
|
|
|
|
|
cord minf;
|
|
|
|
|
maxf.x = -INFINITY;
|
|
|
|
|
maxf.y = -INFINITY;
|
|
|
|
|
maxf.z = -INFINITY;
|
|
|
|
|
|
|
|
|
|
minf.x = INFINITY;
|
|
|
|
|
minf.y = INFINITY;
|
|
|
|
|
minf.z = INFINITY;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i!=c->len; i++){
|
|
|
|
|
double ax = c->c[i].at.x;
|
|
|
|
|
double ay = c->c[i].at.y;
|
|
|
|
|
double az = c->c[i].at.z;
|
|
|
|
|
|
|
|
|
|
double eyz = (coz*(ay-cy)-sinz*ax-cx);
|
|
|
|
|
double yzm = (coy*(az-cz) + siy*(sinz*(ay-cy) + coz*(ax-cx)));
|
|
|
|
|
double dx = coy * (sinz*(ay-cy) + coz*(ax-cx)) - (siy*(az-cz));
|
|
|
|
|
double dy = six * yzm + cox*eyz;
|
|
|
|
|
double dz = cox * yzm - six*eyz;
|
|
|
|
|
|
|
|
|
|
double bx = ez/dz*dx+dx;
|
|
|
|
|
double by = ez/dz*dy+dy;
|
|
|
|
|
maxf.z = greater(maxf.z,dz);
|
|
|
|
|
minf.z = lesser(minf.z,dz);
|
|
|
|
|
|
|
|
|
|
maxf.x = greater(maxf.x,bx);
|
|
|
|
|
minf.x = lesser(minf.x,bx);
|
|
|
|
|
|
|
|
|
|
maxf.y = greater(maxf.y,by);
|
|
|
|
|
minf.y = lesser(minf.y,by);
|
|
|
|
|
if(dz>=0){
|
|
|
|
|
//printf("-- %f\n",dz);
|
|
|
|
|
//if(dz>dep) dep = dz;
|
|
|
|
|
ab_to_vp(xa,ya,get_w(),get_h(),bx,by);
|
|
|
|
|
pixels[c_len*2] = xa+1;
|
|
|
|
|
pixels[c_len*2+1] = ya;
|
|
|
|
|
colors[c_len*3] = c->c[i].color.r;
|
|
|
|
|
colors[c_len*3+1] = c->c[i].color.g;
|
|
|
|
|
colors[c_len*3+2] = c->c[i].color.b;
|
|
|
|
|
trans[c_len] = 0.5;
|
|
|
|
|
c_len++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//printf("%f\n",dep);
|
|
|
|
|
int fc_len = c_len;
|
|
|
|
|
|
|
|
|
|
glfl_ar* tt = poly_to_tri(pixels,colors,fc_len);
|
|
|
|
|
//double dclen = c_len;
|
|
|
|
|
glPointSize(4.0f);
|
|
|
|
|
glfl_ar* rea = malloc(sizeof(*rea));
|
|
|
|
|
rea->tlen = tric;
|
|
|
|
|
rea->tri = tria;
|
|
|
|
|
rea->tlen = tt->tlen;
|
|
|
|
|
rea->tri = tt->tri;
|
|
|
|
|
//rea->depth = dep;
|
|
|
|
|
rea->max = maxf;
|
|
|
|
|
rea->min = minf;
|
|
|
|
|
//printf(" %i\n",tric);
|
|
|
|
|
rea->tricol = tricol;
|
|
|
|
|
rea->tricol = tt->tricol;
|
|
|
|
|
rea->col = colors;
|
|
|
|
|
rea->pix = pixels;
|
|
|
|
|
rea->len = c_len;
|
|
|
|
|
rea->trans = trans;
|
|
|
|
|
free(tt);
|
|
|
|
|
return rea;
|
|
|
|
|
}
|
|
|
|
|
point_arr* basier3d(double*xx,double*yy,double*zz,int n,float rr, float gg, float bb){
|
|
|
|
@ -742,7 +1062,7 @@ void join_glfl_a(glfl_ar* a, glfl_ar* b){
|
|
|
|
|
int a_len = a->len;
|
|
|
|
|
int a_tlen = a->tlen;
|
|
|
|
|
a->pix = realloc(a->pix,sizeof(*a->pix)*(a->len+b->len+1)*20);
|
|
|
|
|
a->col = realloc(a->col,sizeof(*a->col)*(a->len+b->len+1)*20);
|
|
|
|
|
a->col = realloc(a->col,sizeof(*a->col)*(a->len+b->len+1)*90);
|
|
|
|
|
a->trans = realloc(a->trans,sizeof(*a->trans)*(a->len+b->len+1)*20);
|
|
|
|
|
a->tri = realloc(a->tri,sizeof(*a->tri)*(a->tlen+b->tlen+1)*60);
|
|
|
|
|
a->tricol = realloc(a->tricol,sizeof(*a->tricol)*(a->tlen+b->tlen+1)*30);
|
|
|
|
@ -754,7 +1074,7 @@ void join_glfl_a(glfl_ar* a, glfl_ar* b){
|
|
|
|
|
a->pix[a_len*2+i] = b->pix[i];
|
|
|
|
|
}
|
|
|
|
|
for(int i = 0; i<=b->len*3; i++){
|
|
|
|
|
a->col[a_len*3+i] = b->col[i];
|
|
|
|
|
a->col[a_len*3+i] = b->col[i];
|
|
|
|
|
}
|
|
|
|
|
for(int i = 0; i<=b->len; i++){
|
|
|
|
|
a->trans[a_len+i] = b->trans[i];
|
|
|
|
@ -783,7 +1103,7 @@ point_arr* polygon3d(double* vx, double*vy, double* vz, int n,float r, float g,
|
|
|
|
|
}*/
|
|
|
|
|
point_arr* pa;
|
|
|
|
|
pa = malloc(sizeof(*pa));
|
|
|
|
|
pa->c = malloc(sizeof(*pa->c)*(get_w()*60));
|
|
|
|
|
pa->c = malloc(sizeof(*pa->c)*(get_w()*90));
|
|
|
|
|
pa->vert = malloc(sizeof(*pa->vert)*(n*60));
|
|
|
|
|
if(pa->c==NULL||pa->vert==NULL)
|
|
|
|
|
err("failed to allocate polygon array",pexit);
|
|
|
|
@ -941,14 +1261,14 @@ point_m* rect3d_gen(double* tl, double* tr, double* bl, double*br,
|
|
|
|
|
double xx1[5]={tl[0],tr[0],br[0],bl[0], tl[0]};
|
|
|
|
|
double yy1[5]={tl[1],tr[1],br[1],bl[1], tl[1]};
|
|
|
|
|
double zz1[5]={tl[2],tr[2],br[2],bl[2], tl[2]};
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,1.0,0.0,0.0);
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,1.0,0.1,0.1);
|
|
|
|
|
mm->len++;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
double xx1[5]={tl2[0],tr2[0],br2[0],bl2[0], tl2[0]};
|
|
|
|
|
double yy1[5]={tl2[1],tr2[1],br2[1],bl2[1], tl2[1]};
|
|
|
|
|
double zz1[5]={tl2[2],tr2[2],br2[2],bl2[2], tl2[2]};
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.5,0.5,0.0);
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.5,0.5,0.1);
|
|
|
|
|
mm->len++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -956,14 +1276,14 @@ point_m* rect3d_gen(double* tl, double* tr, double* bl, double*br,
|
|
|
|
|
double xx1[5]={tl2[0],tr2[0],tr[0],tl[0], tl2[0]};
|
|
|
|
|
double yy1[5]={tl2[1],tr2[1],tr[1],tl[1], tl2[1]};
|
|
|
|
|
double zz1[5]={tl2[2],tr2[2],tr[2],tl[2], tl2[2]};
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.0,1.0,0.0);
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.1,1.0,0.1);
|
|
|
|
|
mm->len++;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
double xx1[5]={bl2[0],br2[0],br[0],bl[0], bl2[0]};
|
|
|
|
|
double yy1[5]={bl2[1],br2[1],br[1],bl[1], bl2[1]};
|
|
|
|
|
double zz1[5]={bl2[2],br2[2],br[2],bl[2], bl2[2]};
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.0,0.5,0.5);
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.1,0.5,0.5);
|
|
|
|
|
mm->len++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -971,7 +1291,7 @@ point_m* rect3d_gen(double* tl, double* tr, double* bl, double*br,
|
|
|
|
|
double xx1[5]={tl2[0],bl2[0],bl[0],tl[0], tl2[0]};
|
|
|
|
|
double yy1[5]={tl2[1],bl2[1],bl[1],tl[1], tl2[1]};
|
|
|
|
|
double zz1[5]={tl2[2],bl2[2],bl[2],tl[2], tl2[2]};
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.0,0.0,0.1);
|
|
|
|
|
mm[mm->len].at = polygon3d(xx1,yy1,zz1,6,0.1,0.1,0.1);
|
|
|
|
|
mm->len++;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
@ -1002,7 +1322,7 @@ int main(int argc,char*argv[]){
|
|
|
|
|
logm("built shaders");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///*
|
|
|
|
|
/*
|
|
|
|
|
double tl[3] = {5.0,200.0,200.0};
|
|
|
|
|
double tr[3] = {200.0,200.0,200.0};
|
|
|
|
|
double bl[3] = {5.0,5.0,200.0};
|
|
|
|
@ -1019,12 +1339,47 @@ int main(int argc,char*argv[]){
|
|
|
|
|
//*/
|
|
|
|
|
/*
|
|
|
|
|
double xxx[4] = {2.0,100.0,50.0,2.0};
|
|
|
|
|
double yyy[4] = {2.0,2.0,100.0,2.0};
|
|
|
|
|
double yyy[4] = {2.0,2.0,50.0,2.0};
|
|
|
|
|
double zzz[4] = {2.0,2.0,2.0,2.0};
|
|
|
|
|
point_m* aaaa = malloc(sizeof(*aaaa)*5);
|
|
|
|
|
aaaa->len = 0;
|
|
|
|
|
aaaa[0].at = polygon3d(xxx,yyy,zzz,5,1.0,1.0,0.0);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
double xxx2[5] = {2.0,100.0,75.0,50.0,2.0};
|
|
|
|
|
double yyy2[5] = {100.0,100.0,25.0,20.0,100.0};
|
|
|
|
|
double zzz2[5] = {20.0,20.0,20.0,20.0,20.0};
|
|
|
|
|
//point_m* aaaa = malloc(sizeof(*aaaa)*5);
|
|
|
|
|
aaaa->len = 2;
|
|
|
|
|
aaaa[1].at = polygon3d(xxx2,yyy2,zzz2,6,1.0,1.0,0.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*/
|
|
|
|
|
///*
|
|
|
|
|
|
|
|
|
|
double xxx[5] = {0.0,100.0,100.0,0.0,0.0};
|
|
|
|
|
double yyy[5] = {0.0,0.0,100.0,100.0,0.0};
|
|
|
|
|
double zzz[5] = {2.0,2.0,2.0,2.0,2.0};
|
|
|
|
|
|
|
|
|
|
point_m* aaaa = malloc(sizeof(*aaaa)*5);
|
|
|
|
|
aaaa->len = 0;
|
|
|
|
|
aaaa[0].at = polygon3d(xxx,yyy,zzz,6,1.0,1.0,0.0);
|
|
|
|
|
|
|
|
|
|
double xxx2[5] = {2.0,100.0,75.0,50.0,2.0};
|
|
|
|
|
double yyy2[5] = {100.0,100.0,25.0,20.0,100.0};
|
|
|
|
|
double zzz2[5] = {20.0,20.0,20.0,20.0,20.0};
|
|
|
|
|
//point_m* aaaa = malloc(sizeof(*aaaa)*5);
|
|
|
|
|
aaaa->len = 2;
|
|
|
|
|
aaaa[1].at = polygon3d(xxx2,yyy2,zzz2,6,1.0,0.0,1.0);
|
|
|
|
|
|
|
|
|
|
double xxx3[5] = {2.0,100.0,75.0,50.0,2.0};
|
|
|
|
|
double yyy3[5] = {100.0,100.0,25.0,20.0,100.0};
|
|
|
|
|
double zzz3[5] = {40.0,40.0,40.0,40.0,40.0};
|
|
|
|
|
//point_m* aaaa = malloc(sizeof(*aaaa)*5);
|
|
|
|
|
aaaa->len = 3;
|
|
|
|
|
aaaa[2].at = polygon3d(xxx3,yyy3,zzz3,6,0.0,0.0,1.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*/
|
|
|
|
|
int max_r = 630;
|
|
|
|
|
double half_max_r = (double)max_r/2/2;
|
|
|
|
|
double pl_x = 0;
|
|
|
|
@ -1079,7 +1434,7 @@ int main(int argc,char*argv[]){
|
|
|
|
|
}
|
|
|
|
|
for(int i = 0; i<=aaaa->len-2; i++){
|
|
|
|
|
//printf("%i %i\n",i,aaaa->len-1);
|
|
|
|
|
if(con[i]->max.z<con[i+1]->min.z||
|
|
|
|
|
if(con[i]->max.z<con[i+1]->min.z&&
|
|
|
|
|
con[i]->min.z<con[i+1]->min.z||
|
|
|
|
|
con[i]->max.z<con[i+1]->max.z){
|
|
|
|
|
|
|
|
|
@ -1087,14 +1442,32 @@ int main(int argc,char*argv[]){
|
|
|
|
|
con[i] = con[i+1];
|
|
|
|
|
con[i+1] = tempp;
|
|
|
|
|
|
|
|
|
|
i-=1;
|
|
|
|
|
i=-1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//printf("---\n");
|
|
|
|
|
//TODO: HERE
|
|
|
|
|
glfl_ar** neww = transp(con,aaaa->len);
|
|
|
|
|
//for(int i = 0; i!=neww2[0]->lin-1;i++)
|
|
|
|
|
// printf("%i\n",neww2[i]->len);
|
|
|
|
|
//glfl_ar** neww2 = transp(con,aaaa->len);
|
|
|
|
|
|
|
|
|
|
//printf("end\n");
|
|
|
|
|
//printf("%f %f %f %f\n",neww)
|
|
|
|
|
//printf("--- %i\n",neww2[0]->lin);
|
|
|
|
|
glfl_ar** neww2 = transp(neww,neww[0]->lin);
|
|
|
|
|
//for(int i = 0; i!=neww[0]->lin-1;i++)
|
|
|
|
|
//printf("%i\n",neww[0]->len);
|
|
|
|
|
//printf("e\n");
|
|
|
|
|
//for(int i = 0; i!=neww2[0]->lin; i++)
|
|
|
|
|
//printf("%f %f %f\n",neww2[i])
|
|
|
|
|
int neww_l = neww[0]->lin;
|
|
|
|
|
int neww_l2 = neww2[0]->lin;
|
|
|
|
|
//printf("%i\n",neww_l);
|
|
|
|
|
//abort();
|
|
|
|
|
|
|
|
|
|
//char* absabd = malloc(1000);
|
|
|
|
|
//absabd = "aaa\n";
|
|
|
|
|
glfl_ar* push = con[0];
|
|
|
|
|
for(int i = 1; i<=con_len-1;i++){
|
|
|
|
|
for(int i = 1; i<=con_len-1;i++){
|
|
|
|
|
//printf("%f %f\n",con[i]->max.x,con[i]->min.x);
|
|
|
|
|
join_glfl_a(push,con[i]);
|
|
|
|
|
free(con[i]->tri);
|
|
|
|
@ -1104,7 +1477,8 @@ int main(int argc,char*argv[]){
|
|
|
|
|
free(con[i]->trans);
|
|
|
|
|
free(con[i]);
|
|
|
|
|
}
|
|
|
|
|
render_p(push);
|
|
|
|
|
//printf("dd\n");
|
|
|
|
|
render_p(push,1);
|
|
|
|
|
free(con[0]->tri);
|
|
|
|
|
free(con[0]->tricol);
|
|
|
|
|
free(con[0]->pix);
|
|
|
|
@ -1112,6 +1486,42 @@ int main(int argc,char*argv[]){
|
|
|
|
|
free(con[0]->trans);
|
|
|
|
|
free(con[0]);
|
|
|
|
|
free(con);
|
|
|
|
|
//printf("pre %i\n",neww_l);
|
|
|
|
|
for(int i = 0; i<=neww_l2-1; i++){
|
|
|
|
|
free(neww2[i]->col);
|
|
|
|
|
free(neww2[i]->pix);
|
|
|
|
|
free(neww2[i]);
|
|
|
|
|
}
|
|
|
|
|
//printf("a5\n");
|
|
|
|
|
free(neww2);
|
|
|
|
|
for(int i = 0; i<=neww_l-1; i++){
|
|
|
|
|
for(int z = 0; z<=neww[i]->len-1;z++){
|
|
|
|
|
//printf("%i | %f %f\n",neww[i]->len,neww[i]->pix[z*2],neww[i]->pix[z*2+1]);
|
|
|
|
|
}
|
|
|
|
|
if(i!=-9&&neww[i]->len>0){
|
|
|
|
|
int tee = i;
|
|
|
|
|
glfl_ar* ttee = poly_to_tri(neww[tee]->pix,neww[tee]->col, neww[tee]->len);
|
|
|
|
|
|
|
|
|
|
neww[tee]->tri = ttee->tri;
|
|
|
|
|
for(int z = 0; z<=neww[tee]->len*3; z++)
|
|
|
|
|
neww[tee]->col[z] = 0.5f;
|
|
|
|
|
neww[tee]->tricol=ttee->tricol;
|
|
|
|
|
neww[tee]->tlen = ttee->tlen;
|
|
|
|
|
render_p(neww[tee],0);
|
|
|
|
|
|
|
|
|
|
render_p(neww[tee],1);
|
|
|
|
|
free(neww[tee]->tri);
|
|
|
|
|
free(neww[tee]->tricol);
|
|
|
|
|
free(ttee);
|
|
|
|
|
}
|
|
|
|
|
free(neww[i]->col);
|
|
|
|
|
free(neww[i]->pix);
|
|
|
|
|
free(neww[i]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//printf("a5\n");
|
|
|
|
|
free(neww);
|
|
|
|
|
//printf("df\n");
|
|
|
|
|
//free(bba->tricol);
|
|
|
|
|
//free(bba->tri);
|
|
|
|
|
//free(bba->trans);
|
|
|
|
@ -1193,6 +1603,14 @@ int main(int argc,char*argv[]){
|
|
|
|
|
pl_x+=cosf((half_max_r+plr_y)*0.01)*mul;
|
|
|
|
|
pl_y+=sinf((half_max_r+plr_y)*0.01)*mul;
|
|
|
|
|
}
|
|
|
|
|
if(glfwGetKey(w,GLFW_KEY_N)){
|
|
|
|
|
NNNN--;
|
|
|
|
|
printf("%i\n",NNNN);
|
|
|
|
|
}
|
|
|
|
|
if(glfwGetKey(w,GLFW_KEY_M)){
|
|
|
|
|
NNNN++;
|
|
|
|
|
printf("%i\n",NNNN);
|
|
|
|
|
}
|
|
|
|
|
if(glfwWindowShouldClose(w)||(glfwGetKey(w,GLFW_KEY_Q)))break;
|
|
|
|
|
|
|
|
|
|
if(1){
|
|
|
|
|