Panda3D
projectionScreen.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 projectionScreen.h
10  * @author drose
11  * @date 2001-12-11
12  */
13 
14 #ifndef PROJECTIONSCREEN_H
15 #define PROJECTIONSCREEN_H
16 
17 #include "pandabase.h"
18 
19 #include "pandaNode.h"
20 #include "lensNode.h"
21 #include "geomNode.h"
22 #include "nodePath.h"
23 #include "internalName.h"
24 #include "pointerTo.h"
25 #include "pfmFile.h"
26 
27 class Geom;
28 class WorkingNodePath;
29 
30 /**
31  * A ProjectionScreen implements a simple system for projective texturing.
32  * The ProjectionScreen node is the parent of a hierarchy of geometry that is
33  * considered a "screen"; the ProjectionScreen will automatically recompute
34  * all the UV's (for a particular texture stage) on its subordinate geometry
35  * according to the relative position and lens parameters of the indicated
36  * LensNode.
37  *
38  * All this does is recompute UV's; the caller is responsible for applying the
39  * appropriate texture(s) to the geometry.
40  *
41  * This does not take advantage of any hardware-assisted projective texturing;
42  * all of the UV's are computed in the CPU. (Use NodePath::project_texture()
43  * to enable hardware-assisted projective texturing.) However, the
44  * ProjectionScreen interface does support any kind of lens, linear or
45  * nonlinear, that might be defined using the Lens interface, including
46  * fisheye and cylindrical lenses.
47  */
48 class EXPCL_PANDAFX ProjectionScreen : public PandaNode {
49 PUBLISHED:
50  explicit ProjectionScreen(const std::string &name = "");
51  virtual ~ProjectionScreen();
52 
53 protected:
55 
56 public:
57  virtual PandaNode *make_copy() const;
58  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
59 
60 PUBLISHED:
61  void set_projector(const NodePath &projector);
62  INLINE const NodePath &get_projector() const;
63 
64  INLINE void clear_undist_lut();
65  INLINE void set_undist_lut(const PfmFile &undist_lut);
66  INLINE bool has_undist_lut() const;
67  INLINE const PfmFile &get_undist_lut() const;
68 
69  PT(GeomNode) generate_screen(const NodePath &projector,
70  const std::string &screen_name,
71  int num_x_verts, int num_y_verts,
72  PN_stdfloat distance, PN_stdfloat fill_ratio);
73  void regenerate_screen(const NodePath &projector, const std::string &screen_name,
74  int num_x_verts, int num_y_verts, PN_stdfloat distance,
75  PN_stdfloat fill_ratio);
76  PT(PandaNode) make_flat_mesh(const NodePath &this_np, const NodePath &camera);
77 
78  INLINE void set_texcoord_name(const std::string &texcoord_name);
79  INLINE std::string get_texcoord_name() const;
80 
81  INLINE void set_invert_uvs(bool invert_uvs);
82  INLINE bool get_invert_uvs() const;
83 
84  INLINE void set_texcoord_3d(bool texcoord_3d);
85  INLINE bool get_texcoord_3d() const;
86 
87  INLINE void set_vignette_on(bool vignette_on);
88  INLINE bool get_vignette_on() const;
89 
90  INLINE void set_vignette_color(const LColor &vignette_color);
91  INLINE const LColor &get_vignette_color() const;
92  INLINE void set_frame_color(const LColor &frame_color);
93  INLINE const LColor &get_frame_color() const;
94 
95  INLINE void set_auto_recompute(bool auto_recompute);
96  INLINE bool get_auto_recompute() const;
97 
98  void recompute();
99  INLINE const UpdateSeq &get_last_screen() const;
100  bool recompute_if_stale();
101  bool recompute_if_stale(const NodePath &this_np);
102 
103 private:
104  void do_recompute(const NodePath &this_np);
105  void recompute_node(const WorkingNodePath &np, LMatrix4 &rel_mat, bool &computed_rel_mat);
106  void recompute_child(const WorkingNodePath &np, LMatrix4 &rel_mat, bool &computed_rel_mat);
107  void recompute_geom_node(const WorkingNodePath &np, LMatrix4 &rel_mat, bool &computed_rel_mat);
108  void recompute_geom(Geom *geom, const LMatrix4 &rel_mat);
109 
110  PandaNode *
111  make_mesh_node(PandaNode *result_parent, const WorkingNodePath &np,
112  const NodePath &camera,
113  LMatrix4 &rel_mat, bool &computed_rel_mat);
114  void make_mesh_children(PandaNode *new_node, const WorkingNodePath &np,
115  const NodePath &camera,
116  LMatrix4 &rel_mat, bool &computed_rel_mat);
117  PT(GeomNode) make_mesh_geom_node(const WorkingNodePath &np,
118  const NodePath &camera,
119  LMatrix4 &rel_mat,
120  bool &computed_rel_mat);
121  PT(Geom) make_mesh_geom(const Geom *geom, Lens *lens, LMatrix4 &rel_mat);
122 
123 
124  NodePath _projector;
125  PT(LensNode) _projector_node;
126  bool _has_undist_lut;
127  PfmFile _undist_lut;
128  PT(InternalName) _texcoord_name;
129  bool _invert_uvs;
130  bool _texcoord_3d;
131  bool _vignette_on;
132  LColor _vignette_color;
133  LColor _frame_color;
134 
135  LMatrix4 _rel_top_mat;
136  bool _computed_rel_top_mat;
137  bool _stale;
138  UpdateSeq _projector_lens_change;
139  UpdateSeq _last_screen;
140  bool _auto_recompute;
141 
142 public:
143  static TypeHandle get_class_type() {
144  return _type_handle;
145  }
146  static void init_type() {
147  PandaNode::init_type();
148  register_type(_type_handle, "ProjectionScreen",
149  PandaNode::get_class_type());
150  }
151  virtual TypeHandle get_type() const {
152  return get_class_type();
153  }
154  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
155 
156 private:
157  static TypeHandle _type_handle;
158 };
159 
160 #include "projectionScreen.I"
161 
162 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:41
A node that contains a Lens.
Definition: lensNode.h:29
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a class designed to support low-overhead traversals of the complete scene graph,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a pfm file, a 2-d table of floating-point numbers, either 3-component or 1-component,...
Definition: pfmFile.h:31
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A container for geometry primitives.
Definition: geom.h:54
A ProjectionScreen implements a simple system for projective texturing.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:487
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
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
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34