X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2F3dengfx%2Fsrc%2Fgfx%2Fcurves.hpp;fp=src%2F3dengfx%2Fsrc%2Fgfx%2Fcurves.hpp;h=0d0887ac8985cfc352ecc768c56ff84f439239b7;hb=6e23259dbabaeb1711a2a5ca25b9cb421f693759;hp=0000000000000000000000000000000000000000;hpb=fe068fa879814784c45e0cb2e65dac489e8f5594;p=summerhack diff --git a/src/3dengfx/src/gfx/curves.hpp b/src/3dengfx/src/gfx/curves.hpp new file mode 100644 index 0000000..0d0887a --- /dev/null +++ b/src/3dengfx/src/gfx/curves.hpp @@ -0,0 +1,122 @@ +/* +This file is part of the 3dengfx, realtime visualization system. +Copyright (c) 2004, 2005 John Tsiombikas + +the 3dengfx library is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +the 3dengfx library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the 3dengfx library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* 3D Curves + * + * author: John Tsiombikas 2003 + * modified: + * John Tsiombikas 2004, 2005, 2006 + * Mihalis Georgoulopoulos 2004 + */ + +#ifndef _CURVES_HPP_ +#define _CURVES_HPP_ + +#include "3dengfx_config.h" + +#include +#include "n3dmath2/n3dmath2.hpp" +#include "common/linkedlist.hpp" + + +class Curve { +protected: + LinkedList control_points; + Vector2 *samples; // used for parametrizing by arc length + int sample_count; + bool arc_parametrize; + + Curve *ease_curve; // ease in/out curve (1D, x&z discarded) + int ease_sample_count, ease_step; + + void sample_arc_lengths(); + scalar_t parametrize(scalar_t t) const; + scalar_t ease(scalar_t t) const; + + Vector3 (*xform_cv)(const Vector3 &pt); + + virtual Vector3 interpolate(scalar_t t) const = 0; + +public: + std::string name; + + Curve(); + virtual ~Curve(); + virtual void add_control_point(const Vector3 &cp); + virtual void remove_control_point(int index); + virtual Vector3 *get_control_point(int index); + + virtual int get_point_count() const; + virtual int get_segment_count() const = 0; + virtual void set_arc_parametrization(bool state); + virtual void set_ease_curve(Curve *curve); + virtual void set_ease_sample_count(int count); + + virtual Vector3 operator ()(scalar_t t) const; + + virtual void set_xform_func(Vector3 (*func)(const Vector3&)); + + friend bool save_curve(const char *fname, const Curve *curve); +}; + +class BSpline : public Curve { +protected: + virtual Vector3 interpolate(scalar_t t) const; + +public: + virtual int get_segment_count() const; +}; + +typedef BSpline BSplineCurve; + + +class CatmullRomSpline : public Curve { +protected: + virtual Vector3 interpolate(scalar_t t) const; + +public: + virtual int get_segment_count() const; +}; + +typedef CatmullRomSpline CatmullRomSplineCurve; + + +class BezierSpline : public Curve { +protected: + virtual Vector3 interpolate(scalar_t t) const; + +public: + virtual int get_segment_count() const; + + Vector3 get_control_point(int i) const; + Vector3 get_tangent(scalar_t t); +}; + +class PolyLine : public Curve { +protected: + virtual Vector3 interpolate(scalar_t t) const; + +public: + virtual int get_segment_count() const; +}; + +bool save_curve(const char *fname, const Curve *curve); +Curve *load_curve(const char *fname); + +#endif // _CURVES_HPP_