tavli

annotate src/revol.cc @ 23:3e6430028d54

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