Merge branch 'master' into divVerent/crypto2
authorRudolf Polzer <divverent@alientrap.org>
Wed, 13 Oct 2010 19:40:52 +0000 (21:40 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Wed, 13 Oct 2010 19:40:52 +0000 (21:40 +0200)
Conflicts:
all

all
misc/tools/brightspot.c
misc/tools/brightspot.sh
misc/tools/spherefunc2skybox.c

diff --git a/all b/all
index 38c19007c51d70c5ae19bebae1a3c1d2fe77087e..4a39eed57fd55f1fb12ccc9fc49bff64b8476697 100755 (executable)
--- a/all
+++ b/all
@@ -1089,6 +1089,8 @@ case "$cmd" in
                                                verbose git branch -D "${B#refs/heads/}"
                                        fi
                                done
+                               git rev-parse refs/heads/master >/dev/null 2>&1 || verbose git branch -t master origin/master || true
+                               git rev-parse "refs/heads/`repobranch "$d"`" >/dev/null 2>&1 || verbose git branch -t "`repobranch "$d"`" origin/"`repobranch "$d"`" || true
                        fi
                done
                ;;
@@ -1216,7 +1218,7 @@ case "$cmd" in
                ;;
        release-engine-win32)
                verbose "$SELF" release-compile win32 \
-                       'STRIP=: DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib -DUSE_WSPIAPI_H -DSUPPORTIPV6" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN32RELEASE=1 D3D=0' \
+                       'STRIP=: DP_MAKE_TARGET=mingw CC="i586-mingw32msvc-gcc -march=i686 -mtune=generic -g -Wl,--dynamicbase -Wl,--nxcompat -I.deps/include -L.deps/lib -DUSE_WSPIAPI_H -DSUPPORTIPV6" WINDRES="i586-mingw32msvc-windres" SDL_CONFIG=".deps/bin/sdl-config" LIB_JPEG= CFLAGS_LIBJPEG= WIN32RELEASE=1 D3D=0' \
                        win 'fteqcc.exe:Xonotic/fteqcc/fteqcc.exe' \
                        '' ''
                verbose "$SELF" release-compile win32 \
@@ -1247,7 +1249,7 @@ case "$cmd" in
                ;;
        release-engine-linux32)
                verbose "$SELF" release-compile linux32 \
-                       'STRIP=: CC="gcc -m32 -g -I.deps/include -L.deps/lib -DSUPPORTIPV6" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a DP_CRYPTO_STATIC_LIBDIR=.deps/lib' \
+                       'STRIP=: CC="gcc -m32 -march=i686 -mtune=generic -g -I.deps/include -L.deps/lib -DSUPPORTIPV6" DP_MODPLUG_STATIC_LIBDIR=.deps/lib LIB_JPEG=.deps/lib/libjpeg.a DP_CRYPTO_STATIC_LIBDIR=.deps/lib' \
                        all 'fteqcc.bin:Xonotic/fteqcc/fteqcc.linux32' \
                        release 'darkplaces-glx:Xonotic/xonotic-linux32-glx darkplaces-sdl:Xonotic/xonotic-linux32-sdl darkplaces-dedicated:Xonotic/xonotic-linux32-dedicated'
                ;;
index fe3bb6b8ee5bebbf3bc3d0b10cb4cb0a9759c93e..fee8074c741a6ea63ce553d0d3a68f82bcbe361b 100644 (file)
@@ -52,6 +52,20 @@ static const double skyboxtexcoord2f[6*4*2] =
     0, 0
 };
 
