voxfract

changeset 1:d0297d001505 tip

some command line options
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 15 Jun 2017 05:10:00 +0300
parents 8171de5a000b
children
files Makefile src/main.c
diffstat 2 files changed, 55 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Wed Jun 14 18:03:57 2017 +0300
     1.2 +++ b/Makefile	Thu Jun 15 05:10:00 2017 +0300
     1.3 @@ -2,7 +2,7 @@
     1.4  obj = $(src:.c=.o)
     1.5  bin = voxfract
     1.6  
     1.7 -CFLAGS = -pedantic -Wall -g
     1.8 +CFLAGS = -pedantic -Wall -g -O3 -ffast-math
     1.9  LDFLAGS = -lGL -lGLU -lglut -lmetasurf -lm
    1.10  
    1.11  $(bin): $(obj)
     2.1 --- a/src/main.c	Wed Jun 14 18:03:57 2017 +0300
     2.2 +++ b/src/main.c	Thu Jun 15 05:10:00 2017 +0300
     2.3 @@ -22,15 +22,15 @@
     2.4  
     2.5  int julia(struct quat *qres, struct quat *qprime, struct quat *q, struct quat *seed, int max_iter);
     2.6  float julia_dist(struct quat *z, struct quat *seed, int max_iter);
     2.7 -void julia_grad(float *grad, float dist, struct quat *q, struct quat *seed, int max_iter);
     2.8 +void julia_grad(float *grad, struct quat *q, struct quat *seed, int max_iter);
     2.9  
    2.10  void show_waitscr(void);
    2.11  
    2.12  float cam_theta, cam_phi = 25, cam_dist = 5;
    2.13 -int grid_size = 350;
    2.14 +int grid_size = 300;
    2.15  float grid_scale = 1.7;
    2.16  struct quat seed = {0.4, 0.0, 0.0, -0.8};
    2.17 -int max_iter = 9;
    2.18 +int max_iter = 10;
    2.19  
    2.20  struct metasurface *msurf;
    2.21  int dlist;
    2.22 @@ -38,6 +38,41 @@
    2.23  
    2.24  int main(int argc, char **argv)
    2.25  {
    2.26 +	int i;
    2.27 +
    2.28 +	for(i=1; i<argc; i++) {
    2.29 +		if(argv[i][0] == '-') {
    2.30 +			if(argv[i][2] != 0) {
    2.31 +				fprintf(stderr, "invalid option: %s\n", argv[i]);
    2.32 +				return 1;
    2.33 +			}
    2.34 +			switch(argv[i][1]) {
    2.35 +			case 'g':
    2.36 +				if((grid_size = atoi(argv[++i])) <= 0) {
    2.37 +					fprintf(stderr, "invalid grid size value: %s\n", argv[i]);
    2.38 +					return 1;
    2.39 +				}
    2.40 +				break;
    2.41 +
    2.42 +			case 'i':
    2.43 +				if((max_iter = atoi(argv[++i])) <= 0) {
    2.44 +					fprintf(stderr, "invalid iterations count: %s\n", argv[i]);
    2.45 +					return 1;
    2.46 +				}
    2.47 +				break;
    2.48 +
    2.49 +			default:
    2.50 +				fprintf(stderr, "invalid option: %s\n", argv[i]);
    2.51 +				return 1;
    2.52 +			}
    2.53 +		} else {
    2.54 +			fprintf(stderr, "unexpected argument: %s\n", argv[i]);
    2.55 +			return 1;
    2.56 +		}
    2.57 +	}
    2.58 +	printf("grid size: %d\n", grid_size);
    2.59 +	printf("max iter: %d\n", max_iter);
    2.60 +
    2.61  	glutInit(&argc, argv);
    2.62  	glutInitWindowSize(800, 600);
    2.63  	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    2.64 @@ -128,9 +163,20 @@
    2.65  
    2.66  void keypress(unsigned char key, int x, int y)
    2.67  {
    2.68 +	static int flat;
    2.69 +
    2.70  	switch(key) {
    2.71  	case 27:
    2.72  		exit(0);
    2.73 +
    2.74 +	case 's':
    2.75 +		flat = !flat;
    2.76 +		if(flat) {
    2.77 +			glShadeModel(GL_FLAT);
    2.78 +		} else {
    2.79 +			glShadeModel(GL_SMOOTH);
    2.80 +		}
    2.81 +		glutPostRedisplay();
    2.82  	}
    2.83  }
    2.84  
    2.85 @@ -184,7 +230,6 @@
    2.86  void vertex(struct metasurface *ms, float x, float y, float z)
    2.87  {
    2.88  	struct quat q;
    2.89 -	float dist;
    2.90  	float norm[3];
    2.91  	float norm_len, nscale = 1.0;
    2.92  
    2.93 @@ -193,13 +238,11 @@
    2.94  	q.y = grid_scale * z;
    2.95  	q.z = 0.0f;
    2.96  
    2.97 -	dist = julia_dist(&q, &seed, max_iter);
    2.98 -
    2.99 -	julia_grad(norm, dist, &q, &seed, max_iter);
   2.100 +	julia_grad(norm, &q, &seed, max_iter);
   2.101  	norm_len = sqrt(norm[0] * norm[0] + norm[1] * norm[1] + norm[2] * norm[2]);
   2.102  
   2.103 -	if(norm_len != 0.0f) {
   2.104 -		nscale = 1.0f / norm_len;
   2.105 +	if(norm_len != 0.0) {
   2.106 +		nscale = 1.0 / norm_len;
   2.107  	}
   2.108  
   2.109  	glNormal3f(norm[0] * nscale, norm[1] * nscale, norm[2] * nscale);
   2.110 @@ -284,8 +327,8 @@
   2.111  	return 0.5 * lenq * log(lenq) / lenqp;
   2.112  }
   2.113  
   2.114 -#define OFFS 1e-4
   2.115 -void julia_grad(float *grad, float dist, struct quat *q, struct quat *seed, int max_iter)
   2.116 +#define OFFS 1e-5
   2.117 +void julia_grad(float *grad, struct quat *q, struct quat *seed, int max_iter)
   2.118  {
   2.119  	struct quat qnext = *q;
   2.120  	struct quat qprev = *q;