Panda3D
compassEffect.h
1 // Filename: compassEffect.h
2 // Created by: drose (16Jul02)
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 
15 #ifndef COMPASSEFFECT_H
16 #define COMPASSEFFECT_H
17 
18 #include "pandabase.h"
19 
20 #include "renderEffect.h"
21 #include "luse.h"
22 #include "nodePath.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : CompassEffect
26 // Description : A CompassEffect causes a node to inherit its rotation
27 // (or pos or scale, if specified) from some other
28 // reference node in the graph, or more often from the
29 // root.
30 //
31 // In its purest form, a CompassEffect is used to keep
32 // the node's rotation fixed relative to the top of the
33 // scene graph, despite other transforms that may exist
34 // above the node. Hence the name: the node behaves
35 // like a magnetic compass, always pointing in the same
36 // direction.
37 //
38 // As an couple of generalizing extensions, the
39 // CompassEffect may also be set up to always orient its
40 // node according to some other reference node than the
41 // root of the scene graph. Furthermore, it may
42 // optionally adjust any of pos, rotation, or scale,
43 // instead of necessarily rotation; and it may adjust
44 // individual pos and scale components. (Rotation may
45 // not be adjusted on an individual component basis;
46 // that's just asking for trouble.)
47 //
48 // Be careful when using the pos and scale modes. In
49 // these modes, it's possible for the CompassEffect to
50 // move its node far from its normal bounding volume,
51 // causing culling to fail. If this is an issue, you
52 // may need to explicitly set a large (or infinite)
53 // bounding volume on the effect node.
54 ////////////////////////////////////////////////////////////////////
55 class EXPCL_PANDA_PGRAPH CompassEffect : public RenderEffect {
56 private:
57  INLINE CompassEffect();
58 
59 PUBLISHED:
60  enum Properties {
61  P_x = 0x001,
62  P_y = 0x002,
63  P_z = 0x004,
64  P_pos = 0x007,
65  P_rot = 0x008,
66  P_sx = 0x010,
67  P_sy = 0x020,
68  P_sz = 0x040,
69  P_scale = 0x070,
70  P_all = 0x07f,
71  };
72  static CPT(RenderEffect) make(const NodePath &reference,
73  int properties = P_rot);
74 
75  INLINE const NodePath &get_reference() const;
76  INLINE int get_properties() const;
77 
78 public:
79  virtual bool safe_to_transform() const;
80  virtual void output(ostream &out) const;
81 
82  virtual bool has_cull_callback() const;
83  virtual void cull_callback(CullTraverser *trav, CullTraverserData &data,
84  CPT(TransformState) &node_transform,
85  CPT(RenderState) &node_state) const;
86 
87  virtual bool has_adjust_transform() const;
88  virtual void adjust_transform(CPT(TransformState) &net_transform,
89  CPT(TransformState) &node_transform,
90  PandaNode *node) const;
91 
92 protected:
93  virtual int compare_to_impl(const RenderEffect *other) const;
94 
95 private:
96  NodePath _reference;
97  int _properties;
98 
99 public:
100  static void register_with_read_factory();
101  virtual void write_datagram(BamWriter *manager, Datagram &dg);
102 
103 protected:
104  static TypedWritable *make_from_bam(const FactoryParams &params);
105  void fillin(DatagramIterator &scan, BamReader *manager);
106 
107 public:
108  static TypeHandle get_class_type() {
109  return _type_handle;
110  }
111  static void init_type() {
112  RenderEffect::init_type();
113  register_type(_type_handle, "CompassEffect",
114  RenderEffect::get_class_type());
115  }
116  virtual TypeHandle get_type() const {
117  return get_class_type();
118  }
119  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
120 
121 private:
122  static TypeHandle _type_handle;
123 };
124 
125 #include "compassEffect.I"
126 
127 #endif
128 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is the base class for a number of special render effects that may be set on scene graph nodes to...
Definition: renderEffect.h:56
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
virtual bool safe_to_transform() const
Returns true if it is generally safe to transform this particular kind of RenderEffect by calling the...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
A CompassEffect causes a node to inherit its rotation (or pos or scale, if specified) from some other...
Definition: compassEffect.h:55
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48