tavli
view src/revol.cc @ 16:d6209903454b
opengl capabilities
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 28 Jun 2015 08:48:25 +0300 |
parents | |
children |
line source
1 #include <algorithm>
2 #include "revol.h"
4 Vector2 bezier_revol(float u, float v, void *cls)
5 {
6 BezCurve *curve = (BezCurve*)cls;
7 int nseg = (curve->numcp - 1) / 2;
9 if(v >= 1.0) v = 1.0 - 1e-6;
10 int cidx = std::min((int)(v * nseg), nseg - 1);
11 float t = fmod(v * (float)nseg, 1.0);
13 const vec2_t *cp = curve->cp + cidx * 2;
15 float resx = bezier(cp[0].x, cp[1].x, cp[1].x, cp[2].x, t);
16 float resy = bezier(cp[0].y, cp[1].y, cp[1].y, cp[2].y, t);
17 return Vector2(resx * curve->scale, resy * curve->scale);
18 }
20 Vector2 bezier_revol_normal(float u, float v, void *cls)
21 {
22 BezCurve *curve = (BezCurve*)cls;
23 int nseg = (curve->numcp - 1) / 2;
25 if(v >= 1.0) v = 1.0 - 1e-6;
26 int cidx = std::min((int)(v * nseg), nseg - 1);
27 float t = fmod(v * (float)nseg, 1.0);
29 const vec2_t *cp = curve->cp + cidx * 2;
30 Vector2 cp0 = cp[0];
31 Vector2 cp1 = cp[1];
32 Vector2 cp2 = cp[2];
34 Vector2 pprev, pnext;
35 for(int i=0; i<2; i++) {
36 pprev[i] = bezier(cp0[i], cp1[i], cp1[i], cp2[i], t - 0.05);
37 pnext[i] = bezier(cp0[i], cp1[i], cp1[i], cp2[i], t + 0.05);
38 }
40 float tx = pnext.x - pprev.x;
41 float ty = pnext.y - pprev.y;
43 return Vector2(-ty, tx);
44 }