From 167169abe4df9bd67b5994b6a665abb437947815 Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 6 Apr 2020 04:41:47 -0500 Subject: added a lot of code while trying to fix the 3D projection to be less suck. ended up adding some code to have multiple "eyes" on a camera, instead of moving the camera around. --- src/common.h | 7 +-- src/graphics_c3.c | 150 ++++++++++++++++++++++++++++++++++++------------------ src/graphics_c3.h | 3 +- 3 files changed, 106 insertions(+), 54 deletions(-) diff --git a/src/common.h b/src/common.h index a555cb1..9dddf3d 100644 --- a/src/common.h +++ b/src/common.h @@ -49,10 +49,10 @@ typedef struct { } c3_rot_t; typedef struct { - char *id; + char *id;//for the camera this is $USER, right? c3_rot_t r;//rotation c3_t p;//position - c3_t s;//??? shape??? I dunno. + c3_t s;//??? shape??? I dunno. really. wtf was this for? c3_t v;//velocity } c3_group_rot_t; @@ -113,7 +113,8 @@ struct hvr_global { int shapes; c3_group_rot_t *group_rot[SHAPES];//there can be less of these. struct hashtable ht_group; - c3_group_rot_t camera; + c3_group_rot_t eye[MAX_SIDES];//lol. 1000 eyes! array of group_rots for each eye. how to arrange eyes? + c3_group_rot_t camera;//should there be an array for this? camera has .s which is a shape struct. each point is the eye? real zoom; int derp; real split; diff --git a/src/graphics_c3.c b/src/graphics_c3.c index dd45fb9..98c2c25 100644 --- a/src/graphics_c3.c +++ b/src/graphics_c3.c @@ -127,12 +127,17 @@ c3_t c3_subtract(c3_t p1,c3_t p2) { //how is this supposed to work? x is distance? #define MAGIC(x) (1.0l-(1.0l/pow(1.01l,(x)))) //??? might want to have some changables in here +//#define MAGIC(x) (-250.0l / x ) +#define TOO_CLOSE (.25l) +#define TOO_FAR (15l) + +//input is distance from camera point. real magic(real x) { return MAGIC(x); } -c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE +c2_t c3_to_c2(c3_group_rot_t eye,c3_t p3) { //DO NOT DRAW STUFF IN HERE c2_t p2; c3_t tmp1; // c3_t tmp2; @@ -140,18 +145,19 @@ c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE c3_t final; //these rotations need to be about the previous axis after the axis itself has been rotated. //this rotation needs to not be applied to objects attached to the camera? - tmp1=rotate_c3_yr(p3,global.camera.p,d2r(global.camera.r.y));//rotate everything around the camera's location. + tmp1=rotate_c3_yr(p3,eye.p,d2r(eye.r.y));//rotate everything around the camera's location. //now to rotate the shape around it's group's center. //final=rotate_c3_yr(p3,(c3_t){0,0,0},d2r(camera.yr));//rotate everything around the center no matter what. - final=rotate_c3_xr(tmp1,global.camera.p,d2r(global.camera.r.x)); + final=rotate_c3_xr(tmp1,eye.p,d2r(eye.r.x)); // final=rotate_c3_zr(tmp2,camera.p,d2r(camera.zr)); - real delta_x=(global.camera.p.x - final.x);//I guess X needs this flippage too. - real delta_y=(global.camera.p.y - final.y);//I dunno. Y is weird. - real delta_z=(final.z - global.camera.p.z); + real delta_x=(eye.p.x - final.x);//I guess X needs this flippage too. + real delta_y=(eye.p.y - final.y);//I dunno. Y is weird. + real delta_z=(final.z - eye.p.z); //real d=distance3(global.camera.p,final); p2.x=global.zoom * (delta_x * MAGIC(delta_z) - delta_x); p2.y=global.zoom * (delta_y * MAGIC(delta_z) - delta_y);//this doesn't look right either. -// p2.x=global.zoom * (delta_x * MAGIC(d) - delta_x); // this doesn't look quite right + + // p2.x=global.zoom * (delta_x * MAGIC(d) - delta_x); // this doesn't look quite right // p2.y=global.zoom * (delta_y * MAGIC(d) - delta_y);//dunno if this is better or not. return p2; } @@ -164,7 +170,9 @@ void draw_minimap_shape(c3_s_t s) {//this should replace the draw_minimap_line a int i=0; //if(gra_global.drawminimap == 1) { for(i=0;i TOO_FAR) { + //return;// + } + if(d < TOO_CLOSE) {//how close is too close? + //return;//ha. not going to draw a shape that we're too close to. + } + } //all s2 needs to bet set before this loop. for(i=0;i 1) draw_minimap_line(s2.p[i],s2.p[(i+1)%s2.len]);//we shouldn't draw circles in here. //yeah. we probably should. - s3.p[i]=c3_to_c2(s2.p[i]);//we need to convert all points in the shape if we have to draw any parts of it. + s3.p[i]=c3_to_c2(eye,s2.p[i]);//we need to convert all points in the shape if we have to draw any parts of it. } - //draw_minimap_shape(s2); + draw_minimap_shape(s2); if(gra_global.draw3d == 1) { set_ansi_color(s.attrib.col%16); draw_c2_shape(s3); @@ -257,8 +279,8 @@ void draw_graph(real (*fun)(real x)) { } } -cs_t c3_to_cs(c3_t p) { - return c2_to_cs(c3_to_c2(p)); +cs_t c3_to_cs(c3_group_rot_t eye,c3_t p) { + return c2_to_cs(c3_to_c2(eye,p)); } real shitdist2(c3_t p1,c3_t p2) { @@ -274,9 +296,9 @@ real shitdist(struct c3_shape *s,c3_t p) {//this function is a killer. :/ c3_group_rot_t *gr=get_group_relative(s->id); for(i=0;i< s->len+(s->len==1);i++) { if(gr) { - curdist=shitdist2(global.camera.p,rotate_c3_yr(c3_add(gr->p,s->p[i]),gr->p,d2r(gr->r.y))); + curdist=shitdist2(p,rotate_c3_yr(c3_add(gr->p,s->p[i]),gr->p,d2r(gr->r.y))); } else { - curdist=shitdist2(global.camera.p,s->p[i]);//if there's no gr we're basically just this point. no rotation, not offests. + curdist=shitdist2(p,s->p[i]);//if there's no gr we're basically just this point. no rotation, not offests. } if(curdist > maxdist) maxdist=curdist; } @@ -326,8 +348,8 @@ void HatchLines(c2_t p1,c2_t p2,c2_t p3,int density) { //black out the rest of the triangle first? //sounds alright to me... -void draw_c3_text(c3_t p,char *text) { - c2_t p2=c3_to_c2(p); +void draw_c3_text(c3_group_rot_t eye,c3_t p,char *text) { + c2_t p2=c3_to_c2(eye,p); draw_c2_text(p2,text); } @@ -359,27 +381,25 @@ void draw_c3_point_text(c3_t p,char *text) { void draw_screen() { int i; - int cn=0;//camera number. + int en=0;//eye number. different from "camera number" because a camera can have multiple eyes... a camera is like a "shape"??? hrm.. //char tmp[256]; zsort_t zs[SHAPES]; clear_backbuffer(); - real oldx=global.camera.p.x; - real oldz=global.camera.p.z; - - for(i=0;global.shape[i];i++) zs[i].s=global.shape[i]; - for(i=0;global.shape[i];i++) zs[i].d=shitdist(zs[i].s,global.camera.p); - qsort(&zs,i,sizeof(zs[0]),(int (*)(const void *,const void *))compar);//sort these zs structs based on d. farthest first. - if(i > 0 && zs[i-1].s) strcpy(global.selected_object,zs[i-1].s->id); if(gra_global.split_screen > 1) { -//oh... this will need to be a couple more lines... of what? I forgot. -Sep 2017 - radians tmprad=d2r((degrees){global.camera.r.y.d+90}); - radians tmprad2=d2r((degrees){global.camera.r.y.d+90}); - global.camera.p.z-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*cos( tmprad.r )); - global.camera.p.x-=(gra_global.split_flip)*((gra_global.split/gra_global.split_screen)*sin( tmprad2.r )); + recalculate_eyes();//still have to redo this even if we only have one eye. + } + if(gra_global.split_screen == 1) { + global.eye[0]=global.camera;//shortcut. } //return 0;//after this - for(cn=0;cn 0 && zs[i-1].s) strcpy(global.selected_object,zs[i-1].s->id); + // set_color();//restart each draw with the default color. if(gra_global.red_and_blue) { //set color for left half to red and right half to blue @@ -387,7 +407,7 @@ void draw_screen() { red_and_blue_magic(); gra_global.xoff=0;//we're overlapping our drawing so no offset based on camera. } else { - gra_global.xoff=(gra_global.width/gra_global.split_screen)*cn; + gra_global.xoff=(gra_global.width/gra_global.split_screen)*en; } if(!gra_global.red_and_blue) { set_clipping_rectangle(gra_global.xoff,0,gra_global.width/gra_global.split_screen,gra_global.height);// @@ -403,7 +423,7 @@ void draw_screen() { ///// shiiiit. I should be applying group rotations to all these shapes before sorting them. //when I do that. I need to make sure to take the group rotation out of draw_c3_shape()'s code. for(i=0;global.shape[i];i++) { - zs[i].d=shitdist(zs[i].s,global.camera.p); + zs[i].d=shitdist(zs[i].s,global.eye[en].p); } qsort(&zs,i,sizeof(zs[0]),(int (*)(const void *,const void *))compar);//sort these zs structs based on d. //draw all triangles @@ -414,7 +434,7 @@ void draw_screen() { for(;global.shape[i];i++) { //now we pick the color of this triangle! if(gra_global.red_and_blue) {//this can be moved to the draw_c3_shape function and color can be set then. - if(cn%2==0) { + if(en%2==0) { set_color_red(); } else { set_color_blue(); @@ -430,7 +450,7 @@ void draw_screen() { } //if(between_angles(points_to_angle((c2_t){zs[i].s->p[0].x,zs[i].s->p[0].z},(c2_t){camera.p.x,camera.p.z}),d2r(camera.yr+45),d2r(camera.yr+135))) { // set_color_based_on_distance(zs[i].d); - draw_c3_shape(*(zs[i].s)); + draw_c3_shape(global.eye[en],*(zs[i].s));//the eye viewing it, and the shape //} } //we check here to see if the mouse button is still down @@ -452,20 +472,22 @@ void draw_screen() { }*/ // XSetForeground(global.dpy, global.backgc, global.green.pixel); - radians tmprad=d2r((degrees){global.camera.r.y.d+90}); - radians tmprad2=d2r((degrees){global.camera.r.y.d+90}); - global.camera.p.z+=(gra_global.split_flip)*(gra_global.split*cos( tmprad.r )); - global.camera.p.x+=(gra_global.split_flip)*(gra_global.split*sin( tmprad2.r )); + set_color(); + draw_c2_line((c2_t){0,0},rotate_c2((c2_t){40,0},(c2_t){0,0},d2r(global.eye[en].r.x))); + set_color_red(); + draw_c2_line((c2_t){0,0},rotate_c2((c2_t){-40,0},(c2_t){0,0},d2r((degrees){360-global.eye[en].r.y.d}))); + set_color_blue(); + draw_c2_line((c2_t){0,0},rotate_c2((c2_t){40,0},(c2_t){0,0},d2r(global.eye[en].r.z))); } //just draw a line from center to 40 away from the center at the angle of the camera's y-rotation -//this should be minimap shit draw_c2_line((c2_t){0,0},rotate_c2((c2_t){40,0},(c2_t){0,0},d2r(global.camera.r.y))); +//this should be minimap shit + //draw a line from the center to 80 away from the center in the angle of what should point at the mouse. + /*draw_c2_line((c2_t){0,0},gra_global.mouse); + set_color(); //if(points_on_same_side_of_line(gra_global.mouse,(c2_t){80,80},(c2_t){0,0},(c2_t){0,80})) { - // draw_c2_line((c2_t){0,0},rotate_c2((c2_t){80,0},(c2_t){0,0},points_to_angle((c2_t){0,0},gra_global.mouse)))); - //} - //draw_c2_line((c2_t){0,0},gra_global.mouse); - global.camera.p.x = oldx; - global.camera.p.z = oldz; //-= cn*CAMERA_SEPARATION; + draw_c2_line((c2_t){0,0},rotate_c2((c2_t){80,0},(c2_t){0,0},points_to_angle((c2_t){0,0},gra_global.mouse))); + //}*/ flipscreen(); } @@ -476,12 +498,40 @@ void redraw() {//something is requesting a redraw. } } +void recalculate_eyes() {//should I put the eyes into the global group_rot array so we can move them? + int i; + radians rad=d2r((degrees){global.camera.r.y.d+90}); + //radians tmprad2=d2r((degrees){global.camera.r.y.d+90}); + for(i=0;i