Blender V2.61 - r43446
|
00001 /* 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 (RAS_ICanvas* m_canvas, 00062 RAS_IRasterizer* m_rasterizer, 00064 RAS_IRenderTools* m_rendertools, 00066 KX_KetsjiEngine* m_engine, 00067 00068 short res, 00069 short mode, 00070 short angle, 00071 float resbuf, 00072 short tilt, 00073 struct Text* warptext 00074 ); 00075 00077 virtual ~KX_Dome (void); 00078 00079 //openGL checks: 00080 bool dlistSupported; 00081 bool fboSupported; 00082 00083 //openGL names: 00084 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 00085 GLuint dlistId; // ID of the Display Lists of the images (used as an offset) 00086 00087 typedef struct { 00088 double u[3], v[3]; 00089 MT_Vector3 verts[3]; //three verts 00090 } DomeFace; 00091 00092 //mesh warp functions 00093 typedef struct { 00094 double x, y, u, v, i; 00095 } WarpMeshNode; 00096 00097 struct { 00098 bool usemesh; 00099 int mode; 00100 int n_width, n_height; //nodes width and height 00101 int imagesize; 00102 int bufferwidth, bufferheight; 00103 GLuint fboId; 00104 vector <vector <WarpMeshNode> > nodes; 00105 } warp; 00106 00107 bool ParseWarpMesh(STR_String text); 00108 00109 vector <DomeFace> cubetop, cubebottom, cuberight, cubeleft, cubefront, cubeback; //for fisheye 00110 vector <DomeFace> cubeleftback, cuberightback; //for panorama 00111 00112 int nfacestop, nfacesbottom, nfacesleft, nfacesright, nfacesfront, nfacesback; 00113 int nfacesleftback, nfacesrightback; 00114 00115 int GetNumberRenders(){return m_numfaces;}; 00116 00117 void RenderDome(void); 00118 void RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i); 00119 void BindImages(int i); 00120 00121 void SetViewPort(GLuint viewport[4]); 00122 void CalculateFrustum(KX_Camera* cam); 00123 void RotateCamera(KX_Camera* cam, int i); 00124 00125 //Mesh creation Functions 00126 void CreateMeshDome180(void); 00127 void CreateMeshDome250(void); 00128 void CreateMeshPanorama(void); 00129 00130 void SplitFace(vector <DomeFace>& face, int *nfaces); 00131 00132 void FlattenDome(MT_Vector3 verts[3]); 00133 void FlattenPanorama(MT_Vector3 verts[3]); 00134 00135 //Draw functions 00136 void GLDrawTriangles(vector <DomeFace>& face, int nfaces); 00137 void GLDrawWarpQuads(void); 00138 void Draw(void); 00139 void DrawDomeFisheye(void); 00140 void DrawEnvMap(void); 00141 void DrawPanorama(void); 00142 void DrawDomeWarped(void); 00143 00144 //setting up openGL 00145 void CreateGLImages(void); 00146 void ClearGLImages(void);//called on resize 00147 bool CreateDL(void); //create Display Lists 00148 void ClearDL(void); //remove Display Lists 00149 bool CreateFBO(void);//create FBO (for warp mesh) 00150 void ClearFBO(void); //remove FBO 00151 00152 void CalculateCameraOrientation(); 00153 void CalculateImageSize(); //set m_imagesize 00154 00155 int canvaswidth; 00156 int canvasheight; 00157 00158 protected: 00159 int m_drawingmode; 00160 00161 int m_imagesize; 00162 int m_buffersize; // canvas small dimension 00163 int m_numfaces; // 4 to 6 depending on the kind of dome image 00164 int m_numimages; //numfaces +1 if we have warp mesh 00165 00166 short m_resolution; //resolution to tesselate the mesh 00167 short m_mode; // the mode (truncated, warped, panoramic,...) 00168 short m_angle; //the angle of the fisheye 00169 float m_radangle; //the angle of the fisheye in radians 00170 float m_resbuffer; //the resolution of the buffer 00171 short m_tilt; //the dome tilt (camera rotation on horizontal axis) 00172 00173 RAS_Rect m_viewport; 00174 00175 MT_Matrix4x4 m_projmat; 00176 00177 MT_Matrix3x3 m_locRot [6];// the rotation matrix 00178 00180 KX_Scene * m_scene; 00181 00183 RAS_ICanvas* m_canvas; 00185 RAS_IRasterizer* m_rasterizer; 00187 RAS_IRenderTools* m_rendertools; 00189 KX_KetsjiEngine* m_engine; 00190 00191 00192 #ifdef WITH_CXX_GUARDEDALLOC 00193 public: 00194 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_Dome"); } 00195 void operator delete( void *mem ) { MEM_freeN(mem); } 00196 #endif 00197 }; 00198 00199 #endif 00200