Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/gobj/lens.h

Go to the documentation of this file.
00001 // Filename: lens.h
00002 // Created by:  drose (18Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef LENS_H
00020 #define LENS_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "typedReferenceCount.h"
00025 #include "luse.h"
00026 #include "geom.h"
00027 #include "updateSeq.h"
00028 
00029 class BoundingVolume;
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : Lens
00033 // Description : A base class for any number of different kinds of
00034 //               lenses, linear and otherwise.  Presently, this
00035 //               includes perspective and orthographic lenses.
00036 //
00037 //               A Lens object is the main part of a Camera node
00038 //               (defined in sgraph), which defines the fundamental
00039 //               interface to point-of-view for rendering.  Lenses are
00040 //               also used in other contexts, however; for instance, a
00041 //               Spotlight is also defined using a lens.
00042 ////////////////////////////////////////////////////////////////////
00043 class EXPCL_PANDA Lens : public TypedReferenceCount {
00044 public:
00045   Lens();
00046   Lens(const Lens &copy);
00047   void operator = (const Lens &copy);
00048 
00049 PUBLISHED:
00050   virtual PT(Lens) make_copy() const=0;
00051 
00052   INLINE bool extrude(const LPoint2f &point2d,
00053                       LPoint3f &near_point, LPoint3f &far_point) const;
00054   INLINE bool extrude(const LPoint3f &point2d,
00055                       LPoint3f &near_point, LPoint3f &far_point) const;
00056   INLINE bool project(const LPoint3f &point3d, LPoint3f &point2d) const;
00057   INLINE bool project(const LPoint3f &point3d, LPoint2f &point2d) const;
00058 
00059   INLINE void set_change_event(const string &event);
00060   INLINE const string &get_change_event() const;
00061 
00062   void set_coordinate_system(CoordinateSystem cs);
00063   INLINE CoordinateSystem get_coordinate_system() const;
00064 
00065   void clear();
00066 
00067   void set_film_size(float width);
00068   INLINE void set_film_size(float width, float height);
00069   void set_film_size(const LVecBase2f &film_size);
00070   const LVecBase2f &get_film_size() const;
00071 
00072   INLINE void set_film_offset(float x, float y);
00073   INLINE void set_film_offset(const LVecBase2f &film_offset);
00074   INLINE const LVector2f &get_film_offset() const;
00075 
00076   void set_focal_length(float focal_length);
00077   float get_focal_length() const;
00078 
00079   void set_fov(float fov);
00080   INLINE void set_fov(float hfov, float vfov);
00081   void set_fov(const LVecBase2f &fov);
00082   const LVecBase2f &get_fov() const;
00083   INLINE float get_hfov() const;
00084   INLINE float get_vfov() const;
00085 
00086   void set_aspect_ratio(float aspect_ratio);
00087   float get_aspect_ratio() const;
00088 
00089   INLINE void set_near(float near_distance);
00090   INLINE float get_near() const;
00091   INLINE void set_far(float far_distance);
00092   INLINE float get_far() const;
00093   INLINE void set_near_far(float near_distance, float far_distance);
00094 
00095   static float get_default_near();
00096   static float get_default_far();
00097   
00098   INLINE void set_view_hpr(float h, float p, float r);
00099   void set_view_hpr(const LVecBase3f &view_hpr);
00100   const LVecBase3f &get_view_hpr() const;
00101   INLINE void set_view_vector(float x, float y, float z, float i, float j, float k);
00102   void set_view_vector(const LVector3f &view_vector, const LVector3f &up_vector);
00103   const LVector3f &get_view_vector() const;
00104   const LVector3f &get_up_vector() const;
00105   LPoint3f get_nodal_point() const;
00106   void set_iod_offset(float offset);
00107   float get_iod_offset() const;
00108 
00109   void set_view_mat(const LMatrix4f &view_mat);
00110   const LMatrix4f &get_view_mat() const;
00111   
00112   // These flags are passed in as the last parameter to control the
00113   // behavior of set_frustum_from_corners().  See the documentation
00114   // for that method for an explanation of each flag.
00115   enum FromCorners {
00116     FC_roll         = 0x0001,
00117     FC_camera_plane = 0x0002,
00118     FC_off_axis     = 0x0004,
00119     FC_aspect_ratio = 0x0008,
00120     FC_shear        = 0x0010,
00121   };
00122   void set_frustum_from_corners(const LVecBase3f &ul, const LVecBase3f &ur,
00123                                 const LVecBase3f &ll, const LVecBase3f &lr,
00124                                 int flags);
00125 
00126   void recompute_all();
00127 
00128   virtual bool is_linear() const;
00129   virtual PT(Geom) make_geometry();
00130 
00131   virtual PT(BoundingVolume) make_bounds() const;
00132 
00133   const LMatrix4f &get_projection_mat() const;
00134   const LMatrix4f &get_projection_mat_inv() const;
00135 
00136   virtual void output(ostream &out) const;
00137   virtual void write(ostream &out, int indent_level = 0) const;
00138 
00139 public:
00140   INLINE const UpdateSeq &get_last_change() const;
00141 
00142 protected:
00143   INLINE void adjust_user_flags(int clear_flags, int set_flags);
00144   INLINE void adjust_comp_flags(int clear_flags, int set_flags);
00145 
00146   void throw_change_event();
00147 
00148   const LMatrix4f &get_film_mat() const;
00149   const LMatrix4f &get_film_mat_inv() const;
00150 
00151   const LMatrix4f &get_lens_mat() const;
00152   const LMatrix4f &get_lens_mat_inv() const;
00153 
00154   virtual bool extrude_impl(const LPoint3f &point2d,
00155                             LPoint3f &near_point, LPoint3f &far_point) const;
00156   virtual bool project_impl(const LPoint3f &point3d, LPoint3f &point2d) const;
00157 
00158   virtual void compute_film_size();
00159   virtual void compute_focal_length();
00160   virtual void compute_fov();
00161   virtual void compute_aspect_ratio();
00162   virtual void compute_view_hpr();
00163   virtual void compute_view_vector();
00164   virtual void compute_iod_offset();
00165   virtual void compute_projection_mat();
00166   virtual void compute_film_mat();
00167   virtual void compute_lens_mat();
00168 
00169   virtual float fov_to_film(float fov, float focal_length, bool horiz) const;
00170   virtual float fov_to_focal_length(float fov, float film_size, bool horiz) const;
00171   virtual float film_to_fov(float film_size, float focal_length, bool horiz) const;
00172 
00173 private:
00174   static void resequence_fov_triad(char &newest, char &older_a, char &older_b);
00175   int define_geom_coords();
00176   static void build_shear_mat(LMatrix4f &shear_mat,
00177                               const LPoint3f &cul, const LPoint3f &cur,
00178                               const LPoint3f &cll, const LPoint3f &clr);
00179   static float sqr_dist_to_line(const LPoint3f &point, const LPoint3f &origin, 
00180                                 const LVector3f &vec);
00181 
00182 protected:
00183   string _change_event;
00184   UpdateSeq _last_change;
00185   CoordinateSystem _cs;
00186 
00187   LVecBase2f _film_size;
00188   LVector2f _film_offset;
00189   float _focal_length;
00190   LVecBase2f _fov;
00191   float _aspect_ratio;
00192   float _near_distance, _far_distance;
00193 
00194   LVecBase3f _view_hpr;
00195   LVector3f _view_vector, _up_vector;
00196   float _iod_offset;
00197 
00198   LMatrix4f _film_mat, _film_mat_inv;
00199   LMatrix4f _lens_mat, _lens_mat_inv;
00200   LMatrix4f _projection_mat, _projection_mat_inv;
00201 
00202   enum UserFlags {
00203     // Parameters the user may have explicitly specified.
00204     UF_film_width          = 0x0001,
00205     UF_film_height         = 0x0002,
00206     UF_focal_length        = 0x0004,
00207     UF_hfov                = 0x0008,
00208     UF_vfov                = 0x0010,
00209     UF_aspect_ratio        = 0x0020,
00210     UF_view_hpr            = 0x0040,
00211     UF_view_vector         = 0x0080,
00212     UF_iod_offset          = 0x0100,
00213     UF_view_mat            = 0x0200,
00214   };
00215 
00216   enum CompFlags {
00217     // Values that may need to be recomputed.
00218     CF_film_mat            = 0x0001,
00219     CF_film_mat_inv        = 0x0002,
00220     CF_lens_mat            = 0x0004,
00221     CF_lens_mat_inv        = 0x0008,
00222     CF_projection_mat      = 0x0010,
00223     CF_projection_mat_inv  = 0x0020,
00224     CF_mat                 = 0x003f,  // all of the above.
00225 
00226     CF_focal_length        = 0x0040,
00227     CF_fov                 = 0x0080,
00228     CF_film_size           = 0x0100,
00229     CF_aspect_ratio        = 0x0200,
00230     CF_view_hpr            = 0x0400,
00231     CF_view_vector         = 0x0800,
00232     CF_iod_offset          = 0x1000,
00233   };
00234   short _user_flags;
00235   short _comp_flags;
00236 
00237   // The user may only specify two of these three parameters.
00238   // Specifying the third parameter wipes out the first one specified.
00239   // We therefore need to remember the order in which the user has
00240   // specified these three parameters.  A bit of a mess.
00241   char _focal_length_seq, _fov_seq, _film_size_seq;
00242 
00243   PTA_Vertexf _geom_coords;
00244 
00245   static const float _default_fov;
00246 
00247 public:
00248   virtual TypeHandle get_type() const {
00249     return get_class_type();
00250   }
00251   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00252   static TypeHandle get_class_type() {
00253     return _type_handle;
00254   }
00255   static void init_type() {
00256     TypedReferenceCount::init_type();
00257     register_type(_type_handle, "Lens",
00258                   TypedReferenceCount::get_class_type());
00259   }
00260 
00261 private:
00262   static TypeHandle _type_handle;
00263 };
00264 
00265 EXPCL_PANDA INLINE ostream &operator << (ostream &out, const Lens &lens);
00266 
00267 #include "lens.I"
00268 
00269 #endif
00270 

Generated on Fri May 2 00:39:35 2003 for Panda by doxygen1.3