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

panda/src/parametrics/cubicCurveseg.h

Go to the documentation of this file.
00001 // Filename: cubicCurveseg.h
00002 // Created by:  drose (04Mar01)
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 CUBICCURVESEG_H
00020 #define CUBICCURVESEG_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "parametricCurve.h"
00025 
00026 
00027 // These symbols are used to define the shape of the curve segment to
00028 // CubicCurveseg::compute_seg().
00029 
00030 #define RT_POINT       0x01
00031 #define RT_TANGENT     0x02
00032 #define RT_CV          0x03
00033 #define RT_BASE_TYPE   0xff
00034 
00035 #define RT_KEEP_ORIG  0x100
00036 
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //       Class : CubicCurveseg
00040 // Description : A CubicCurveseg is any curve that can be completely
00041 //               described by four 4-valued basis vectors, one for
00042 //               each dimension in three-space, and one for the
00043 //               homogeneous coordinate.  This includes Beziers,
00044 //               Hermites, and NURBS.
00045 //
00046 //               This class encapsulates a single curve segment of the
00047 //               cubic curve.  Normally, when we think of Bezier and
00048 //               Hermite curves, we think of a piecewise collection of
00049 //               such segments.
00050 //
00051 //               Although this class includes methods such as
00052 //               hermite_basis() and nurbs_basis(), to generate a
00053 //               Hermite and NURBS curve segment, respectively, only
00054 //               the final basis vectors are stored: the product of
00055 //               the basis matrix of the corresponding curve type, and
00056 //               its geometry vectors.  This is the minimum
00057 //               information needed to evaluate the curve.  However,
00058 //               the individual CV's that were used to compute these
00059 //               basis vectors are not retained; this might be handled
00060 //               in a subclass (for instance, HermiteCurve).
00061 ////////////////////////////////////////////////////////////////////
00062 class EXPCL_PANDA CubicCurveseg : public ParametricCurve {
00063 PUBLISHED:
00064   virtual bool get_point(float t, LVecBase3f &point) const;
00065   virtual bool get_tangent(float t, LVecBase3f &tangent) const;
00066   virtual bool get_pt(float t, LVecBase3f &point, LVecBase3f &tangent) const;
00067   virtual bool get_2ndtangent(float t, LVecBase3f &tangent2) const;
00068 
00069 public:
00070   CubicCurveseg();
00071   CubicCurveseg(const LMatrix4f &basis);
00072   CubicCurveseg(const BezierSeg &seg);
00073   CubicCurveseg(int order, const float knots[], const LVecBase4f cvs[]);
00074 
00075   virtual ~CubicCurveseg();
00076 
00077   void hermite_basis(const HermiteCurveCV &cv0,
00078                      const HermiteCurveCV &cv1,
00079                      float tlength = 1.0f);
00080   void bezier_basis(const BezierSeg &seg);
00081   void nurbs_basis(int order, const float knots[], const LVecBase4f cvs[]);
00082 
00083   // evaluate_point() and evaluate_vector() both evaluate the curve at
00084   // a given point by applying the basis vector against the vector
00085   // [t3 t2 t 1] (or some derivative).  The difference between the
00086   // two is that evaluate_point() is called only with the vector
00087   // [t3 t2 t 1] and computes a point in three-space and will scale by
00088   // the homogeneous coordinate when the curve demands it (e.g. a
00089   // NURBS), while evaluate_vector() is called with some derivative
00090   // vector like [3t2 2t 1 0] and computes a vector difference between
00091   // points, and will never scale by the homogeneous coordinate (which
00092   // would be zero anyway).
00093 
00094   void evaluate_point(const LVecBase4f &tv, LVecBase3f &result) const {
00095     float recip_h = (rational) ? 1.0f/tv.dot(Bw) : 1.0f;
00096     result.set(tv.dot(Bx) * recip_h,
00097                tv.dot(By) * recip_h,
00098                tv.dot(Bz) * recip_h);
00099   }
00100 
00101   void evaluate_vector(const LVecBase4f &tv, LVecBase3f &result) const {
00102     result.set(tv.dot(Bx),
00103                tv.dot(By),
00104                tv.dot(Bz));
00105   }
00106 
00107   virtual bool get_bezier_seg(BezierSeg &seg) const;
00108 
00109   static bool compute_seg(int rtype0, float t0, const LVecBase4f &v0,
00110                           int rtype1, float t1, const LVecBase4f &v1,
00111                           int rtype2, float t2, const LVecBase4f &v2,
00112                           int rtype3, float t3, const LVecBase4f &v3,
00113                           const LMatrix4f &B,
00114                           const LMatrix4f &Bi,
00115                           LMatrix4f &G);
00116 
00117   LVecBase4f Bx, By, Bz, Bw;
00118   bool rational;
00119 
00120 
00121 // TypedWritable stuff
00122 public:
00123   static void register_with_read_factory();
00124 
00125 protected:
00126   static TypedWritable *make_CubicCurveseg(const FactoryParams &params);
00127   virtual void write_datagram(BamWriter *manager, Datagram &me);
00128   void fillin(DatagramIterator &scan, BamReader *manager);
00129 
00130 public:
00131   static TypeHandle get_class_type() {
00132     return _type_handle;
00133   }
00134   static void init_type() {
00135     ParametricCurve::init_type();
00136     register_type(_type_handle, "CubicCurveseg",
00137                   ParametricCurve::get_class_type());
00138   }
00139   virtual TypeHandle get_type() const {
00140     return get_class_type();
00141   }
00142   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00143 
00144 private:
00145   static TypeHandle _type_handle;
00146 };
00147 
00148 // This function is used internally to build the NURBS basis matrix
00149 // based on a given knot sequence.
00150 void compute_nurbs_basis(int order,
00151                          const float knots_in[],
00152                          LMatrix4f &basis);
00153 
00154 
00155 #endif

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