Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
bspline.cpp
1 /***************************************************************************
2  * Copyright (C) 2009 by Anton R. <commanderkyle@gmail.com> *
3  * *
4  * This file is a part of QAquarelle project. *
5  * *
6  * QAquarelle is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
21 #include "bspline.h"
22 
23 static const float B[3][3] = {
24  {+1.0f, -2.0f, +1.0f},
25  {-2.0f, +2.0f, +0.0f},
26  {+1.0f, +1.0f, +0.0f}
27 };
28 
33 void BSpline::interpolate_quad (int * x, int * y, float t) {
34  const float t_vec[] = {t * t, t, 1.0f};
35  float r_vec[3];
36 
37  r_vec[0] = t_vec[0] * B[0][0] + t_vec[1] * B[1][0] + t_vec[2] * B[2][0];
38  r_vec[1] = t_vec[0] * B[0][1] + t_vec[1] * B[1][1] + t_vec[2] * B[2][1];
39  r_vec[2] = t_vec[0] * B[0][2] + t_vec[1] * B[1][2] + t_vec[2] * B[2][2];
40  r_vec[0] *= 0.5;
41  r_vec[1] *= 0.5;
42  r_vec[2] *= 0.5;
43 
44  x[3] = (int)(r_vec[0] * x[0] + r_vec[1] * x[1] + r_vec[2] * x[2]);
45  y[3] = (int)(r_vec[0] * y[0] + r_vec[1] * y[1] + r_vec[2] * y[2]);
46 }
47 
52 void BSpline::interpolate_quad (float * x, float * y, float t) {
53  const float t_vec[] = {t * t, t, 1.0f};
54  float r_vec[3];
55 
56  r_vec[0] = t_vec[0] * B[0][0] + t_vec[1] * B[1][0] + t_vec[2] * B[2][0];
57  r_vec[1] = t_vec[0] * B[0][1] + t_vec[1] * B[1][1] + t_vec[2] * B[2][1];
58  r_vec[2] = t_vec[0] * B[0][2] + t_vec[1] * B[1][2] + t_vec[2] * B[2][2];
59  r_vec[0] *= 0.5;
60  r_vec[1] *= 0.5;
61  r_vec[2] *= 0.5;
62 
63  x[3] = r_vec[0] * x[0] + r_vec[1] * x[1] + r_vec[2] * x[2];
64  y[3] = r_vec[0] * y[0] + r_vec[1] * y[1] + r_vec[2] * y[2];
65 }
66