dbf-udg

diff src/mballs.cc @ 8:f0a47f46ee45

lalala
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 18 Feb 2013 06:53:44 +0200
parents e09cbb2e9d4f
children 7056437a361b
line diff
     1.1 --- a/src/mballs.cc	Mon Feb 18 05:44:17 2013 +0200
     1.2 +++ b/src/mballs.cc	Mon Feb 18 06:53:44 2013 +0200
     1.3 @@ -23,6 +23,7 @@
     1.4  static float grid[MBALL_GRID_SZ][MBALL_GRID_SZ][MBALL_GRID_SZ];
     1.5  static std::vector<MetaBall> balls;
     1.6  static struct metasurface *msurf;
     1.7 +static float floor_height = -0.95;
     1.8  
     1.9  bool mball_init()
    1.10  {
    1.11 @@ -54,14 +55,61 @@
    1.12  {
    1.13  	update();
    1.14  
    1.15 +	const float blue[] = {0.4, 0.45, 1.0, 1};
    1.16 +	const float dark_red[] = {0.6, 0.2, 0.1, 1};
    1.17 +	const float white[] = {1, 1, 1, 1};
    1.18 +	const float black[] = {0, 0, 0, 1};
    1.19 +
    1.20  	glMatrixMode(GL_MODELVIEW);
    1.21  	glPushMatrix();
    1.22  	glScalef(4.0, 4.0, 4.0);
    1.23  
    1.24 +	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
    1.25 +	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
    1.26 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0);
    1.27 +
    1.28  	glBegin(GL_TRIANGLES);
    1.29  	msurf_polygonize(msurf);
    1.30  	glEnd();
    1.31  
    1.32 +	// floor
    1.33 +	glBegin(GL_QUADS);
    1.34 +	glNormal3f(0, 1, 0);
    1.35 +	glVertex3f(-5, -1, 5);
    1.36 +	glVertex3f(5, -1, 5);
    1.37 +	glVertex3f(5, -1, -5);
    1.38 +	glVertex3f(-5, -1, -5);
    1.39 +	glEnd();
    1.40 +
    1.41 +	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dark_red);
    1.42 +	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
    1.43 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80.0);
    1.44 +
    1.45 +	// box
    1.46 +	glPushMatrix();
    1.47 +	glTranslatef(0, -1.7, 1);
    1.48 +	glScalef(1.05, 1, 0.05);
    1.49 +	glutSolidCube(2.0);
    1.50 +	glPopMatrix();
    1.51 +
    1.52 +	glPushMatrix();
    1.53 +	glTranslatef(0, -1.7, -1);
    1.54 +	glScalef(1.05, 1, 0.05);
    1.55 +	glutSolidCube(2.0);
    1.56 +	glPopMatrix();
    1.57 +
    1.58 +	glPushMatrix();
    1.59 +	glTranslatef(1, -1.7, 0);
    1.60 +	glScalef(0.05, 1, 1);
    1.61 +	glutSolidCube(2.0);
    1.62 +	glPopMatrix();
    1.63 +
    1.64 +	glPushMatrix();
    1.65 +	glTranslatef(-1, -1.7, 0);
    1.66 +	glScalef(0.05, 1, 1);
    1.67 +	glutSolidCube(2.0);
    1.68 +	glPopMatrix();
    1.69 +
    1.70  	glPopMatrix();
    1.71  }
    1.72  
    1.73 @@ -103,6 +151,15 @@
    1.74  			sum += 1000.0;
    1.75  		}
    1.76  	}
    1.77 +
    1.78 +	// floor
    1.79 +	float height = y - floor_height;
    1.80 +	if(height > 1e-6) {
    1.81 +		sum += 1.0 / height;
    1.82 +	} else {
    1.83 +		sum += 1000.0;
    1.84 +	}
    1.85 +
    1.86  	return sum;
    1.87  }
    1.88