forked from eu07/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spline.h
103 lines (92 loc) · 2.8 KB
/
Spline.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef SplineH
#define SplineH
#include "dumb3d.h"
#include "QueryParserComp.hpp"
using namespace Math3D;
#define B1(t) (t * t * t)
#define B2(t) (3 * t * t * (1 - t))
#define B3(t) (3 * t * (1 - t) * (1 - t))
#define B4(t) ((1 - t) * (1 - t) * (1 - t))
#define Interpolate(t, p1, cp1, cp2, p2) (B4(t) * p1 + B3(t) * cp1 + B2(t) * cp2 + B1(t) * p2)
class TKnot
{
public:
// inline bool IsCurve() { return (!(Point==CPointIn)); };
// inline vector3 GetDirection() { return (CPointOut-Point); };
TKnot();
TKnot(int n);
~TKnot();
inline float GetRoll(float s)
{
if (Next)
{
s /= Length;
return ((1 - s) * fRoll + (s)*Next->fRoll);
}
else
return fRoll;
// (Length-s) (s-Length)
}
vector3 GetDirection(float t = 0);
inline vector3 InterpolateSegm(float t)
{
return (Interpolate(t, Point, CPointOut, Next->CPointIn, Next->Point));
};
float GetTFromS(float s);
bool Init(TKnot *NNext, TKnot *NPrev);
bool InitCPoints();
bool InitLength();
vector3 Point, CPointIn, CPointOut;
float fRoll;
bool IsCurve;
float Length;
TKnot *Next, *Prev;
float fLengthIn, fLengthOut;
bool bSwitchDirectionForward;
bool bSwitchDirectionBackward;
private:
vector3 GetFirstDerivative(float fTime);
float RombergIntegral(float fA, float fB);
};
class TSpline
{
public:
TSpline();
TSpline(AnsiString asNName);
~TSpline();
bool Create(int n, AnsiString asNName = "foo");
bool AssignKnots(TKnot *FirstKnot, int n);
int LoadFromFile(AnsiString FileName, TKnot *FirstKnot = NULL);
int Load(TQueryParserComp *Parser, AnsiString asEndString = "endspline");
float GetLength();
vector3 GetCenter();
TKnot * GetLastKnot();
bool Render();
// inline int NextIndex(int n) { return (n<KnotsCount-1 ? n+1 : 0); };
// inline vector3 InterpolateSegm(int i, float t) { return
// (Interpolate(t,Knots[i].Point,Knots[i].CPointOut,Knots[NextIndex(i)].CPointIn,Knots[NextIndex(i)].Point)
// ); };
// inline vector3 InterpolateSegm(TKnot *Knot, float t) { return
// (Interpolate(t,Knots[i].Point,Knots[i].CPointOut,Knots[NextIndex(i)].CPointIn,Knots[NextIndex(i)].Point)
// ); };
// bool Closed;
// AnsiString asName;
// TKnot *Knots;
TKnot *RootKnot;
bool KnotsAllocated;
int iNumKnots;
// TSpline *Next,*Prev;
// TKnot Next,Prev;
private:
};
bool Connect(TKnot *k1, TKnot *k2);
//---------------------------------------------------------------------------
#endif