1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <OpenGl_GlCore11.hxx>
23 #include <OpenGl_View.hxx>
25 #include <Visual3d_Layer.hxx>
27 #include <OpenGl_tgl_funcs.hxx>
28 #include <OpenGl_PrinterContext.hxx>
29 #include <OpenGl_Workspace.hxx>
31 /*----------------------------------------------------------------------*/
33 //TelProjectionRaster in OpenGl_telem_util.cxx
34 Standard_Boolean OpenGl_View::ProjectObjectToRaster (const Standard_Integer w, const Standard_Integer h,
35 const Standard_ShortReal x, const Standard_ShortReal y, const Standard_ShortReal z,
36 Standard_ShortReal &xr, Standard_ShortReal &yr)
40 GLdouble modelMatrix[16];
41 for (k = 0, i = 0; i < 4; i++)
42 for (j = 0; j < 4; j++, k++)
43 modelMatrix[k] = ( GLdouble )myOrientationMatrix[i][j];
45 GLdouble projMatrix[16];
46 for (k = 0, i = 0; i < 4; i++)
47 for (j = 0; j < 4; j++, k++)
48 projMatrix[k] = ( GLdouble )myMappingMatrix[i][j];
57 * glGetIntegerv (GL_VIEWPORT, viewport);
58 * glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
59 * glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
62 GLdouble winx, winy, winz;
63 if (gluProject (( GLdouble )x, ( GLdouble )y, ( GLdouble )z, modelMatrix, projMatrix, viewport, &winx, &winy, &winz))
65 xr = ( Standard_ShortReal )winx;
66 yr = ( Standard_ShortReal )winy;
72 return Standard_False;
75 /*----------------------------------------------------------------------*/
76 //TelUnProjectionRaster
77 Standard_Boolean OpenGl_View::ProjectRasterToObject (const Standard_Integer w, const Standard_Integer h,
78 const Standard_Integer xr, const Standard_Integer yr,
79 Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z)
83 GLdouble modelMatrix[16];
84 for (k = 0, i = 0; i < 4; i++)
85 for (j = 0; j < 4; j++, k++)
86 modelMatrix[k] = ( GLdouble )myOrientationMatrix[i][j];
88 GLdouble projMatrix[16];
89 for (k = 0, i = 0; i < 4; i++)
90 for (j = 0; j < 4; j++, k++)
91 projMatrix[k] = ( GLdouble )myMappingMatrix[i][j];
100 * glGetIntegerv (GL_VIEWPORT, viewport);
101 * glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
102 * glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
105 GLdouble objx, objy, objz;
106 if (gluUnProject (( GLdouble )xr, ( GLdouble )yr, 0.0, modelMatrix, projMatrix, viewport, &objx, &objy, &objz))
108 x = ( Standard_ShortReal )objx;
109 y = ( Standard_ShortReal )objy;
110 z = ( Standard_ShortReal )objz;
111 return Standard_True;
117 return Standard_False;
120 /*----------------------------------------------------------------------*/
121 //TelUnProjectionRasterWithRay
122 Standard_Boolean OpenGl_View::ProjectRasterToObjectWithRay (const Standard_Integer w, const Standard_Integer h,
123 const Standard_Integer xr, const Standard_Integer yr,
124 Standard_ShortReal &x, Standard_ShortReal &y, Standard_ShortReal &z,
125 Standard_ShortReal &dx, Standard_ShortReal &dy, Standard_ShortReal &dz)
129 GLdouble modelMatrix[16];
130 for (k = 0, i = 0; i < 4; i++)
131 for (j = 0; j < 4; j++, k++)
132 modelMatrix[k] = ( GLdouble )myOrientationMatrix[i][j];
134 GLdouble projMatrix[16];
135 for (k = 0, i = 0; i < 4; i++)
136 for (j = 0; j < 4; j++, k++)
137 projMatrix[k] = ( GLdouble )myMappingMatrix[i][j];
146 * glGetIntegerv (GL_VIEWPORT, viewport);
147 * glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
148 * glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
151 const GLdouble winx = ( GLdouble )xr;
152 const GLdouble winy = ( GLdouble )yr;
154 GLdouble objx, objy, objz;
155 if (gluUnProject (winx, winy, 0.0, modelMatrix, projMatrix, viewport, &objx, &objy, &objz))
157 GLdouble objx1, objy1, objz1;
158 if (gluUnProject (winx, winy, -10.0, modelMatrix, projMatrix, viewport, &objx1, &objy1, &objz1))
160 x = ( Standard_ShortReal )objx;
161 y = ( Standard_ShortReal )objy;
162 z = ( Standard_ShortReal )objz;
163 dx = ( Standard_ShortReal )(objx-objx1);
164 dy = ( Standard_ShortReal )(objy-objy1);
165 dz = ( Standard_ShortReal )(objz-objz1);
166 return Standard_True;
176 return Standard_False;
179 /*----------------------------------------------------------------------*/
181 //call_togl_inquiremat
182 void OpenGl_View::GetMatrices (TColStd_Array2OfReal& theMatOrient,
183 TColStd_Array2OfReal& theMatMapping,
184 const Standard_Boolean theIsCustom) const
189 // OCC18942: Trying to return the current matrices instead of calculating them anew.
190 // This in particular allows using application-defined matrices.
191 for (i = 0; i < 4; ++i)
193 for (j = 0; j < 4; ++j)
195 theMatOrient (i, j) = myOrientationMatrix[j][i];
196 theMatMapping (i, j) = myMappingMatrix[j][i];
204 Tmatrix3 aMatMapping;
207 memcpy (&aViewMap.win, &myExtra.map.window, sizeof(Tlimit));
208 memcpy (&aViewMap.proj_vp, &myExtra.map.viewport, sizeof(Tlimit3));
209 switch (myExtra.map.proj)
212 case TelParallel: aViewMap.proj_type = TYPE_PARAL; break;
213 case TelPerspective: aViewMap.proj_type = TYPE_PERSPECT; break;
215 aViewMap.proj_ref_point.x = myExtra.map.prp[0];
216 aViewMap.proj_ref_point.y = myExtra.map.prp[1];
217 aViewMap.proj_ref_point.z = myExtra.map.prp[2];
218 aViewMap.view_plane = myExtra.map.vpd;
219 aViewMap.back_plane = myExtra.map.bpd;
220 aViewMap.front_plane = myExtra.map.fpd;
222 call_func_eval_ori_matrix3 ((const point3* )myExtra.vrp,
223 (const vec3* )myExtra.vpn,
224 (const vec3* )myExtra.vup,
227 call_func_eval_map_matrix3 (&aViewMap, &anErr, aMatMapping);
231 for (i = 0; i < 4; ++i)
233 for (j = 0; j < 4; ++j)
235 theMatOrient (i, j) = aMatOri[j][i];
236 theMatMapping (i, j) = aMatMapping[j][i];
242 // return just identity matrices
243 for (i = 0; i < 4; ++i)
245 for (j = 0; j < 4; ++j)
248 theMatMapping (i, j) = 1.0;
249 theMatOrient (i, j) = 1.0;
252 theMatMapping (i, j) = 0.0;
253 theMatOrient (i, j) = 0.0;
259 /*----------------------------------------------------------------------*/