Panda3D
compassEffect.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file compassEffect.h
10  * @author drose
11  * @date 2002-07-16
12  */
13 
14 #ifndef COMPASSEFFECT_H
15 #define COMPASSEFFECT_H
16 
17 #include "pandabase.h"
18 
19 #include "renderEffect.h"
20 #include "luse.h"
21 #include "nodePath.h"
22 
23 /**
24  * A CompassEffect causes a node to inherit its rotation (or pos or scale, if
25  * specified) from some other reference node in the graph, or more often from
26  * the root.
27  *
28  * In its purest form, a CompassEffect is used to keep the node's rotation
29  * fixed relative to the top of the scene graph, despite other transforms that
30  * may exist above the node. Hence the name: the node behaves like a magnetic
31  * compass, always pointing in the same direction.
32  *
33  * As an couple of generalizing extensions, the CompassEffect may also be set
34  * up to always orient its node according to some other reference node than
35  * the root of the scene graph. Furthermore, it may optionally adjust any of
36  * pos, rotation, or scale, instead of necessarily rotation; and it may adjust
37  * individual pos and scale components. (Rotation may not be adjusted on an
38  * individual component basis; that's just asking for trouble.)
39  *
40  * Be careful when using the pos and scale modes. In these modes, it's
41  * possible for the CompassEffect to move its node far from its normal
42  * bounding volume, causing culling to fail. If this is an issue, you may
43  * need to explicitly set a large (or infinite) bounding volume on the effect
44  * node.
45  */
46 class EXPCL_PANDA_PGRAPH CompassEffect : public RenderEffect {
47 private:
48  INLINE CompassEffect();
49 
50 PUBLISHED:
51  enum Properties {
52  P_x = 0x001,
53  P_y = 0x002,
54  P_z = 0x004,
55  P_pos = 0x007,
56  P_rot = 0x008,
57  P_sx = 0x010,
58  P_sy = 0x020,
59  P_sz = 0x040,
60  P_scale = 0x070,
61  P_all = 0x07f,
62  };
63  static CPT(RenderEffect) make(const NodePath &reference,
64  int properties = P_rot);
65 
66  INLINE const NodePath &get_reference() const;
67  INLINE int get_properties() const;
68 
69 public:
70  virtual bool safe_to_transform() const;
71  virtual void output(std::ostream &out) const;
72 
73  virtual bool has_cull_callback() const;
74  virtual void cull_callback(CullTraverser *trav, CullTraverserData &data,
75  CPT(TransformState) &node_transform,
76  CPT(RenderState) &node_state) const;
77 
78  virtual bool has_adjust_transform() const;
79  virtual void adjust_transform(CPT(TransformState) &net_transform,
80  CPT(TransformState) &node_transform,
81  const PandaNode *node) const;
82 
83 protected:
84  virtual int compare_to_impl(const RenderEffect *other) const;
85 
86 private:
87  NodePath _reference;
88  int _properties;
89 
90 public:
91  static void register_with_read_factory();
92  virtual void write_datagram(BamWriter *manager, Datagram &dg);
94  BamReader *manager);
95 
96 protected:
97  static TypedWritable *make_from_bam(const FactoryParams &params);
98  void fillin(DatagramIterator &scan, BamReader *manager);
99 
100 public:
101  static TypeHandle get_class_type() {
102  return _type_handle;
103  }
104  static void init_type() {
105  RenderEffect::init_type();
106  register_type(_type_handle, "CompassEffect",
107  RenderEffect::get_class_type());
108  }
109  virtual TypeHandle get_type() const {
110  return get_class_type();
111  }
112  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
113 
114 private:
115  static TypeHandle _type_handle;
116 };
117 
118 #include "compassEffect.I"
119 
120 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
Indicates a coordinate-system transform on vertices.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:63
This is the base class for a number of special render effects that may be set on scene graph nodes to...
Definition: renderEffect.h:48
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
A CompassEffect causes a node to inherit its rotation (or pos or scale, if specified) from some other...
Definition: compassEffect.h:46
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45