diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 10 | ||||
-rw-r--r-- | src/graphics.c | 50 | ||||
-rw-r--r-- | src/graphics.h | 11 | ||||
-rw-r--r-- | src/graphics_x11.c | 66 | ||||
-rw-r--r-- | src/hackvr.c | 18 | ||||
-rw-r--r-- | src/math.c | 29 | ||||
-rw-r--r-- | src/math.h | 12 |
7 files changed, 99 insertions, 97 deletions
diff --git a/src/common.h b/src/common.h index e8896ed..859c826 100644 --- a/src/common.h +++ b/src/common.h @@ -33,11 +33,15 @@ typedef struct { short y; } cs_t; +typedef struct c3_rotation { + degrees x; + degrees y; + degrees z; +} c3_rot_t; + struct camera { c3_t p; - degrees xr;//rotations - degrees yr; - degrees zr; + c3_rot_t r; real zoom; } camera; diff --git a/src/graphics.c b/src/graphics.c index f8d2bf6..cdd9c4a 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -202,33 +202,6 @@ void draw_graph(real (*fun)(real x)) { } } -/* -c2_t rotate_c2(c2_t p1,c2_t p2,real dr) {//dr is in radians - c2_t p3; - real d=distance2(p1,p2); - real r=points_to_angle(p1,p2); - r=r+dr; - p3.x=(sinl(r) * d) + p2.x; - p3.y=(cosl(r) * d) + p2.y; - return p3; -} - -c3_t rotate_c3_xr(c3_t p1,c3_t p2,real xr) {//rotate y and z around camera based on xr (looking up and down) - c2_t tmp; - tmp=rotate_c2((c2_t){p1.y,p1.z},(c2_t){p2.y,p2.z},xr); - return (c3_t){p1.x,tmp.x,tmp.y}; -} -c3_t rotate_c3_yr(c3_t p1,c3_t p2,real yr) {//rotate x and z around camera based on yr (looking left and right) - c2_t tmp; - tmp=rotate_c2((c2_t){p1.x,p1.z},(c2_t){p2.x,p2.z},yr); - return (c3_t){tmp.x,p1.y,tmp.y}; -} -c3_t rotate_c3_zr(c3_t p1,c3_t p2,real zr) {//rotate x and y around camera based on zr (cocking your head to a side) - c2_t tmp; - tmp=rotate_c2((c2_t){p1.x,p1.y},(c2_t){p2.x,p2.y},zr); - return (c3_t){tmp.x,tmp.y,p1.z}; -} -*/ c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE c2_t p2; // c3_t tmp1; @@ -236,7 +209,7 @@ c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE // c3_t tmp3; c3_t final; //these rotations need to be about the previous axis after the axis itself has been rotated. - final=rotate_c3_yr(p3,camera.p,d2r(camera.yr.d));//rotate everything around the camera's location. + final=rotate_c3_yr(p3,camera.p,d2r(camera.r.y));//rotate everything around the camera's location. // final=rotate_c3_yr(p3,(c3_t){0,0,0},d2r(camera.yr));//rotate everything around the center no matter what. // tmp2=rotate_c3_xr(tmp1,camera.p,d2r(camera.xr)); // final=rotate_c3_zr(tmp2,camera.p,d2r(camera.zr)); @@ -258,8 +231,8 @@ void draw_c3_line(c3_t p1,c3_t p2) { draw_c2_line((c2_t){p1.x*global.mmz,p1.z*global.mmz},(c2_t){p2.x*global.mmz,p2.z*global.mmz}); } if(gra_global.drawminimap == 2) {//map rotates. - c3_t t1=rotate_c3_yr(p1,camera.p,d2r(camera.yr.d)); - c3_t t2=rotate_c3_yr(p2,camera.p,d2r(camera.yr.d)); + c3_t t1=rotate_c3_yr(p1,camera.p,d2r(camera.r.y)); + c3_t t2=rotate_c3_yr(p2,camera.p,d2r(camera.r.y)); draw_c2_line((c2_t){t1.x*global.mmz,t1.z*global.mmz},(c2_t){t2.x*global.mmz,t2.z*global.mmz}); } if(gra_global.draw3d != 0) draw_c2_line(c3_to_c2(p1),c3_to_c2(p2)); @@ -284,7 +257,7 @@ real shitdist(struct c3_shape *s,c3_t p) { real total=0; for(i=0;i< s->len+(s->len==1);i++) { // total=total+shitdist2(rotate_c3_yr(s->p[i],(c3_t){0,0,0},d2r(camera.yr)),camera.p); - total=total+shitdist2(rotate_c3_yr(s->p[i],camera.p,d2r(camera.yr.d)),camera.p); + total=total+shitdist2(rotate_c3_yr(s->p[i],camera.p,d2r(camera.r.y)),camera.p); } return (total) / (real)(s->len+(s->len==1)); } @@ -378,8 +351,11 @@ void draw_screen() { if(i > 0 && zs[i-1].s) strcpy(global.selected_object,zs[i-1].s->id); if(gra_global.split_screen > 1) { - camera.p.z-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*cosl(d2r(camera.yr.d+180))); - camera.p.x-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*sinl(d2r(camera.yr.d+180))); +//oh... this will need to be a couple more lines + radians tmprad=d2r((degrees){camera.r.y.d+180}); + radians tmprad2=d2r((degrees){camera.r.y.d+180}); + camera.p.z-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*cosl( tmprad.r )); + camera.p.x-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*sinl( tmprad2.r )); } for(cn=0;cn<gra_global.split_screen;cn++) { set_color();//restart each draw with the default color. @@ -417,7 +393,7 @@ void draw_screen() { draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+20},tmp); snprintf(tmp,sizeof(tmp)-1,"cx: %Lf cy: %Lf cz: %Lf",camera.p.x,camera.p.y,camera.p.z); draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+30},tmp); - snprintf(tmp,sizeof(tmp)-1,"xr: %d yr: %d zr: %d",camera.xr.d,camera.yr.d,camera.zr.d); + snprintf(tmp,sizeof(tmp)-1,"xr: %d yr: %d zr: %d",camera.r.x.d,camera.r.y.d,camera.r.z.d); draw_cs_text((cs_t){gra_global.xoff,(gra_global.height/2)+40},tmp); } @@ -463,8 +439,10 @@ void draw_screen() { //} } // XSetForeground(global.dpy, global.backgc, global.green.pixel); - camera.p.z+=(CAMERA_SEPARATION)*(gra_global.split_flip)*(gra_global.split*cosl(d2r(camera.yr.d+180))); - camera.p.x+=(CAMERA_SEPARATION)*(gra_global.split_flip)*(gra_global.split*sinl(d2r(camera.yr.d+180))); + radians tmprad=d2r((degrees){camera.r.y.d+180}); + radians tmprad2=d2r((degrees){camera.r.y.d+180}); + camera.p.z+=(gra_global.split_flip)*(gra_global.split*cosl( tmprad.r )); + camera.p.x+=(gra_global.split_flip)*(gra_global.split*sinl( tmprad2.r )); } //TODO: figure out what all this shit is and either update or remove. diff --git a/src/graphics.h b/src/graphics.h index b351d2c..eadaa54 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -11,7 +11,7 @@ struct gra_global { int greyscale; int xoff; int split_screen; - int split; + real split; int split_flip; char force_redraw; char red_and_blue; @@ -42,12 +42,11 @@ void draw_screen(); void set_aspect_ratio(); int selfcommand(char *s); cs_t c3_to_cs(c3_t p); -real d2r(int d); +radians d2r(degrees d); real shitdist(struct c3_shape *s,c3_t p); -c3_t rotate_c3_xr(c3_t p1,c3_t p2,real xr); -c3_t rotate_c3_yr(c3_t p1,c3_t p2,real yr); -c3_t rotate_c3_zr(c3_t p1,c3_t p2,real zr); -real points_to_angle(c2_t p1,c2_t p2); +c3_t rotate_c3_xr(c3_t p1,c3_t p2,radians xr); +c3_t rotate_c3_yr(c3_t p1,c3_t p2,radians yr); +c3_t rotate_c3_zr(c3_t p1,c3_t p2,radians zr); int compar(zsort_t *a,zsort_t *b); diff --git a/src/graphics_x11.c b/src/graphics_x11.c index f86b31e..31a78e4 100644 --- a/src/graphics_x11.c +++ b/src/graphics_x11.c @@ -166,6 +166,8 @@ void set_aspect_ratio() { int keypress_handler(int sym) { char line[1024]; + radians tmprad; + radians tmprad2; real tmpx; // real tmpy; //unused atm real tmpz; @@ -175,32 +177,40 @@ int keypress_handler(int sym) { selfcommand(line); break; case XK_Up: - tmpx=WALK_SPEED*sinl(d2r(camera.yr.d+90)); - tmpz=WALK_SPEED*cosl(d2r(camera.yr.d+90)); + tmprad=d2r((degrees){camera.r.y.d+90}); + tmprad2=d2r((degrees){camera.r.y.d+90}); + tmpx=WALK_SPEED*sinl(tmprad.r); + tmpz=WALK_SPEED*cosl(tmprad2.r); camera.p.x+=tmpx; camera.p.z+=tmpz; snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz); selfcommand(line); break; case XK_Down: - tmpx=WALK_SPEED*sinl(d2r(camera.yr.d+270)); - tmpz=WALK_SPEED*cosl(d2r(camera.yr.d+270)); + tmprad=d2r((degrees){camera.r.y.d+270}); + tmprad2=d2r((degrees){camera.r.y.d+270}); + tmpx=WALK_SPEED*sinl(tmprad.r); + tmpz=WALK_SPEED*cosl(tmprad2.r); camera.p.x+=tmpx; camera.p.z+=tmpz; snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz); selfcommand(line); break; case XK_Left: - tmpx=WALK_SPEED*sinl(d2r(camera.yr.d)); - tmpz=WALK_SPEED*cosl(d2r(camera.yr.d)); + tmprad=d2r(camera.r.y); + tmprad2=d2r(camera.r.y); + tmpx=WALK_SPEED*sinl(tmprad.r); + tmpz=WALK_SPEED*cosl(tmprad2.r); camera.p.x+=tmpx; camera.p.z+=tmpz; snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz); selfcommand(line); break; case XK_Right: - tmpx=WALK_SPEED*sinl(d2r(camera.yr.d+180)); - tmpz=WALK_SPEED*cosl(d2r(camera.yr.d+180)); + tmprad=d2r((degrees){camera.r.y.d+180}); + tmprad2=d2r((degrees){camera.r.y.d+180}); + tmpx=WALK_SPEED*sinl(tmprad.r); + tmpz=WALK_SPEED*cosl(tmprad2.r); camera.p.x+=tmpx; camera.p.z+=tmpz; snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,tmpx,tmpz); @@ -217,28 +227,34 @@ int keypress_handler(int sym) { selfcommand(line); break; case XK_r: - camera.xr.d+=5; - while(camera.xr.d > 360) camera.xr.d-=360; + camera.r.x.d+=5; + while(camera.r.x.d > 360) camera.r.x.d-=360; break; case XK_y: - camera.xr.d-=5; - while(camera.xr.d < 0) camera.xr.d+=360; + camera.r.x.d-=5; + while(camera.r.x.d < 0) camera.r.x.d+=360; break; case XK_q: - camera.yr.d+=5; - while(camera.yr.d > 360) camera.yr.d-=360; + camera.r.y.d+=5; + while(camera.r.y.d > 360) camera.r.y.d-=360; break; case XK_e: - camera.yr.d-=5; - while(camera.yr.d < 0) camera.yr.d+=360; + camera.r.y.d-=5; + while(camera.r.y.d < 0) camera.r.y.d+=360; break; case XK_u: - camera.zr.d+=5; - while(camera.zr.d > 360) camera.zr.d-=360; + camera.r.z.d+=5; + while(camera.r.z.d > 360) camera.r.z.d-=360; break; case XK_o: - camera.zr.d-=5; - while(camera.zr.d < 0) camera.zr.d+=360; + camera.r.z.d-=5; + while(camera.r.z.d < 0) camera.r.z.d+=360; + break; + case XK_p: + gra_global.split+=.1; + break; + case XK_l: + gra_global.split-=.1; break; case XK_z: camera.zoom+=1; break; case XK_x: camera.zoom-=1; break; @@ -274,7 +290,7 @@ int keypress_handler(int sym) { #endif int graphics_init() { - int i,j; + int i; char tmp[64]; Cursor cursor; XSetWindowAttributes attributes; @@ -296,7 +312,7 @@ int graphics_init() { assert(x11_global.dpy); gra_global.split_screen=SPLIT_SCREEN; gra_global.split_flip=-1; - gra_global.split=5; + gra_global.split=CAMERA_SEPARATION; x11_global.root_window=0; gra_global.red_and_blue=RED_AND_BLUE; //global.colors[0]=BlackPixel(x11_global.dpy,DefaultScreen(x11_global.dpy)); @@ -372,9 +388,9 @@ int graphics_init() { //this should be in graphics.c ? camera.zoom=30.0l; - camera.xr.d=270; - camera.yr.d=90; - camera.zr.d=0; + camera.r.x.d=270; + camera.r.y.d=90; + camera.r.z.d=0; global.mmz=1; camera.p.x=0; camera.p.z=-6; diff --git a/src/hackvr.c b/src/hackvr.c index f708e65..6828f59 100644 --- a/src/hackvr.c +++ b/src/hackvr.c @@ -213,9 +213,9 @@ int load_stdin() { printf("%s set camera.p.x %Lf\n",global.user,camera.p.x); printf("%s set camera.p.y %Lf\n",global.user,camera.p.y); printf("%s set camera.p.z %Lf\n",global.user,camera.p.z); - printf("%s set camera.xr %d\n",global.user,camera.xr.d); - printf("%s set camera.yr %d\n",global.user,camera.yr.d); - printf("%s set camera.zr %d\n",global.user,camera.zr.d); + printf("%s set camera.r.x %d\n",global.user,camera.r.x.d); + printf("%s set camera.r.y %d\n",global.user,camera.r.y.d); + printf("%s set camera.r.z %d\n",global.user,camera.r.z.d); printf("%s set camera.zoom %Lf\n",global.user,camera.zoom); continue; } @@ -231,9 +231,9 @@ int load_stdin() { else if(!strcmp(a[2],"camera.p.y")) camera.p.y=strtold(a[3],0); else if(!strcmp(a[2],"camera.p.z")) camera.p.z=strtold(a[3],0); else if(!strcmp(a[2],"camera.zoom")) camera.zoom=strtold(a[3],0); - else if(!strcmp(a[2],"camera.xr")) camera.xr.d=atoi(a[3]); - else if(!strcmp(a[2],"camera.yr")) camera.yr.d=atoi(a[3]); - else if(!strcmp(a[2],"camera.zr")) camera.zr.d=atoi(a[3]); + else if(!strcmp(a[2],"camera.r.x")) camera.r.x.d=atoi(a[3]); + else if(!strcmp(a[2],"camera.r.y")) camera.r.y.d=atoi(a[3]); + else if(!strcmp(a[2],"camera.r.z")) camera.r.z.d=atoi(a[3]); #endif else printf("# unknown variable: %s\n",a[2]); continue; @@ -293,12 +293,14 @@ int load_stdin() { } continue; } - if(!strcmp(command,"rotate")) { + if(!strcmp(command,"rotate")) {//this probably won't be needed with the new rotation structs per group. if(len > 4) { for(i=0;global.shape[i];i++) { if(!strcmp(global.shape[i]->id,id)) { for(j=0;j < global.shape[i]->len+(global.shape[i]->len==1);j++) { - global.shape[i]->p[j]=rotate_c3_yr(global.shape[i]->p[j],(c3_t){0,0,0},points_to_angle((c2_t){global.shape[i]->p[j].x,global.shape[i]->p[j].z},(c2_t){0,0})+d2r(atoi(a[2]))); + radians tmprad=points_to_angle((c2_t){global.shape[i]->p[j].x,global.shape[i]->p[j].z},(c2_t){0,0}); + radians tmprad2=d2r((degrees){atoi(a[2])}); + global.shape[i]->p[j]=rotate_c3_yr(global.shape[i]->p[j],(c3_t){0,0,0},(radians){tmprad.r+tmprad2.r}); //global.shape[i]->p[j]=rotate_c3_yr(global.shape[i]->p[j],(c3_t){0,0,0},d2r(atoi(a[3]))); //global.shape[i]->p[j]=rotate_c3_zr(global.shape[i]->p[j],(c3_t){0,0,0},d2r(atoi(a[4]))); } @@ -1,38 +1,41 @@ #include "math.h" -c3_t rotate_c3_xr(c3_t p1,c3_t p2,real xr) {//rotate y and z around camera based on xr (looking up and down) +//should these use the radians struct? + +c3_t rotate_c3_xr(c3_t p1,c3_t p2,radians xr) {//rotate y and z around camera based on xr (looking up and down) c2_t tmp; tmp=rotate_c2((c2_t){p1.y,p1.z},(c2_t){p2.y,p2.z},xr); return (c3_t){p1.x,tmp.x,tmp.y}; } -c3_t rotate_c3_yr(c3_t p1,c3_t p2,real yr) {//rotate x and z around camera based on yr (looking left and right) +c3_t rotate_c3_yr(c3_t p1,c3_t p2,radians yr) {//rotate x and z around camera based on yr (looking left and right) c2_t tmp; tmp=rotate_c2((c2_t){p1.x,p1.z},(c2_t){p2.x,p2.z},yr); return (c3_t){tmp.x,p1.y,tmp.y}; } -c3_t rotate_c3_zr(c3_t p1,c3_t p2,real zr) {//rotate x and y around camera based on zr (cocking your head to a side) +c3_t rotate_c3_zr(c3_t p1,c3_t p2,radians zr) {//rotate x and y around camera based on zr (cocking your head to a side) c2_t tmp; tmp=rotate_c2((c2_t){p1.x,p1.y},(c2_t){p2.x,p2.y},zr); return (c3_t){tmp.x,tmp.y,p1.z}; } -c2_t rotate_c2(c2_t p1,c2_t p2,real dr) {//dr is in radians +c2_t rotate_c2(c2_t p1,c2_t p2,radians dr) {//dr is in radians c2_t p3; real d=distance2(p1,p2); - real r=points_to_angle(p1,p2); - r=r+dr; - p3.x=(sinl(r) * d) + p2.x; - p3.y=(cosl(r) * d) + p2.y; + radians r=points_to_angle(p1,p2); + r.r=r.r+dr.r; + p3.x=(sinl(r.r) * d) + p2.x; + p3.y=(cosl(r.r) * d) + p2.y; return p3; } real distance2(c2_t p1,c2_t p2) { return sqrtl(( (p1.x-p2.x)*(p1.x-p2.x) )+( (p1.y-p2.y)*(p1.y-p2.y) )); } -real d2r(int d) { - while(d<0) d+=360; - return (real)(d%360) / (real)180 * M_PIl; + +radians d2r(degrees d) { + while(d.d<0) d.d+=360; + return (radians){(real)(d.d%360) / (real)180 * M_PIl}; } -real points_to_angle(c2_t p1,c2_t p2) { +radians points_to_angle(c2_t p1,c2_t p2) { real a=atan2l(p2.y-p1.y,p2.x-p1.x); - return a>=0?a:M_PIl+M_PIl+a; + return (radians){a>=0?a:M_PIl+M_PIl+a}; } @@ -8,11 +8,11 @@ #undef __USE_GNU real distance2(c2_t p1,c2_t p2); -c2_t rotate_c2(c2_t p1,c2_t p2,real dr); -c3_t rotate_c3_xr(c3_t p1,c3_t p2,real xr); -c3_t rotate_c3_yr(c3_t p1,c3_t p2,real yr); -c3_t rotate_c3_zr(c3_t p1,c3_t p2,real zr); -real d2r(int d); -real points_to_angle(c2_t p1,c2_t p2); +c2_t rotate_c2(c2_t p1,c2_t p2,radians dr); +c3_t rotate_c3_xr(c3_t p1,c3_t p2,radians xr); +c3_t rotate_c3_yr(c3_t p1,c3_t p2,radians yr); +c3_t rotate_c3_zr(c3_t p1,c3_t p2,radians zr); +radians d2r(degrees d); +radians points_to_angle(c2_t p1,c2_t p2); #endif |