tavli

diff src/board.cc @ 18:986c0b76513f

shadows, not completed
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 29 Jun 2015 01:29:36 +0300
parents 16a420432aa3
children 37dead56f01e
line diff
     1.1 --- a/src/board.cc	Sun Jun 28 23:04:37 2015 +0300
     1.2 +++ b/src/board.cc	Mon Jun 29 01:29:36 2015 +0300
     1.3 @@ -21,6 +21,28 @@
     1.4  #define PIECES_PER_LAYER	5
     1.5  
     1.6  
     1.7 +static const vec2_t piece_cp[] = {
     1.8 +		{0, 0.25},
     1.9 +		{1, 0.25},	// mid0
    1.10 +		{2, 0.5},
    1.11 +		{2.5, 0.5},	// mid1
    1.12 +		{3, 0.5},
    1.13 +		{4, 0.5},	// mid2
    1.14 +		{4, 0},
    1.15 +		{4, -0.5},	// mid3
    1.16 +		{3, -0.5},
    1.17 +		{2.5, -0.5}, // mid4
    1.18 +		{0, -0.5}
    1.19 +};
    1.20 +static const BezCurve piece_curve = {
    1.21 +	sizeof piece_cp / sizeof *piece_cp,
    1.22 +	(vec2_t*)piece_cp,
    1.23 +	0.25 * PIECE_RAD
    1.24 +};
    1.25 +
    1.26 +#define PIECE_HEIGHT	(0.25 * PIECE_RAD)
    1.27 +
    1.28 +
    1.29  Piece::Piece()
    1.30  {
    1.31  	owner = 0;
    1.32 @@ -138,7 +160,7 @@
    1.33  	int layer = level / PIECES_PER_LAYER;
    1.34  	int layer_level = level % PIECES_PER_LAYER;
    1.35  
    1.36 -	pos.y = (layer + 1) * 0.25 * PIECE_RAD;
    1.37 +	pos.y = (layer + 0.5) * PIECE_HEIGHT;
    1.38  
    1.39  	pos.z = (-VSIZE * 0.5 + PIECE_RAD + PIECE_RAD * 2.0 * layer_level);
    1.40  	if(top_side) {
    1.41 @@ -168,28 +190,13 @@
    1.42  }
    1.43  
    1.44  
    1.45 -static const vec2_t piece_cp[] = {
    1.46 -		{0, 0.25},
    1.47 -		{1, 0.25},	// mid0
    1.48 -		{2, 0.5},
    1.49 -		{2.5, 0.5},	// mid1
    1.50 -		{3, 0.5},
    1.51 -		{4, 0.5},	// mid2
    1.52 -		{4, 0},
    1.53 -		{4, -0.5},	// mid3
    1.54 -		{3, -0.5},
    1.55 -		{2.5, -0.5}, // mid4
    1.56 -		{0, -0.5}
    1.57 -};
    1.58 -static const BezCurve piece_curve = {
    1.59 -	sizeof piece_cp / sizeof *piece_cp,
    1.60 -	(vec2_t*)piece_cp,
    1.61 -	0.25 * PIECE_RAD
    1.62 -};
    1.63 -
    1.64 -
    1.65  bool Board::generate()
    1.66  {
    1.67 +	static const float board_spec = 0.4;
    1.68 +	bool use_shadows = opt.shadows && sdr_shadow;
    1.69 +	unsigned int board_sdr = use_shadows ? sdr_shadow : sdr_phong;
    1.70 +	unsigned int piece_sdr = use_shadows ? sdr_shadow_notex : sdr_phong_notex;
    1.71 +
    1.72  	Mesh tmp;
    1.73  	Matrix4x4 xform;
    1.74  
    1.75 @@ -208,6 +215,8 @@
    1.76  		obottom->set_mesh(bottom);
    1.77  		obottom->xform().set_translation(Vector3(sign * BOARD_OFFSET, 0, 0));
    1.78  		obottom->set_texture(img_field.texture());
    1.79 +		obottom->set_shader(board_sdr);
    1.80 +		obottom->mtl.specular = Vector3(board_spec, board_spec, board_spec);
    1.81  		obj.push_back(obottom);
    1.82  
    1.83  
    1.84 @@ -248,6 +257,8 @@
    1.85  		osides->set_texture(img_wood.texture());
    1.86  		osides->tex_xform().set_scaling(Vector3(2, 2, 2));
    1.87  		osides->tex_xform().rotate(-Vector3(1, 0, 0.5), M_PI / 4.0);
    1.88 +		osides->mtl.specular = Vector3(board_spec, board_spec, board_spec);
    1.89 +		osides->set_shader(board_sdr);
    1.90  		obj.push_back(osides);
    1.91  
    1.92  	}
    1.93 @@ -321,7 +332,7 @@
    1.94  	opiece->mtl.diffuse = Vector3(0.6, 0.6, 0.6);
    1.95  	opiece->mtl.specular = Vector3(0.8, 0.8, 0.8);
    1.96  	opiece->xform().set_translation(Vector3(0, 0.2, 0));
    1.97 -	opiece->set_shader(sdr_phong_notex);
    1.98 +	opiece->set_shader(piece_sdr);
    1.99  	//obj.push_back(opiece);
   1.100  
   1.101  	piece_obj = opiece;