parametricCurveCollection.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Filename: parametricCurveCollection.h
  2. // Created by: drose (04Mar01)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef NODEPATHCOLLECTION_H
  15. #define NODEPATHCOLLECTION_H
  16. #include "pandabase.h"
  17. #include "parametricCurve.h"
  18. #include "referenceCount.h"
  19. #include "pointerTo.h"
  20. #include "luse.h"
  21. #include "pvector.h"
  22. #include "plist.h"
  23. class ParametricCurveDrawer;
  24. ////////////////////////////////////////////////////////////////////
  25. // Class : ParametricCurveCollection
  26. // Description : This is a set of zero or more ParametricCurves, which
  27. // may or may not be related. If they are related, the
  28. // set should contain no more than one XYZ curve, no
  29. // more than one HPR curve, and zero or more Timewarp
  30. // curves, which can then be evaluated as a unit to
  31. // return a single transformation matrix for a given
  32. // unit of time.
  33. ////////////////////////////////////////////////////////////////////
  34. class EXPCL_PANDA_PARAMETRICS ParametricCurveCollection : public ReferenceCount {
  35. PUBLISHED:
  36. ParametricCurveCollection();
  37. INLINE ~ParametricCurveCollection();
  38. void add_curve(ParametricCurve *curve);
  39. void add_curve(ParametricCurve *curve, int index);
  40. int add_curves(PandaNode *node);
  41. bool remove_curve(ParametricCurve *curve);
  42. void remove_curve(int index);
  43. bool has_curve(ParametricCurve *curve) const;
  44. void clear();
  45. void clear_timewarps();
  46. INLINE int get_num_curves() const;
  47. INLINE ParametricCurve *get_curve(int index) const;
  48. MAKE_SEQ(get_curves, get_num_curves, get_curve);
  49. ParametricCurve *get_xyz_curve() const;
  50. ParametricCurve *get_hpr_curve() const;
  51. ParametricCurve *get_default_curve() const;
  52. int get_num_timewarps() const;
  53. ParametricCurve *get_timewarp_curve(int n) const;
  54. MAKE_SEQ(get_timewarp_curves, get_num_timewarps, get_timewarp_curve);
  55. INLINE PN_stdfloat get_max_t() const;
  56. void make_even(PN_stdfloat max_t, PN_stdfloat segments_per_unit);
  57. void face_forward(PN_stdfloat segments_per_unit);
  58. void reset_max_t(PN_stdfloat max_t);
  59. bool evaluate(PN_stdfloat t, LVecBase3 &xyz, LVecBase3 &hpr) const;
  60. bool evaluate(PN_stdfloat t, LMatrix4 &result, CoordinateSystem cs = CS_default) const;
  61. PN_stdfloat evaluate_t(PN_stdfloat t) const;
  62. INLINE bool evaluate_xyz(PN_stdfloat t, LVecBase3 &xyz) const;
  63. INLINE bool evaluate_hpr(PN_stdfloat t, LVecBase3 &hpr) const;
  64. INLINE bool adjust_xyz(PN_stdfloat t, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
  65. bool adjust_xyz(PN_stdfloat t, const LVecBase3 &xyz);
  66. INLINE bool adjust_hpr(PN_stdfloat t, PN_stdfloat h, PN_stdfloat p, PN_stdfloat r);
  67. bool adjust_hpr(PN_stdfloat t, const LVecBase3 &xyz);
  68. bool recompute();
  69. bool stitch(const ParametricCurveCollection *a,
  70. const ParametricCurveCollection *b);
  71. void output(ostream &out) const;
  72. void write(ostream &out, int indent_level = 0) const;
  73. bool write_egg(Filename filename, CoordinateSystem cs = CS_default);
  74. bool write_egg(ostream &out, const Filename &filename, CoordinateSystem cs);
  75. public:
  76. int r_add_curves(PandaNode *node);
  77. void register_drawer(ParametricCurveDrawer *drawer);
  78. void unregister_drawer(ParametricCurveDrawer *drawer);
  79. private:
  80. bool determine_hpr(PN_stdfloat t, ParametricCurve *xyz_curve, LVecBase3 &hpr) const;
  81. void prepare_add_curve(ParametricCurve *curve);
  82. void prepare_remove_curve(ParametricCurve *curve);
  83. void redraw();
  84. private:
  85. typedef pvector< PT(ParametricCurve) > ParametricCurves;
  86. ParametricCurves _curves;
  87. typedef plist<ParametricCurveDrawer *> DrawerList;
  88. DrawerList _drawers;
  89. };
  90. INLINE ostream &
  91. operator << (ostream &out, const ParametricCurveCollection &col) {
  92. col.output(out);
  93. return out;
  94. }
  95. #include "parametricCurveCollection.I"
  96. #endif