GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Effect2.hh
Go to the documentation of this file.
1//
2// Copyright (C) 2009 Tero Pulkkinen
3// Released under LGPL License.
4//
5// This file is part of Polygon.
6//
7// Polygon is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Polygon is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Library General Public License
18// along with Polygon. If not, see <http://www.gnu.org/licenses/>.
19//
20
21
22#include "Effect.hh"
23
24class BezierCurve : public CurveIn3d
25{
26public:
28
29 Point Index(float pos) const
30 {
31 //std::cout << "Bezier: " << pos << std::endl;
32 int count = p.NumPoints();
33 Vector val(0.0,0.0,0.0);
34 for(int i=0;i<count;i++)
35 {
36 val += bin(pos,i,count-1)*Vector(p.Points(i));
37 //std::cout << "val: " << p.Points(i) << ":" << bin(pos,i,count-1) << ":" << val << std::endl;
38 }
39 return Point(val);
40 }
41 float bin(float pos, int i, int n) const
42 {
43 return float(ni(n,i)) * pow(double(pos), double(i))*pow(double(1.0-pos), double(n-i));
44 }
45 int ni(int n, int i) const
46 {
47 if (i==0) { return 1; }
48 if (n==i) { return 1; }
49 return ni(n-1,i-1)+ni(n-1,i);
50 }
51 float Size() const
52 {
53 return 1.0;
54 }
55private:
57};
58
59class BezierPath : public MatrixCurve
60{
61public:
62 BezierPath(PointCollection &coll) : bezier(coll),move(bezier) { }
63 float Size() const { return move.Size(); }
64 Matrix Index(float x) const { return move.Index(x); }
65private:
66 BezierCurve bezier;
67 CurveMovement move;
68};
69
70
72{
73public:
74#if 0
75 ConnectCurves(CurveIn3d &curve, CurveIn3d &curve2) : curve(curve), curve2(curve2), p0(curve.Index(curve.Size()*5/6)), p1(curve.Index(curve.Size())), p2(curve2.Index(0.0)), p3(curve2.Index(curve2.Size()*1/6)), vec(&p0, &p3+1), bezier(conv) { }
76 float Size() const { return curve.Size()+bezier.Size()+curve2.Size(); }
77 Point Index(float x) const
78 {
79 if (x<curve.Size())
80 {
81 return curve.Index(x);
82 }
83 else if (x < curve.Size()+bezier.Size())
84 {
85 return bezier.Index(1.0-(x-curve.Size()));
86 }
87 else
88 {
89 return curve2.Index(x-curve.Size()-bezier.Size());
90 }
91 }
92private:
93 CurveIn3d &curve, &curve2;
94 Point p0,p1,p2,p3;
96 //PointCollectionConvert conv;
97 BezierCurve bezier;
98#endif
99};
100
101#if 0
102void LinkDist(const Point2d &p1, const Point2d &p2, Point2d &ptarget, Point2d &ptarget2, float dist1, float dist2);
103
104
105class Circle
106{
107public:
108 Circle(float r) : r(r) { }
109 typedef float A;
110 typedef std::pair<float,float> B;
111 B f(A a) const { return make_pair(r*cos(a), r*sin(a)); }
112private:
113 float r;
114};
115
116template<class I1, class I2>
117class Intersection
118{
119 Intersection(I1 i1, I2 i2) : i1(i1), i2(i2) { }
120 typedef bool A;
121 typedef std::pair<float,float> B;
122 B f(A a) const { return i1.f(f1(a)); }
123 B f2(A a) const { return i2.f(f2(a)); }
124 virtual I1::A f1(A i)=0;
125 virtual I2::A f2(A i)=0;
126private:
127 I1 i1;
128 I2 i2;
129};
130#endif
131
132
133
void LinkDist(const Point2d &p1, const Point2d &p2, Point2d &ptarget, Point2d &ptarget2, float dist1, float dist2)
Definition Effect2.cc:9
virtual I Size() const =0
Definition Effect2.hh:25
float bin(float pos, int i, int n) const
Definition Effect2.hh:41
float Size() const
Definition Effect2.hh:51
Point Index(float pos) const
Definition Effect2.hh:29
BezierCurve(PointCollection &p)
Definition Effect2.hh:27
int ni(int n, int i) const
Definition Effect2.hh:45
float Size() const
Definition Effect2.hh:63
BezierPath(PointCollection &coll)
Definition Effect2.hh:62
Matrix Index(float x) const
Definition Effect2.hh:64
Definition Effect.hh:2060
Circle()
Definition Effect.hh:2062
Definition Effect2.hh:72
Definition EffectI.hh:49
Definition Effect.hh:4565
virtual B Index(A a) const =0
Definition Equalizer.hh:478
Intersection(PowerSet< A > &m, PowerSet< A > &m2)
Definition Equalizer.hh:480
Definition Effect.hh:1582
Definition VectorTools.hh:279
Definition Effect.hh:2456
Definition Effect.hh:1122
Definition VectorTools.hh:125
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition VectorTools.hh:910
Definition Parser.cc:60