Panda3D

projectionScreen.h

00001 // Filename: projectionScreen.h
00002 // Created by:  drose (11Dec01)
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 PROJECTIONSCREEN_H
00016 #define PROJECTIONSCREEN_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "pandaNode.h"
00021 #include "lensNode.h"
00022 #include "geomNode.h"
00023 #include "nodePath.h"
00024 #include "internalName.h"
00025 #include "pointerTo.h"
00026 
00027 class Geom;
00028 class WorkingNodePath;
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : ProjectionScreen
00032 // Description : A ProjectionScreen implements a simple system for
00033 //               projective texturing.  The ProjectionScreen node is
00034 //               the parent of a hierarchy of geometry that is
00035 //               considered a "screen"; the ProjectionScreen will
00036 //               automatically recompute all the UV's (for a
00037 //               particular texture stage) on its subordinate geometry
00038 //               according to the relative position and lens
00039 //               parameters of the indicated LensNode.
00040 //
00041 //               All this does is recompute UV's; the caller is
00042 //               responsible for applying the appropriate texture(s)
00043 //               to the geometry.
00044 //
00045 //               This does not take advantage of any hardware-assisted
00046 //               projective texturing; all of the UV's are computed in
00047 //               the CPU.  (Use NodePath::project_texture() to enable
00048 //               hardware-assisted projective texturing.)  However,
00049 //               the ProjectionScreen interface does support any kind
00050 //               of lens, linear or nonlinear, that might be defined
00051 //               using the Lens interface, including fisheye and
00052 //               cylindrical lenses.
00053 ////////////////////////////////////////////////////////////////////
00054 class EXPCL_PANDAFX ProjectionScreen : public PandaNode {
00055 PUBLISHED:
00056   ProjectionScreen(const string &name = "");
00057   virtual ~ProjectionScreen();
00058 
00059 protected:
00060   ProjectionScreen(const ProjectionScreen &copy);
00061 
00062 public:
00063   virtual PandaNode *make_copy() const;
00064   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00065 
00066 PUBLISHED:
00067   void set_projector(const NodePath &projector);
00068   INLINE const NodePath &get_projector() const;
00069 
00070   PT(GeomNode) generate_screen(const NodePath &projector,
00071                                const string &screen_name,
00072                                int num_x_verts, int num_y_verts,
00073                                float distance, float fill_ratio);
00074   void regenerate_screen(const NodePath &projector, const string &screen_name,
00075                          int num_x_verts, int num_y_verts, float distance,
00076                          float fill_ratio);
00077   PT(PandaNode) make_flat_mesh(const NodePath &this_np, const NodePath &camera);
00078 
00079   INLINE void set_texcoord_name(const string &texcoord_name);
00080   INLINE string get_texcoord_name() const;
00081 
00082   INLINE void set_invert_uvs(bool invert_uvs);
00083   INLINE bool get_invert_uvs() const;
00084 
00085   INLINE void set_vignette_on(bool vignette_on);
00086   INLINE bool get_vignette_on() const;
00087 
00088   INLINE void set_vignette_color(const Colorf &vignette_color);
00089   INLINE const Colorf &get_vignette_color() const;
00090   INLINE void set_frame_color(const Colorf &frame_color);
00091   INLINE const Colorf &get_frame_color() const;
00092 
00093   void recompute();
00094 
00095 public:
00096   INLINE const UpdateSeq &get_last_screen() const;
00097   void recompute_if_stale(const NodePath &this_np);
00098 
00099 private:
00100   void do_recompute(const NodePath &this_np);
00101   void recompute_node(const WorkingNodePath &np, LMatrix4f &rel_mat, bool &computed_rel_mat);
00102   void recompute_child(const WorkingNodePath &np, LMatrix4f &rel_mat, bool &computed_rel_mat);
00103   void recompute_geom_node(const WorkingNodePath &np, LMatrix4f &rel_mat, bool &computed_rel_mat);
00104   void recompute_geom(Geom *geom, const LMatrix4f &rel_mat);
00105 
00106   PandaNode *
00107   make_mesh_node(PandaNode *result_parent, const WorkingNodePath &np,
00108                  const NodePath &camera,
00109                  LMatrix4f &rel_mat, bool &computed_rel_mat);
00110   void make_mesh_children(PandaNode *new_node, const WorkingNodePath &np,
00111                           const NodePath &camera,
00112                           LMatrix4f &rel_mat, bool &computed_rel_mat);
00113   PT(GeomNode) make_mesh_geom_node(const WorkingNodePath &np, 
00114                                    const NodePath &camera,
00115                                    LMatrix4f &rel_mat,
00116                                    bool &computed_rel_mat);
00117   PT(Geom) make_mesh_geom(const Geom *geom, Lens *lens, LMatrix4f &rel_mat);
00118 
00119 
00120   NodePath _projector;
00121   PT(LensNode) _projector_node;
00122   PT(InternalName) _texcoord_name;
00123   bool _invert_uvs;
00124   bool _vignette_on;
00125   Colorf _vignette_color;
00126   Colorf _frame_color;
00127 
00128   LMatrix4f _rel_top_mat;
00129   bool _computed_rel_top_mat;
00130   bool _stale;
00131   UpdateSeq _projector_lens_change;
00132   UpdateSeq _last_screen;
00133 
00134 public:
00135   static TypeHandle get_class_type() {
00136     return _type_handle;
00137   }
00138   static void init_type() {
00139     PandaNode::init_type();
00140     register_type(_type_handle, "ProjectionScreen",
00141                   PandaNode::get_class_type());
00142   }
00143   virtual TypeHandle get_type() const {
00144     return get_class_type();
00145   }
00146   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00147 
00148 private:
00149   static TypeHandle _type_handle;
00150 };
00151 
00152 #include "projectionScreen.I"
00153 
00154 #endif
 All Classes Functions Variables Enumerations