tavli
diff src/revol.cc @ 14:283eb6e9f0a3
scenery
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 28 Jun 2015 07:44:23 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/revol.cc Sun Jun 28 07:44:23 2015 +0300 1.3 @@ -0,0 +1,44 @@ 1.4 +#include <algorithm> 1.5 +#include "revol.h" 1.6 + 1.7 +Vector2 bezier_revol(float u, float v, void *cls) 1.8 +{ 1.9 + BezCurve *curve = (BezCurve*)cls; 1.10 + int nseg = (curve->numcp - 1) / 2; 1.11 + 1.12 + if(v >= 1.0) v = 1.0 - 1e-6; 1.13 + int cidx = std::min((int)(v * nseg), nseg - 1); 1.14 + float t = fmod(v * (float)nseg, 1.0); 1.15 + 1.16 + const vec2_t *cp = curve->cp + cidx * 2; 1.17 + 1.18 + float resx = bezier(cp[0].x, cp[1].x, cp[1].x, cp[2].x, t); 1.19 + float resy = bezier(cp[0].y, cp[1].y, cp[1].y, cp[2].y, t); 1.20 + return Vector2(resx * curve->scale, resy * curve->scale); 1.21 +} 1.22 + 1.23 +Vector2 bezier_revol_normal(float u, float v, void *cls) 1.24 +{ 1.25 + BezCurve *curve = (BezCurve*)cls; 1.26 + int nseg = (curve->numcp - 1) / 2; 1.27 + 1.28 + if(v >= 1.0) v = 1.0 - 1e-6; 1.29 + int cidx = std::min((int)(v * nseg), nseg - 1); 1.30 + float t = fmod(v * (float)nseg, 1.0); 1.31 + 1.32 + const vec2_t *cp = curve->cp + cidx * 2; 1.33 + Vector2 cp0 = cp[0]; 1.34 + Vector2 cp1 = cp[1]; 1.35 + Vector2 cp2 = cp[2]; 1.36 + 1.37 + Vector2 pprev, pnext; 1.38 + for(int i=0; i<2; i++) { 1.39 + pprev[i] = bezier(cp0[i], cp1[i], cp1[i], cp2[i], t - 0.05); 1.40 + pnext[i] = bezier(cp0[i], cp1[i], cp1[i], cp2[i], t + 0.05); 1.41 + } 1.42 + 1.43 + float tx = pnext.x - pprev.x; 1.44 + float ty = pnext.y - pprev.y; 1.45 + 1.46 + return Vector2(-ty, tx); 1.47 +}