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