# HG changeset patch # User John Tsiombikas # Date 1435402423 -10800 # Node ID ae1c60726c413c14fc7d50cd4d81e5ba40fda98b # Parent a8e26f163f990b899fcec07e3a7f9566827c2444 better pieces diff -r a8e26f163f99 -r ae1c60726c41 src/board.cc --- a/src/board.cc Sat Jun 27 08:01:51 2015 +0300 +++ b/src/board.cc Sat Jun 27 13:53:43 2015 +0300 @@ -84,6 +84,28 @@ return res * 0.25 * PIECE_RAD; } +static Vector2 piece_revol_normal(float u, float v, void *cls) +{ + if(v >= 1.0) v = 1.0 - 1e-6; + int idx = std::min((int)(v * piece_ncurves), piece_ncurves - 1); + float t = fmod(v * (float)piece_ncurves, 1.0); + + Vector2 pprev, pnext; + for(int i=0; i<2; i++) { + float start = piece_cp[idx][0][i]; + float mid = piece_cp[idx][1][i]; + float end = piece_cp[idx][2][i]; + + pprev[i] = bezier(start, mid, mid, end, t - 0.05); + pnext[i] = bezier(start, mid, mid, end, t + 0.05); + } + + float tx = pnext.x - pprev.x; + float ty = pnext.y - pprev.y; + + return Vector2(-ty, tx); +} + bool Board::generate() { Mesh tmp; @@ -210,10 +232,12 @@ */ Mesh *piece = new Mesh; - gen_revol(piece, 18, 15, piece_revol, 0); + gen_revol(piece, 18, 17, piece_revol, piece_revol_normal, 0); Object *opiece = new Object; opiece->set_mesh(piece); + opiece->mtl.diffuse = Vector3(0.6, 0.6, 0.6); + opiece->mtl.specular = Vector3(0.8, 0.8, 0.8); opiece->xform().set_translation(Vector3(0, 0.2, 0)); obj.push_back(opiece); diff -r a8e26f163f99 -r ae1c60726c41 src/meshgen.cc --- a/src/meshgen.cc Sat Jun 27 08:01:51 2015 +0300 +++ b/src/meshgen.cc Sat Jun 27 13:53:43 2015 +0300 @@ -501,6 +501,12 @@ // ------ surface of revolution ------- void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls) { + gen_revol(mesh, usub, vsub, rfunc, 0, cls); +} + +void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), + Vector2 (*nfunc)(float, float, void*), void *cls) +{ if(!rfunc) return; if(usub < 3) usub = 3; if(vsub < 1) vsub = 1; @@ -537,15 +543,20 @@ tang = nextu - pos; } - Vector3 nextv = rev_vert(u, v + dv, rfunc, cls); - Vector3 bitan = nextv - pos; - if(bitan.length_sq() < 1e-6) { - nextv = rev_vert(u, v - dv, rfunc, cls); - bitan = pos - nextv; + Vector3 normal; + if(nfunc) { + normal = rev_vert(u, v, nfunc, cls); + } else { + Vector3 nextv = rev_vert(u, v + dv, rfunc, cls); + Vector3 bitan = nextv - pos; + if(bitan.length_sq() < 1e-6) { + nextv = rev_vert(u, v - dv, rfunc, cls); + bitan = pos - nextv; + } + + normal = cross_product(tang, bitan); } - Vector3 normal = cross_product(tang, bitan); - *varr++ = pos; *narr++ = normal.normalized(); *tarr++ = tang.normalized(); diff -r a8e26f163f99 -r ae1c60726c41 src/meshgen.h --- a/src/meshgen.h Sat Jun 27 08:01:51 2015 +0300 +++ b/src/meshgen.h Sat Jun 27 13:53:43 2015 +0300 @@ -11,6 +11,8 @@ void gen_plane(Mesh *mesh, float width, float height, int usub = 1, int vsub = 1); void gen_heightmap(Mesh *mesh, float width, float height, int usub, int vsub, float (*hf)(float, float, void*), void *hfdata = 0); void gen_box(Mesh *mesh, float xsz, float ysz, float zsz); -void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls); + +void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls = 0); +void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), Vector2 (*nfunc)(float, float, void*), void *cls); #endif // MESHGEN_H_