NGL  6.5
The NCCA Graphics Library
BezierCurve.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #ifndef BEZIER_CURVE_H_
18 #define BEZIER_CURVE_H_
19 // must include types.h first for Real and GLEW if required
22 #include "Types.h"
23 #include "Vec3.h"
24 #include <vector>
25 #include "VAOFactory.h"
26 #include "SimpleVAO.h"
27 
28 namespace ngl
29 {
30 //----------------------------------------------------------------------------------------------------------------------
44 //----------------------------------------------------------------------------------------------------------------------
46 {
47 public :
48  //----------------------------------------------------------------------------------------------------------------------
50  //----------------------------------------------------------------------------------------------------------------------
51  BezierCurve() noexcept;
52  //----------------------------------------------------------------------------------------------------------------------
58  //----------------------------------------------------------------------------------------------------------------------
59  BezierCurve(const Vec3 *_p,unsigned int _nPoints,const Real *_k,unsigned int _nKnots ) noexcept;
60 
61  //----------------------------------------------------------------------------------------------------------------------
66  //----------------------------------------------------------------------------------------------------------------------
67  BezierCurve(const Real *_p,unsigned int _nPoints) noexcept;
68  //----------------------------------------------------------------------------------------------------------------------
71  //----------------------------------------------------------------------------------------------------------------------
72  BezierCurve(const BezierCurve &_c) noexcept;
73  //----------------------------------------------------------------------------------------------------------------------
75  //----------------------------------------------------------------------------------------------------------------------
76  ~BezierCurve() noexcept;
77  //----------------------------------------------------------------------------------------------------------------------
81  //----------------------------------------------------------------------------------------------------------------------
82  void draw() const noexcept;
83  //----------------------------------------------------------------------------------------------------------------------
85  //----------------------------------------------------------------------------------------------------------------------
86  void drawControlPoints() const noexcept;
87  //----------------------------------------------------------------------------------------------------------------------
89  //----------------------------------------------------------------------------------------------------------------------
90  void drawHull() const noexcept;
91  //----------------------------------------------------------------------------------------------------------------------
95  //----------------------------------------------------------------------------------------------------------------------
96  Vec3 getPointOnCurve(Real _value) const noexcept;
97 
98  //----------------------------------------------------------------------------------------------------------------------
101  //----------------------------------------------------------------------------------------------------------------------
102  void addPoint(const Vec3 &_p) noexcept;
103 
104  //----------------------------------------------------------------------------------------------------------------------
109  //----------------------------------------------------------------------------------------------------------------------
110  void addPoint(Real _x, Real _y, Real _z) noexcept;
111  //----------------------------------------------------------------------------------------------------------------------
114  //----------------------------------------------------------------------------------------------------------------------
115  void addKnot(Real _k) noexcept;
116  //----------------------------------------------------------------------------------------------------------------------
118  //----------------------------------------------------------------------------------------------------------------------
119  void createKnots() noexcept;
120  //----------------------------------------------------------------------------------------------------------------------
128  //----------------------------------------------------------------------------------------------------------------------
129  Real coxDeBoor(Real _u,unsigned int _i,unsigned int _k,const std::vector <Real> &_knots) const noexcept;
130 
131  //----------------------------------------------------------------------------------------------------------------------
137  //----------------------------------------------------------------------------------------------------------------------
138  void setLOD(int _lod) noexcept{m_lod=_lod;}
139  //----------------------------------------------------------------------------------------------------------------------
141  //----------------------------------------------------------------------------------------------------------------------
142  void createVAO() noexcept;
143 protected :
144 
145  //----------------------------------------------------------------------------------------------------------------------
147  //----------------------------------------------------------------------------------------------------------------------
149  //----------------------------------------------------------------------------------------------------------------------
151  //----------------------------------------------------------------------------------------------------------------------
152  unsigned int m_order;
153  //----------------------------------------------------------------------------------------------------------------------
155  //----------------------------------------------------------------------------------------------------------------------
156  unsigned int m_lod;
157  //----------------------------------------------------------------------------------------------------------------------
159  //----------------------------------------------------------------------------------------------------------------------
160  unsigned int m_numCP;
161  //----------------------------------------------------------------------------------------------------------------------
163  //----------------------------------------------------------------------------------------------------------------------
164  unsigned int m_degree;
165  //----------------------------------------------------------------------------------------------------------------------
167  //----------------------------------------------------------------------------------------------------------------------
168  unsigned int m_numKnots;
169  //----------------------------------------------------------------------------------------------------------------------
171  //----------------------------------------------------------------------------------------------------------------------
172  std::vector <Vec3> m_cp;
173  //----------------------------------------------------------------------------------------------------------------------
175  //----------------------------------------------------------------------------------------------------------------------
176  std::vector <Real> m_knots;
177  //----------------------------------------------------------------------------------------------------------------------
179  //----------------------------------------------------------------------------------------------------------------------
181  //----------------------------------------------------------------------------------------------------------------------
183  //----------------------------------------------------------------------------------------------------------------------
185 }; // end class BezierCurve
186 } // end NGL Lib namespace
187 #endif // end header file
188 
189 //----------------------------------------------------------------------------------------------------------------------
unsigned int GLuint
Definition: glew.h:280
Generic Bezier Curve Class allowing the user to generate basic curves using a number of different con...
Definition: BezierCurve.h:45
main definition of types and namespace
#define NGL_DLLEXPORT
Definition: Types.h:65
unsigned int m_lod
The level of detail used to calculate how much detail to draw.
Definition: BezierCurve.h:156
std::vector< Vec3 > m_cp
the contol points for the curve
Definition: BezierCurve.h:172
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
std::vector< Real > m_knots
the knot vector for the curve
Definition: BezierCurve.h:176
base class for all VAO from the VAOFactory this defines the base class type with simple draw / bind b...
Definition: AbstractVAO.h:34
a simple 3 tuple container for compatibility with glsl
unsigned int m_degree
The degree of the curve, Calculated from the Number of Control Points.
Definition: BezierCurve.h:164
unsigned int m_numCP
The ammount of Control Points in the Curve.
Definition: BezierCurve.h:160
unsigned int m_order
The Order of the Curve = Degree +1.
Definition: BezierCurve.h:152
GLuint m_listIndex
the display list index created from glCreateLists
Definition: BezierCurve.h:148
AbstractVAO * m_vaoPoints
a vertex array object for our point drawing
Definition: BezierCurve.h:184
unsigned int m_numKnots
The knot vector always has as many values as the numer of verts (cp) + the degree.
Definition: BezierCurve.h:168
AbstractVAO * m_vaoCurve
a vertex array object for our curve drawing
Definition: BezierCurve.h:180
void setLOD(int _lod) noexcept
set the Level of Detail for Drawing
Definition: BezierCurve.h:138