diff options
author | epochqwert <epoch@hacking.allowed.org> | 2019-02-07 09:08:01 +0000 |
---|---|---|
committer | epochqwert <epoch@hacking.allowed.org> | 2019-02-07 09:08:01 +0000 |
commit | 750473faa49be1a3490d8336190ee920014d8169 (patch) | |
tree | 2f14646e064321419c7942981863f571e9a6339b | |
parent | 9f4b99177d8e563f5cfceaf34277d79a681c41f7 (diff) | |
parent | 978e097ebfb50d70e5e45530cdf0fecc7654c641 (diff) | |
download | hackvr-750473faa49be1a3490d8336190ee920014d8169.tar.gz hackvr-750473faa49be1a3490d8336190ee920014d8169.zip |
merge with testing
-rwxr-xr-x | bin/height2cyl.py | 77 | ||||
-rwxr-xr-x | share/hackvr/examples/chess/board.sh | 28 | ||||
-rwxr-xr-x | share/hackvr/examples/chess/gnuchess-to-hackvr.sh | 5 | ||||
-rwxr-xr-x | share/hackvr/examples/chess/run | 3 | ||||
-rwxr-xr-x | share/hackvr/examples/tictactoe/run | 2 | ||||
-rw-r--r-- | src/graphics_cs_fb.c | 2 | ||||
-rw-r--r-- | src/hackvr.c | 20 |
7 files changed, 120 insertions, 17 deletions
diff --git a/bin/height2cyl.py b/bin/height2cyl.py new file mode 100755 index 0000000..37eef49 --- /dev/null +++ b/bin/height2cyl.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +import random +import math +import sys +from PIL import Image +#we're going to make triangles. lots of triangles. +#since the heightmap is in a square pattern +#we're going to have a point that is the average +#of between the 4 around it. +#subpixel[x,y] = pixel[x,y] pixel[x+1,y] pixel[x,y+1] pixel[x+1,y+1] +#we can do this first. +#then we draw 4 triangles that go around subpixel[x,y] +#triangle pixel[x,y] pixel[x+1,y] subpixel[x,y] +#triagnle pixel[x+1,y] pixel[x+1,y+1] subpixel[x,y] +#triagnle pixel[x+1,y+1] pixel[x,y+1] subpixel[x,y] +#triagnle pixel[x,y+1] pixel[x,y] subpixel[x,y] + +width=32 +height=16 + +im=Image.open(sys.argv[1]).convert('L').resize((width,height)) #load image as greyscale +#im=Image.open(sys.argv[1]).convert('L') #load image as greyscale +width=im.width +height=im.height +pixel_derp=im.load() +#print(dir(im)) +#print(dir(im.getdata().getpixel(0,0))) +#quit() +#width=6 +#height=6 + +def trianglize(x1,y1,x2,y2,xs,ys): + x1%=width + y1%=height + x2%=width + y2%=height + xs%=width + ys%=height + + yscale= 32 / height + + tx1=math.sin(x1 / (width / (2 * math.pi)) ) * (pixel[x1][y1] / (127 / math.pi)) + tz1=math.cos(x1 / (width / (2 * math.pi)) ) * (pixel[x1][y1] / (127 / math.pi)) + ty1=-((y1 * yscale) / 5) + 15 + + tx2=math.sin(x2 / (width / (2 * math.pi)) ) * (pixel[x2][y2] / (127 / math.pi)) + tz2=math.cos(x2 / (width / (2 * math.pi)) ) * (pixel[x2][y2] / (127 / math.pi)) + ty2=-((y2 * yscale) / 5) + 15 + +# xs=(xs * 2) + 1 + tx3=math.sin(xs / (width / (2 * math.pi)) ) * (subpixel[xs][ys] / (127 / math.pi)) + tz3=math.cos(xs / (width / (2 * math.pi)) ) * (subpixel[xs][ys] / (127 / math.pi)) + ty3=-(((ys * yscale) + 1) / 5) + 15 + print("test addshape 3 3 {} {} {} {} {} {} {} {} {}".format(tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3)) + + +#width=16 +#height=16 +pixel=[[0]*height for i in range(width)] +subpixel=[[0]*height for i in range(width)] +## initialize for testing: +for y in range(0,height): + for x in range(0,width): +# pixel[x][y]=random.randint(1,255) +# pixel[x][y]=im.tobytes()[y * width + x] + pixel[x][y]=pixel_derp[x,y] +# pixel[x][y]=y * 20 +#subpixel=pixel +#im.show() + +for y in range(0,height-1): + for x in range(0,width): + subpixel[x][y] = ( pixel[x][y] + pixel[(x+1)%width][y] + pixel[x][(y+1)%height] + pixel[(x+1)%width][(y+1)%height] ) / 4 + trianglize(x,y, x+1,y, x,y) + trianglize(x+1,y, x+1,y+1, x,y) + trianglize(x+1,y+1, x,y+1, x,y) + trianglize(x,y+1, x,y, x,y) diff --git a/share/hackvr/examples/chess/board.sh b/share/hackvr/examples/chess/board.sh index 5848c98..dc3fb3b 100755 --- a/share/hackvr/examples/chess/board.sh +++ b/share/hackvr/examples/chess/board.sh @@ -1,16 +1,29 @@ #!/usr/bin/env bash +e=$1 #elevation of board width=8 height=8 cols="a b c d e f g h" +printf "junk set camera.r.x -45\n" + for x in $(seq 1 $width);do for y in $(seq 1 $height);do color=$[((($y % 2) + ($x % 2))%2)+16] ### board is on the wall. draw in x and y. -# printf "%s%s addshape %s 4 %s %s 0 %s %s 0 %s %s 0 %s %s 0\n" $(printf "%s\n" "$cols" | cut '-d ' -f$x) $y $color $x $y $[x+1] $y $[x+1] $[y+1] $x $[y+1] +# printf "%s%s addshape %s 4 %s %s %s %s %s %s %s %s %s %s %s %s\n" \ +# $(printf "%s\n" "$cols" | cut '-d ' -f$x) $y $color \ +# $x $y $e \ +# $[x+1] $y $e \ +# $[x+1] $[y+1] $e \ +# $x $[y+1] $e ### board is on floor. draw in x and z. - printf "%s%s addshape %s 4 %s 0 %s %s 0 %s %s 0 %s %s 0 %s\n" $(printf "%s\n" "$cols" | cut '-d ' -f$x) $y $color $x $y $[x+1] $y $[x+1] $[y+1] $x $[y+1] + printf "%s%s addshape %s 4 %s %s %s %s %s %s %s %s %s %s %s %s\n" \ + $(printf "%s\n" "$cols" | cut '-d ' -f$x) $y $color \ + $x $e $y \ + $[x+1] $e $y \ + $[x+1] $e $[y+1] \ + $x $e $[y+1] done done @@ -25,16 +38,17 @@ for x in $(seq $width);do locat="$(printf "%s\n" "$cols" | cut '-d ' "-f$x")$y" cat "./pieces/pawn" | sed 's/^[^ ][^ ]* addshape [0-9][0-9]* /piece_'"${locat}"' addshape '"$(printf "%s\n" "$color" | cut '-d ' "-f$y")"' /g' ### board is on wall. use x and y. -# printf "piece_%s move %s %s 0\n" "$locat" "$x" "$y" +# printf "piece_%s move %s %s %s\n" "$locat" "$x" "$y" "$e" ### board is on floor. use x and z. - printf "piece_%s move %s 0 %s\n" "$locat" "$x" "$y" + printf "piece_%s move %s %s %s\n" "$locat" "$x" "$e" "$y" done for y in 1 8;do locat="$(printf "%s\n" "$cols" | cut '-d ' "-f$x")$y" - cat "./pieces/$(printf "%s\n" "$row1" | cut '-d ' "-f$x")" | sed 's/^[^ ][^ ]* addshape [0-9][0-9]* /piece_'"${locat}"' addshape '"$(printf "%s\n" "$color" | cut '-d ' "-f$y")"' /g' + cat "./pieces/$(printf "%s\n" "$row1" | cut '-d ' "-f$x")" \ + | sed 's/^[^ ][^ ]* addshape [0-9][0-9]* /piece_'"${locat}"' addshape '"$(printf "%s\n" "$color" | cut '-d ' "-f$y")"' /g' ### board is on wall. use x and y. -# printf "piece_%s move %s %s 0\n" "$locat" "$x" "$y" +# printf "piece_%s move %s %s %s\n" "$locat" "$x" "$y" "$e" ### board is on floor. use x and z. - printf "piece_%s move %s 0 %s\n" "$locat" "$x" "$y" + printf "piece_%s move %s %s %s\n" "$locat" "$x" "$e" "$y" done done diff --git a/share/hackvr/examples/chess/gnuchess-to-hackvr.sh b/share/hackvr/examples/chess/gnuchess-to-hackvr.sh index 0b94a87..841389b 100755 --- a/share/hackvr/examples/chess/gnuchess-to-hackvr.sh +++ b/share/hackvr/examples/chess/gnuchess-to-hackvr.sh @@ -1,4 +1,5 @@ #!/bin/sh +e=$1 tee /dev/stderr | while read first second third;do if [ "_$first" = "_feature" ];then printf "# just gnuchess saying what features it has: %s %s %s\n" "$first" "$second" "$third" >&2 @@ -17,9 +18,9 @@ tee /dev/stderr | while read first second third;do y=$(printf "%s\n" "$to" | fold -w1 | tail -n1) magic=$(printf "%s\n" "$move" | fold -w1 | tail -n+5 | tr -d '\n') ### if the board is on the wall we need to use x and y -# printf "piece_%s move %s %s 0\n" "$from" "$x" "$y" | tee /dev/stderr +# printf "piece_%s move %s %s %s\n" "$from" "$x" "$y" "$e" | tee /dev/stderr ### the board is on the floor atm. use x and z - printf "piece_%s move %s 0 %s\n" "$from" "$x" "$y" | tee /dev/stderr + printf "piece_%s move %s %s %s\n" "$from" "$x" "$e" "$y" | tee /dev/stderr printf "#delete the old piece_%s group\n" printf "epoch deletegroup piece_%s\n" "$to" diff --git a/share/hackvr/examples/chess/run b/share/hackvr/examples/chess/run index 0fdfdf3..1168044 100755 --- a/share/hackvr/examples/chess/run +++ b/share/hackvr/examples/chess/run @@ -1,4 +1,5 @@ #!/usr/bin/env bash +export elevation=0 mknod p p -stdbuf -oL cat camera.pos <(./board.sh) <(cat p | ./gnuchess-to-hackvr.sh) | hackvr "$USER" | ./hackvr-to-gnuchess.sh | gnuchess -x > p +stdbuf -oL cat camera.pos <(./board.sh $elevation) <(cat p | ./gnuchess-to-hackvr.sh $elevation) | hackvr "$USER" | ./hackvr-to-gnuchess.sh | gnuchess -x > p rm p diff --git a/share/hackvr/examples/tictactoe/run b/share/hackvr/examples/tictactoe/run index 0f14b8f..4d49770 100755 --- a/share/hackvr/examples/tictactoe/run +++ b/share/hackvr/examples/tictactoe/run @@ -2,5 +2,5 @@ turn=$( expr $RANDOM % 2) echo "go. player: $turn" mknod p p -stdbuf -oL cat board p | hackvr | ./game.sh > p +stdbuf -oL p | hackvr | ./game.sh > p rm p diff --git a/src/graphics_cs_fb.c b/src/graphics_cs_fb.c index 292f7e7..edfa4b6 100644 --- a/src/graphics_cs_fb.c +++ b/src/graphics_cs_fb.c @@ -84,7 +84,7 @@ void draw_cs_point(int x,int y) {//this should write to a backbuffer then I can fb_global.backbuf[i]=0; break; default: - printf("# derp. unknown draw_mode %d\n",fb_global.draw_mode); + fprintf(stderr,"# derp. unknown draw_mode %d\n",fb_global.draw_mode); break; } } diff --git a/src/hackvr.c b/src/hackvr.c index 88ce2f9..c272074 100644 --- a/src/hackvr.c +++ b/src/hackvr.c @@ -30,6 +30,16 @@ extern struct gra_global gra_global; //TODO: will have to make some pixmaps get resized when the window does. //for now set them to be as big as you think you'll ever resize the window to. +int lum_based_on_distance(c3_s_t *s) { + int i; + real sum; + for(i=0;i < s->len;i++) { + sum+=distance2((c2_t){s->p[i].x,s->p[i].z},(c2_t){0,0}); + } + //sum /= s->len; + return sum * 5; +} + struct global global; //might be able to make this faster by just using fgets() and not using recursion and malloc. @@ -112,7 +122,7 @@ int glob_match(char *a,char *b) { } void hvr_version() { - printf("# hackvr version: %s\n",HVR_VERSION); + fprintf(stderr,"# hackvr version: %s\n",HVR_VERSION); } int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, and 1 to ask for redraw @@ -266,7 +276,7 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, //we don't need this gr anymore. //we could clean it up, but its values are already zero. }*/ - printf("# this group doesn't have a gr.\n"); + fprintf(stderr,"# this group doesn't have a gr.\n"); } if(!strcmp(command,"deletegroup")) {//should the grouprot get deleted too? sure... if(len == 3) { @@ -396,12 +406,12 @@ int load_stdin() {//this function returns -1 to quit, 0 to not ask for a redraw, global.shape[i]->len=strtold(a[3],0); global.shape[i]->id=strdup(id); global.shape[i]->attrib.col=strtold(a[2],0); - global.shape[i]->attrib.lum=0; for(j=0;j < global.shape[i]->len+(global.shape[i]->len==1);j++) { global.shape[i]->p[j].x=strtold(a[(j*3)+4],0);//second arg is just for a return value. set to 0 if you don't want it. global.shape[i]->p[j].y=strtold(a[(j*3)+5],0); global.shape[i]->p[j].z=strtold(a[(j*3)+6],0); } + global.shape[i]->attrib.lum=0;//lum_based_on_distance(global.shape[i]);//set to distance from center? i++; global.shapes=i; global.shape[i]=0; @@ -613,9 +623,9 @@ int main(int argc,char *argv[]) { //fprintf(stderr,"# derping.\n"); if(global.periodic_output == 1) {//this is the same type of thing the debug output does. debug output now goes here. #ifdef GRAPHICAL - printf("# loops per second: %d mouse.x: %f mouse.y: %f\n",global.lps,gra_global.mouse.x,gra_global.mouse.y); + fprintf(stderr,"# loops per second: %d mouse.x: %f mouse.y: %f\n",global.lps,gra_global.mouse.x,gra_global.mouse.y); #else - printf("# loops per second: %d\n",global.lps); + fprintf(stderr,"# loops per second: %d\n",global.lps); #endif global.periodic_output = PERIODIC_OUTPUT; //output any difference between current camera's state |