From b4dddad64122649d9da6340032275d1756930e74 Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 9 Dec 2016 15:54:33 -0600 Subject: LOTS OF SHIT --- IPs_to_triangle.sh | 2 + cornell_box/cb.dat | 5 + filebrowser/backend-filebrowser.sh | 19 ++ filebrowser/backend-gopher.sh | 14 ++ filebrowser/filebrow.sh | 16 -- filebrowser/frontend-hackvr.sh | 2 + filebrowser/frontend-zenity.sh | 2 + filebrowser/hackvr-frontend.sh | 2 - filebrowser/list_to_cubes.sh | 9 + filebrowser/zenity-frontend.sh | 2 - ma2.dat | 9 + map.dat | 18 ++ map2globe.py | 47 ++++ meshes/monkey.blend | Bin 0 -> 439088 bytes tests/automata | Bin 0 -> 17760 bytes tests/automata.c | 453 ++++++++++++++++++++++++++++++++++++ tests/automata_text | Bin 0 -> 5900 bytes tests/automata_text.c | 34 +++ tests/prog-2 | Bin 0 -> 10820 bytes tests/prog-2.c | 175 ++++++++++++++ tests/readline | Bin 0 -> 5352 bytes tests/readline.c | 20 ++ tests/rotate | Bin 0 -> 17784 bytes tests/rotate.c | 458 ++++++++++++++++++++++++++++++++++++ tests/splitter.c | 53 +++++ tests/test | Bin 0 -> 5140 bytes tests/test.c | 26 +++ tests/triangle | Bin 0 -> 17788 bytes tests/triangle.c | 460 +++++++++++++++++++++++++++++++++++++ tests/ungets.c | 9 + tools/dat2hackvr.pl | 34 +++ tools/obj2hackvr.pl | 17 +- traceroute_hackvr.sh | 2 + traceroute_to_dat.sh | 2 + traceroute_to_triangles.sh | 2 + world_camera | 7 + 36 files changed, 1878 insertions(+), 21 deletions(-) create mode 100755 IPs_to_triangle.sh create mode 100644 cornell_box/cb.dat create mode 100755 filebrowser/backend-filebrowser.sh create mode 100755 filebrowser/backend-gopher.sh delete mode 100755 filebrowser/filebrow.sh create mode 100755 filebrowser/frontend-hackvr.sh create mode 100755 filebrowser/frontend-zenity.sh delete mode 100755 filebrowser/hackvr-frontend.sh delete mode 100755 filebrowser/zenity-frontend.sh create mode 100644 ma2.dat create mode 100644 map.dat create mode 100755 map2globe.py create mode 100644 meshes/monkey.blend create mode 100755 tests/automata create mode 100644 tests/automata.c create mode 100755 tests/automata_text create mode 100644 tests/automata_text.c create mode 100755 tests/prog-2 create mode 100644 tests/prog-2.c create mode 100755 tests/readline create mode 100644 tests/readline.c create mode 100755 tests/rotate create mode 100644 tests/rotate.c create mode 100644 tests/splitter.c create mode 100755 tests/test create mode 100644 tests/test.c create mode 100755 tests/triangle create mode 100644 tests/triangle.c create mode 100644 tests/ungets.c create mode 100755 tools/dat2hackvr.pl create mode 100755 traceroute_hackvr.sh create mode 100755 traceroute_to_dat.sh create mode 100755 traceroute_to_triangles.sh create mode 100644 world_camera diff --git a/IPs_to_triangle.sh b/IPs_to_triangle.sh new file mode 100755 index 0000000..a84e3db --- /dev/null +++ b/IPs_to_triangle.sh @@ -0,0 +1,2 @@ +#!/bin/sh +whob | egrep '^IP|^Lat|^Long' | cut '-d ' -f2- | paste - - - | tr '\t' ' ' | awk '{print $1, $3, $2, 0, $3, $2, 0, $3, $2, 0}' | xargs -L1 printf '%s addtriangle %s %s %s %s %s %s %s %s %s\n' diff --git a/cornell_box/cb.dat b/cornell_box/cb.dat new file mode 100644 index 0000000..33c189d --- /dev/null +++ b/cornell_box/cb.dat @@ -0,0 +1,5 @@ +#floor +552.8 0.0 0.0 + 0.0 0.0 0.0 + 0.0 0.0 559.2 +549.6 0.0 559.2 diff --git a/filebrowser/backend-filebrowser.sh b/filebrowser/backend-filebrowser.sh new file mode 100755 index 0000000..9cbf11a --- /dev/null +++ b/filebrowser/backend-filebrowser.sh @@ -0,0 +1,19 @@ +#!/bin/bash +#give a list of files. +#wait for a selection on stdin +#cd or start that file +#repeat. +while true;do +#not sure why this needs to be printed to show up every time. + echo .. + echo .. + find . -maxdepth 1 #| tr ' ' '\n' #wut? no? + read -r selection + if [ -f "$selection" ];then + xdg-open "$selection" #good enough? + fi + if [ -d "$selection" ];then + cd "$selection" + fi + echo +done diff --git a/filebrowser/backend-gopher.sh b/filebrowser/backend-gopher.sh new file mode 100755 index 0000000..69e1bbe --- /dev/null +++ b/filebrowser/backend-gopher.sh @@ -0,0 +1,14 @@ +#!/bin/bash +#give a list of files. +#wait for a selection on stdin +#cd or start that file +#repeat. +server=192.168.0.2 +port=70 +selection=/ +while true;do +#not sure why this needs to be printed to show up every time. + printf '%s\n' "$selection" | ncat "$server" "$port" + read -r selection + echo +done diff --git a/filebrowser/filebrow.sh b/filebrowser/filebrow.sh deleted file mode 100755 index ef6911a..0000000 --- a/filebrowser/filebrow.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -#give a list of files. -#wait for a selection on stdin -#cd or start that file -#repeat. -while true;do - echo - echo .* * | tr ' ' '\n' - read -r selection - if [ -f "$selection" ];then - xdg-open "$selection" #good enough? - fi - if [ -d "$selection" ];then - cd "$selection" - fi -done diff --git a/filebrowser/frontend-hackvr.sh b/filebrowser/frontend-hackvr.sh new file mode 100755 index 0000000..f04e534 --- /dev/null +++ b/filebrowser/frontend-hackvr.sh @@ -0,0 +1,2 @@ +#!/bin/sh +stdbuf -oL $1 < p | ./list_to_cubes.sh | ../hackvr epoch | ./action_to_target.sh > p diff --git a/filebrowser/frontend-zenity.sh b/filebrowser/frontend-zenity.sh new file mode 100755 index 0000000..acb7cd7 --- /dev/null +++ b/filebrowser/frontend-zenity.sh @@ -0,0 +1,2 @@ +#!/bin/bash +stdbuf -oL $1 < p | stdbuf -oL tr '\n' ' ' | sed -u 's/$/_/' | stdbuf -oL tr '_' '\n' | xargs -L1 zenity --list --column file > p diff --git a/filebrowser/hackvr-frontend.sh b/filebrowser/hackvr-frontend.sh deleted file mode 100755 index 002ba42..0000000 --- a/filebrowser/hackvr-frontend.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -stdbuf -oL ./filebrow.sh < p | ./list_to_cubes.sh | ../hackvr epoch | ./action_to_target.sh > p diff --git a/filebrowser/list_to_cubes.sh b/filebrowser/list_to_cubes.sh index 5de89a6..d4ad688 100755 --- a/filebrowser/list_to_cubes.sh +++ b/filebrowser/list_to_cubes.sh @@ -1,4 +1,13 @@ #!/bin/bash +# blank lines deleteallexcept epoch +# expected input format: +# +# line1 +# line2 +# line3 +# +# line1 +# line2 while read -r line;do if [ "_$line" != '_' ];then # ../tools/obj2hackvr.pl "$line" ../meshes/cube.obj diff --git a/filebrowser/zenity-frontend.sh b/filebrowser/zenity-frontend.sh deleted file mode 100755 index 0ba5efb..0000000 --- a/filebrowser/zenity-frontend.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -cat p | ./filebrow.sh | tr -d '\n' | xargs -L1 zenity --list --column file > p diff --git a/ma2.dat b/ma2.dat new file mode 100644 index 0000000..f771aa3 --- /dev/null +++ b/ma2.dat @@ -0,0 +1,9 @@ +-180.0 1.0 +-135.0 -1.0 +-90.0 1.0 +-45.0 -1.0 +0.0 1.0 +45.0 -1.0 +90.0 1.0 +135.0 -1.0 +180.0 1.0 diff --git a/map.dat b/map.dat new file mode 100644 index 0000000..13b026c --- /dev/null +++ b/map.dat @@ -0,0 +1,18 @@ +1.0 -180.0 +-1.0 -135.0 +1.0 -90.0 +-1.0 -45.0 +1.0 0.0 +-1.0 45.0 +1.0 90.0 +-1.0 135.0 +1.0 180.0 +-180.0 1.0 +-135.0 -1.0 +-90.0 1.0 +-45.0 -1.0 +0.0 1.0 +45.0 -1.0 +90.0 1.0 +135.0 -1.0 +180.0 1.0 diff --git a/map2globe.py b/map2globe.py new file mode 100755 index 0000000..52ab416 --- /dev/null +++ b/map2globe.py @@ -0,0 +1,47 @@ +#!/usr/bin/python3.4 + +import sys +import math + +plat=0 +plon=0 +lat=0 +lon=0 +x="0" +y="0" +z="0" + +#lon goes from -180 to +180 +#lat goes from -90 to +90 +# / 90 * math.pi +#they need to be in the range 0 to 2pi? + +while(1): + #print (plat,plon,lat,lon) + try: + line=input() + line.strip('\r\n') + (lon,lat)=map(float,filter(None,line.split(' '))) + slat=(((lat)/180)*math.pi) + slon=(((lon)/180)*math.pi) + (x,y,z)=map(str,(math.cos(slat)*math.cos(slon), math.sin(slat),math.cos(slat)*math.sin(slon))) +# (x,y,z)=map(str,(slon,slat,0)) + except EOFError: + print("# reached EOF") + break + except ValueError: + #ignore this line + print("# read an invalid line: " + line) + if(line == ""): + (lat,lon,x,y,z)=(0,0,"","","") + except: + e = sys.exc_info()[0] + print("# error: " + str(e)) + break + if(lat and lon and x and y and z and plat and plon and px and py and pz): #if the previouses exist + print("globe addshape 3 " + x + " " + y + " " + z + " " + x + " " + y + " " + z + " " + px + " " + py + " " + pz) + +#set previouses to currents + (plat,plon,px,py,pz)=(lat,lon,x,y,z) + +print("# done") diff --git a/meshes/monkey.blend b/meshes/monkey.blend new file mode 100644 index 0000000..1561c59 Binary files /dev/null and b/meshes/monkey.blend differ diff --git a/tests/automata b/tests/automata new file mode 100755 index 0000000..7cec568 Binary files /dev/null and b/tests/automata differ diff --git a/tests/automata.c b/tests/automata.c new file mode 100644 index 0000000..35629e0 --- /dev/null +++ b/tests/automata.c @@ -0,0 +1,453 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define __USE_GNU //for longer math constants +#include + +//#define DEBUG + +#define SPLIT_SCREEN 2 +#define CAMERA_SEPARATION 3 + +#define DEPTH_FACTOR 0.965 + +#define TRIANGLES 256 + +#define min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) + +//for one camera, not the whole thing. +//3 camera +//#define WIDTH 320 +//#define HEIGHT 240 +//1 camera +//#define WIDTH 800 +//#define HEIGHT 600 +//2 camera +#define WIDTH 400 +#define HEIGHT 300 + +struct object_1 { + int type; + unsigned char x; + unsigned char y; + unsigned char z; +}; + +struct object_2 { + int type; + unsigned short x; + unsigned short y; + unsigned short z; +}; + +struct object_4 { + int type; + unsigned int x; + unsigned int y; + unsigned int z; +}; + +struct camera { + int x; + int y; + int z; + int xr;//rotations + int yr; + int zr; +} camera; + +struct triangle {//use array or linked list? + char *id; + int x1; + int y1; + int z1; + int x2; + int y2; + int z2; + int x3; + int y3; + int z3; +// int dist;//most recent distance calculated from the camera +}; + +struct mainwin { + int x; + int y; + int depth; + int mousex; + int mousey; + int rmousex; + int rmousey; + int buttonpressed; + int width; + int height; + int border_width; + int xoff; + int math_error; + char *user; + XColor green; + Colormap color_map; + Display *dpy; + Window w; + GC gc; + struct triangle *triangle[TRIANGLES]; +} global; + + +float zmagic(int z) { + float tmp=pow(DEPTH_FACTOR,(camera.z-z)); +// float tmp=pow(DEPTH_FACTOR,(camera.z-z))/(camera.z-z); +// float tmp=pow(DEPTH_FACTOR,(camera.z-z)*(camera.z-z)*(camera.z-z)); + //measure the distance form the camera and error out if it is too far away. +// if((camera.z - z) >= 0) return(global.math_error=1); + //return (float)1 / (float)(camera.z - z); + return tmp; +} + +int to2D(int cw,int w,int z,int d) { + return (d/2) - (((w-cw) / zmagic(z)) * 16 ); +} + + +float distance(int x1,int y1,int x2,int y2) { + return sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); +} + +long double d2r(int d) { + while(d<0) d+=360; + return (long double)(d%360) / 180.0l * M_PIl; +} + +int rotateXabout(int x1,int y1,int z1,int x2,int y2,int z2,int degrees) { + long double radians=(long double)degrees / (long double)180 * M_PIl;//M_PIl for long double + long double radius=distance(x1,z1,x2,z2); + if(radius == 0) return x2; + return x2 + radius * cosl(acosl(((long double)x2-(long double)x1)/radius)+radians); +} + +int rotateZabout(int x1,int y1,int z1,int x2,int y2,int z2,int degrees) { + long double radians=(long double)degrees / (long double)180 * M_PIl;//M_PIl for long double + long double radius=distance(x1,z1,x2,z2); + if(radius == 0) return z2; + return z2 + radius * sinl(asinl(((long double)z2-(long double)z1)/radius)+radians); +} + + +int to2Dx(int x,int y,int z) { + int newx=rotateXabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newy=y;//rotateYabout(x,y,z,camera.x,camera.y,camera.z,camera.xr); + int newz=rotateZabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + return to2D(camera.x,newx,newz,global.width/SPLIT_SCREEN); +// return to2D(camera.x,x,z,global.width/SPLIT_SCREEN); +} + +int to2Dy(int x,int y,int z) { + int newx=rotateXabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newy=y;//rotateYabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newz=rotateZabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + return to2D(camera.y,newy,newz,global.height); +// return to2D(camera.y,y,z,global.height); +} + +void XDrawTriangle(int x1,int y1,int x2,int y2,int x3,int y3) { + int x; + XDrawLine(global.dpy,global.w,global.gc,x1,y1,x2,y2); + XDrawLine(global.dpy,global.w,global.gc,x2,y2,x3,y3); + XDrawLine(global.dpy,global.w,global.gc,x3,y3,x1,y1); +} + +void XDrawFilledTriangle(int x1,int y1,int x2,int y2,int x3,int y3,int density) { + int x,y; + int b; + float m; + + XDrawLine(global.dpy,global.w,global.gc,x1,y1,x2,y2); + XDrawLine(global.dpy,global.w,global.gc,x2,y2,x3,y3); + XDrawLine(global.dpy,global.w,global.gc,x3,y3,x1,y1); + + m=(float)(y1-y2)/(float)(x1-x2); + b=y1-(m*x1); + for(x=min(x1,x2);xx1=x1; +//} +//void pushSquare() { +// pushTriangle(); +// pushTriangle(); +//} + +void drawCube(int x,int y,int z,int i) { +//this is just drawing the cube. + draw3Dline(x,y,z,x,y,z+i); + draw3Dline(x,y,z,x,y+i,z); + draw3Dline(x,y,z,x+i,y,z); + + draw3Dline(x+i,y+i,z+0,x+i,y+0,z+0); + draw3Dline(x+i,y+i,z+0,x+0,y+i,z+0); + + draw3Dline(x+0,y+i,z+i,x+0,y+i,z+0); + draw3Dline(x+0,y+i,z+i,x+0,y+0,z+i); + + draw3Dline(x+i,y+0,z+i,x+i,y+0,z+0); + draw3Dline(x+i,y+0,z+i,x+0,y+0,z+i); + + draw3Dline(x+i,y+i,z+i,x+i,y+i,z+0); + draw3Dline(x+i,y+i,z+i,x+i,y+0,z+i); + draw3Dline(x+i,y+i,z+i,x+0,y+i,z+i); +} + +int applyrule(int a,int b,int c,int rule) { + return (rule >> ((!!a<<2) | (!!b<<1) | (!!c)) ) % 2; +} + +char field[HEIGHT+1][WIDTH+1]; + +void draw_screen(Display *dpy,Window w,GC gc) { + int i,j,k; + int cn=0;//camera number. + char **files; + static int offset=0; + XFontStruct *font=XLoadQueryFont(dpy,"fixed"); + XCharStruct overall; + int direction,ascent,descent; + char coords[256]; + int x,y,z,x1,y1,x2,y2; + XEvent e; + XClearWindow(dpy, w); + + j=0; + for(i=0;i 0) { + /*if(!strcmp(command,"addsquare")) { } */ + if(!strcmp(command,"addtriangle")) { + global.triangle[i]=malloc(sizeof(struct triangle)); + to=global.triangle[i]; + memcpy(to,&t,sizeof(t)); + } + if(!strcmp(command,"move")) { + for(i=0;global.triangle[i];i++) { + if(!strcmp(global.triangle[i]->id,t.id)) { + global.triangle[i]->x1+=t.x1; + global.triangle[i]->y1+=t.y1; + global.triangle[i]->z1+=t.z1; + + global.triangle[i]->x2+=t.x1; + global.triangle[i]->y2+=t.y1; + global.triangle[i]->z2+=t.z1; + + global.triangle[i]->x3+=t.x1; + global.triangle[i]->y3+=t.y1; + global.triangle[i]->z3+=t.z1; + } + } + } + global.triangle[i+1]=0; + draw_screen(global.dpy,global.w,global.gc); + } else { + global.triangle[i]=0; + break; + } + } +} + +int export_file(FILE *fp) { + struct triangle *to; + int i; + for(i=0;global.triangle[i];i++) { + to=global.triangle[i]; + printf("%s addtriangle %d %d %d %d %d %d %d %d %d\n",to->id,to->x1,to->y1,to->z1,to->x2,to->y2,to->z2,to->x3,to->y3,to->z3); + } +} + + +int main(int argc,char *argv[]) { + char redraw=0; + if(argc < 2) { + fprintf(stderr,"usage: hackvr yourname < from_others > to_others\n"); + return 1; + } else { + global.user=strdup(argv[1]); + } + setbuf(stdin,0); + setbuf(stdout,0); + Display *dpy = XOpenDisplay(0); + assert(dpy); + global.dpy=dpy; + unsigned int mask; + int i; + XEvent e; + XSetWindowAttributes attributes; + int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); + int whiteColor = //WhitePixel(dpy, DefaultScreen(dpy)); + attributes.background_pixel=blackColor; + Window w = XCreateWindow(dpy,DefaultRootWindow(dpy),0,0,WIDTH*SPLIT_SCREEN,HEIGHT,1,DefaultDepth(dpy,DefaultScreen(dpy)),InputOutput,DefaultVisual(dpy,DefaultScreen(dpy))\ + ,CWBackPixel, &attributes); + global.w=w; + global.triangle[0]=0;//we'll allocate as we need more. + + int j; + + for(i=0;i +#include + +#define HE he +#define WI wi +#define RULE rule + + +int main(int argc,char *argv[]) { + int i,j; + int rule=atoi(argv[1]); + char str[256];//lel. close enough. + int wi=read(0,str,sizeof(str)-1)*8; + int he=atoi(argv[2]); + char f[HE+1][WI+1]; + f[0][WI/2]=1; + for(i=0;i>(j%8))%2; + else f[i][j]=(RULE >> ((!!f[(i+HE-1)%HE][(j+WI-1)%WI]<<2) | (!!f[(i+HE-1)%HE][j]<<1) | (!!f[(i+HE-1)%HE][(j+1)%WI])) & 1); + } + } + for(i=0;i +#include +#include +#include +#include +#include +#include + +struct mainwin { + int x; + int y; + int depth; + int mousex; + int mousey; + int rmousex; + int rmousey; + int buttonpressed; + int width; + int height; + int border_width; + XColor green; + Colormap color_map; +} global; + +int mycmp(const void *a,const void *b) { +// printf("comparing '%s' and '%s'\n",*(char **)a,*(char **)b); + return strcmp(*(char **)a,*(char **)b); +} + +char **ls(char *dir) { + DIR *fd; + char **files=malloc(sizeof(char *) * 1000); + struct dirent *d; + int i; + fd = opendir("."); + if (fd) { + for (i=0;(d = readdir(fd)) != NULL;i++) { + files[i]=strdup(d->d_name); + } + files[i]=0; + closedir(fd); + } + //now to sort files in numerical order. +// void qsort(void *base, size_t nmemb, size_t size, +// int (*compar)(const void *, const void *)); + qsort(files,i,sizeof(char *),mycmp); + return files; +} + +void freels(char **files) { + int i; + for(i=0;files[i];i++) { + free(files[i]); + } + free(files); +} + +void draw_screen(Display *dpy,Window w,GC gc) { + int i; + char **files; + static int offset=0; + XFontStruct *font=XLoadQueryFont(dpy,"fixed"); + XCharStruct overall; + int direction,ascent,descent; + char coords[256]; + int x,y; + XEvent e; + XClearWindow(dpy, w); + snprintf(coords,sizeof(coords)-1,"x: %d y: %d",global.mousex,global.mousey); + files=ls("."); + for(i=0;files[i];i++) { + XTextExtents(font,files[i],strlen(files[i]),&direction,&ascent,&descent,&overall); + x=30; + y=((ascent+descent)*(i+3))+offset; + XDrawString(dpy,w,gc,x,y,files[i],strlen(files[i])); + if(global.mousex > x && global.mousex < x+overall.width && global.mousey > y-ascent && global.mousey < y+descent) { + if(global.buttonpressed) { + if(chdir(files[i])) if(!fork()) execlp("xdg-open","xdg-open",files[i],0); + else offset=0; + } + //top line + XDrawLine(dpy,w,gc,0,y-ascent,x+overall.width,y-ascent); + //bottom line + XDrawLine(dpy,w,gc,x,y+descent,global.width,y+descent); + //left line + XDrawLine(dpy,w,gc,x,y-ascent,x,y+descent); + //right line + XDrawLine(dpy,w,gc,x+overall.width,y-ascent,x+overall.width,y+descent); + } + } + // || + // \||/ + // \/ + x=4; + y=global.height-16; + + XDrawLine(dpy,w,gc,x+4+1,y+0+1,x+4+1,y+8+1); + XDrawLine(dpy,w,gc,x+0+1,y+4+1,x+4+1,y+8+1); + XDrawLine(dpy,w,gc,x+8+1,y+4+1,x+4+1,y+8+1); + + if(global.mousex > x && global.mousex < x+10 && global.mousey > y && global.mousey < y+10) { + if(global.buttonpressed) { + offset-=40; + } + XDrawLine(dpy,w,gc,x,y,x+10,y); + XDrawLine(dpy,w,gc,x,y+10,x+10,y+10); + XDrawLine(dpy,w,gc,x,y,x,y+10); + XDrawLine(dpy,w,gc,x+10,y,x+10,y+10); + } + // /\ + // /||\ + // || + x=4; + y=16; + + XDrawLine(dpy,w,gc,x+4+1,y+0+1,x+4+1,y+8+1); + XDrawLine(dpy,w,gc,x+0+1,y+4+1,x+4+1,y+0+1); + XDrawLine(dpy,w,gc,x+8+1,y+4+1,x+4+1,y+0+1); + + if(global.mousex > x && global.mousex < x+10 && global.mousey > y && global.mousey < y+10) { + if(global.buttonpressed) { + offset+=40; + } + XDrawLine(dpy,w,gc,x,y,x+10,y); + XDrawLine(dpy,w,gc,x,y+10,x+10,y+10); + XDrawLine(dpy,w,gc,x,y,x,y+10); + XDrawLine(dpy,w,gc,x+10,y,x+10,y+10); + } + + XDrawString(dpy,w,gc,0,0+ascent,coords,strlen(coords)); + XFlush(dpy); +} + +int main(int argc,char *argv[]) +{ + Display *dpy = XOpenDisplay(0); + assert(dpy); + unsigned int mask; + XEvent e; + XSetWindowAttributes attributes; + int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); + int whiteColor = //WhitePixel(dpy, DefaultScreen(dpy)); + attributes.background_pixel=blackColor; + Window w = XCreateWindow(dpy,DefaultRootWindow(dpy),0,0,500,400,1,DefaultDepth(dpy,DefaultScreen(dpy)),InputOutput,DefaultVisual(dpy,DefaultScreen(dpy))\ + ,CWBackPixel, &attributes); + Window root,child; + XSelectInput(dpy, w, PointerMotionMask|StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|ResizeRedirectMask); + XMapWindow(dpy, w); + XStoreName(dpy,w,"hackhackhack"); + GC gc = XCreateGC(dpy, w, 0, 0); + global.color_map=DefaultColormap(dpy, DefaultScreen(dpy)); + XAllocNamedColor(dpy, global.color_map, "green", &global.green, &global.green); + XSetForeground(dpy, gc, global.green.pixel); +// XSetForeground(dpy, gc, whiteColor); + for(;;) { + draw_screen(dpy,w,gc); + XNextEvent(dpy, &e); + switch(e.type) { + case MotionNotify: + XQueryPointer(dpy,w,&root,&child,&global.rmousex,&global.rmousey,&global.mousex,&global.mousey,&mask); + break; + case ButtonPress: + global.buttonpressed=e.xbutton.button; + break; + case ButtonRelease: + global.buttonpressed=0; + break; + case ResizeRequest: + XGetGeometry(dpy,w,&root,&global.x,&global.y,&global.width,&global.height,&global.border_width,&global.depth); + default: + break; + } + } + return 0; +} diff --git a/tests/readline b/tests/readline new file mode 100755 index 0000000..f45ea8c Binary files /dev/null and b/tests/readline differ diff --git a/tests/readline.c b/tests/readline.c new file mode 100644 index 0000000..76d6a2d --- /dev/null +++ b/tests/readline.c @@ -0,0 +1,20 @@ +#include +#include + +char *read_line_hack(FILE *fp,int len) { + short in; + char *t; + if((in=fgetc(fp)) == '\n') { + t=malloc(len+1); + t[len]=0; + return t; + } + t=read_line_hack(fp,len+1); + t[len]=in; + return t; +} + +int main() { + char *t=read_line_hack(stdin,0); + printf("%s\n",t); +} diff --git a/tests/rotate b/tests/rotate new file mode 100755 index 0000000..9266b2b Binary files /dev/null and b/tests/rotate differ diff --git a/tests/rotate.c b/tests/rotate.c new file mode 100644 index 0000000..7f7b9bc --- /dev/null +++ b/tests/rotate.c @@ -0,0 +1,458 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define __USE_GNU //for longer math constants +#include + +//#define DEBUG + +#define SPLIT_SCREEN 2 +#define CAMERA_SEPARATION 3 + +#define DEPTH_FACTOR 0.965 + +#define TRIANGLES 256 + +#define min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) + +//for one camera, not the whole thing. +//3 camera +//#define WIDTH 320 +//#define HEIGHT 240 +//1 camera +//#define WIDTH 800 +//#define HEIGHT 600 +//2 camera +#define WIDTH 400 +#define HEIGHT 300 + +struct object_1 { + int type; + unsigned char x; + unsigned char y; + unsigned char z; +}; + +struct object_2 { + int type; + unsigned short x; + unsigned short y; + unsigned short z; +}; + +struct object_4 { + int type; + unsigned int x; + unsigned int y; + unsigned int z; +}; + +struct camera { + int x; + int y; + int z; + int xr;//rotations + int yr; + int zr; +} camera; + +struct triangle {//use array or linked list? + char *id; + int x1; + int y1; + int z1; + int x2; + int y2; + int z2; + int x3; + int y3; + int z3; +// int dist;//most recent distance calculated from the camera +}; + +struct mainwin { + int x; + int y; + int depth; + int mousex; + int mousey; + int rmousex; + int rmousey; + int buttonpressed; + int width; + int height; + int border_width; + int xoff; + int math_error; + char *user; + XColor green; + Colormap color_map; + Display *dpy; + Window w; + GC gc; + struct triangle *triangle[TRIANGLES]; +} global; + + +float zmagic(int z) { + float tmp=pow(DEPTH_FACTOR,(camera.z-z)); +// float tmp=pow(DEPTH_FACTOR,(camera.z-z))/(camera.z-z); +// float tmp=pow(DEPTH_FACTOR,(camera.z-z)*(camera.z-z)*(camera.z-z)); + //measure the distance form the camera and error out if it is too far away. +// if((camera.z - z) >= 0) return(global.math_error=1); + //return (float)1 / (float)(camera.z - z); + return tmp; +} + +int to2D(int cw,int w,int z,int d) { + return (d/2) - (((w-cw) / zmagic(z)) * 16 ); +} + + +float distance(int x1,int y1,int x2,int y2) { + return sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); +} + +long double d2r(int d) { + while(d<0) d+=360; + return (long double)(d%360) / 180.0l * M_PIl; +} + +int rotateXabout(int x1,int y1,int z1,int x2,int y2,int z2,int degrees) { + long double radians=(long double)degrees / (long double)180 * M_PIl;//M_PIl for long double + long double radius=distance(x1,z1,x2,z2); + if(radius == 0) return x2; + return x2 + radius * cosl(acosl(((long double)x2-(long double)x1)/radius)+radians); +} + +int rotateZabout(int x1,int y1,int z1,int x2,int y2,int z2,int degrees) { + long double radians=(long double)degrees / (long double)180 * M_PIl;//M_PIl for long double + long double radius=distance(x1,z1,x2,z2); + if(radius == 0) return z2; + return z2 + radius * sinl(asinl(((long double)z2-(long double)z1)/radius)+radians); +} + + +int to2Dx(int x,int y,int z) { + int newx=rotateXabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newy=y;//rotateYabout(x,y,z,camera.x,camera.y,camera.z,camera.xr); + int newz=rotateZabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + return to2D(camera.x,newx,newz,global.width/SPLIT_SCREEN); +// return to2D(camera.x,x,z,global.width/SPLIT_SCREEN); +} + +int to2Dy(int x,int y,int z) { + int newx=rotateXabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newy=y;//rotateYabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newz=rotateZabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + return to2D(camera.y,newy,newz,global.height); +// return to2D(camera.y,y,z,global.height); +} + +void XDrawTriangle(int x1,int y1,int x2,int y2,int x3,int y3) { + int x; + XDrawLine(global.dpy,global.w,global.gc,x1,y1,x2,y2); + XDrawLine(global.dpy,global.w,global.gc,x2,y2,x3,y3); + XDrawLine(global.dpy,global.w,global.gc,x3,y3,x1,y1); +} + +void XDrawFilledTriangle(int x1,int y1,int x2,int y2,int x3,int y3) { + int x,y; + int b; + float m; + + XDrawLine(global.dpy,global.w,global.gc,x1,y1,x2,y2); + XDrawLine(global.dpy,global.w,global.gc,x2,y2,x3,y3); + XDrawLine(global.dpy,global.w,global.gc,x3,y3,x1,y1); + + m=(float)(y1-y2)/(float)(x1-x2); + b=y1-(m*x1); + for(x=min(x1,x2);xx1=x1; +//} +//void pushSquare() { +// pushTriangle(); +// pushTriangle(); +//} + +void drawCube(int x,int y,int z,int i) { +//this is just drawing the cube. + draw3Dline(x,y,z,x,y,z+i); + draw3Dline(x,y,z,x,y+i,z); + draw3Dline(x,y,z,x+i,y,z); + + draw3Dline(x+i,y+i,z+0,x+i,y+0,z+0); + draw3Dline(x+i,y+i,z+0,x+0,y+i,z+0); + + draw3Dline(x+0,y+i,z+i,x+0,y+i,z+0); + draw3Dline(x+0,y+i,z+i,x+0,y+0,z+i); + + draw3Dline(x+i,y+0,z+i,x+i,y+0,z+0); + draw3Dline(x+i,y+0,z+i,x+0,y+0,z+i); + + draw3Dline(x+i,y+i,z+i,x+i,y+i,z+0); + draw3Dline(x+i,y+i,z+i,x+i,y+0,z+i); + draw3Dline(x+i,y+i,z+i,x+0,y+i,z+i); +} + +void draw_screen(Display *dpy,Window w,GC gc) { + int i,j,k; + int cn=0;//camera number. + char **files; + static int offset=0; + XFontStruct *font=XLoadQueryFont(dpy,"fixed"); + XCharStruct overall; + int direction,ascent,descent; + char coords[256]; + int x,y,z,x1,y1,x2,y2; + XEvent e; + XClearWindow(dpy, w); + + //struct triangle **triangle; + //for(i=0;global.triangle[i];i++); + //triangle=malloc(sizeof(struct triangle *) * i); + //for(i=0;global.triangle[i];i++) { + // triangle[i]=malloc(sizeof(struct triangle)); + // memcpy(triangle[i],global.triangle[i],sizeof(triangle)); + //} + //triangle[i]=0; + + XDrawLine(dpy,w,gc,global.xoff,global.height/2,global.xoff+WIDTH,global.height/2); + snprintf(coords,sizeof(coords)-1,"x: %d y: %d",global.mousex,global.mousey); + XTextExtents(font,coords,strlen(coords),&direction,&ascent,&descent,&overall); + XDrawString(dpy,w,gc,global.xoff,0+ascent,coords,strlen(coords)); + snprintf(coords,sizeof(coords)-1,"cx: %d cy: %d cz: %d",camera.x,camera.y,camera.z); + XTextExtents(font,coords,strlen(coords),&direction,&ascent,&descent,&overall); + XDrawString(dpy,w,gc,global.xoff,(descent+0+ascent)*2,coords,strlen(coords)); + + snprintf(coords,sizeof(coords)-1,"xr: %d yr: %d zr: %d",camera.xr,camera.yr,camera.zr); + XTextExtents(font,coords,strlen(coords),&direction,&ascent,&descent,&overall); + XDrawString(dpy,w,gc,global.xoff,(descent+0+ascent)*3,coords,strlen(coords)); + + j=0; + for(i=camera.yr;i 0) { + /*if(!strcmp(command,"addsquare")) { } */ + if(!strcmp(command,"addtriangle")) { + global.triangle[i]=malloc(sizeof(struct triangle)); + to=global.triangle[i]; + memcpy(to,&t,sizeof(t)); + } + if(!strcmp(command,"move")) { + for(i=0;global.triangle[i];i++) { + if(!strcmp(global.triangle[i]->id,t.id)) { + global.triangle[i]->x1+=t.x1; + global.triangle[i]->y1+=t.y1; + global.triangle[i]->z1+=t.z1; + + global.triangle[i]->x2+=t.x1; + global.triangle[i]->y2+=t.y1; + global.triangle[i]->z2+=t.z1; + + global.triangle[i]->x3+=t.x1; + global.triangle[i]->y3+=t.y1; + global.triangle[i]->z3+=t.z1; + } + } + } + global.triangle[i+1]=0; + draw_screen(global.dpy,global.w,global.gc); + } else { + global.triangle[i]=0; + break; + } + } +} + +int export_file(FILE *fp) { + struct triangle *to; + int i; + for(i=0;global.triangle[i];i++) { + to=global.triangle[i]; + printf("%s addtriangle %d %d %d %d %d %d %d %d %d\n",to->id,to->x1,to->y1,to->z1,to->x2,to->y2,to->z2,to->x3,to->y3,to->z3); + } +} + + +int main(int argc,char *argv[]) { + char redraw=0; + if(argc < 2) { + fprintf(stderr,"usage: hackvr yourname < from_others > to_others\n"); + return 1; + } else { + global.user=strdup(argv[1]); + } + setbuf(stdin,0); + setbuf(stdout,0); + Display *dpy = XOpenDisplay(0); + assert(dpy); + global.dpy=dpy; + unsigned int mask; + int i; + XEvent e; + XSetWindowAttributes attributes; + int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); + int whiteColor = //WhitePixel(dpy, DefaultScreen(dpy)); + attributes.background_pixel=blackColor; + Window w = XCreateWindow(dpy,DefaultRootWindow(dpy),0,0,WIDTH*SPLIT_SCREEN,HEIGHT,1,DefaultDepth(dpy,DefaultScreen(dpy)),InputOutput,DefaultVisual(dpy,DefaultScreen(dpy))\ + ,CWBackPixel, &attributes); + global.w=w; + global.triangle[0]=0;//we'll allocate as we need more. + Window root,child; + XSelectInput(dpy, w, PointerMotionMask|StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|ResizeRedirectMask|KeyPressMask); + XMapWindow(dpy, w); + XStoreName(dpy,w,"hackvr"); + GC gc = XCreateGC(dpy, w, 0, 0); + global.gc=gc; + global.color_map=DefaultColormap(dpy, DefaultScreen(dpy)); + XAllocNamedColor(dpy, global.color_map, "green", &global.green, &global.green); + XSetForeground(dpy, gc, global.green.pixel); +// XSetForeground(dpy, gc, whiteColor); + for(;;) { + load_file(stdin); + XNextEvent(dpy, &e); + redraw=1; + switch(e.type) { + case MotionNotify: + XQueryPointer(dpy,w,&root,&child,&global.rmousex,&global.rmousey,&global.mousex,&global.mousey,&mask); + break; + case ButtonPress: + global.buttonpressed=e.xbutton.button; + break; + case ButtonRelease: + global.buttonpressed=0; + break; + case ResizeRequest: + XGetGeometry(dpy,w,&root,&global.x,&global.y,&global.width,&global.height,&global.border_width,&global.depth); + case KeyPress: + switch(XLookupKeysym(&e.xkey,0)) { + case XK_Up: + //fix these to use calculated values down there. + //printf("%s move 0 0 1 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr)); + camera.x+=5*sinl(d2r(camera.yr)); break; + case XK_Down: + //printf("%s move 0 0 -1 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr+180)); + camera.x+=5*sinl(d2r(camera.yr+180)); break; + case XK_Left: + //printf("%s move 1 0 0 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr+90)); + camera.x+=5*sinl(d2r(camera.yr+90)); break; + case XK_Right: + //printf("%s move -1 0 0 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr+270)); + camera.x+=5*sinl(d2r(camera.yr+270)); break; + case XK_w: + //printf("%s move 0 1 0 0 0 0 0 0 0\n",global.user); + camera.y+=5; break; + case XK_s: + //printf("%s move 0 -1 0 0 0 0 0 0 0\n",global.user); + camera.y-=5; break; + case XK_q: + camera.yr+=5; break; + case XK_e: + camera.yr-=5; break; + case XK_Escape: return 0; + default: + redraw=0; + break; + } + default: + redraw=0; + break; + } + //if(redraw) + draw_screen(dpy,w,gc); + } + return 0; +} diff --git a/tests/splitter.c b/tests/splitter.c new file mode 100644 index 0000000..25292f6 --- /dev/null +++ b/tests/splitter.c @@ -0,0 +1,53 @@ +char **line_splitter(char *line,int *rlen) { + char **a; + int i=0,j=0; + int len; + len=1; + for(i=0;line[i] && line[i] == ' ';i++);//skip leading space + for(;line[i];) { + for(;line[i] && line[i] != ' ';i++);//skip rest of data + for(;line[i] && line[i] == ' ';i++);//skip rest of space + len++; + } + a=malloc(sizeof(char *) * len+1); + a[len]=0; + len=0;//reuse! + for(i=0;line[i] && line[i] == ' ';i++);//skip leading space + a[len]=line+i; + for(;;) { + for(;line[i] && line[i] != ' ';i++);//skip rest of data + if(line[i]) { + line[i]=0; + i++; + } else { + //we're at the end! I guess return this shit. + len++; + a[len]=0; + *rlen=len; + return a; + } + for(;line[i] && line[i] == ' ';i++);//skip rest of space + if(line[i]) { + len++; + a[len]=line+i; + } else { + len++; + a[len]=0; + *rlen=len; + return a; + } + } + *rlen=len; + return a; +} + +int main(int argc,char *argv[]) { + char **a; + int len; + int i; + a=line_splitter(strdup(argv[1]),&len); + for(i=0;i + +typedef double long c3_t; +typedef double long c2_t; +typedef struct { + int x; + int y; +} cs_t; + +cs_t derp() { + return (cs_t){2,3}; +} + +int main(int argc,char *argv[]) { + cs_t cs=derp(); + printf("%d,%d\n",cs.x,cs.y); + switch(1) { + case 1: + printf("first\n"); + break; + default: + printf("third.\n"); + break; + } + return 0; +} diff --git a/tests/triangle b/tests/triangle new file mode 100755 index 0000000..beb83ca Binary files /dev/null and b/tests/triangle differ diff --git a/tests/triangle.c b/tests/triangle.c new file mode 100644 index 0000000..e503cce --- /dev/null +++ b/tests/triangle.c @@ -0,0 +1,460 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define __USE_GNU //for longer math constants +#include + +//#define DEBUG + +#define SPLIT_SCREEN 2 +#define CAMERA_SEPARATION 3 + +#define DEPTH_FACTOR 0.965 + +#define TRIANGLES 256 + +#define min(a,b) (((a)<(b))?(a):(b)) +#define max(a,b) (((a)>(b))?(a):(b)) + +//for one camera, not the whole thing. +//3 camera +//#define WIDTH 320 +//#define HEIGHT 240 +//1 camera +//#define WIDTH 800 +//#define HEIGHT 600 +//2 camera +#define WIDTH 400 +#define HEIGHT 300 + +struct object_1 { + int type; + unsigned char x; + unsigned char y; + unsigned char z; +}; + +struct object_2 { + int type; + unsigned short x; + unsigned short y; + unsigned short z; +}; + +struct object_4 { + int type; + unsigned int x; + unsigned int y; + unsigned int z; +}; + +struct camera { + int x; + int y; + int z; + int xr;//rotations + int yr; + int zr; +} camera; + +struct triangle {//use array or linked list? + char *id; + int x1; + int y1; + int z1; + int x2; + int y2; + int z2; + int x3; + int y3; + int z3; +// int dist;//most recent distance calculated from the camera +}; + +struct mainwin { + int x; + int y; + int depth; + int mousex; + int mousey; + int rmousex; + int rmousey; + int buttonpressed; + int width; + int height; + int border_width; + int xoff; + int math_error; + char *user; + XColor green; + Colormap color_map; + Display *dpy; + Window w; + GC gc; + struct triangle *triangle[TRIANGLES]; +} global; + + +float zmagic(int z) { + float tmp=pow(DEPTH_FACTOR,(camera.z-z)); +// float tmp=pow(DEPTH_FACTOR,(camera.z-z))/(camera.z-z); +// float tmp=pow(DEPTH_FACTOR,(camera.z-z)*(camera.z-z)*(camera.z-z)); + //measure the distance form the camera and error out if it is too far away. +// if((camera.z - z) >= 0) return(global.math_error=1); + //return (float)1 / (float)(camera.z - z); + return tmp; +} + +int to2D(int cw,int w,int z,int d) { + return (d/2) - (((w-cw) / zmagic(z)) * 16 ); +} + + +float distance(int x1,int y1,int x2,int y2) { + return sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); +} + +long double d2r(int d) { + while(d<0) d+=360; + return (long double)(d%360) / 180.0l * M_PIl; +} + +int rotateXabout(int x1,int y1,int z1,int x2,int y2,int z2,int degrees) { + long double radians=(long double)degrees / (long double)180 * M_PIl;//M_PIl for long double + long double radius=distance(x1,z1,x2,z2); + if(radius == 0) return x2; + return x2 + radius * cosl(acosl(((long double)x2-(long double)x1)/radius)+radians); +} + +int rotateZabout(int x1,int y1,int z1,int x2,int y2,int z2,int degrees) { + long double radians=(long double)degrees / (long double)180 * M_PIl;//M_PIl for long double + long double radius=distance(x1,z1,x2,z2); + if(radius == 0) return z2; + return z2 + radius * sinl(asinl(((long double)z2-(long double)z1)/radius)+radians); +} + + +int to2Dx(int x,int y,int z) { + int newx=rotateXabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newy=y;//rotateYabout(x,y,z,camera.x,camera.y,camera.z,camera.xr); + int newz=rotateZabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + return to2D(camera.x,newx,newz,global.width/SPLIT_SCREEN); +// return to2D(camera.x,x,z,global.width/SPLIT_SCREEN); +} + +int to2Dy(int x,int y,int z) { + int newx=rotateXabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newy=y;//rotateYabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + int newz=rotateZabout(x,y,z,camera.x,camera.y,camera.z,camera.yr); + return to2D(camera.y,newy,newz,global.height); +// return to2D(camera.y,y,z,global.height); +} + +void XDrawTriangle(int x1,int y1,int x2,int y2,int x3,int y3) { + int x; + XDrawLine(global.dpy,global.w,global.gc,x1,y1,x2,y2); + XDrawLine(global.dpy,global.w,global.gc,x2,y2,x3,y3); + XDrawLine(global.dpy,global.w,global.gc,x3,y3,x1,y1); +} + +void XDrawFilledTriangle(int x1,int y1,int x2,int y2,int x3,int y3,int density) { + int x,y; + int b; + float m; + + XDrawLine(global.dpy,global.w,global.gc,x1,y1,x2,y2); + XDrawLine(global.dpy,global.w,global.gc,x2,y2,x3,y3); + XDrawLine(global.dpy,global.w,global.gc,x3,y3,x1,y1); + + m=(float)(y1-y2)/(float)(x1-x2); + b=y1-(m*x1); + for(x=min(x1,x2);xx1=x1; +//} +//void pushSquare() { +// pushTriangle(); +// pushTriangle(); +//} + +void drawCube(int x,int y,int z,int i) { +//this is just drawing the cube. + draw3Dline(x,y,z,x,y,z+i); + draw3Dline(x,y,z,x,y+i,z); + draw3Dline(x,y,z,x+i,y,z); + + draw3Dline(x+i,y+i,z+0,x+i,y+0,z+0); + draw3Dline(x+i,y+i,z+0,x+0,y+i,z+0); + + draw3Dline(x+0,y+i,z+i,x+0,y+i,z+0); + draw3Dline(x+0,y+i,z+i,x+0,y+0,z+i); + + draw3Dline(x+i,y+0,z+i,x+i,y+0,z+0); + draw3Dline(x+i,y+0,z+i,x+0,y+0,z+i); + + draw3Dline(x+i,y+i,z+i,x+i,y+i,z+0); + draw3Dline(x+i,y+i,z+i,x+i,y+0,z+i); + draw3Dline(x+i,y+i,z+i,x+0,y+i,z+i); +} + +void draw_screen(Display *dpy,Window w,GC gc) { + int i,j,k; + int cn=0;//camera number. + char **files; + static int offset=0; + XFontStruct *font=XLoadQueryFont(dpy,"fixed"); + XCharStruct overall; + int direction,ascent,descent; + char coords[256]; + int x,y,z,x1,y1,x2,y2; + XEvent e; + XClearWindow(dpy, w); + + //struct triangle **triangle; + //for(i=0;global.triangle[i];i++); + //triangle=malloc(sizeof(struct triangle *) * i); + //for(i=0;global.triangle[i];i++) { + // triangle[i]=malloc(sizeof(struct triangle)); + // memcpy(triangle[i],global.triangle[i],sizeof(triangle)); + //} + //triangle[i]=0; + + XDrawLine(dpy,w,gc,global.xoff,global.height/2,global.xoff+WIDTH,global.height/2); + snprintf(coords,sizeof(coords)-1,"x: %d y: %d",global.mousex,global.mousey); + XTextExtents(font,coords,strlen(coords),&direction,&ascent,&descent,&overall); + XDrawString(dpy,w,gc,global.xoff,0+ascent,coords,strlen(coords)); + snprintf(coords,sizeof(coords)-1,"cx: %d cy: %d cz: %d",camera.x,camera.y,camera.z); + XTextExtents(font,coords,strlen(coords),&direction,&ascent,&descent,&overall); + XDrawString(dpy,w,gc,global.xoff,(descent+0+ascent)*2,coords,strlen(coords)); + + snprintf(coords,sizeof(coords)-1,"xr: %d yr: %d zr: %d",camera.xr,camera.yr,camera.zr); + XTextExtents(font,coords,strlen(coords),&direction,&ascent,&descent,&overall); + XDrawString(dpy,w,gc,global.xoff,(descent+0+ascent)*3,coords,strlen(coords)); + + j=0; +/* + for(i=camera.yr;i 0) { + /*if(!strcmp(command,"addsquare")) { } */ + if(!strcmp(command,"addtriangle")) { + global.triangle[i]=malloc(sizeof(struct triangle)); + to=global.triangle[i]; + memcpy(to,&t,sizeof(t)); + } + if(!strcmp(command,"move")) { + for(i=0;global.triangle[i];i++) { + if(!strcmp(global.triangle[i]->id,t.id)) { + global.triangle[i]->x1+=t.x1; + global.triangle[i]->y1+=t.y1; + global.triangle[i]->z1+=t.z1; + + global.triangle[i]->x2+=t.x1; + global.triangle[i]->y2+=t.y1; + global.triangle[i]->z2+=t.z1; + + global.triangle[i]->x3+=t.x1; + global.triangle[i]->y3+=t.y1; + global.triangle[i]->z3+=t.z1; + } + } + } + global.triangle[i+1]=0; + draw_screen(global.dpy,global.w,global.gc); + } else { + global.triangle[i]=0; + break; + } + } +} + +int export_file(FILE *fp) { + struct triangle *to; + int i; + for(i=0;global.triangle[i];i++) { + to=global.triangle[i]; + printf("%s addtriangle %d %d %d %d %d %d %d %d %d\n",to->id,to->x1,to->y1,to->z1,to->x2,to->y2,to->z2,to->x3,to->y3,to->z3); + } +} + + +int main(int argc,char *argv[]) { + char redraw=0; + if(argc < 2) { + fprintf(stderr,"usage: hackvr yourname < from_others > to_others\n"); + return 1; + } else { + global.user=strdup(argv[1]); + } + setbuf(stdin,0); + setbuf(stdout,0); + Display *dpy = XOpenDisplay(0); + assert(dpy); + global.dpy=dpy; + unsigned int mask; + int i; + XEvent e; + XSetWindowAttributes attributes; + int blackColor = BlackPixel(dpy, DefaultScreen(dpy)); + int whiteColor = //WhitePixel(dpy, DefaultScreen(dpy)); + attributes.background_pixel=blackColor; + Window w = XCreateWindow(dpy,DefaultRootWindow(dpy),0,0,WIDTH*SPLIT_SCREEN,HEIGHT,1,DefaultDepth(dpy,DefaultScreen(dpy)),InputOutput,DefaultVisual(dpy,DefaultScreen(dpy))\ + ,CWBackPixel, &attributes); + global.w=w; + global.triangle[0]=0;//we'll allocate as we need more. + Window root,child; + XSelectInput(dpy, w, PointerMotionMask|StructureNotifyMask|ButtonPressMask|ButtonReleaseMask|ResizeRedirectMask|KeyPressMask); + XMapWindow(dpy, w); + XStoreName(dpy,w,"hackvr"); + GC gc = XCreateGC(dpy, w, 0, 0); + global.gc=gc; + global.color_map=DefaultColormap(dpy, DefaultScreen(dpy)); + XAllocNamedColor(dpy, global.color_map, "green", &global.green, &global.green); + XSetForeground(dpy, gc, global.green.pixel); +// XSetForeground(dpy, gc, whiteColor); + for(;;) { + load_file(stdin); + XNextEvent(dpy, &e); + redraw=1; + switch(e.type) { + case MotionNotify: + XQueryPointer(dpy,w,&root,&child,&global.rmousex,&global.rmousey,&global.mousex,&global.mousey,&mask); + break; + case ButtonPress: + global.buttonpressed=e.xbutton.button; + break; + case ButtonRelease: + global.buttonpressed=0; + break; + case ResizeRequest: + XGetGeometry(dpy,w,&root,&global.x,&global.y,&global.width,&global.height,&global.border_width,&global.depth); + case KeyPress: + switch(XLookupKeysym(&e.xkey,0)) { + case XK_Up: + //fix these to use calculated values down there. + //printf("%s move 0 0 1 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr)); + camera.x+=5*sinl(d2r(camera.yr)); break; + case XK_Down: + //printf("%s move 0 0 -1 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr+180)); + camera.x+=5*sinl(d2r(camera.yr+180)); break; + case XK_Left: + //printf("%s move 1 0 0 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr+90)); + camera.x+=5*sinl(d2r(camera.yr+90)); break; + case XK_Right: + //printf("%s move -1 0 0 0 0 0 0 0 0\n",global.user); + camera.z+=5*cosl(d2r(camera.yr+270)); + camera.x+=5*sinl(d2r(camera.yr+270)); break; + case XK_w: + //printf("%s move 0 1 0 0 0 0 0 0 0\n",global.user); + camera.y+=5; break; + case XK_s: + //printf("%s move 0 -1 0 0 0 0 0 0 0\n",global.user); + camera.y-=5; break; + case XK_q: + camera.yr+=5; break; + case XK_e: + camera.yr-=5; break; + case XK_Escape: return 0; + default: + redraw=0; + break; + } + default: + redraw=0; + break; + } + //if(redraw) + draw_screen(dpy,w,gc); + } + return 0; +} diff --git a/tests/ungets.c b/tests/ungets.c new file mode 100644 index 0000000..7374100 --- /dev/null +++ b/tests/ungets.c @@ -0,0 +1,9 @@ +#include + +int main() { + ungetc('a',stdin); + ungetc('b',stdin); + printf("%c",fgetc(stdin)); + printf("%c",fgetc(stdin)); + printf("\n"); +} diff --git a/tools/dat2hackvr.pl b/tools/dat2hackvr.pl new file mode 100755 index 0000000..2a2fbe1 --- /dev/null +++ b/tools/dat2hackvr.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +use strict; + +die "usage: dat2hackvr.pl name file\n" unless $ARGV[0]; + +my $line; +my $prev; +my $first; +open(FILE,$ARGV[1]) if $ARGV[1]; +while($line=) { + chomp $line; + if(!($line =~ m/^#/)) { + if($line eq "") { +# print $ARGV[0]; +# print " addtriangle "; +# print $prev . " 0 " . $first . " 0 " . $first . " 0"; +# print "\n"; + $first=""; + } else { + if($prev ne "") { + print $ARGV[0]; + print " addshape 2 "; + print $line . " 0 " . $prev . " 0"; + print "\n"; + } + $prev=""; + } + if($first eq "") { + $first=$line; + } + $prev=$line; + } +} diff --git a/tools/obj2hackvr.pl b/tools/obj2hackvr.pl index 793b5ea..d8727e2 100755 --- a/tools/obj2hackvr.pl +++ b/tools/obj2hackvr.pl @@ -32,13 +32,28 @@ while() { # } #} +#foreach $tmp (@faces) { +# @points=split(/ /,$tmp); +# @points = map { $_ =~ s/\/.+$//g; $_; } @points; +## print @points; +# print $ARGV[0]; +# print " addshape "; +# print @points+0; +# for($i=0;$i<(@points+0);$i++) { +# print " "; +# print $vertices[$points[$i]]; +# } +# print "\n"; +#} + +#convert to triangles foreach $tmp (@faces) { @points=split(/ /,$tmp); @points = map { $_ =~ s/\/.+$//g; $_; } @points; # print @points; for($i=2;$i<(@points);$i++) { print $ARGV[0]; - print " addtriangle "; + print " addshape 3 "; print $vertices[$points[0]-1]; print " "; print $vertices[$points[$i-1]-1]; diff --git a/traceroute_hackvr.sh b/traceroute_hackvr.sh new file mode 100755 index 0000000..cdf9c69 --- /dev/null +++ b/traceroute_hackvr.sh @@ -0,0 +1,2 @@ +#!/bin/bash +cat <(./tools/dat2hackvr.pl world world/world_110m.txt) ./world_camera <(./traceroute_to_dat.sh $1 | cut '-d ' -f2- | awk '{print $2,$1}' | tail -n+2 | ./tools/dat2hackvr.pl route /dev/stdin) /dev/stdin | ./hackvr epoch diff --git a/traceroute_to_dat.sh b/traceroute_to_dat.sh new file mode 100755 index 0000000..5b08884 --- /dev/null +++ b/traceroute_to_dat.sh @@ -0,0 +1,2 @@ +#!/bin/sh +traceroute -n $1 | tail -n+2 | sed 's/^ *//g' | cut '-d ' -f3 | whob | egrep '^IP|^Lat|^Long' | cut '-d ' -f2- | paste - - - | tr '\t' ' ' diff --git a/traceroute_to_triangles.sh b/traceroute_to_triangles.sh new file mode 100755 index 0000000..4f1a1c7 --- /dev/null +++ b/traceroute_to_triangles.sh @@ -0,0 +1,2 @@ +#!/bin/sh +traceroute -n $1 | tail -n+2 | cut '-d ' -f4 | ./IPs_to_triangle.sh diff --git a/world_camera b/world_camera new file mode 100644 index 0000000..074688a --- /dev/null +++ b/world_camera @@ -0,0 +1,7 @@ +epoch set camera.p.x -0.000000 +epoch set camera.p.y 5.000000 +epoch set camera.p.z -12.000000 +epoch set camera.xr 270 +epoch set camera.yr 270 +epoch set camera.zr 0 +epoch set camera.zoom 2.000000 -- cgit v1.2.3