backup :p
This commit is contained in:
parent
c5112eebdd
commit
e7331cb0c9
258
src/point.c
258
src/point.c
|
@ -9,21 +9,18 @@ typedef struct {
|
|||
double z;
|
||||
} cord;
|
||||
typedef struct {
|
||||
int roll; //x axis
|
||||
int pitch; //y axis
|
||||
int yaw; //z axis
|
||||
} rot;
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
} color;
|
||||
typedef struct {
|
||||
float opacity;
|
||||
} opts;
|
||||
typedef struct {
|
||||
cord loc;
|
||||
rot rot;
|
||||
int uid;
|
||||
int id;
|
||||
opts opts;
|
||||
cord at;
|
||||
color color;
|
||||
} point;
|
||||
|
||||
typedef struct {
|
||||
point* c;
|
||||
double len;
|
||||
} point_arr;
|
||||
double binominal(int n, int k){
|
||||
if(n==k)
|
||||
return 1.0;
|
||||
|
@ -55,9 +52,9 @@ void perspective_proj(GLFWwindow* b,cord* c, int len,double ctx,double cty,doubl
|
|||
//double ctz = 0;
|
||||
//cz=100-cz;
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
|
||||
GLfloat* pixels = malloc(sizeof(*pixels)*len*800*500*2);
|
||||
|
||||
GLfloat* pixels = malloc(sizeof(*pixels)*len*2);
|
||||
if(pixels==NULL)
|
||||
err("failed to allocate perspective array:(",pexit);
|
||||
|
||||
//glfwSwapBuffers(b);
|
||||
//return;
|
||||
|
@ -76,7 +73,7 @@ void perspective_proj(GLFWwindow* b,cord* c, int len,double ctx,double cty,doubl
|
|||
//double ez = 1/tan(fov/2);
|
||||
//glBegin(GL_POINTS);
|
||||
GLuint fb = 0;
|
||||
double ez=500; //i dont get this at all
|
||||
double ez=get_h(); //i dont get this at all
|
||||
//glGenFramebuffers(1,&fb);
|
||||
|
||||
for(int i = 0; i!=len; i++){
|
||||
|
@ -125,14 +122,17 @@ void perspective_proj(GLFWwindow* b,cord* c, int len,double ctx,double cty,doubl
|
|||
//glEnd();
|
||||
}
|
||||
cord* basier3d(double*xx,double*yy,double*zz,int n){
|
||||
cord* pa = malloc(sizeof(*pa)*(3000));
|
||||
cord* pa = malloc(sizeof(*pa)*(get_w()*30));
|
||||
if(pa==NULL)
|
||||
err("failed to allocate basier array",pexit);
|
||||
//double xx[5] = {5.0,5.0,50.0,5.0,5.0};
|
||||
//double yy[5] = {5.0,5.0,5.0,5.0,10.0};
|
||||
//double zz[5] = {10.0,5.0,5.0,5.0,5.0};
|
||||
//int n = 5-1;
|
||||
n-=1;
|
||||
for(int iy = 0; iy<=100;iy+=1){
|
||||
double t = 0.01*iy;
|
||||
double aaar = (1.0/get_w());
|
||||
for(int iy = 0; iy<=get_w();iy+=1){
|
||||
double t = aaar*iy;
|
||||
double bcx = 0;
|
||||
double bcy = 0;
|
||||
double bcz = 0;
|
||||
|
@ -163,99 +163,87 @@ cord* basier3d(double*xx,double*yy,double*zz,int n){
|
|||
//sdl_loop(b);
|
||||
return pa;
|
||||
}
|
||||
void join_cords(cord* a, cord* b, int a_len, int b_len){
|
||||
printf("%lu\n",sizeof(*a)*(a_len+b_len+2));
|
||||
int join_cords(cord* a, cord* b, int a_len, int b_len){
|
||||
//printf("%lu\n",sizeof(*a)*(a_len+b_len+2));
|
||||
a = realloc(a,sizeof(*a)*(a_len+b_len+2));
|
||||
if(a==NULL)
|
||||
err("failed to reallocate cords",pexit);
|
||||
for(int i = 0; i<=a_len+b_len; i++){
|
||||
a[a_len+i] = b[i];
|
||||
}
|
||||
return a_len+b_len;
|
||||
}
|
||||
|
||||
int main(){
|
||||
double xx[5] = {5.0,5.0,5.0};
|
||||
double yy[5] = {5.0,100.0,200.0};
|
||||
double zz[5] = {95.0,95.0,95.0};
|
||||
cord* a = basier3d(xx,yy,zz,3);
|
||||
|
||||
double xx2[5] = {200.0,200.0,200.0};
|
||||
double yy2[5] = {5.0,100.0,200.0};
|
||||
double zz2[5] = {95.0,95.0,95.0};
|
||||
cord* b = basier3d(xx2,yy2,zz2,3);
|
||||
cord* square_gen(double* tl, double* tr, double* bl, double*br){
|
||||
double xx[3] = {tl[0],tr[0]};
|
||||
double yy[3] = {tl[1],tr[1]};
|
||||
double zz[3] = {tl[2],tr[2]};
|
||||
cord* a = basier3d(xx,yy,zz,2);
|
||||
|
||||
double xx3[5] = {5.0,100.0,200.0};
|
||||
double yy3[5] = {5.0,5.0,5.0};
|
||||
double zz3[5] = {95.0,95.0,95.0};
|
||||
cord* c = basier3d(xx3,yy3,zz3,3);
|
||||
double xx1[3] = {tl[0],bl[0]};
|
||||
double yy1[3] = {tl[1],bl[1]};
|
||||
double zz1[3] = {tl[2],bl[2]};
|
||||
cord* b = basier3d(xx1,yy1,zz1,2);
|
||||
|
||||
double xx4[5] = {5.0,100.0,200.0};
|
||||
double yy4[5] = {200.0,200.0,200.0};
|
||||
double zz4[5] = {95.0,95.0,95.0};
|
||||
cord* d = basier3d(xx4,yy4,zz4,3);
|
||||
double xx2[3] = {tr[0],br[0]};
|
||||
double yy2[3] = {tr[1],br[1]};
|
||||
double zz2[3] = {tr[2],br[2]};
|
||||
cord* c = basier3d(xx2,yy2,zz2,2);
|
||||
|
||||
double xx5[5] = {5.0,100.0,200.0};
|
||||
double yy5[5] = {200.0,200.0,200.0};
|
||||
double zz5[5] = {290.0,290.0,290.0};
|
||||
cord* e = basier3d(xx5,yy5,zz5,3);
|
||||
double xx3[3] = {bl[0],br[0]};
|
||||
double yy3[3] = {bl[1],br[1]};
|
||||
double zz3[3] = {bl[2],br[2]};
|
||||
cord* d = basier3d(xx3,yy3,zz3,2);
|
||||
|
||||
double xx6[5] = {5.0,100.0,200.0};
|
||||
double yy6[5] = {5.0,5.0,5.0};
|
||||
double zz6[5] = {290.0,290.0,290.0};
|
||||
cord* f = basier3d(xx6,yy6,zz6,3);
|
||||
|
||||
double xx7[5] = {200.0,200.0,200.0};
|
||||
double yy7[5] = {5.0,100.0,200.0};
|
||||
double zz7[5] = {290.0,290.0,290.0};
|
||||
cord* g = basier3d(xx7,yy7,zz7,3);
|
||||
|
||||
double xx8[5] = {5.0,5.0,5.0};
|
||||
double yy8[5] = {5.0,100.0,200.0};
|
||||
double zz8[5] = {290.0,290.0,290.0};
|
||||
cord* h = basier3d(xx8,yy8,zz8,3);
|
||||
//next
|
||||
double xx9[5] = {5.0,5.0,5.0};
|
||||
double yy9[5] = {200.0,200.0,200.0};
|
||||
double zz9[5] = {290.0,290.0,95.0};
|
||||
cord* ii = basier3d(xx9,yy9,zz9,3);
|
||||
|
||||
double xx10[5] = {5.0,5.0,5.0};
|
||||
double yy10[5] = {5.0,5.0,5.0};
|
||||
double zz10[5] = {290.0,290.0,95.0};
|
||||
cord* j = basier3d(xx10,yy10,zz10,3);
|
||||
|
||||
double xx11[5] = {200.0,200.0,200.0};
|
||||
double yy11[5] = {200.0,200.0,200.0};
|
||||
double zz11[5] = {290.0,290.0,95.0};
|
||||
cord* k = basier3d(xx11,yy11,zz11,3);
|
||||
|
||||
double xx12[5] = {200.0,200.0,200.0};
|
||||
double yy12[5] = {5.0,5.0,5.0};
|
||||
double zz12[5] = {290.0,290.0,95.0};
|
||||
cord* l = basier3d(xx12,yy12,zz12,3);
|
||||
join_cords(a,b,100,100);
|
||||
int ss = join_cords(a,b,get_w(),get_w());
|
||||
ss = join_cords(a,c,ss,get_w());
|
||||
ss = join_cords(a,d,ss,get_w());
|
||||
free(b);
|
||||
join_cords(a,c,200,100);
|
||||
free(c);
|
||||
join_cords(a,d,300,100);
|
||||
free(d);
|
||||
join_cords(a,e,400,100);
|
||||
free(e);
|
||||
join_cords(a,f,500,100);
|
||||
free(f);
|
||||
join_cords(a,g,600,100);
|
||||
free(g);
|
||||
join_cords(a,h,700,100);
|
||||
free(h);
|
||||
join_cords(a,ii,800,100);
|
||||
free(ii);
|
||||
join_cords(a,j,900,100);
|
||||
free(j);
|
||||
join_cords(a,k,1000,100);
|
||||
free(k);
|
||||
join_cords(a,l,1100,100);
|
||||
free(l);
|
||||
return a;
|
||||
}
|
||||
cord* cube_gen(double* tl, double* tr, double* bl, double*br,
|
||||
double* tl2, double* tr2, double* bl2, double*br2){
|
||||
|
||||
double n_len = get_w()*4;
|
||||
cord*a = square_gen(tl,tr,bl,br);
|
||||
cord*b = square_gen(tl2,tr2,bl2,br2);
|
||||
double s;
|
||||
s = join_cords(a,b,n_len,n_len);
|
||||
free(b);
|
||||
cord*c = square_gen(tl2,tr2,tl,tr);
|
||||
s = join_cords(a,c,s,n_len);
|
||||
free(c);
|
||||
cord*d = square_gen(bl2,br2,bl,br);
|
||||
s = join_cords(a,d,s,n_len);
|
||||
free(d);
|
||||
cord*e = square_gen(tl,tl2,bl,bl2);
|
||||
s = join_cords(a,e,s,n_len);
|
||||
free(e);
|
||||
cord*f = square_gen(br2,br,tr2,tr);
|
||||
s = join_cords(a,f,s,n_len);
|
||||
free(f);
|
||||
return a;
|
||||
}
|
||||
int main(){
|
||||
GLFWwindow* w = glfw_init();
|
||||
refresh_size(w);
|
||||
double tl2[3] = {5.0,200.0,400.0};
|
||||
double tr2[3] = {200.0,200.0,400.0};
|
||||
double bl2[3] = {5.0,5.0,200.0};
|
||||
double br2[3] = {200.0,5.0,200.0};
|
||||
|
||||
double tl1[3] = {5.0,200.0,200.0};
|
||||
double tr1[3] = {200.0,200.0,200.0};
|
||||
double bl1[3] = {5.0,5.0,5.0};
|
||||
double br1[3] = {200.0,5.0,5.0};
|
||||
cord*a = cube_gen(tl1,tr1,bl1,br1,tl2,tr2,bl2,br2);
|
||||
double s = get_w()*24;
|
||||
|
||||
|
||||
int max_r = 630;
|
||||
double half_max_r = (double)max_r/2/2;
|
||||
GLFWwindow* w = glfw_init();
|
||||
|
||||
//glfwSetKeyCallback(w,key_press);
|
||||
double pl_x = 0;
|
||||
double pl_y = 0;
|
||||
|
@ -269,40 +257,70 @@ int main(){
|
|||
double p4 = pl_y;
|
||||
double p5 = -pl_y+pl_z;
|
||||
double p6 = pl_x;
|
||||
perspective_proj(w,a,1200,p1,p2,p3,p4,p5,p6);
|
||||
|
||||
perspective_proj(w,a,s,p1,p2,p3,p4,p5,p6);
|
||||
|
||||
glfw_load(w);
|
||||
|
||||
int mod_move=1;
|
||||
double run_mul=2;
|
||||
usleep(10000);
|
||||
glfwPollEvents();
|
||||
if(glfwGetKey(w,GLFW_KEY_I))
|
||||
plr_x--;
|
||||
if(glfwGetKey(w,GLFW_KEY_K))
|
||||
plr_x++;
|
||||
if(glfwGetKey(w,GLFW_KEY_J))
|
||||
plr_y--;
|
||||
if(glfwGetKey(w,GLFW_KEY_L))
|
||||
plr_y++;
|
||||
if(glfwGetKey(w,GLFW_KEY_I)){
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
plr_x-=mod_move;
|
||||
else
|
||||
plr_x--;
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_K)){
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
plr_x+=mod_move;
|
||||
else
|
||||
plr_x++;
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_J)){
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
plr_y-=mod_move;
|
||||
else
|
||||
plr_y--;
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_L)){
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
plr_y+=mod_move;
|
||||
else
|
||||
plr_y++;
|
||||
}
|
||||
plr_x = fmod(plr_x,max_r);
|
||||
plr_y = fmod(plr_y,max_r);
|
||||
if(glfwGetKey(w,GLFW_KEY_W)){
|
||||
pl_x+=cosf(plr_y*0.01);
|
||||
pl_y+=sinf(plr_y*0.01);
|
||||
pl_z-=sinf(plr_x*0.01);
|
||||
printf("%f\n",pl_z);
|
||||
double mul = 1;
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
mul = run_mul;
|
||||
pl_x+=cosf(plr_y*0.01)*mul;
|
||||
pl_y+=sinf(plr_y*0.01)*mul;
|
||||
pl_z-=sinf(plr_x*0.01)*mul;
|
||||
//printf("%f\n",pl_z);
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_S)){
|
||||
pl_x-=cosf(plr_y*0.01);
|
||||
pl_y-=sinf(plr_y*0.01);
|
||||
pl_z+=sinf(plr_x*0.01);
|
||||
double mul = 1;
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
mul = run_mul;
|
||||
pl_x-=cosf(plr_y*0.01)*mul;
|
||||
pl_y-=sinf(plr_y*0.01)*mul;
|
||||
pl_z+=sinf(plr_x*0.01)*mul;
|
||||
}
|
||||
if(glfwGetKey(w,GLFW_KEY_A)){
|
||||
pl_x-=cosf((half_max_r+plr_y)*0.01);
|
||||
pl_y-=sinf((half_max_r+plr_y)*0.01);
|
||||
double mul = 1;
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
mul = run_mul;
|
||||
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_D)){
|
||||
pl_x+=cosf((half_max_r+plr_y)*0.01);
|
||||
pl_y+=sinf((half_max_r+plr_y)*0.01);
|
||||
double mul = 1;
|
||||
if(glfwGetKey(w,GLFW_KEY_LEFT_SHIFT))
|
||||
mul = run_mul;
|
||||
pl_x+=cosf((half_max_r+plr_y)*0.01)*mul;
|
||||
pl_y+=sinf((half_max_r+plr_y)*0.01)*mul;
|
||||
}
|
||||
//printf("%f %f %f\n",plr_y,cosf(plr_y*0.01),sinf(plr_y*0.01));
|
||||
glfw_clear(w);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#ifndef __util__
|
||||
#define __util__
|
||||
#include "string.h"
|
||||
#define greater(a,b) (a>b?a:b)
|
||||
#define lesser(a,b) (a>b?b:a)
|
||||
void err_m(char*,void (*)(int),char*,int);
|
||||
void warn_m(char*,char*,int ,...);
|
||||
void info_m(char*,char*,int ,...);
|
||||
|
|
Loading…
Reference in New Issue