rayfract

changeset 5:48e0e7d33d9e

foo
author John Tsiombikas <nuclear@siggraph.org>
date Sat, 28 May 2011 22:31:07 +0300
parents e4349f5804b9
children 8a9aa21b32cf
files src/gui.cc src/rayfract.cc
diffstat 2 files changed, 41 insertions(+), 22 deletions(-) [+]
line diff
     1.1 --- a/src/gui.cc	Fri Apr 29 07:30:31 2011 +0300
     1.2 +++ b/src/gui.cc	Sat May 28 22:31:07 2011 +0300
     1.3 @@ -1,4 +1,5 @@
     1.4  #include <stdio.h>
     1.5 +#include <math.h>
     1.6  
     1.7  #ifndef __APPLE__
     1.8  #include <GL/glut.h>
     1.9 @@ -11,55 +12,64 @@
    1.10  #include "sdr.h"
    1.11  #include "vmath.h"
    1.12  
    1.13 -
    1.14 -int xsz, ysz;
    1.15  static int show_gui = 1;
    1.16 +static float fiter = 10;
    1.17  
    1.18  extern unsigned int sdr;
    1.19  extern Vector4 seed;
    1.20  extern int iter;
    1.21  extern float err_thres;
    1.22  extern float reflectivity;
    1.23 +extern Vector3 color;
    1.24  
    1.25  int gui_init(int width, int height)
    1.26  {
    1.27 -	xsz = width;
    1.28 -	ysz = height;
    1.29 -
    1.30  	imtk_set_viewport(width, height);
    1.31 -
    1.32 -	/*imtk_set_alpha(0.5);*/
    1.33 +	imtk_set_alpha(0.5);
    1.34  	return 0;
    1.35  }
    1.36  
    1.37  void gui_draw()
    1.38  {
    1.39 +
    1.40  	if(!show_gui) {
    1.41  		return;
    1.42  	}
    1.43  
    1.44  	imtk_begin();
    1.45 +	imtk_layout_start(10, 10, 10, IMTK_HORIZONTAL);
    1.46  
    1.47 -	imtk_label("seed x", 10, 20);
    1.48 -	seed.x = imtk_slider(IMUID, seed.x, -1.0, 1.0, 80, 20);
    1.49 +	imtk_label("seed x", IMTK_AUTO, IMTK_AUTO);
    1.50 +	seed.x = imtk_slider(IMUID, seed.x, -1.0, 1.0, IMTK_AUTO, IMTK_AUTO);
    1.51 +	imtk_layout_newline();
    1.52  
    1.53 -	imtk_label("seed y", 10, 50);
    1.54 -	seed.y = imtk_slider(IMUID, seed.y, -1.0, 1.0, 80, 50);
    1.55 +	imtk_label("seed y", IMTK_AUTO, IMTK_AUTO);
    1.56 +	seed.y = imtk_slider(IMUID, seed.y, -1.0, 1.0, IMTK_AUTO, IMTK_AUTO);
    1.57 +	imtk_layout_newline();
    1.58  
    1.59 -	imtk_label("seed z", 10, 80);
    1.60 -	seed.z = imtk_slider(IMUID, seed.z, -1.0, 1.0, 80, 80);
    1.61 +	imtk_label("seed z", IMTK_AUTO, IMTK_AUTO);
    1.62 +	seed.z = imtk_slider(IMUID, seed.z, -1.0, 1.0, IMTK_AUTO, IMTK_AUTO);
    1.63 +	imtk_layout_newline();
    1.64  
    1.65 -	imtk_label("seed w", 10, 110);
    1.66 -	seed.w = imtk_slider(IMUID, seed.w, -1.0, 1.0, 80, 110);
    1.67 +	imtk_label("seed w", IMTK_AUTO, IMTK_AUTO);
    1.68 +	seed.w = imtk_slider(IMUID, seed.w, -2.0, 2.0, IMTK_AUTO, IMTK_AUTO);
    1.69 +	imtk_layout_newline();
    1.70  
    1.71 -	imtk_label("iterations", 10, 140);
    1.72 -	iter = imtk_slider(IMUID, iter, 0, 32, 80, 140);
    1.73 +	imtk_label("iterations", IMTK_AUTO, IMTK_AUTO);
    1.74 +	fiter = imtk_slider(IMUID, fiter, 0, 32, IMTK_AUTO, IMTK_AUTO);
    1.75 +	iter = round(fiter);
    1.76 +	imtk_layout_newline();
    1.77  
    1.78 -	imtk_label("max error", 10, 170);
    1.79 -	err_thres = imtk_slider(IMUID, err_thres, 0, 0.075, 80, 170);
    1.80 +	imtk_label("max error", IMTK_AUTO, IMTK_AUTO);
    1.81 +	err_thres = imtk_slider(IMUID, err_thres, 0, 0.075, IMTK_AUTO, IMTK_AUTO);
    1.82  
    1.83 -	imtk_label("reflectivity", 280, 20);
    1.84 -	reflectivity = imtk_slider(IMUID, reflectivity, 0, 1.0, 350, 20);
    1.85 +	imtk_layout_start(280, 10, 10, IMTK_HORIZONTAL);
    1.86 +	imtk_label("reflectivity", IMTK_AUTO, IMTK_AUTO);
    1.87 +	reflectivity = imtk_slider(IMUID, reflectivity, 0, 1.0, IMTK_AUTO, IMTK_AUTO);
    1.88 +	imtk_layout_newline();
    1.89 +
    1.90 +	imtk_label("diffuse", IMTK_AUTO, IMTK_AUTO);
    1.91 +	color.x = color.y = color.z = imtk_slider(IMUID, color.x, 0, 1.0, IMTK_AUTO, IMTK_AUTO);
    1.92  
    1.93  	imtk_end();
    1.94  }
     2.1 --- a/src/rayfract.cc	Fri Apr 29 07:30:31 2011 +0300
     2.2 +++ b/src/rayfract.cc	Sat May 28 22:31:07 2011 +0300
     2.3 @@ -31,7 +31,7 @@
     2.4  float err_thres = 0.0075;
     2.5  int iter = 10;
     2.6  float reflectivity = 0.2;
     2.7 -Vector3 color(0.9, 0.95, 1.0);
     2.8 +Vector3 color(0.75, 0.75, 0.75);
     2.9  
    2.10  int main(int argc, char **argv)
    2.11  {
    2.12 @@ -109,6 +109,7 @@
    2.13  	set_uniform_float(sdr, "reflectivity", reflectivity);
    2.14  	set_uniform_int(sdr, "iter", iter);
    2.15  	set_uniform_float(sdr, "err_thres", err_thres);
    2.16 +	set_uniform_float3(sdr, "diffuse_color", color.x, color.y, color.z);
    2.17  
    2.18  	glMatrixMode(GL_TEXTURE);
    2.19  	glPushMatrix();
    2.20 @@ -145,6 +146,8 @@
    2.21  	glLoadIdentity();
    2.22  	gluPerspective(45.0, (float)x / (float)y, 1.0, 1000.0);
    2.23  
    2.24 +	imtk_set_viewport(x, y);
    2.25 +
    2.26  	if(ray_tex) {
    2.27  		glDeleteTextures(1, &ray_tex);
    2.28  	}
    2.29 @@ -207,6 +210,12 @@
    2.30  			glutPostRedisplay();
    2.31  		}
    2.32  		break;
    2.33 +
    2.34 +	case '\n':
    2.35 +	case '\r':
    2.36 +		printf("(%.3f %+.3fi %+.3fj %+.3fk) i:%d err: %.4f cam(theta: %.2f phi: %.2f rad: %.2f)\n", seed.w,
    2.37 +				seed.x, seed.y, seed.z, iter, err_thres, cam_theta, cam_phi, cam_dist);
    2.38 +		break;
    2.39  	}
    2.40  
    2.41  	imtk_inp_key(key, 1);