+#define GET_SKY_IMAGE(x,y,z) \
+       (fabs(x)>=fabs(y) && fabs(x)>=fabs(z)) ?  (((x) > 0) ? 0 : 1) : \
+       (fabs(y)>=fabs(x) && fabs(y)>=fabs(z)) ?  (((y) > 0) ? 2 : 3) : \
+                                                 (((z) > 0) ? 4 : 5)
+
+int highest[6] =
+{
+       0,
+       0,
+       1,
+       1,
+       2,
+       2
+};
 
 static const double skyboxvertex3f[6*4*3] =
 {
@@ -117,6 +131,56 @@ void Map3f(double u, double v, const double *corners, double *x, double *y, doub
        *z = corners[2] + u * (corners[5] - corners[2]) + v * (corners[8] - corners[5]);
 }
 
+void Map2f(double u, double v, const double *corners, double *x, double *y)
+{
+       *x = u * (corners[2] - corners[0]) + v * (corners[4] - corners[2]) + corners[0];
+       *y = u * (corners[3] - corners[1]) + v * (corners[5] - corners[3]) + corners[1];
+}
+
+void Unmap3f(double x, double y, double z, const double *corners, double *u, double *v)
+{
+       //*x = corners[0] + u * (corners[3] - corners[0]) + v * (corners[6] - corners[3]);
+       //*y = corners[1] + u * (corners[4] - corners[1]) + v * (corners[7] - corners[4]);
+       //*z = corners[2] + u * (corners[5] - corners[2]) + v * (corners[8] - corners[5]);
+       // THREE equations, TWO would be better! Let's simply use the two "better" ones
+       
+       double xc0 = x - corners[0];
+       double yc1 = y - corners[1];
+       double zc2 = z - corners[2];
+       double c30 = corners[3] - corners[0];
+       double c41 = corners[4] - corners[1];
+       double c52 = corners[5] - corners[2];
+       double c63 = corners[6] - corners[3];
+       double c74 = corners[7] - corners[4];
+       double c85 = corners[8] - corners[5];
+
+       double det_x = c41 * c85 - c52 * c74;
+       double det_y = c30 * c85 - c52 * c63;
+       double det_z = c30 * c74 - c41 * c63;
+
+       if(fabs(det_x) >= fabs(det_y) && fabs(det_x) >= fabs(det_z))
+       {
+               double du = yc1 * c85 - zc2 * c74;
+               double dv = c41 * zc2 - c52 * yc1;
+               *u = du / det_x;
+               *v = dv / det_x;
+       }
+       else if(fabs(det_y) >= fabs(det_z))
+       {
+               double du = xc0 * c85 - zc2 * c63;
+               double dv = c30 * zc2 - c52 * xc0;
+               *u = du / det_y;
+               *v = dv / det_y;
+       }
+       else
+       {
+               double du = xc0 * c74 - yc1 * c63;
+               double dv = c30 * yc1 - c41 * xc0;
+               *u = du / det_z;
+               *v = dv / det_z;
+       }
+}
+
 void MapCoord(int pic, int y, int x, double vec[3])
 {
        int h;
@@ -140,6 +204,44 @@ void MapCoord(int pic, int y, int x, double vec[3])
        Map3f(u, v, skyboxvertex3f + 6*2*pic, &vec[0], &vec[1], &vec[2]);
 }
 
+void UnmapCoord(const double vec_[3], int *pic, int *y, int *x)
+{
+       int h;
+       int flipx;
+       int flipy;
+       int flipdiag;
+       double u, v, xx, yy;
+       double f;
+       double vec[3];
+
+       // identify which pic it is
+       *pic = GET_SKY_IMAGE(vec_[0], vec_[1], vec_[2]);
+       f = 16.0/fabs(vec_[highest[*pic]]);
+       vec[0] = vec_[0] * f;
+       vec[1] = vec_[1] * f;
+       vec[2] = vec_[2] * f;
+       flipx = flip[3*(*pic)+0];
+       flipy = flip[3*(*pic)+1];
+       flipdiag = flip[3*(*pic)+2];
+
+       *x = *y = 0;
+       Unmap3f(vec[0], vec[1], vec[2], skyboxvertex3f + 6*2*(*pic), &u, &v);
+       Map2f(u, v, skyboxtexcoord2f + 4*2*(*pic), &xx, &yy);
+       *x = (int) (xx * 512.0 + 0.5);
+       *y = (int) (yy * 512.0 + 0.5);
+
+       if(flipdiag)
+       {
+               h = *x; *x = *y; *y = h;
+       }
+
+       if(flipy)
+               *y = 511 - *y;
+
+       if(flipx)
+               *x = 511 - *x;
+}
+
 int main(int argc, char **argv)
 {
        FILE *f;
@@ -185,11 +287,18 @@ int main(int argc, char **argv)
                        }
 
        l = sqrt(brightvec[0]*brightvec[0] + brightvec[1]*brightvec[1] + brightvec[2]*brightvec[2]);
-       fprintf(stderr, "vec = %f %f %f\n", brightvec[0] / l, brightvec[1] / l, brightvec[2] / l);
+       l /= 16;
+       brightvec[0] /= l;
+       brightvec[1] /= l;
+       brightvec[2] /= l;
+       fprintf(stderr, "vec = %f %f %f\n", brightvec[0], brightvec[1], brightvec[2]);
+       UnmapCoord(brightvec, &i, &j, &k);
+       fprintf(stderr, "picture %d pixel (%d %d) value %d\n", i, k, j, picture[i][j][k]);
        
        pitch = atan2(brightvec[2], sqrt(brightvec[0]*brightvec[0] + brightvec[1]*brightvec[1]));
        yaw = atan2(brightvec[1], brightvec[0]);
 
        printf("%f %f\n", yaw * 180 / M_PI, pitch * 180 / M_PI);
+
        return 0;
 }
