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

panda/src/parametrics/hermiteCurve.h

Go to the documentation of this file.
00001 // Filename: hermiteCurve.h
00002 // Created by:  drose (27Feb98)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef HERMITECURVE_H
00020 #define HERMITECURVE_H
00021 
00022 #include "piecewiseCurve.h"
00023 #include "cubicCurveseg.h"
00024 
00025 
00026 BEGIN_PUBLISH //[
00027 // Hermite curve continuity types.
00028 #define HC_CUT         1
00029 // The curve is disconnected at this point.  All points between
00030 // this and the following CV are not part of the curve.
00031 
00032 #define HC_FREE        2
00033 // Tangents are unconstrained.  The curve is continuous, but its first
00034 // derivative is not.  This is G0 geometric continuity.
00035 
00036 #define HC_G1          3
00037 // Tangents are constrained to be collinear.  The curve's derivative
00038 // is not continuous in parametric space, but its geometric slope is.
00039 // The distinction is mainly relevant in the context of animation
00040 // along the curve--when crossing the join point, direction of motion
00041 // will change continuously, but the speed of motion may change
00042 // suddenly.  This is G1 geometric continuity.
00043 
00044 #define HC_SMOOTH     4
00045 // Tangents are constrained to be identical.  The curve and its first
00046 // derivative are continuous in parametric space.  When animating
00047 // motion across the join point, speed and direction of motion will
00048 // change continuously.  This is C1 parametric continuity.
00049 END_PUBLISH //]
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //       Class : HermiteCurveCV
00053 // Description : A single CV of a Hermite curve.  Hermite curve CV's
00054 //               include an in and out tangent, as well as a position.
00055 ////////////////////////////////////////////////////////////////////
00056 class HermiteCurveCV {
00057 public:
00058   HermiteCurveCV();
00059   HermiteCurveCV(const HermiteCurveCV &c);
00060   ~HermiteCurveCV();
00061 
00062   void set_point(const LVecBase3f &point) { _p = point; }
00063   void set_in(const LVecBase3f &in);
00064   void set_out(const LVecBase3f &out);
00065   void set_type(int type);
00066   void set_name(const string &name);
00067 
00068   void format_egg(ostream &out, int indent, int num_dimensions,
00069               bool show_in, bool show_out,
00070               float scale_in, float scale_out) const;
00071 
00072   void write_datagram(BamWriter *manager, Datagram &me) const;
00073   void fillin(DatagramIterator &scan, BamReader *manager);
00074 
00075   LVecBase3f _p, _in, _out;
00076   int _type;
00077   string _name;
00078 };
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //       Class : HermiteCurve
00082 // Description : A parametric curve defined by a sequence of control
00083 //               vertices, each with an in and out tangent.
00084 //
00085 //               This class is actually implemented as a
00086 //               PiecewiseCurve made up of several CubicCurvesegs,
00087 //               each of which is created using the hermite_basis()
00088 //               method.  The HermiteCurve class itself keeps its own
00089 //               list of the CV's that are used to define the curve
00090 //               (since the CubicCurveseg class doesn't retain these).
00091 ////////////////////////////////////////////////////////////////////
00092 class HermiteCurve : public PiecewiseCurve {
00093 PUBLISHED:
00094   HermiteCurve();
00095   HermiteCurve(const ParametricCurve &pc);
00096   virtual ~HermiteCurve();
00097 
00098   int get_num_cvs() const;
00099 
00100   int insert_cv(float t);
00101   int append_cv(int type, float x, float y, float z);
00102   inline int append_cv(int type, const LVecBase3f &v) {
00103     return append_cv(type, v[0], v[1], v[2]);
00104   }
00105 
00106   bool remove_cv(int n);
00107   void remove_all_cvs();
00108 
00109   bool set_cv_type(int n, int type);
00110   bool set_cv_point(int n, float x, float y, float z);
00111   inline bool set_cv_point(int n, const LVecBase3f &v) {
00112     return set_cv_point(n, v[0], v[1], v[2]);
00113   }
00114   bool set_cv_in(int n, float x, float y, float z);
00115   inline bool set_cv_in(int n, const LVecBase3f &v) {
00116     return set_cv_in(n, v[0], v[1], v[2]);
00117   }
00118   bool set_cv_out(int n, float x, float y, float z);
00119   inline bool set_cv_out(int n, const LVecBase3f &v) {
00120     return set_cv_out(n, v[0], v[1], v[2]);
00121   }
00122   bool set_cv_tstart(int n, float tstart);
00123   bool set_cv_name(int n, const char *name);
00124 
00125 
00126   int get_cv_type(int n) const;
00127   const LVecBase3f &get_cv_point(int n) const;
00128   void get_cv_point(int n, LVecBase3f &v) const;
00129   const LVecBase3f &get_cv_in(int n) const;
00130   void get_cv_in(int n, LVecBase3f &v) const;
00131   const LVecBase3f &get_cv_out(int n) const;
00132   void get_cv_out(int n, LVecBase3f &v) const;
00133   float get_cv_tstart(int n) const;
00134   string get_cv_name(int n) const;
00135 
00136   virtual void output(ostream &out) const;
00137   void write_cv(ostream &out, int n) const;
00138 
00139 public:
00140 
00141   CubicCurveseg *get_curveseg(int ti) {
00142     return (CubicCurveseg *)PiecewiseCurve::get_curveseg(ti);
00143   }
00144 
00145   virtual bool
00146   rebuild_curveseg(int rtype0, float t0, const LVecBase4f &v0,
00147                    int rtype1, float t1, const LVecBase4f &v1,
00148                    int rtype2, float t2, const LVecBase4f &v2,
00149                    int rtype3, float t3, const LVecBase4f &v3);
00150 
00151 protected:
00152   virtual bool format_egg(ostream &out, const string &name,
00153                           const string &curve_type, int indent_level) const;
00154 
00155   void invalidate_cv(int n, bool redo_all);
00156   int find_cv(float t);
00157   void recompute_basis();
00158 
00159   pvector<HermiteCurveCV> _points;
00160 
00161 // TypedWritable stuff
00162 public:
00163   static void register_with_read_factory();
00164 
00165 protected:
00166   static TypedWritable *make_HermiteCurve(const FactoryParams &params);
00167   virtual void write_datagram(BamWriter *manager, Datagram &me);
00168   void fillin(DatagramIterator &scan, BamReader *manager);
00169 
00170 public:
00171   static TypeHandle get_class_type() {
00172     return _type_handle;
00173   }
00174   static void init_type() {
00175     register_type(_type_handle, "HermiteCurve");
00176   }
00177   virtual TypeHandle get_type() const {
00178     return get_class_type();
00179   }
00180   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00181 
00182 private:
00183   static TypeHandle _type_handle;
00184 };
00185 
00186 #endif

Generated on Fri May 2 00:40:44 2003 for Panda by doxygen1.3