2 This file is part of the 3dengfx, realtime visualization system.
3 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
5 the 3dengfx library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 the 3dengfx library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with the 3dengfx library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * author: John Tsiombikas 2003
24 * John Tsiombikas 2004, 2005, 2006
25 * Mihalis Georgoulopoulos 2004
31 #include "3dengfx_config.h"
34 #include "n3dmath2/n3dmath2.hpp"
35 #include "common/linkedlist.hpp"
40 LinkedList<Vector3> control_points;
41 Vector2 *samples; // used for parametrizing by arc length
45 Curve *ease_curve; // ease in/out curve (1D, x&z discarded)
46 int ease_sample_count, ease_step;
48 void sample_arc_lengths();
49 scalar_t parametrize(scalar_t t) const;
50 scalar_t ease(scalar_t t) const;
52 Vector3 (*xform_cv)(const Vector3 &pt);
54 virtual Vector3 interpolate(scalar_t t) const = 0;
61 virtual void add_control_point(const Vector3 &cp);
62 virtual void remove_control_point(int index);
63 virtual Vector3 *get_control_point(int index);
65 virtual int get_point_count() const;
66 virtual int get_segment_count() const = 0;
67 virtual void set_arc_parametrization(bool state);
68 virtual void set_ease_curve(Curve *curve);
69 virtual void set_ease_sample_count(int count);
71 virtual Vector3 operator ()(scalar_t t) const;
73 virtual void set_xform_func(Vector3 (*func)(const Vector3&));
75 friend bool save_curve(const char *fname, const Curve *curve);
78 class BSpline : public Curve {
80 virtual Vector3 interpolate(scalar_t t) const;
83 virtual int get_segment_count() const;
86 typedef BSpline BSplineCurve;
89 class CatmullRomSpline : public Curve {
91 virtual Vector3 interpolate(scalar_t t) const;
94 virtual int get_segment_count() const;
97 typedef CatmullRomSpline CatmullRomSplineCurve;
100 class BezierSpline : public Curve {
102 virtual Vector3 interpolate(scalar_t t) const;
105 virtual int get_segment_count() const;
107 Vector3 get_control_point(int i) const;
108 Vector3 get_tangent(scalar_t t);
111 class PolyLine : public Curve {
113 virtual Vector3 interpolate(scalar_t t) const;
116 virtual int get_segment_count() const;
119 bool save_curve(const char *fname, const Curve *curve);
120 Curve *load_curve(const char *fname);
122 #endif // _CURVES_HPP_