summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/graphics_c3.c26
-rw-r--r--src/graphics_cs_x11.c45
-rw-r--r--src/hackvr.c15
-rw-r--r--src/math.c10
-rw-r--r--tictactoe/board11
-rw-r--r--tictactoe/marker02
-rw-r--r--tictactoe/marker11
-rwxr-xr-xtictactoe/run22
-rwxr-xr-xtools/line2hackvr.sh6
9 files changed, 114 insertions, 24 deletions
diff --git a/src/graphics_c3.c b/src/graphics_c3.c
index b1d0bd7..9655f18 100644
--- a/src/graphics_c3.c
+++ b/src/graphics_c3.c
@@ -185,7 +185,9 @@ void draw_c3_shape(c3_s_t s) {//outlined. needs to be filled? //draw minimap shi
s2.len=s.len;
c3_group_rot_t *gr=get_group_rotation(s.id);
for(i=0;i<s.len+(s.len==1);i++) {
+ //this is causing rotation even when values are 0. this should not be. this is why the tictactoe game has hacks.
s2.p[i]=c3_to_c2(gr?c3_add(gr->p,rotate_c3_yr(s.p[i],gr->p,d2r(gr->r.y))):s.p[i]);
+ //s2.p[i]=c3_to_c2(s.p[i]);
}
if(gra_global.draw3d == 1) {
draw_c2_shape(s2);
@@ -219,7 +221,6 @@ void draw_graph(real (*fun)(real x)) {
}
}
-
void draw_c3_line(c3_t p1,c3_t p2) {
// if(!between_angles(points_to_angle((c2_t){camera.p.x,camera.p.z},(c2_t){p1.x,p1.z}),0,90) ||
// !between_angles(points_to_angle((c2_t){camera.p.x,camera.p.z},(c2_t){p2.x,p2.z}),0,90)) return;
@@ -373,7 +374,7 @@ void draw_screen() {
//XCopyArea(global.dpy,skypixmap,global.backbuffer,global.backgc,((camera.yr*5)+SKYW)%SKYW,0,WIDTH,global.height/2,0,0);
}
if(gra_global.draw3d) {
- draw_c2_line((c2_t){LEFT,0},(c2_t){RIGHT,0}); //horizon
+// draw_c2_line((c2_t){LEFT,0},(c2_t){RIGHT,0}); //horizon
}
if(time(0) == gra_global.oldtime) {
gra_global.fps++;
@@ -385,16 +386,21 @@ void draw_screen() {
}
//XSetForeground(global.dpy, global.backgc, global.green.pixel);
if(global.debug) {//the way I have text done won't scale...
-/* draw_c2_text((cs_t){0,0},global.user);
+// draw_c2_text((cs_t){0,0},global.user);
+// fprintf(stderr,"\x1b[H");
+// fprintf(stderr,"\x1b[2J");
snprintf(tmp,sizeof(tmp)-1,"debug: %s minimap: %d 3d: %d fps: %d shapes: %d",global.debug?"on":"off",gra_global.drawminimap,gra_global.draw3d,gra_global.oldfps,global.shapes);
- draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+10},tmp);
+ fprintf(stderr,"%s\n",tmp);
+// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+10},tmp);
snprintf(tmp,sizeof(tmp)-1,"x: %d y: %d",gra_global.mousex,gra_global.mousey);
- draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+20},tmp);
+ fprintf(stderr,"%s\n",tmp);
+// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+20},tmp);
snprintf(tmp,sizeof(tmp)-1,"cx: %Lf cy: %Lf cz: %Lf",global.camera.p.x,global.camera.p.y,global.camera.p.z);
- draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+30},tmp);
+ fprintf(stderr,"%s\n",tmp);
+// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+30},tmp);
snprintf(tmp,sizeof(tmp)-1,"xr: %d yr: %d zr: %d",global.camera.r.x.d,global.camera.r.y.d,global.camera.r.z.d);
- draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+40},tmp);
-*/
+ fprintf(stderr,"%s\n",tmp);
+// draw_c2_text((cs_t){gra_global.xoff,(gra_global.height/2)+40},tmp);
}
// if(global.drawminimap) {//this isn't even useful I guess.
@@ -413,8 +419,8 @@ void draw_screen() {
qsort(&zs,i,sizeof(zs[0]),(__compar_fn_t)compar);//sort these zs structs based on d.
//draw all triangles
if(global.debug) {
- snprintf(tmp,sizeof(tmp)-1,"selected object: %s",global.selected_object);
- draw_c2_text((c2_t){gra_global.xoff,(gra_global.height/2)+50},tmp);
+ //snprintf(tmp,sizeof(tmp)-1,"selected object: %s",global.selected_object);
+ //draw_c2_text((c2_t){gra_global.xoff,(gra_global.height/2)+50},tmp);
}
//i already equals the length of the array.
i-=gra_global.maxshapes;
diff --git a/src/graphics_cs_x11.c b/src/graphics_cs_x11.c
index 37faeb1..a4c9a88 100644
--- a/src/graphics_cs_x11.c
+++ b/src/graphics_cs_x11.c
@@ -62,7 +62,8 @@ void calculate_shape_color(c3_s_t s,real d) {
*/
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);
+ //XSetForeground(x11_global.dpy,x11_global.backgc,x11_global.colors[i].pixel);
+ XSetForeground(x11_global.dpy,x11_global.backgc,x11_global.colors[99].pixel);
}
void draw_cs_line(cs_t p1,cs_t p2) {
@@ -80,6 +81,12 @@ 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.
+ //test in here whether a mouse click is within this shape's... bounding box? sure.
+ cs_s_t bb;//bounding box
+ int minx=s.p[0].x;
+ int miny=s.p[0].y;
+ int maxx=s.p[0].x;
+ int maxy=s.p[0].y;
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) {
@@ -90,8 +97,32 @@ void draw_cs_shape(cs_s_t s) {//this is implemented as draw_cs_line... hrm. it c
break;
default:
for(i=0;i<s.len+(s.len==1);i++) {//this shape is closed!
+ minx=(s.p[i].x<minx)?s.p[i].x:minx;
+ miny=(s.p[i].y<miny)?s.p[i].y:miny;
+ maxx=(s.p[i].x>maxx)?s.p[i].x:maxx;
+ maxy=(s.p[i].y>maxy)?s.p[i].y:maxy;
draw_cs_line(s.p[i],s.p[(i+1)%(s.len+(s.len==1))]);
}
+ if(gra_global.mousex > minx &&
+ gra_global.mousey > miny &&
+ gra_global.mousex < maxx &&
+ gra_global.mousey < maxy) {
+ if(gra_global.buttonpressed) {//if we're inside the bounding box let's make SOMETHING happen.
+ printf("# clicked on object! %s\n",s.id);
+ }
+ bb.id=strdup("boundingbox");
+ bb.len=4;
+ bb.p[0].x=minx;
+ bb.p[0].y=miny;
+ bb.p[1].x=minx;
+ bb.p[1].y=maxy;
+ bb.p[2].x=maxx;
+ bb.p[2].y=maxy;
+ bb.p[3].x=maxx;
+ bb.p[3].y=miny;
+ draw_cs_filled_shape(bb);
+ free(bb.id);
+ }
break;
}
}
@@ -181,7 +212,7 @@ void x11_keypress_handler(int sym,int x,int y) {
tmprad2=d2r((degrees){global.camera.r.y.d+90});
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_Down:
@@ -189,7 +220,7 @@ void x11_keypress_handler(int sym,int x,int y) {
tmprad2=d2r((degrees){global.camera.r.y.d+270});
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_Left:
@@ -197,7 +228,7 @@ void x11_keypress_handler(int sym,int x,int y) {
tmprad2=d2r(global.camera.r.y);
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_Right:
@@ -205,15 +236,15 @@ void x11_keypress_handler(int sym,int x,int y) {
tmprad2=d2r((degrees){global.camera.r.y.d+180});
tmpx=WALK_SPEED*sinl(tmprad.r);
tmpz=WALK_SPEED*cosl(tmprad2.r);
- snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf 0 0 0 0 0 0\n",global.user,-tmpx,tmpz);
+ snprintf(line,sizeof(line)-1,"%s move %Lf 0 %Lf\n",global.user,-tmpx,tmpz);
selfcommand(line);
break;
case XK_w:
- snprintf(line,sizeof(line)-1,"%s move 0 1 0 0 0 0 0 0 0\n",global.user);
+ snprintf(line,sizeof(line)-1,"%s move 0 1 0\n",global.user);
selfcommand(line);
break;
case XK_s:
- snprintf(line,sizeof(line)-1,"%s move 0 -1 0 0 0 0 0 0 0\n",global.user);
+ snprintf(line,sizeof(line)-1,"%s move 0 -1 0\n",global.user);
selfcommand(line);
break;
case XK_r:
diff --git a/src/hackvr.c b/src/hackvr.c
index d97417a..04fa9a2 100644
--- a/src/hackvr.c
+++ b/src/hackvr.c
@@ -84,6 +84,7 @@ char **line_splitter(char *line,int *rlen) {
int load_stdin() {//what is this returning?
struct c3_shape s;
// struct c3_line l;
+ c3_group_rot_t *gr;
char *command;
char *line;
char *id;
@@ -173,15 +174,16 @@ int load_stdin() {//what is this returning?
continue;
}
if(!strcmp(command,"deletegroup")) {
- for(j=0;global.shape[j];j++) {//mark first. compress later.
- if(!strcmp(global.shape[j]->id,s.id)) {//??? where is s.id supposed to be set from?
- free(global.shape[j]->id);
- free(global.shape[j]);
+ for(j=0;global.shape[j];j++) {
+ if(!strcmp(global.shape[j]->id,a[2])) {
+// free(global.shape[j]->id);
+// free(global.shape[j]);
global.shape[j]=0;
}
}
l=0;
for(k=0;k<j;k++) {
+ l=k;
while(global.shape[l] == 0 && l < j) l++;
global.shape[k]=global.shape[l];
}
@@ -206,6 +208,11 @@ int load_stdin() {//what is this returning?
global.shape[j]->id=strdup(a[3]);
}
}
+ gr=get_group_rotation(a[2]);
+ if(gr) {
+ free(gr->id);
+ gr->id=strdup(a[3]);
+ }
}
continue;
}
diff --git a/src/math.c b/src/math.c
index b5c82de..7c7fff4 100644
--- a/src/math.c
+++ b/src/math.c
@@ -31,13 +31,19 @@ c3_t rotate_c3_zr(c3_t p1,c3_t p2,radians zr) {//rotate x and y around camera ba
return (c3_t){tmp.x,tmp.y,p1.z};
}
+//sin(0) = 0
+//sin(90deg) = 1
+//cos(0) = 1
+//cos(90deg) = 0
c2_t rotate_c2(c2_t p1,c2_t p2,radians dr) {//dr is in radians
c2_t p3;
real d=distance2(p1,p2);
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;
+ p3.x=(sinl(r.r) * d) + p2.x;//switchiing this to cos and the next line to sin seems
+ p3.y=(cosl(r.r) * d) + p2.y;//to make some bug less weird.
+// p3.x=(cosl(r.r) * d) + p2.x;//switchiing this to cos and the next line to sin seems
+// p3.y=(sinl(r.r) * d) + p2.y;//to make some bug less weird.
return p3;
}
real distance2(c2_t p1,c2_t p2) {
diff --git a/tictactoe/board b/tictactoe/board
new file mode 100644
index 0000000..88f20fb
--- /dev/null
+++ b/tictactoe/board
@@ -0,0 +1,11 @@
+topleft addshape 4 0 -3 3 0 -1 3 0 -1 1 0 -3 1
+topcenter addshape 4 0 -1 3 0 1 3 0 1 1 0 -1 1
+topright addshape 4 0 1 3 0 3 3 0 3 1 0 1 1
+
+middleleft addshape 4 0 -3 1 0 -1 1 0 -1 -1 0 -3 -1
+middlecenter addshape 4 0 -1 1 0 1 1 0 1 -1 0 -1 -1
+middleright addshape 4 0 1 1 0 3 1 0 3 -1 0 1 -1
+
+bottomleft addshape 4 0 -3 -1 0 -1 -1 0 -1 -3 0 -3 -3
+bottomcenter addshape 4 0 -1 -1 0 1 -1 0 1 -3 0 -1 -3
+bottomright addshape 4 0 1 -1 0 3 -1 0 3 -3 0 1 -3
diff --git a/tictactoe/marker0 b/tictactoe/marker0
new file mode 100644
index 0000000..613fbb4
--- /dev/null
+++ b/tictactoe/marker0
@@ -0,0 +1,2 @@
+_marker addshape 2 0 .5 .5 0 1.5 1.5
+_marker addshape 2 0 1.5 .5 0 .5 1.5
diff --git a/tictactoe/marker1 b/tictactoe/marker1
new file mode 100644
index 0000000..61a3a22
--- /dev/null
+++ b/tictactoe/marker1
@@ -0,0 +1 @@
+_marker addshape 4 0 1.5 1.5 0 .5 1.5 0 .5 .5 0 1.5 .5
diff --git a/tictactoe/run b/tictactoe/run
new file mode 100755
index 0000000..4e06a75
--- /dev/null
+++ b/tictactoe/run
@@ -0,0 +1,22 @@
+#!/bin/bash
+turn=$( expr $RANDOM % 2)
+echo "go. player: $turn"
+stdbuf -oL cat <(echo "$USER" move 0 -5 0) board p | ../src/hackvr_x11 "$USER" 2>/dev/null \
+ | stdbuf -oL uniq \
+ | grep --line-buffered clicked \
+ | stdbuf -oL cut '-d ' -f5 | while read group;do
+ if grep "_" <<<$group >/dev/null;then
+# xmessage "CUT IT OUT"
+ echo CUT IT OUT > /dev/stderr
+ else
+ turn=$(expr \( $turn + 1 \) % 2)
+ printf "# turn: %d\n" "$turn" > /dev/stderr
+ printf "$USER deletegroup %s\n" "$group"
+#need to get the first point of the group clicked and translate the new shape by that much
+ translatex="$(grep "$group" board | grep -v '^#' | tr -s ' ' | cut '-d ' -f5)"
+ translatey="$(grep "$group" board | grep -v '^#' | tr -s ' ' | cut '-d ' -f6)"
+ cat "marker$turn"
+ printf "%s move 0 %s %s\n" "_marker" "$(expr "$translatex")" "$(expr -1 \* "$translatey" + 2)"
+ printf "%s renamegroup _marker _marker%s%s\n" "$USER" "$(date +%s)" "$RANDOM"
+ fi
+ done > p
diff --git a/tools/line2hackvr.sh b/tools/line2hackvr.sh
index d46d73d..f2ea143 100755
--- a/tools/line2hackvr.sh
+++ b/tools/line2hackvr.sh
@@ -1,3 +1,7 @@
#!/bin/sh
#this is used on turn2line output
-xargs -L 1 printf "dragon addshape 2 0 %d %d 0 %d %d\n" $line
+if [ "_$1" = '_' ];then
+ echo 'usage: line2hackvr.sh name' >&2
+ exit 1
+fi
+xargs -L 1 printf "%s addshape 2 0 %d %d 0 %d %d\n" "$1" $line