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