Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

bezier.h

Go to the documentation of this file.
00001 /*
00002         ------------------------------------------------------------------------
00003         ClanLib, the platform independent game SDK.
00004 
00005         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00006         version 2. See COPYING for details.
00007 
00008         For a total list of contributers see CREDITS.
00009 
00010         ------------------------------------------------------------------------
00011 
00012         USE AT YOUR OWN RISK TILL THIS CLASS IS EXTENSIVELY TESTED!!! I WILL
00013         REMOVE THIS WARNING ONCE IT BASICALLY WORKS.
00014 
00015         I hate documentation work and I won't document this code before any
00016         one besides me actually uses it. So if you want to use it simply
00017         write a mail on the ClanLib User list and I will do what I can :-)
00018 
00019         1999/12/30      vogel       renamed CL_Bezier to CL_BezierCurve
00020                                 added CL_BezierSurface
00021 
00022         1999/07/07      vogel       initial version
00023 
00024 
00025         BezierCurve TODO: 
00026         
00027         - length and stepping per curve
00028         
00029         stepping per curve means that the generated points are equidistant to 
00030         each other and this requires get_length() working. So at the moment all
00031         that is working is having 'n' equidistant points per segment.
00032         
00033         same applies to BezierSurface.
00034 */
00035 
00037 
00038 #ifndef header_bezier
00039 #define header_bezier
00040 
00041 #include "cl_vector.h"
00042 
00043 class CL_BezierCurve
00044 //: Class for Bezier curves
00045 // This class generates points on a Bezier curve from given control points
00046 {
00047 protected:
00048         CL_Vector *curve;       // the generated curve
00049         CL_Vector *cp;          // control points
00050 
00051         int steps, cs;          // number of steps, curve segments 
00052         bool stepping;          // steps per segment or per curve
00053                 
00054         virtual void make_curve();
00055 
00056 public:
00057         CL_BezierCurve(const CL_Vector *cp, int cs, int steps, bool stepping = true);
00058         //: Constructor
00063 
00064         virtual ~CL_BezierCurve();
00065         //: Destructor
00066         
00067         virtual int get_steps() const { return steps; }
00068         //: Returns the number of steps
00070         
00071         virtual int get_cs() const { return cs; }
00072         //: Returns the number of curve segments
00074 
00075         virtual bool get_stepping() const { return stepping; }
00076         //: Returns whether steps is the number of points per segment or per curve.
00078 
00079         virtual float get_length(int segment = -1) const;
00080         //: Returns the lenght of a segment (or the curve)
00083         
00084         virtual void set_steps(int steps);
00085         //: Sets the number of steps
00087         
00088         virtual void set_stepping(bool stepping);
00089         //: Sets the stepping
00091 
00092         virtual CL_Vector* get_curve() const { return curve; }
00093         //: Returns an array of cs * steps CL_Vectors -> the curve
00095         
00096         virtual CL_Vector* get_control_points() const { return cp; }
00097         //: Returns the 4 * cs control points
00099 
00100         CL_Vector operator [] (int n) { return curve[n]; }
00101         //: Returns the n-th vector of the curve (_doesn't_ return a reference)
00104 };
00105 
00106 
00107 
00108 class CL_BezierSurface
00109 //: Class for Bezier surfaces
00110 // This class generates points on a Bezier surface from given control points
00111 {
00112 protected:
00113         CL_Vector *surface;     // the generated surface
00114         CL_Vector *cp;          // control points
00115 
00116         int xsteps, ysteps;     // number of steps in x and y direction, 
00117         int xs, ys;             // number of surface segments om x and y direction 
00118         bool stepping;          // steps per segment or per surface
00119 
00120         virtual CL_Vector evaluate(float, float, int);
00121         virtual void make_surface();
00122 
00123 public:
00124         CL_BezierSurface(const CL_Vector *cp, int xs, int ys, int xsteps, int ysteps, bool stepping = true);
00125         //: Constructor
00132 
00133         virtual ~CL_BezierSurface();
00134         //: Destructor
00135         
00136         virtual int get_xsteps() const { return xsteps; }
00137         //: Returns the number of steps
00139         
00140         virtual int get_ysteps() const { return ysteps; }
00141         //: Returns the number of steps
00143         
00144         virtual int get_xs() const { return xs; }
00145         //: Returns the number of surface segments
00147 
00148         virtual int get_ys() const { return ys; }
00149         //: Returns the number of surface segments
00151 
00152         virtual bool get_stepping() const { return stepping; }
00153         //: Returns whether steps is the number of points per segment or per curve.
00155 
00156         // virtual float get_length(int segment = -1) const;
00157         //: Nak Nak - don't expect it to be implemented too soon...
00158         //: Returns the length of a segment (or the surface)
00161         
00162         virtual void set_xsteps(int xsteps);
00163         //: Sets the number of steps
00165         
00166         virtual void set_ysteps(int ysteps);
00167         //: Sets the number of steps
00169         
00170         virtual void set_stepping(bool stepping);
00171         //: Sets the stepping
00173 
00174         virtual CL_Vector* get_surface() const { return surface; }
00175         //: Returns an array of xs * xsteps * ys * ysteps CL_Vectors -> the surface
00177         
00178         virtual CL_Vector* get_control_points() const { return cp; }
00179         //: Returns the 16 * xs * ys control points
00181 
00182         CL_Vector operator [] (int n) { return surface[n]; }
00183         //: Returns the n-th vector of the curve (_doesn't_ return a reference)
00186 };
00187 
00188 
00189 
00190 #endif

Generated at Wed Apr 4 19:53:58 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001