planeNode.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Filename: planeNode.h
  2. // Created by: drose (11Jul02)
  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 PLANENODE_H
  15. #define PLANENODE_H
  16. #include "pandabase.h"
  17. #include "plane.h"
  18. #include "pandaNode.h"
  19. #include "updateSeq.h"
  20. #include "geom.h"
  21. #include "cycleData.h"
  22. #include "cycleDataLockedReader.h"
  23. #include "cycleDataReader.h"
  24. #include "cycleDataWriter.h"
  25. #include "cycleDataStageReader.h"
  26. #include "cycleDataStageWriter.h"
  27. #include "pipelineCycler.h"
  28. ////////////////////////////////////////////////////////////////////
  29. // Class : PlaneNode
  30. // Description : A node that contains a plane. This is most often
  31. // used as a clipping plane, but it can serve other
  32. // purposes as well; whenever a plane is needed to be
  33. // defined in some coordinate space in the world.
  34. ////////////////////////////////////////////////////////////////////
  35. class EXPCL_PANDA_PGRAPH PlaneNode : public PandaNode {
  36. PUBLISHED:
  37. PlaneNode(const string &name, const Planef &plane = Planef());
  38. protected:
  39. PlaneNode(const PlaneNode &copy);
  40. public:
  41. virtual void output(ostream &out) const;
  42. virtual PandaNode *make_copy() const;
  43. virtual void xform(const LMatrix4f &mat);
  44. virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
  45. virtual bool is_renderable() const;
  46. PUBLISHED:
  47. INLINE void set_plane(const Planef &plane);
  48. INLINE const Planef &get_plane() const;
  49. INLINE void set_viz_scale(float viz_scale);
  50. INLINE float get_viz_scale() const;
  51. INLINE void set_priority(int priority);
  52. INLINE int get_priority() const;
  53. enum ClipEffect {
  54. CE_visible = 0x0001,
  55. CE_collision = 0x0002,
  56. };
  57. INLINE void set_clip_effect(int clip_effect);
  58. INLINE int get_clip_effect() const;
  59. public:
  60. INLINE static UpdateSeq get_sort_seq();
  61. protected:
  62. virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
  63. int &internal_vertices,
  64. int pipeline_stage,
  65. Thread *current_thread) const;
  66. PT(Geom) get_viz(CullTraverser *trav, CullTraverserData &data);
  67. private:
  68. // The priority is not cycled, because there's no real reason to do
  69. // so, and cycling it makes it difficult to synchronize with the
  70. // ClipPlaneAttribs.
  71. int _priority;
  72. int _clip_effect;
  73. static UpdateSeq _sort_seq;
  74. // This is the data that must be cycled between pipeline stages.
  75. class EXPCL_PANDA_PGRAPH CData : public CycleData {
  76. public:
  77. INLINE CData();
  78. INLINE CData(const CData &copy);
  79. virtual CycleData *make_copy() const;
  80. virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
  81. virtual void fillin(DatagramIterator &scan, BamReader *manager);
  82. virtual TypeHandle get_parent_type() const {
  83. return PlaneNode::get_class_type();
  84. }
  85. Planef _plane;
  86. PT(Geom) _front_viz, _back_viz;
  87. float _viz_scale;
  88. };
  89. PipelineCycler<CData> _cycler;
  90. typedef CycleDataLockedReader<CData> CDLockedReader;
  91. typedef CycleDataReader<CData> CDReader;
  92. typedef CycleDataWriter<CData> CDWriter;
  93. typedef CycleDataStageReader<CData> CDStageReader;
  94. typedef CycleDataStageWriter<CData> CDStageWriter;
  95. public:
  96. static void register_with_read_factory();
  97. virtual void write_datagram(BamWriter *manager, Datagram &dg);
  98. protected:
  99. static TypedWritable *make_from_bam(const FactoryParams &params);
  100. void fillin(DatagramIterator &scan, BamReader *manager);
  101. public:
  102. static TypeHandle get_class_type() {
  103. return _type_handle;
  104. }
  105. static void init_type() {
  106. PandaNode::init_type();
  107. register_type(_type_handle, "PlaneNode",
  108. PandaNode::get_class_type());
  109. }
  110. virtual TypeHandle get_type() const {
  111. return get_class_type();
  112. }
  113. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  114. private:
  115. static TypeHandle _type_handle;
  116. };
  117. #include "planeNode.I"
  118. #endif