tavli

diff src/meshgen.cc @ 12:ae1c60726c41

better pieces
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 27 Jun 2015 13:53:43 +0300
parents a8e26f163f99
children
line diff
     1.1 --- a/src/meshgen.cc	Sat Jun 27 08:01:51 2015 +0300
     1.2 +++ b/src/meshgen.cc	Sat Jun 27 13:53:43 2015 +0300
     1.3 @@ -501,6 +501,12 @@
     1.4  // ------ surface of revolution -------
     1.5  void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*), void *cls)
     1.6  {
     1.7 +	gen_revol(mesh, usub, vsub, rfunc, 0, cls);
     1.8 +}
     1.9 +
    1.10 +void gen_revol(Mesh *mesh, int usub, int vsub, Vector2 (*rfunc)(float, float, void*),
    1.11 +		Vector2 (*nfunc)(float, float, void*), void *cls)
    1.12 +{
    1.13  	if(!rfunc) return;
    1.14  	if(usub < 3) usub = 3;
    1.15  	if(vsub < 1) vsub = 1;
    1.16 @@ -537,15 +543,20 @@
    1.17  				tang = nextu - pos;
    1.18  			}
    1.19  
    1.20 -			Vector3 nextv = rev_vert(u, v + dv, rfunc, cls);
    1.21 -			Vector3 bitan = nextv - pos;
    1.22 -			if(bitan.length_sq() < 1e-6) {
    1.23 -				nextv = rev_vert(u, v - dv, rfunc, cls);
    1.24 -				bitan = pos - nextv;
    1.25 +			Vector3 normal;
    1.26 +			if(nfunc) {
    1.27 +				normal = rev_vert(u, v, nfunc, cls);
    1.28 +			} else {
    1.29 +				Vector3 nextv = rev_vert(u, v + dv, rfunc, cls);
    1.30 +				Vector3 bitan = nextv - pos;
    1.31 +				if(bitan.length_sq() < 1e-6) {
    1.32 +					nextv = rev_vert(u, v - dv, rfunc, cls);
    1.33 +					bitan = pos - nextv;
    1.34 +				}
    1.35 +
    1.36 +				normal = cross_product(tang, bitan);
    1.37  			}
    1.38  
    1.39 -			Vector3 normal = cross_product(tang, bitan);
    1.40 -
    1.41  			*varr++ = pos;
    1.42  			*narr++ = normal.normalized();
    1.43  			*tarr++ = tang.normalized();