tavli
changeset 12:ae1c60726c41
better pieces
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 27 Jun 2015 13:53:43 +0300 |
parents | a8e26f163f99 |
children | f3c5134b4914 |
files | src/board.cc src/meshgen.cc src/meshgen.h |
diffstat | 3 files changed, 46 insertions(+), 9 deletions(-) [+] |
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
2.1 --- a/src/meshgen.cc Sat Jun 27 08:01:51 2015 +0300 2.2 +++ b/src/meshgen.cc Sat Jun 27 13:53:43 2015 +0300 2.3 @@ -501,6 +501,12 @@ 2.4 // ------ surface of revolution ------- 2.5 void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls) 2.6 { 2.7 + gen_revol(mesh, usub, vsub, rfunc, 0, cls); 2.8 +} 2.9 + 2.10 +void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), 2.11 + Vector2 (*nfunc)(float, float, void*), void *cls) 2.12 +{ 2.13 if(!rfunc) return; 2.14 if(usub < 3) usub = 3; 2.15 if(vsub < 1) vsub = 1; 2.16 @@ -537,15 +543,20 @@ 2.17 tang = nextu - pos; 2.18 } 2.19 2.20 - Vector3 nextv = rev_vert(u, v + dv, rfunc, cls); 2.21 - Vector3 bitan = nextv - pos; 2.22 - if(bitan.length_sq() < 1e-6) { 2.23 - nextv = rev_vert(u, v - dv, rfunc, cls); 2.24 - bitan = pos - nextv; 2.25 + Vector3 normal; 2.26 + if(nfunc) { 2.27 + normal = rev_vert(u, v, nfunc, cls); 2.28 + } else { 2.29 + Vector3 nextv = rev_vert(u, v + dv, rfunc, cls); 2.30 + Vector3 bitan = nextv - pos; 2.31 + if(bitan.length_sq() < 1e-6) { 2.32 + nextv = rev_vert(u, v - dv, rfunc, cls); 2.33 + bitan = pos - nextv; 2.34 + } 2.35 + 2.36 + normal = cross_product(tang, bitan); 2.37 } 2.38 2.39 - Vector3 normal = cross_product(tang, bitan); 2.40 - 2.41 *varr++ = pos; 2.42 *narr++ = normal.normalized(); 2.43 *tarr++ = tang.normalized();
3.1 --- a/src/meshgen.h Sat Jun 27 08:01:51 2015 +0300 3.2 +++ b/src/meshgen.h Sat Jun 27 13:53:43 2015 +0300 3.3 @@ -11,6 +11,8 @@ 3.4 void gen_plane(Mesh *mesh, float width, float height, int usub = 1, int vsub = 1); 3.5 void gen_heightmap(Mesh *mesh, float width, float height, int usub, int vsub, float (*hf)(float, float, void*), void *hfdata = 0); 3.6 void gen_box(Mesh *mesh, float xsz, float ysz, float zsz); 3.7 -void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls); 3.8 + 3.9 +void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls = 0); 3.10 +void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), Vector2 (*nfunc)(float, float, void*), void *cls); 3.11 3.12 #endif // MESHGEN_H_