index d2131adc44ac6f78e8e15f66490dc48f48d71623..a14b3685ed44d017c1ce0854391f2626a94d5905 100755 (executable)
@@ -26,6 +26,7 @@ ext=${i##*.}
 name=${i%.*}
 name=${name%_[rlbfud][tfktpn]}
 
+echo >&2 "Order: 0=rt 1=lf 2=bk 3=ft 4=up 5=dn"
 {
        convert "$name"_rt."$ext" -depth 8 -geometry 512x512 GRAY:-
        convert "$name"_lf."$ext" -depth 8 -geometry 512x512 GRAY:-
index 3e3e7a5ad007bed931add27f01fcdee1233521d3..1f5481c3eb8269e2a1c3dab3f1d357aabad5dbb6 100644 (file)
@@ -141,6 +141,77 @@ void color_mandelbrot(double x, double y, double z, double *r, double *g, double
        *b = pow(iterations, color_mandelbrot_parms[12]);
 }
 
+struct
+{
+       int n;
+       double darkness;
+       double power;
+       double density;
+}
+color_starfield_parms;
+void color_starfield(double x, double y, double z, double *r, double *g, double *b)
+{
+       static struct
+       {
+               double x, y, z, e;
+               double R, G, B, A;
+       } *starfield = NULL;
+       int i;
+       double f;
+
+       if(!starfield)
+       {
+               fprintf(stderr, "Initializing starfield...\n");
+               starfield = malloc(sizeof(*starfield) * color_starfield_parms.n);
+               for(i = 0; i < color_starfield_parms.n; ++i)
+               {
+                       double r;
+                       do
+                       {
+                               starfield[i].x = rnd() * 2 - 1;
+                               starfield[i].y = rnd() * 2 - 1;
+                               starfield[i].z = rnd() * 2 - 1;
+                               r = starfield[i].x * starfield[i].x
+                                 + starfield[i].y * starfield[i].y
+                                 + starfield[i].z * starfield[i].z;
+                       }
+                       while(r > 1);
+                       r = sqrt(r);
+                       starfield[i].x /= r;
+                       starfield[i].y /= r;
+                       starfield[i].z /= r;
+
+                       starfield[i].e = color_starfield_parms.density * pow(rnd(), -color_starfield_parms.power);
+
+                       starfield[i].R = rnd();
+                       starfield[i].G = rnd();
+                       starfield[i].B = rnd();
+                       f = starfield[i].R * 0.299 + starfield[i].G * 0.587 + starfield[i].B * 0.114;
+                       starfield[i].R /= f;
+                       starfield[i].G /= f;
+                       starfield[i].B /= f;
+                       starfield[i].A = rnd();
+               }
+               fprintf(stderr, "Done.\n");
+       }
+
+       *r = *g = *b = 0;
+       for(i = 0; i < color_starfield_parms.n; ++i)
+       {
+               double dot = x * starfield[i].x + y * starfield[i].y + z * starfield[i].z;
+               if(dot <= 0)
+                       continue;
+               double f = pow(dot, starfield[i].e) * starfield[i].A;
+               *r += starfield[i].R * f;
+               *g += starfield[i].G * f;
+               *b += starfield[i].B * f;
+       }
+       // make fit in 0..1
+       *r = *r / (color_starfield_parms.darkness + *r);
+       *g = *g / (color_starfield_parms.darkness + *g);
+       *b = *b / (color_starfield_parms.darkness + *b);
+}
+
 void map_back(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
 {
        *x_out = 2 * x_in - 1;
@@ -187,6 +258,7 @@ void writepic(colorfunc_t f, mapfunc_t m, const char *fn, int width, int height)
 {
        int x, y;
        uint8_t tga[18];
+       int percent, p;
 
        FILE *file = fopen(fn, "wb");
        if(!file)
@@ -201,7 +273,9 @@ void writepic(colorfunc_t f, mapfunc_t m, const char *fn, int width, int height)
        tga[16] = 24;        // pixel size
 
        fwrite(&tga, sizeof(tga), 1, file);
+       percent = 0;
        for(y = height-1; y >= 0; --y)
+       {
                for(x = 0; x < width; ++x)
                {
                        uint8_t rgb[3];
@@ -222,6 +296,14 @@ void writepic(colorfunc_t f, mapfunc_t m, const char *fn, int width, int height)
                        rgb[0] = floor(rnd() + bb * 255);
                        fwrite(rgb, sizeof(rgb), 1, file);
                }
+               p = (100 * (height - y)) / height;
+               if(p != percent)
+               {
+                       percent = p;
+                       fprintf(stderr, "%d%%\r", percent);
+               }
+       }
+       fprintf(stderr, "\n");
        
        fclose(file);
 }
@@ -229,11 +311,17 @@ void writepic(colorfunc_t f, mapfunc_t m, const char *fn, int width, int height)
 void map_all(const char *fn, colorfunc_t f, int width, int height)
 {
        char buf[1024];
+       fprintf(stderr, "%s_bk.tga\n", fn);
        snprintf(buf, sizeof(buf), "%s_bk.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_back, buf, width, height);
+       fprintf(stderr, "%s_ft.tga\n", fn);
        snprintf(buf, sizeof(buf), "%s_ft.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_front, buf, width, height);
+       fprintf(stderr, "%s_rt.tga\n", fn);
        snprintf(buf, sizeof(buf), "%s_rt.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_right, buf, width, height);
+       fprintf(stderr, "%s_lf.tga\n", fn);
        snprintf(buf, sizeof(buf), "%s_lf.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_left, buf, width, height);
+       fprintf(stderr, "%s_up.tga\n", fn);
        snprintf(buf, sizeof(buf), "%s_up.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_up, buf, width, height);
+       fprintf(stderr, "%s_dn.tga\n", fn);
        snprintf(buf, sizeof(buf), "%s_dn.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_down, buf, width, height);
 }
 
@@ -260,10 +348,18 @@ int main(int argc, char **argv)
                color_mandelbrot_parms[11] = argc<=15 ?   0.5   : atof(argv[15]);
                color_mandelbrot_parms[12] = argc<=16 ?   0.2   : atof(argv[16]);
        }
+       else if(!strcmp(argv[3], "starfield"))
+       {
+               f = color_starfield;
+               color_starfield_parms.n = argc<= 4 ? 8192 : atoi(argv[4]);
+               color_starfield_parms.darkness = argc<= 5 ? 0.4 : atof(argv[5]);
+               color_starfield_parms.power = argc<= 6 ? 2.5 : atof(argv[6]);
+               color_starfield_parms.density = argc<= 7 ? 60000 : atof(argv[7]);
+       }
        else
        {
                f = color_test;
        }
-       map_all(argv[1], color_mandelbrot, res, res);
+       map_all(argv[1], f, res, res);
        return 0;
 }