## tavli

### diff src/board.cc @ 11:a8e26f163f99

poulia
author John Tsiombikas Sat, 27 Jun 2015 08:01:51 +0300 8a167149985d ae1c60726c41
line diff
```     1.1 --- a/src/board.cc	Fri Jun 26 05:41:18 2015 +0300
1.2 +++ b/src/board.cc	Sat Jun 27 08:01:51 2015 +0300
1.3 @@ -1,3 +1,4 @@
1.4 +#include <float.h>
1.5  #include "opengl.h"
1.6  #include "board.h"
1.7  #include "meshgen.h"
1.8 @@ -57,6 +58,31 @@
1.9  #define GAP				(HSIZE * 0.025)
1.10  #define HINGE_RAD		(GAP * 0.5)
1.11  #define HINGE_HEIGHT	(VSIZE * 0.075)
1.12 +#define PIECE_RAD		(0.45 * HSIZE / 5.0)
1.13 +
1.14 +static const float piece_cp[][3][2] = {
1.15 +	{{0, 0.25}, {1, 0.25}, {2, 0.5}},
1.16 +	{{2, 0.5}, {2.5, 0.5}, {3, 0.5}},
1.17 +	{{3, 0.5}, {4, 0.5}, {4, 0}},
1.18 +	{{4, 0}, {4, -0.5}, {3, -0.5}},
1.19 +	{{3, -0.5}, {2.5, -0.5}, {0, -0.5}},
1.20 +	//{{2, -0.5}, {1, -0.25}, {0, -0.25}}
1.21 +};
1.22 +static const int piece_ncurves = sizeof piece_cp / sizeof *piece_cp;
1.23 +
1.24 +static Vector2 piece_revol(float u, float v, void *cls)
1.25 +{
1.26 +	if(v >= 1.0) v = 1.0 - 1e-6;
1.27 +	int idx = std::min((int)(v * piece_ncurves), piece_ncurves - 1);
1.28 +	float t = fmod(v * (float)piece_ncurves, 1.0);
1.29 +
1.30 +	Vector2 res;
1.31 +	for(int i=0; i<2; i++) {
1.32 +		float mid = piece_cp[idx][1][i];
1.33 +		res[i] = bezier(piece_cp[idx][0][i], mid, mid, piece_cp[idx][2][i], t);
1.34 +	}
1.35 +	return res * 0.25 * PIECE_RAD;
1.36 +}
1.37
1.38  bool Board::generate()
1.39  {
1.40 @@ -129,7 +155,7 @@
1.41  		float sign = i * 2 - 1;
1.42
1.43  		// barrel
1.44 -		gen_cylinder(&tmp, HINGE_RAD, HINGE_HEIGHT, 10, 1, 1);
1.45 +		gen_cylinder(&tmp, HINGE_RAD, HINGE_HEIGHT, 8, 1, 1);
1.46  		xform.reset_identity();
1.47  		xform.translate(Vector3(0, WALL_HEIGHT - HINGE_RAD * 0.5, sign * VSIZE / 4.0));
1.48  		xform.rotate(Vector3(-M_PI / 2.0, 0, 0));
1.49 @@ -183,6 +209,15 @@
1.50  	obj.push_back(dbgobj);
1.51  	*/
1.52
1.53 +	Mesh *piece = new Mesh;
1.54 +	gen_revol(piece, 18, 15, piece_revol, 0);
1.55 +
1.56 +	Object *opiece = new Object;
1.57 +	opiece->set_mesh(piece);
1.58 +	opiece->xform().set_translation(Vector3(0, 0.2, 0));
1.59 +	obj.push_back(opiece);
1.60 +
1.61 +
1.62  	// meshgen stats
1.63  	printf("Generated board:\n  %u meshes\n", (unsigned int)obj.size());
1.64  	unsigned int polycount = 0;
```