From fab99221e68f2f494ea3c7a46858d427c6d9c9f8 Mon Sep 17 00:00:00 2001 From: epoch Date: Wed, 4 Jan 2017 16:38:30 -0600 Subject: added a function for drawing a filled cs shape. re-added flat shading based on distance. moved draw3d check into graphics.c instead of graphics lib specific file. --- src/graphics.c | 51 +++++++++++++----------------- src/graphics_x11.c | 91 ++++++++++++++---------------------------------------- 2 files changed, 46 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/src/graphics.c b/src/graphics.c index a8a8e69..e658376 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -156,15 +156,24 @@ void draw_c2_line(c2_t p1,c2_t p2) { draw_cs_line(c2_to_cs(p1),c2_to_cs(p2)); } -void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? +void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? //draw minimap shit in here too? probably... int i; cs_s_t ss; ss.id=s.id;//it shouldn't disappear and we shouldn't need to make a copy. ss.len=s.len; for(i=0;ilen+(s->len==1);i++) s->p[0]=rotate_c3_yr(s->p[0],camera.p,camera.yr); -} - c2_t c3_to_c2(c3_t p3) { //DO NOT DRAW STUFF IN HERE c2_t p2; // c3_t tmp1; @@ -268,17 +272,14 @@ real shitdist2(c3_t p1,c3_t p2) { ((p1.z - p2.z) * (p1.z - p2.z))); } -real shitdist(struct c3_shape s,c3_t p) { +real shitdist(struct c3_shape *s,c3_t p) { // apply rotation then find distance? int i; - struct c3_shape s_; - real total; - s_=s; - rotate_shape_yr(&s_); - for(i=0;ilen+(s->len==1);i++) { + total=total+shitdist2(rotate_c3_yr(s->p[i],(c3_t){0,0,0},d2r(camera.yr)),camera.p); } - return (total) / (real)(s_.len+(s_.len==1)); + return (total) / (real)(s->len+(s->len==1)); } @@ -327,7 +328,7 @@ cs_t *c3s_to_css(c3_t *p3,int len) { }*/ int compar(zsort_t *a,zsort_t *b) { - return ((a->d) > (b->d)); + return ((a->d) < (b->d)); } @@ -357,7 +358,6 @@ int selfcommand(char *s) { void draw_screen() { int i; - int colori=100; int cn=0;//camera number. char tmp[256]; zsort_t zs[SHAPES]; @@ -456,7 +456,7 @@ void draw_screen() { // if(1) {//global.zsort) { for(i=0;global.shape[i];i++) { - zs[i].d=shitdist(*(zs[i].s),camera.p); + zs[i].d=shitdist(zs[i].s,camera.p); } qsort(&zs,i,sizeof(zs[0]),(__compar_fn_t)compar);//sort these zs structs based on d. } @@ -478,18 +478,11 @@ void draw_screen() { if(!strcmp(global.selected_object,zs[i].s->id)) { //XSetForeground(global.dpy,global.backgc,global.green.pixel); } else { - if(gra_global.greyscale) { - if(zs[i].d > 0) { - if(zs[i].d < 100) { - colori=zs[i].d; - } - } - colori=(int)(zs[i].d)%100; -// XSetForeground(global.dpy,global.backgc,global.colors[(int)(100.0-(colori))].pixel);//picking the color here only works if... - } +// set_color_based_on_distance(zs[i].d); } } - set_color(); +// set_color(); + set_color_based_on_distance(zs[i].d); draw_c3_shape(*(zs[i].s)); } // XSetForeground(global.dpy, global.backgc, global.green.pixel); diff --git a/src/graphics_x11.c b/src/graphics_x11.c index 1b31664..aea7dff 100644 --- a/src/graphics_x11.c +++ b/src/graphics_x11.c @@ -39,6 +39,11 @@ struct x11_global x11_global; #ifdef GRAPHICAL +void set_color_based_on_distance(real d) { + int i=100-((int)((d+100.0) * 16.0) % 100); + XSetForeground(x11_global.dpy,x11_global.backgc,x11_global.colors[i].pixel); +} + void draw_cs_line(cs_t p1,cs_t p2) { XDrawLine(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p1.x,p1.y,p2.x,p2.y); } @@ -54,86 +59,39 @@ void draw_cs_text(cs_t p,char *text) { } void draw_cs_shape(cs_s_t s) {//this is implemented as draw_cs_line... hrm. it could be moved up to graphics.c? probl no. - int i; - if(gra_global.draw3d == 1) { //wireframe - for(i=0;imax_aspect.x=AR_W*(gra_global.split_screen / (gra_global.red_and_blue ? gra_global.split_screen : 1)); hints->max_aspect.y=AR_H; hints->flags=PAspect; - XSetWMNormalHints(x11_global.dpy,x11_global.w,hints); } -- cgit v1.2.3