summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c51
-rw-r--r--src/graphics_x11.c91
2 files changed, 46 insertions, 96 deletions
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;i<s.len+(s.len==1);i++) {
- ss.p[i]=c3_to_cs(s.p[i]);
+ ss.p[i]=c3_to_cs(s.p[i]);
+ }
+ if(gra_global.draw3d == 1) {
+ draw_cs_shape(ss);
+ }
+ if(gra_global.draw3d == 2) {
+ //set foreground to a gray based on distance
+ //between 0 to 100
+// color_based_on_distance();//I don't have the distance in here. :/
+//foreground_set();
+ draw_cs_filled_shape(ss);
}
- draw_cs_shape(ss);
}
#define MAGIC(x) (1.0l-(1.0l/powl(1.01l,(x)))) //??? might want to have some changables in here
@@ -214,11 +223,6 @@ c3_t rotate_c3_zr(c3_t p1,c3_t p2,real zr) {//rotate x and y around camera based
return (c3_t){tmp.x,tmp.y,p1.z};
}
-void rotate_shape_yr(struct c3_shape *s) {//changes input value!
- int i=0;
- for(i=0;i<s->len+(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;i<s_.len+(s_.len==1);i++) {
- total+=shitdist2(s_.p[i],camera.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);
}
- 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;i<s.len+(s.len==1);i++) {//this shape is closed!
- draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
- }
- }
- if(gra_global.draw3d == 2) { //filled in
- XPoint Xp[s.len+(s.len==1)];
- for(i=0;i<s.len+(s.len==1);i++) {
- Xp[i]=(XPoint){s.p[i].x,s.p[i].y};
- }
- XFillPolygon(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,Xp,s.len,Convex,CoordModeOrigin);
- }
-}
-
-//this needs to be taken out of this file and left to graphics.c
-#if 0
-void draw_c3_shape(c3_s_t s) {
-// char line[1024];
- int i=0;
- int h;//,w
- XPoint p[s.len+(s.len==1)];
- cs_t tmp;
- for(i=0;i<s.len+(s.len==1);i++) {
- tmp=c3_to_cs(s.p[i]);
- p[i]=(XPoint){tmp.x,tmp.y};
- }
- if(global.draw3d == 1) { // wireframe
+ int h;
+ int i;//all cs shapes can have 1, 2, or 3+ points. guess I gotta do that logic here too.
switch(s.len) {
case 1:
- //w=max(p[0].x,p[1].x)-min(p[0].x,p[1].x);
- h=max(p[0].y,p[1].y)-min(p[0].y,p[1].y);
- p[0].x-=h;
- p[0].y-=h;
- XDrawArc(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p[0].x,p[0].y,h*2,h*2,0,360*64);
- break;
- case 2:
- XDrawLine(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p[0].x,p[0].y,p[1].x,p[1].y);
+ //cicle
+ h=max(s.p[0].y,s.p[1].y)-min(s.p[0].y,s.p[1].y);
+ XDrawArc(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,s.p[0].x-h,s.p[0].y-h,h*2,h*2,0,360*64);
break;
default:
- for(i=0;i<s.len;i++) {
- XDrawLines(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p,s.len,CoordModeOrigin);
+ for(i=0;i<s.len+(s.len==1);i++) {//this shape is closed!
+ draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
}
break;
}
- }
- if(global.draw3d == 2) { //draw it filled in
+}
+
+void draw_cs_filled_shape(cs_s_t s) {
+ int h;
+ int i;
+ XPoint Xp[s.len+(s.len==1)];
+ for(i=0;i<s.len+(s.len==1);i++) {
+ Xp[i]=(XPoint){s.p[i].x,s.p[i].y};
+ }
switch(s.len) {
case 1:
- //w=max(p[0].x,p[1].x)-min(p[0].x,p[1].x);
- h=max(p[0].y,p[1].y)-min(p[0].y,p[1].y);
- p[0].x-=h;
- p[0].y-=h;
- XFillArc(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p[0].x,p[0].y,h*2,h*2,0,360*64);
- break;
- case 2:
- XDrawLine(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p[0].x,p[0].y,p[1].x,p[1].y);
+ h=max(s.p[0].y,s.p[1].y)-min(s.p[0].y,s.p[1].y);
+ XFillArc(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,s.p[0].x-h,s.p[0].y-h,h*2,h*2,0,360*64);
break;
default:
- XFillPolygon(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,p,s.len,Convex,CoordModeOrigin);
+ XFillPolygon(x11_global.dpy,x11_global.backbuffer,x11_global.backgc,Xp,s.len,Convex,CoordModeOrigin);
break;
}
- }
-// if(global.draw3d == 3) { //hashed
-// XSetForeground(x11_global.dpy, x11_global.backgc, global.colors[0].pixel);
- //XDrawFilledShape(c3_to_cs(t.p1),c3_to_cs(t.p2),c3_to_cs(t.p3));//clear out this triangle.
-// XSetForeground(x11_global.dpy, x11_global.backgc, global.green.pixel);
- //upgrade me! DrawHatchedTriangle(t,10 - (shitdist(t,camera.p) / 10));//how to get density?
-// }
-/* if(global.debug) {
- snprintf(line,sizeof(line)-1,"(%Lf,%Lf,%Lf)",t.p1.x,t.p1.y,t.p1.z);
- draw_c3_text(t.p1,line);
- snprintf(line,sizeof(line)-1,"(%Lf,%Lf,%Lf)",t.p2.x,t.p2.y,t.p2.z);
- draw_c3_text(t.p2,line);
- snprintf(line,sizeof(line)-1,"(%Lf,%Lf,%Lf)",t.p3.x,t.p3.y,t.p3.z);
- draw_c3_text(t.p3,line);
-*/
-// }
}
-#endif
//should I do clipping in each graphics lib or make graphics.c just have clipping stuff?
void clear_backbuffer() {
@@ -174,7 +132,6 @@ void set_aspect_ratio() {
hints->max_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);
}