tavli

diff src/board.cc @ 12:ae1c60726c41

better pieces
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 27 Jun 2015 13:53:43 +0300
parents a8e26f163f99
children f3c5134b4914
line diff
     1.1 --- a/src/board.cc	Sat Jun 27 08:01:51 2015 +0300
     1.2 +++ b/src/board.cc	Sat Jun 27 13:53:43 2015 +0300
     1.3 @@ -84,6 +84,28 @@
     1.4  	return res * 0.25 * PIECE_RAD;
     1.5  }
     1.6  
     1.7 +static Vector2 piece_revol_normal(float u, float v, void *cls)
     1.8 +{
     1.9 +	if(v >= 1.0) v = 1.0 - 1e-6;
    1.10 +	int idx = std::min((int)(v * piece_ncurves), piece_ncurves - 1);
    1.11 +	float t = fmod(v * (float)piece_ncurves, 1.0);
    1.12 +
    1.13 +	Vector2 pprev, pnext;
    1.14 +	for(int i=0; i<2; i++) {
    1.15 +		float start = piece_cp[idx][0][i];
    1.16 +		float mid = piece_cp[idx][1][i];
    1.17 +		float end = piece_cp[idx][2][i];
    1.18 +
    1.19 +		pprev[i] = bezier(start, mid, mid, end, t - 0.05);
    1.20 +		pnext[i] = bezier(start, mid, mid, end, t + 0.05);
    1.21 +	}
    1.22 +
    1.23 +	float tx = pnext.x - pprev.x;
    1.24 +	float ty = pnext.y - pprev.y;
    1.25 +
    1.26 +	return Vector2(-ty, tx);
    1.27 +}
    1.28 +
    1.29  bool Board::generate()
    1.30  {
    1.31  	Mesh tmp;
    1.32 @@ -210,10 +232,12 @@
    1.33  	*/
    1.34  
    1.35  	Mesh *piece = new Mesh;
    1.36 -	gen_revol(piece, 18, 15, piece_revol, 0);
    1.37 +	gen_revol(piece, 18, 17, piece_revol, piece_revol_normal, 0);
    1.38  
    1.39  	Object *opiece = new Object;
    1.40  	opiece->set_mesh(piece);
    1.41 +	opiece->mtl.diffuse = Vector3(0.6, 0.6, 0.6);
    1.42 +	opiece->mtl.specular = Vector3(0.8, 0.8, 0.8);
    1.43  	opiece->xform().set_translation(Vector3(0, 0.2, 0));
    1.44  	obj.push_back(opiece);
    1.45