Panda3D
 All Classes Functions Variables Enumerations
compassEffect.h
00001 // Filename: compassEffect.h
00002 // Created by:  drose (16Jul02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef COMPASSEFFECT_H
00016 #define COMPASSEFFECT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "renderEffect.h"
00021 #include "luse.h"
00022 #include "nodePath.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : CompassEffect
00026 // Description : A CompassEffect causes a node to inherit its rotation
00027 //               (or pos or scale, if specified) from some other
00028 //               reference node in the graph, or more often from the
00029 //               root.
00030 //
00031 //               In its purest form, a CompassEffect is used to keep
00032 //               the node's rotation fixed relative to the top of the
00033 //               scene graph, despite other transforms that may exist
00034 //               above the node.  Hence the name: the node behaves
00035 //               like a magnetic compass, always pointing in the same
00036 //               direction.
00037 //
00038 //               As an couple of generalizing extensions, the
00039 //               CompassEffect may also be set up to always orient its
00040 //               node according to some other reference node than the
00041 //               root of the scene graph.  Furthermore, it may
00042 //               optionally adjust any of pos, rotation, or scale,
00043 //               instead of necessarily rotation; and it may adjust
00044 //               individual pos and scale components.  (Rotation may
00045 //               not be adjusted on an individual component basis;
00046 //               that's just asking for trouble.)
00047 //
00048 //               Be careful when using the pos and scale modes.  In
00049 //               these modes, it's possible for the CompassEffect to
00050 //               move its node far from its normal bounding volume,
00051 //               causing culling to fail.  If this is an issue, you
00052 //               may need to explicitly set a large (or infinite)
00053 //               bounding volume on the effect node.
00054 ////////////////////////////////////////////////////////////////////
00055 class EXPCL_PANDA_PGRAPH CompassEffect : public RenderEffect {
00056 private:
00057   INLINE CompassEffect();
00058 
00059 PUBLISHED:
00060   enum Properties {
00061     P_x     = 0x001,
00062     P_y     = 0x002,
00063     P_z     = 0x004,
00064     P_pos   = 0x007,
00065     P_rot   = 0x008,
00066     P_sx    = 0x010,
00067     P_sy    = 0x020,
00068     P_sz    = 0x040,
00069     P_scale = 0x070,
00070     P_all   = 0x07f,
00071   };
00072   static CPT(RenderEffect) make(const NodePath &reference, 
00073                                 int properties = P_rot);
00074 
00075   INLINE const NodePath &get_reference() const;
00076   INLINE int get_properties() const;
00077 
00078 public:
00079   virtual bool safe_to_transform() const;
00080   virtual void output(ostream &out) const;
00081 
00082   virtual bool has_cull_callback() const;
00083   virtual void cull_callback(CullTraverser *trav, CullTraverserData &data,
00084                              CPT(TransformState) &node_transform,
00085                              CPT(RenderState) &node_state) const;
00086 
00087   virtual bool has_adjust_transform() const;
00088   virtual void adjust_transform(CPT(TransformState) &net_transform,
00089                                 CPT(TransformState) &node_transform,
00090                                 PandaNode *node) const;
00091 
00092 protected:
00093   virtual int compare_to_impl(const RenderEffect *other) const;
00094 
00095 private:
00096   NodePath _reference;
00097   int _properties;
00098 
00099 public:
00100   static void register_with_read_factory();
00101   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00102 
00103 protected:
00104   static TypedWritable *make_from_bam(const FactoryParams &params);
00105   void fillin(DatagramIterator &scan, BamReader *manager);
00106   
00107 public:
00108   static TypeHandle get_class_type() {
00109     return _type_handle;
00110   }
00111   static void init_type() {
00112     RenderEffect::init_type();
00113     register_type(_type_handle, "CompassEffect",
00114                   RenderEffect::get_class_type());
00115   }
00116   virtual TypeHandle get_type() const {
00117     return get_class_type();
00118   }
00119   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00120 
00121 private:
00122   static TypeHandle _type_handle;
00123 };
00124 
00125 #include "compassEffect.I"
00126 
00127 #endif
00128 
 All Classes Functions Variables Enumerations