00001 /* 00002 toxic - A Global Illumination Renderer 00003 Copyright (C) 2003-2004 Francois Beaune 00004 Contact: http://toxicengine.sourceforge.net/ 00005 00006 This file is part of toxic. 00007 00008 toxic is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 toxic is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with toxic; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef TOXIC_RENDERER_CAMERA_H 00024 #define TOXIC_RENDERER_CAMERA_H 00025 00026 #include "common/math/matrix4.h" 00027 #include "common/math/point2.h" 00028 #include "common/math/point3.h" 00029 #include "common/math/real.h" 00030 #include "common/math/vector3.h" 00031 #include "basis.h" 00032 #include "globals.h" 00033 00034 namespace toxic { 00035 00036 class Context; 00037 class Ray; 00038 class Scene; 00039 00040 const sheep::Real DEFAULT_CAMERA_HFOV = sheep::dtor(70.0); 00041 const sheep::Real DEFAULT_CAMERA_ASPECT_RATIO = 4.0 / 3.0; // 1.33333... 00042 00043 //! Normalized Device Coordinates (NDC) are normalized pixel coordinates so 00044 //! that x and y both run from -0.5 to +0.5 across the entire (uncropped) 00045 //! image, with (-0.5, -0.5) being at the lower left of the image, and 00046 //! (0.5, 0.5) being at the upper right of the image (regardless of the 00047 //! aspect ratio). 00048 00049 //! The camera is located at the origin and looks toward Z-. 00050 class Camera : public Basis { 00051 public: 00052 //! m is the object space to world space transformation matrix. 00053 Camera( 00054 const sheep::Matrix4 &m, 00055 sheep::Real hfov = DEFAULT_CAMERA_HFOV, 00056 sheep::Real aspect_ratio = DEFAULT_CAMERA_ASPECT_RATIO); 00057 00058 //! This method must be called only once, after the camera is completely 00059 //! configured, and before it is used for the first time. 00060 void Finalize( 00061 const Context &context, 00062 const Scene *scene); 00063 00064 //! Enables depth of field. From "The RenderMan Interface Version 3.2": 00065 //! 'focal_distance' sets the distance along the direction of view at which objects 00066 //! will be in focus. 'focal_length' sets the focal length of the camera. These two 00067 //! parameters should have the units of distance along the view direction in camera 00068 //! coordinates. 'fstop', or aperture number, determines the lens diameter: 00069 //! lens_diameter = focal_length / fstop. 00070 //!\todo Create a new camera class for thin lens camera. 00071 void EnableDepthOfField( 00072 sheep::Real fstop, 00073 sheep::Real focal_length, 00074 sheep::Real focal_distance); 00075 00076 //! Enables autofocus. Autofocus computes the right focal distance so that point of 00077 //! the scene visible through point 'p' is in focus plane. 'p' is a point on the 00078 //! film plane, expressed in NDC. 00079 //!\todo Create a new camera class for thin lens camera. 00080 void EnableAutoFocus(const sheep::Point2 &p); 00081 00082 //! Returns a ray whose origin is at camera location, and which 00083 //! is directed toward the point 'p'. 'p' is a point on the film 00084 //! plane. It is expressed in NDC. The returned ray is expressed 00085 //! in world space. The direction of the returned ray IS unit-length. 00086 Ray ComputeRay(const Context &context, const sheep::Point2 &p) const; 00087 00088 sheep::Point2 Project(const sheep::Point3 &p) const; 00089 00090 private: 00091 sheep::Point3 m_location; //!< Location of the camera, expressed in world space. 00092 sheep::Vector3 m_ex, m_ey, m_ez; //!< Basis vectors, expressed in world space. m_ex is scaled by the aspect ratio. 00093 sheep::Vector3 m_u, m_w; //!< m_u = m_ex * m_aspect_ratio, m_w = m_ez * (-m_focal_length). 00094 00095 //! Frustum parameters. 00096 sheep::Real m_hfov; //!< User defined horizontal field of view, expressed in radians. 00097 sheep::Real m_aspect_ratio; //!< User defined aspect ratio. 00098 sheep::Real m_focal_length; //!< Lens focal length (computed from horizontal field of view and aspect ratio values). 00099 00100 //! Depth of field parameters. 00101 bool m_is_dof_enabled; //!< True if depth of field is enabled, false otherwise. 00102 sheep::Real m_dof_fstop; //!< User defined f-stop number. 00103 sheep::Real m_dof_focal_length; //!< User defined focal length (distinct from m_focal_length). 00104 sheep::Real m_dof_focal_distance; //!< User defined distance of the focus plane from the lens center. 00105 sheep::Real m_dof_lens_radius; //!< Lens radius (computed from DOF focal length value and f-stop number). 00106 bool m_is_autofocus_enabled; //!< True if autofocus is enabled, false otherwise. 00107 sheep::Point2 m_autofocus_target; //!< Focus point, expressed in NDC. Used only by the autofocus mechanism. 00108 }; 00109 00110 #include "camera.inl" 00111 00112 } 00113 00114 #endif // !TOXIC_RENDERER_CAMERA_H
1.3.6