|
Blender
V2.59
|
00001 /* $Id: KX_Dome.h 35063 2011-02-22 10:33:14Z jesterking $ 00002 ----------------------------------------------------------------------------- 00003 00004 This program is free software; you can redistribute it and/or modify it under 00005 the terms of the GNU Lesser General Public License as published by the Free Software 00006 Foundation; either version 2 of the License, or (at your option) any later 00007 version. 00008 00009 This program is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00012 00013 You should have received a copy of the GNU Lesser General Public License along with 00014 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00015 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00016 http://www.gnu.org/copyleft/lesser.txt. 00017 00018 Contributor(s): Dalai Felinto 00019 00020 This source uses some of the ideas and code from Paul Bourke. 00021 Developed as part of a Research and Development project for SAT - La Soci�t� des arts technologiques. 00022 ----------------------------------------------------------------------------- 00023 */ 00024 00029 #if !defined KX_DOME_H 00030 #define KX_DOME_H 00031 00032 #include "KX_Scene.h" 00033 #include "KX_Camera.h" 00034 #include "DNA_screen_types.h" 00035 #include "RAS_ICanvas.h" 00036 #include "RAS_IRasterizer.h" 00037 #include "RAS_IRenderTools.h" 00038 #include "KX_KetsjiEngine.h" 00039 00040 #include "GL/glew.h" 00041 #include <vector> 00042 00043 #include "MEM_guardedalloc.h" 00044 #include "BKE_text.h" 00045 00046 //Dome modes: limit hardcoded in buttons_scene.c 00047 #define DOME_FISHEYE 1 00048 #define DOME_TRUNCATED_FRONT 2 00049 #define DOME_TRUNCATED_REAR 3 00050 #define DOME_ENVMAP 4 00051 #define DOME_PANORAM_SPH 5 00052 #define DOME_NUM_MODES 6 00053 00054 00056 class KX_Dome 00057 { 00058 public: 00060 KX_Dome ( 00061 RAS_ICanvas* m_canvas, 00063 RAS_IRasterizer* m_rasterizer, 00065 RAS_IRenderTools* m_rendertools, 00067 KX_KetsjiEngine* m_engine, 00068 00069 short res, 00070 short mode, 00071 short angle, 00072 float resbuf, 00073 short tilt, 00074 struct Text* warptext 00075 ); 00076 00078 virtual ~KX_Dome (void); 00079 00080 //openGL checks: 00081 bool dlistSupported; 00082 bool fboSupported; 00083 00084 //openGL names: 00085 GLuint domefacesId[7]; // ID of the images -- room for 7 images, using only 4 for 180� x 360� dome, 6 for panoramic and +1 for warp mesh 00086 GLuint dlistId; // ID of the Display Lists of the images (used as an offset) 00087 00088 typedef struct { 00089 double u[3], v[3]; 00090 MT_Vector3 verts[3]; //three verts 00091 } DomeFace; 00092 00093 //mesh warp functions 00094 typedef struct { 00095 double x, y, u, v, i; 00096 } WarpMeshNode; 00097 00098 struct { 00099 bool usemesh; 00100 int mode; 00101 int n_width, n_height; //nodes width and height 00102 int imagesize; 00103 int bufferwidth, bufferheight; 00104 GLuint fboId; 00105 vector <vector <WarpMeshNode> > nodes; 00106 } warp; 00107 00108 bool ParseWarpMesh(STR_String text); 00109 00110 vector <DomeFace> cubetop, cubebottom, cuberight, cubeleft, cubefront, cubeback; //for fisheye 00111 vector <DomeFace> cubeleftback, cuberightback; //for panorama 00112 00113 int nfacestop, nfacesbottom, nfacesleft, nfacesright, nfacesfront, nfacesback; 00114 int nfacesleftback, nfacesrightback; 00115 00116 int GetNumberRenders(){return m_numfaces;}; 00117 00118 void RenderDome(void); 00119 void RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i); 00120 void BindImages(int i); 00121 00122 void SetViewPort(GLuint viewport[4]); 00123 void CalculateFrustum(KX_Camera* cam); 00124 void RotateCamera(KX_Camera* cam, int i); 00125 00126 //Mesh creation Functions 00127 void CreateMeshDome180(void); 00128 void CreateMeshDome250(void); 00129 void CreateMeshPanorama(void); 00130 00131 void SplitFace(vector <DomeFace>& face, int *nfaces); 00132 00133 void FlattenDome(MT_Vector3 verts[3]); 00134 void FlattenPanorama(MT_Vector3 verts[3]); 00135 00136 //Draw functions 00137 void GLDrawTriangles(vector <DomeFace>& face, int nfaces); 00138 void GLDrawWarpQuads(void); 00139 void Draw(void); 00140 void DrawDomeFisheye(void); 00141 void DrawEnvMap(void); 00142 void DrawPanorama(void); 00143 void DrawDomeWarped(void); 00144 00145 //setting up openGL 00146 void CreateGLImages(void); 00147 void ClearGLImages(void);//called on resize 00148 bool CreateDL(void); //create Display Lists 00149 void ClearDL(void); //remove Display Lists 00150 bool CreateFBO(void);//create FBO (for warp mesh) 00151 void ClearFBO(void); //remove FBO 00152 00153 void CalculateCameraOrientation(); 00154 void CalculateImageSize(); //set m_imagesize 00155 00156 int canvaswidth; 00157 int canvasheight; 00158 00159 protected: 00160 int m_drawingmode; 00161 00162 int m_imagesize; 00163 int m_buffersize; // canvas small dimension 00164 int m_numfaces; // 4 to 6 depending on the kind of dome image 00165 int m_numimages; //numfaces +1 if we have warp mesh 00166 00167 short m_resolution; //resolution to tesselate the mesh 00168 short m_mode; // the mode (truncated, warped, panoramic,...) 00169 short m_angle; //the angle of the fisheye 00170 float m_radangle; //the angle of the fisheye in radians 00171 float m_resbuffer; //the resolution of the buffer 00172 short m_tilt; //the dome tilt (camera rotation on horizontal axis) 00173 00174 RAS_Rect m_viewport; 00175 00176 MT_Matrix4x4 m_projmat; 00177 00178 MT_Matrix3x3 m_locRot [6];// the rotation matrix 00179 00181 KX_Scene * m_scene; 00182 00184 RAS_ICanvas* m_canvas; 00186 RAS_IRasterizer* m_rasterizer; 00188 RAS_IRenderTools* m_rendertools; 00190 KX_KetsjiEngine* m_engine; 00191 00192 00193 #ifdef WITH_CXX_GUARDEDALLOC 00194 public: 00195 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_Dome"); } 00196 void operator delete( void *mem ) { MEM_freeN(mem); } 00197 #endif 00198 }; 00199 00200 #endif 00201