Blender V2.61 - r43446

RAS_FramingManager.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef RAS_FRAMINGMANAGER_H
00033 #define RAS_FRAMINGMANAGER_H
00034 
00035 #ifdef WITH_CXX_GUARDEDALLOC
00036 #include "MEM_guardedalloc.h"
00037 #endif
00038 
00039 class RAS_Rect;
00040 
00062 class RAS_FrameSettings 
00063 {
00064 public :
00069     enum RAS_FrameType {
00070         e_frame_scale,
00071         e_frame_extend,
00072         e_frame_bars
00073     };
00074     
00079     RAS_FrameSettings(
00080         RAS_FrameType frame_type,
00081         float bar_r,
00082         float bar_g,
00083         float bar_b,
00084         unsigned int design_aspect_width,
00085         unsigned int design_aspect_height 
00086     ):
00087         m_frame_type(frame_type),
00088         m_bar_r(bar_r),
00089         m_bar_g(bar_g),
00090         m_bar_b(bar_b),
00091         m_design_aspect_width(design_aspect_width),
00092         m_design_aspect_height(design_aspect_height)
00093     {
00094     };
00095 
00096     RAS_FrameSettings(
00097     ):
00098         m_frame_type(e_frame_scale),
00099         m_bar_r(0),
00100         m_bar_g(0),
00101         m_bar_b(0),
00102         m_design_aspect_width(1),
00103         m_design_aspect_height(1)
00104     {
00105     };
00106 
00111     const
00112         RAS_FrameType &     
00113     FrameType(
00114     ) const {
00115         return m_frame_type;
00116     };
00117 
00118         void
00119     SetFrameType(
00120         RAS_FrameType type
00121     ) {
00122         m_frame_type = type;
00123     };
00124     
00125         float
00126     BarRed(
00127     ) const {
00128         return m_bar_r;
00129     };
00130         
00131         float
00132     BarGreen(
00133     ) const {
00134         return m_bar_g;
00135     };
00136 
00137         float
00138     BarBlue(
00139     ) const {
00140         return m_bar_b;
00141     };
00142 
00143         unsigned int
00144     DesignAspectWidth(
00145     ) const {
00146         return m_design_aspect_width;   
00147     };
00148 
00149         unsigned int
00150     DesignAspectHeight(
00151     ) const {
00152         return m_design_aspect_height;  
00153     };
00154 
00155 private :
00156 
00157     RAS_FrameType m_frame_type;
00158     float m_bar_r;
00159     float m_bar_g;
00160     float m_bar_b;
00161     unsigned int m_design_aspect_width;
00162     unsigned int m_design_aspect_height;
00163 
00164 
00165 #ifdef WITH_CXX_GUARDEDALLOC
00166 public:
00167     void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_FrameSettings"); }
00168     void operator delete( void *mem ) { MEM_freeN(mem); }
00169 #endif
00170 }; 
00171 
00172 struct RAS_FrameFrustum
00173 {
00174     float camnear,camfar;
00175     float x1,y1;
00176     float x2,y2;
00177 };  
00178 
00179 /* must match R_CULLING_... from DNA_scene_types.h */
00180 enum RAS_CullingMode
00181 {
00182     RAS_CULLING_DBVT = 0,
00183     RAS_CULLING_NORMAL,
00184     RAS_CULLING_NONE
00185 };
00186 
00187 /* Should match CAMERA_SENSOR_FIT... from DNA_camera_types.h */
00188 enum RAS_SensorFit
00189 {
00190     RAS_SENSORFIT_AUTO = 0,
00191     RAS_SENSORFIT_HOR,
00192     RAS_SENSORFIT_VERT
00193 };
00194 
00206 class RAS_FramingManager
00207 {
00208 public :
00209 
00216     static
00217         void
00218     ComputeViewport(
00219         const RAS_FrameSettings &settings,
00220         const RAS_Rect &availableViewport,
00221         RAS_Rect &viewport
00222     );
00223 
00224     
00231     static
00232         void
00233     ComputeOrtho(
00234         const RAS_FrameSettings &settings,
00235         const RAS_Rect &availableViewport,
00236         const RAS_Rect &viewport,
00237         const float scale,
00238         const float camnear,
00239         const float camfar,
00240         const short sensor_fit,
00241         RAS_FrameFrustum &frustum
00242     );
00243 
00244     static
00245         void
00246     ComputeFrustum(
00247         const RAS_FrameSettings &settings,
00248         const RAS_Rect &availableViewport,
00249         const RAS_Rect &viewport,
00250         const float lens,
00251         const float sensor_x, const float sensor_y, const short sensor_fit,
00252         const float camnear,
00253         const float camfar,
00254         RAS_FrameFrustum &frustum
00255     );
00256 
00257     static
00258         void
00259     ComputeDefaultFrustum(
00260         const float camnear,
00261         const float camfar,
00262         const float lens,
00263         const float sensor_x, const float sensor_y,
00264         const short sensor_fit,
00265         const float design_aspect_ratio,
00266         RAS_FrameFrustum & frustum
00267     );  
00268 
00269     static
00270         void
00271     ComputeDefaultOrtho(
00272         const float camnear,
00273         const float camfar,
00274         const float scale,
00275         const float design_aspect_ratio,
00276         const short sensor_fit,
00277         RAS_FrameFrustum & frustum
00278     );
00279 
00280 private :
00281 
00282     static
00283         void
00284     ComputeBestFitViewRect(
00285         const RAS_Rect &availableViewport,
00286         const float design_aspect_ratio,
00287         RAS_Rect &viewport
00288     );
00289 
00290 
00291 
00297     RAS_FramingManager(
00298     );
00299 
00300     RAS_FramingManager(
00301         const RAS_FramingManager &
00302     );
00303     
00304 
00305 #ifdef WITH_CXX_GUARDEDALLOC
00306 public:
00307     void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_FramingManager"); }
00308     void operator delete( void *mem ) { MEM_freeN(mem); }
00309 #endif
00310 };      
00311         
00312 #endif
00313