tavli

diff src/board.cc @ 14:283eb6e9f0a3

scenery
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 28 Jun 2015 07:44:23 +0300
parents f3c5134b4914
children b1a195c3ee16
line diff
     1.1 --- a/src/board.cc	Sat Jun 27 22:33:27 2015 +0300
     1.2 +++ b/src/board.cc	Sun Jun 28 07:44:23 2015 +0300
     1.3 @@ -1,8 +1,10 @@
     1.4  #include <float.h>
     1.5  #include "opengl.h"
     1.6  #include "board.h"
     1.7 +#include "game.h"
     1.8  #include "meshgen.h"
     1.9  #include "pnoise.h"
    1.10 +#include "revol.h"
    1.11  
    1.12  Board::Board()
    1.13  {
    1.14 @@ -46,7 +48,12 @@
    1.15  void Board::draw() const
    1.16  {
    1.17  	for(size_t i=0; i<obj.size(); i++) {
    1.18 -		obj[i]->draw();
    1.19 +		if(wireframe) {
    1.20 +			obj[i]->draw_wire();
    1.21 +			obj[i]->draw_normals(0.075);
    1.22 +		} else {
    1.23 +			obj[i]->draw();
    1.24 +		}
    1.25  	}
    1.26  }
    1.27  
    1.28 @@ -60,11 +67,6 @@
    1.29  #define HINGE_HEIGHT	(VSIZE * 0.075)
    1.30  #define PIECE_RAD		(0.45 * HSIZE / 5.0)
    1.31  
    1.32 -struct BezCurve {
    1.33 -	int numcp;
    1.34 -	vec2_t *cp;
    1.35 -	float scale;
    1.36 -};
    1.37  
    1.38  static const vec2_t piece_cp[] = {
    1.39  		{0, 0.25},
    1.40 @@ -79,51 +81,13 @@
    1.41  		{2.5, -0.5}, // mid4
    1.42  		{0, -0.5}
    1.43  };
    1.44 -static const BezCurve piece_curve = {sizeof piece_cp / sizeof *piece_cp, (vec2_t*)piece_cp, 0.25 * PIECE_RAD};
    1.45 +static const BezCurve piece_curve = {
    1.46 +	sizeof piece_cp / sizeof *piece_cp,
    1.47 +	(vec2_t*)piece_cp,
    1.48 +	0.25 * PIECE_RAD
    1.49 +};
    1.50  
    1.51  
    1.52 -static Vector2 piece_revol(float u, float v, void *cls)
    1.53 -{
    1.54 -	BezCurve *curve = (BezCurve*)cls;
    1.55 -	int nseg = (curve->numcp - 1) / 2;
    1.56 -
    1.57 -	if(v >= 1.0) v = 1.0 - 1e-6;
    1.58 -	int cidx = std::min((int)(v * nseg), nseg - 1);
    1.59 -	float t = fmod(v * (float)nseg, 1.0);
    1.60 -
    1.61 -	const vec2_t *cp = curve->cp + cidx * 2;
    1.62 -
    1.63 -	float resx = bezier(cp[0].x, cp[1].x, cp[1].x, cp[2].x, t);
    1.64 -	float resy = bezier(cp[0].y, cp[1].y, cp[1].y, cp[2].y, t);
    1.65 -	return Vector2(resx * curve->scale, resy * curve->scale);
    1.66 -}
    1.67 -
    1.68 -static Vector2 piece_revol_normal(float u, float v, void *cls)
    1.69 -{
    1.70 -	BezCurve *curve = (BezCurve*)cls;
    1.71 -	int nseg = (curve->numcp - 1) / 2;
    1.72 -
    1.73 -	if(v >= 1.0) v = 1.0 - 1e-6;
    1.74 -	int cidx = std::min((int)(v * nseg), nseg - 1);
    1.75 -	float t = fmod(v * (float)nseg, 1.0);
    1.76 -
    1.77 -	const vec2_t *cp = curve->cp + cidx * 2;
    1.78 -	Vector2 cp0 = cp[0];
    1.79 -	Vector2 cp1 = cp[1];
    1.80 -	Vector2 cp2 = cp[2];
    1.81 -
    1.82 -	Vector2 pprev, pnext;
    1.83 -	for(int i=0; i<2; i++) {
    1.84 -		pprev[i] = bezier(cp0[i], cp1[i], cp1[i], cp2[i], t - 0.05);
    1.85 -		pnext[i] = bezier(cp0[i], cp1[i], cp1[i], cp2[i], t + 0.05);
    1.86 -	}
    1.87 -
    1.88 -	float tx = pnext.x - pprev.x;
    1.89 -	float ty = pnext.y - pprev.y;
    1.90 -
    1.91 -	return Vector2(-ty, tx);
    1.92 -}
    1.93 -
    1.94  bool Board::generate()
    1.95  {
    1.96  	Mesh tmp;
    1.97 @@ -250,7 +214,7 @@
    1.98  	*/
    1.99  
   1.100  	Mesh *piece = new Mesh;
   1.101 -	gen_revol(piece, 18, 17, piece_revol, piece_revol_normal, (void*)&piece_curve);
   1.102 +	gen_revol(piece, 18, 17, bezier_revol, bezier_revol_normal, (void*)&piece_curve);
   1.103  
   1.104  	Object *opiece = new Object;
   1.105  	opiece->set_mesh(piece);
   1.106 @@ -259,7 +223,6 @@
   1.107  	opiece->xform().set_translation(Vector3(0, 0.2, 0));
   1.108  	obj.push_back(opiece);
   1.109  
   1.110 -
   1.111  	// meshgen stats
   1.112  	printf("Generated board:\n  %u meshes\n", (unsigned int)obj.size());
   1.113  	unsigned int polycount = 0;