Panda3D
 All Classes Functions Variables Enumerations
texProjectorEffect.h
1 // Filename: texProjectorEffect.h
2 // Created by: drose (25Jul04)
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 TEXPROJECTOREFFECT_H
16 #define TEXPROJECTOREFFECT_H
17 
18 #include "pandabase.h"
19 
20 #include "renderEffect.h"
21 #include "luse.h"
22 #include "nodePath.h"
23 
24 class LensNode;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : TexProjectorEffect
28 // Description : This effect automatically applies a computed texture
29 // matrix to the specified texture stage, according to
30 // the relative position of two specified nodes.
31 //
32 // The relative transform from the "from" node to the
33 // "to" node is applied directly to the texture matrix
34 // each frame. If the "to" node happens to be a
35 // LensNode, its lens projection matrix is applied as
36 // well.
37 //
38 // This can be used to apply a number of special
39 // effects. Fundamentally, it may simply be used to
40 // provide a separate PandaNode that may be adjusted
41 // (e.g. via a LerpInterval) in order to easily apply a
42 // linear transformation to an object's texture
43 // coordinates (rather than having to explicitly call
44 // NodePath.set_tex_transform() each frame).
45 //
46 // In a more sophisticated case, the TexProjectorEffect
47 // is particularly useful in conjunction with a
48 // TexGenAttrib that specifies a mode of
49 // M_world_position (which copies the world position of
50 // each vertex to the texture coordinates). Then the
51 // TexProjector can be used to convert these world
52 // coordinates to the relative coordinates of a
53 // particular node, causing (for instance) a texture to
54 // appear to follow a node around as it moves through
55 // the world. With a LensNode, you can project a
56 // texture onto the walls, for instance to apply a
57 // flashlight effect or an image-based shadow.
58 ////////////////////////////////////////////////////////////////////
59 class EXPCL_PANDA_PGRAPH TexProjectorEffect : public RenderEffect {
60 protected:
61  INLINE TexProjectorEffect();
62  INLINE TexProjectorEffect(const TexProjectorEffect &copy);
63 
64 public:
65  virtual ~TexProjectorEffect();
66 
67 PUBLISHED:
68  static CPT(RenderEffect) make();
69 
70  CPT(RenderEffect) add_stage(TextureStage *stage, const NodePath &from, const NodePath &to, int lens_index = 0) const;
71  CPT(RenderEffect) remove_stage(TextureStage *stage) const;
72 
73  bool is_empty() const;
74  bool has_stage(TextureStage *stage) const;
75 
76  NodePath get_from(TextureStage *stage) const;
77  NodePath get_to(TextureStage *stage) const;
78  int get_lens_index(TextureStage *stage) const;
79 
80 public:
81  virtual void output(ostream &out) const;
82 
83  virtual bool has_cull_callback() const;
84  virtual void cull_callback(CullTraverser *trav, CullTraverserData &data,
85  CPT(TransformState) &node_transform,
86  CPT(RenderState) &node_state) const;
87 
88 protected:
89  virtual int compare_to_impl(const RenderEffect *other) const;
90 
91 private:
92  class StageDef {
93  public:
94  INLINE StageDef();
95  INLINE void set_from(const NodePath &from);
96  void set_to(const NodePath &to);
97  INLINE void set_lens_index(int lens_index);
98 
99  INLINE int compare_to(const StageDef &other) const;
100 
101  NodePath _from;
102  NodePath _to;
103  LensNode *_to_lens_node;
104  int _lens_index;
105  };
106 
108  Stages _stages;
109 
110  static CPT(RenderEffect) _empty_effect;
111 
112 public:
113  static void register_with_read_factory();
114  virtual void write_datagram(BamWriter *manager, Datagram &dg);
115  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
116 
117 protected:
118  static TypedWritable *make_from_bam(const FactoryParams &params);
119  void fillin(DatagramIterator &scan, BamReader *manager);
120 
121 public:
122  static TypeHandle get_class_type() {
123  return _type_handle;
124  }
125  static void init_type() {
126  RenderEffect::init_type();
127  register_type(_type_handle, "TexProjectorEffect",
128  RenderEffect::get_class_type());
129  }
130  virtual TypeHandle get_type() const {
131  return get_class_type();
132  }
133  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
134 
135 private:
136  static TypeHandle _type_handle;
137 };
138 
139 #include "texProjectorEffect.I"
140 
141 #endif
142 
virtual void cull_callback(CullTraverser *trav, CullTraverserData &data, CPT(TransformState)&node_transform, CPT(RenderState)&node_state) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A node that contains a Lens.
Definition: lensNode.h:32
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
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
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()...
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
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:79
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This effect automatically applies a computed texture matrix to the specified texture stage...
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
Defines the properties of a named stage of the multitexture pipeline.
Definition: textureStage.h:38
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
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