2 -----------------------------------------------------------------------------
4 This program is free software; you can redistribute it and/or modify it under
5 the terms of the GNU Lesser General Public License as published by the Free Software
6 Foundation; either version 2 of the License, or (at your option) any later
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13 You should have received a copy of the GNU Lesser General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
16 http://www.gnu.org/copyleft/lesser.txt.
18 Contributor(s): Dalai Felinto
20 This source uses some of the ideas and code from Paul Bourke.
21 Developed as part of a Research and Development project for SAT - La Soci�t� des arts technologiques.
22 -----------------------------------------------------------------------------
29 #if !defined KX_DOME_H
33 #include "KX_Camera.h"
34 #include "DNA_screen_types.h"
35 #include "RAS_ICanvas.h"
36 #include "RAS_IRasterizer.h"
37 #include "RAS_IRenderTools.h"
38 #include "KX_KetsjiEngine.h"
43 #include "MEM_guardedalloc.h"
46 //Dome modes: limit hardcoded in buttons_scene.c
47 #define DOME_FISHEYE 1
48 #define DOME_TRUNCATED_FRONT 2
49 #define DOME_TRUNCATED_REAR 3
51 #define DOME_PANORAM_SPH 5
52 #define DOME_NUM_MODES 6
55 /// class for render 3d scene
60 KX_Dome (RAS_ICanvas* m_canvas,
62 RAS_IRasterizer* m_rasterizer,
64 RAS_IRenderTools* m_rendertools,
66 KX_KetsjiEngine* m_engine,
77 virtual ~KX_Dome (void);
84 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
85 GLuint dlistId; // ID of the Display Lists of the images (used as an offset)
89 MT_Vector3 verts[3]; //three verts
100 int n_width, n_height; //nodes width and height
102 int bufferwidth, bufferheight;
104 vector <vector <WarpMeshNode> > nodes;
107 bool ParseWarpMesh(STR_String text);
109 vector <DomeFace> cubetop, cubebottom, cuberight, cubeleft, cubefront, cubeback; //for fisheye
110 vector <DomeFace> cubeleftback, cuberightback; //for panorama
112 int nfacestop, nfacesbottom, nfacesleft, nfacesright, nfacesfront, nfacesback;
113 int nfacesleftback, nfacesrightback;
115 int GetNumberRenders() { return m_numfaces; }
117 void RenderDome(void);
118 void RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i);
119 void BindImages(int i);
121 void SetViewPort(GLuint viewport[4]);
122 void CalculateFrustum(KX_Camera* cam);
123 void RotateCamera(KX_Camera* cam, int i);
125 //Mesh creation Functions
126 void CreateMeshDome180(void);
127 void CreateMeshDome250(void);
128 void CreateMeshPanorama(void);
130 void SplitFace(vector <DomeFace>& face, int *nfaces);
132 void FlattenDome(MT_Vector3 verts[3]);
133 void FlattenPanorama(MT_Vector3 verts[3]);
136 void GLDrawTriangles(vector <DomeFace>& face, int nfaces);
137 void GLDrawWarpQuads(void);
139 void DrawDomeFisheye(void);
140 void DrawEnvMap(void);
141 void DrawPanorama(void);
142 void DrawDomeWarped(void);
145 void CreateGLImages(void);
146 void ClearGLImages(void);//called on resize
147 bool CreateDL(void); //create Display Lists
148 void ClearDL(void); //remove Display Lists
149 bool CreateFBO(void);//create FBO (for warp mesh)
150 void ClearFBO(void); //remove FBO
152 void CalculateCameraOrientation();
153 void CalculateImageSize(); //set m_imagesize
162 int m_buffersize; // canvas small dimension
163 int m_numfaces; // 4 to 6 depending on the kind of dome image
164 int m_numimages; //numfaces +1 if we have warp mesh
166 short m_resolution; //resolution to tesselate the mesh
167 short m_mode; // the mode (truncated, warped, panoramic,...)
168 short m_angle; //the angle of the fisheye
169 float m_radangle; //the angle of the fisheye in radians
170 float m_resbuffer; //the resolution of the buffer
171 short m_tilt; //the dome tilt (camera rotation on horizontal axis)
175 MT_Matrix4x4 m_projmat;
177 MT_Matrix3x3 m_locRot [6];// the rotation matrix
183 RAS_ICanvas* m_canvas;
185 RAS_IRasterizer* m_rasterizer;
187 RAS_IRenderTools* m_rendertools;
189 KX_KetsjiEngine* m_engine;
192 #ifdef WITH_CXX_GUARDEDALLOC
194 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_Dome"); }
195 void operator delete( void *mem ) { MEM_freeN(mem); }