0024070: OpenGL capped object-level clipping planes
[occt.git] / src / OpenGl / OpenGl_View.cxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
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.
9//
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.
12//
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.
19
5f8b738e 20#include <OpenGl_GlCore11.hxx>
21
2166f0fa 22#include <OpenGl_View.hxx>
bf75be98 23#include <OpenGl_Context.hxx>
2166f0fa
SK
24#include <OpenGl_Workspace.hxx>
25#include <OpenGl_Display.hxx>
26
bf75be98 27#include <OpenGl_Texture.hxx>
2166f0fa
SK
28#include <OpenGl_Trihedron.hxx>
29#include <OpenGl_GraduatedTrihedron.hxx>
30
31#include <OpenGl_transform_persistence.hxx>
32
bf75be98 33#include <Graphic3d_TextureEnv.hxx>
34
2166f0fa
SK
35IMPLEMENT_STANDARD_HANDLE(OpenGl_View,MMgt_TShared)
36IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared)
37
38/*----------------------------------------------------------------------*/
39
40static const OPENGL_BG_TEXTURE myDefaultBgTexture = { 0, 0, 0, Aspect_FM_CENTERED };
41static const OPENGL_BG_GRADIENT myDefaultBgGradient = { {{ 0.F, 0.F, 0.F, 1.F }}, {{ 0.F, 0.F, 0.F, 1.F }}, Aspect_GFM_NONE };
42static const Tmatrix3 myDefaultMatrix = { { 1.F, 0.F, 0.F, 0.F }, { 0.F, 1.F, 0.F, 0.F }, { 0.F, 0.F, 1.F, 0.F }, { 0.F, 0.F, 0.F, 1.F } };
43static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } };
44static const OPENGL_EXTRA_REP myDefaultExtra =
45{
46 //vrp
47 { 0.F, 0.F, 0.F },
48 //vpn
49 { 0.F, 0.F, 1.F },
50 //vup
51 { 0.F, 1.F, 0.F },
52 //map
53 {
54 //window
55 { 0.F, 0.F, 1.F, 1.F },
56 //viewport
57 { 0.F, 0.F, 0.F, 1.F, 1.F, 1.F },
58 //proj
59 TelParallel,
60 //prp
61 { 0.F, 0.F, 0.F },
62 //vpd
63 0.F,
64 //fpd
65 0.F,
66 //bpd
67 -1.F
68 },
69 //scaleFactors
70 { 1.F, 1.F, 1.F }
71};
72
73static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
74static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F };
c34dba32 75static const GLdouble THE_IDENTITY_MATRIX[4][4] =
76{
77 {1.0, 0.0, 0.0, 0.0},
78 {0.0, 1.0, 0.0, 0.0},
79 {0.0, 0.0, 1.0, 0.0},
80 {0.0, 0.0, 0.0, 1.0}
81};
2166f0fa
SK
82
83/*----------------------------------------------------------------------*/
84
85OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext)
bf75be98 86: mySurfaceDetail(Visual3d_TOD_NONE),
2166f0fa
SK
87 myBackfacing(0),
88 myBgTexture(myDefaultBgTexture),
89 myBgGradient(myDefaultBgGradient),
90 //myOrientationMatrix(myDefaultMatrix),
91 //myMappingMatrix(myDefaultMatrix),
92 //shield_indicator = TOn,
93 //shield_colour = { { 0.F, 0.F, 0.F, 1.F } },
94 //border_indicator = TOff,
95 //border_colour = { { 0.F, 0.F, 0.F, 1.F } },
96 //active_status = TOn,
97 myZClip(myDefaultZClip),
98 myExtra(myDefaultExtra),
99 myFog(myDefaultFog),
100 myVisualization(AContext.Visualization),
101 myIntShadingMethod(TEL_SM_GOURAUD),
102 myAntiAliasing(Standard_False),
2166f0fa 103 myTransPers(&myDefaultTransPers),
da0e82aa 104 myTrihedron(NULL),
eafb234b 105 myIsTransPers(Standard_False),
da0e82aa 106 myGraduatedTrihedron(NULL)
2166f0fa
SK
107{
108 // Initialize matrices
109 memcpy(myOrientationMatrix,myDefaultMatrix,sizeof(Tmatrix3));
110 memcpy(myMappingMatrix,myDefaultMatrix,sizeof(Tmatrix3));
111
112 // Shading method
113 switch (AContext.Model)
114 {
115 case 1 : /* VISUAL3D_TOM_INTERP_COLOR */
116 case 3 : /* VISUAL3D_TOM_VERTEX */
117 myIntShadingMethod = TEL_SM_GOURAUD;
118 break;
119 default :
120 myIntShadingMethod = TEL_SM_FLAT;
121 break;
122 }
123}
124
125/*----------------------------------------------------------------------*/
126
127OpenGl_View::~OpenGl_View ()
128{
bf75be98 129 ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
130}
131
132void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
133{
a174a3c5 134 OpenGl_Element::Destroy (theCtx, myTrihedron);
135 OpenGl_Element::Destroy (theCtx, myGraduatedTrihedron);
da0e82aa 136
bf75be98 137 if (!myTextureEnv.IsNull())
138 {
139 theCtx->DelayedRelease (myTextureEnv);
140 myTextureEnv.Nullify();
141 }
142 if (myBgTexture.TexId != 0)
143 {
144 glDeleteTextures (1, (GLuint*)&(myBgTexture.TexId));
145 myBgTexture.TexId = 0;
146 }
bf75be98 147}
2166f0fa 148
bf75be98 149void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
150 const Handle(Graphic3d_TextureEnv)& theTexture)
151{
152 if (!myTextureEnv.IsNull())
153 {
154 theCtx->DelayedRelease (myTextureEnv);
155 myTextureEnv.Nullify();
156 }
157
158 if (theTexture.IsNull())
159 {
160 return;
161 }
162
163 myTextureEnv = new OpenGl_Texture (theTexture->GetParams());
164 Handle(Image_PixMap) anImage = theTexture->GetImage();
da0e82aa 165 if( !anImage.IsNull())
166 myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type());
2166f0fa
SK
167}
168
169/*----------------------------------------------------------------------*/
170
de75ed09 171void OpenGl_View::SetBackfacing (const Standard_Integer theMode)
2166f0fa 172{
de75ed09 173 myBackfacing = theMode;
2166f0fa
SK
174}
175
176/*----------------------------------------------------------------------*/
177
178//call_togl_setlight
179void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT &AContext)
180{
181 myLights.Clear();
182
183 const int nb_lights = AContext.NbActiveLight;
184
185 int i = 0;
186 const CALL_DEF_LIGHT *alight = &(AContext.ActiveLight[0]);
187 for ( ; i < nb_lights; i++, alight++ )
188 {
189 OpenGl_Light rep;
190
191 switch( alight->LightType )
192 {
193 case 0 : /* TOLS_AMBIENT */
194 rep.type = TLightAmbient;
195 rep.col.rgb[0] = alight->Color.r;
196 rep.col.rgb[1] = alight->Color.g;
197 rep.col.rgb[2] = alight->Color.b;
198 break;
199
200 case 1 : /* TOLS_DIRECTIONAL */
201 rep.type = TLightDirectional;
202 rep.col.rgb[0] = alight->Color.r;
203 rep.col.rgb[1] = alight->Color.g;
204 rep.col.rgb[2] = alight->Color.b;
205 rep.dir[0] = alight->Direction.x;
206 rep.dir[1] = alight->Direction.y;
207 rep.dir[2] = alight->Direction.z;
208 break;
209
210 case 2 : /* TOLS_POSITIONAL */
211 rep.type = TLightPositional;
212 rep.col.rgb[0] = alight->Color.r;
213 rep.col.rgb[1] = alight->Color.g;
214 rep.col.rgb[2] = alight->Color.b;
215 rep.pos[0] = alight->Position.x;
216 rep.pos[1] = alight->Position.y;
217 rep.pos[2] = alight->Position.z;
218 rep.atten[0] = alight->Attenuation[0];
219 rep.atten[1] = alight->Attenuation[1];
220 break;
221
222 case 3 : /* TOLS_SPOT */
223 rep.type = TLightSpot;
224 rep.col.rgb[0] = alight->Color.r;
225 rep.col.rgb[1] = alight->Color.g;
226 rep.col.rgb[2] = alight->Color.b;
227 rep.pos[0] = alight->Position.x;
228 rep.pos[1] = alight->Position.y;
229 rep.pos[2] = alight->Position.z;
230 rep.dir[0] = alight->Direction.x;
231 rep.dir[1] = alight->Direction.y;
232 rep.dir[2] = alight->Direction.z;
233 rep.shine = alight->Concentration;
234 rep.atten[0] = alight->Attenuation[0];
235 rep.atten[1] = alight->Attenuation[1];
236 rep.angle = alight->Angle;
237 break;
238 }
239
240 rep.HeadLight = alight->Headlight;
241
242 myLights.Append(rep);
243 }
244}
245
246/*----------------------------------------------------------------------*/
247
2166f0fa
SK
248//call_togl_setvisualisation
249void OpenGl_View::SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext)
250{
251 myVisualization = AContext.Visualization;
252 // Shading method
253 switch (AContext.Model)
254 {
255 case 1 : /* VISUAL3D_TOM_INTERP_COLOR */
256 case 3 : /* VISUAL3D_TOM_VERTEX */
257 myIntShadingMethod = TEL_SM_GOURAUD;
258 break;
259 default :
260 myIntShadingMethod = TEL_SM_FLAT;
261 break;
262 }
263}
264
265/*----------------------------------------------------------------------*/
266
267//call_togl_cliplimit
bf75be98 268void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView)
2166f0fa
SK
269{
270 myZClip.Back.Limit =
bf75be98 271 (theCView.Context.ZClipBackPlane - theCView.Mapping.BackPlaneDistance) /
272 (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
2166f0fa 273 myZClip.Front.Limit =
bf75be98 274 (theCView.Context.ZClipFrontPlane - theCView.Mapping.BackPlaneDistance) /
275 (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
276 if (myZClip.Back.Limit < 0.0f)
277 myZClip.Back.Limit = 0.0f;
278 if (myZClip.Front.Limit > 1.0f)
279 myZClip.Front.Limit = 1.0f;
280 if (myZClip.Back.Limit > myZClip.Front.Limit)
2166f0fa 281 {
bf75be98 282 myZClip.Back.Limit = 0.0f;
283 myZClip.Front.Limit = 1.0f;
2166f0fa
SK
284 }
285
bf75be98 286 myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0);
287 myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0);
2166f0fa
SK
288}
289
290/*----------------------------------------------------------------------*/
291
292//call_togl_viewmapping
bf75be98 293void OpenGl_View::SetMapping (const Graphic3d_CView& theCView)
2166f0fa 294{
bf75be98 295 const float ratio = theCView.DefWindow.dy / theCView.DefWindow.dx;
296 const float r_ratio = theCView.DefWindow.dx / theCView.DefWindow.dy;
2166f0fa
SK
297
298 TEL_VIEW_MAPPING Map;
299
bf75be98 300 Map.window.xmin = theCView.Mapping.WindowLimit.um;
301 Map.window.ymin = theCView.Mapping.WindowLimit.vm;
302 Map.window.xmax = theCView.Mapping.WindowLimit.uM;
303 Map.window.ymax = theCView.Mapping.WindowLimit.vM;
2166f0fa
SK
304
305 Map.viewport.xmin = 0.F;
306 Map.viewport.xmax = ( 1.F < r_ratio ? 1.F : r_ratio );
307 Map.viewport.ymin = 0.F;
308 Map.viewport.ymax = ( 1.F < ratio ? 1.F : ratio );
309 Map.viewport.zmin = 0.F;
310 Map.viewport.zmax = 1.F;
311
bf75be98 312 // projection type
313 switch (theCView.Mapping.Projection)
2166f0fa
SK
314 {
315 case 0 :
316 Map.proj = TelPerspective;
317 break;
318 case 1 :
319 Map.proj = TelParallel;
320 break;
321 }
322
bf75be98 323 // projection reference point
324 Map.prp[0] = theCView.Mapping.ProjectionReferencePoint.x;
325 Map.prp[1] = theCView.Mapping.ProjectionReferencePoint.y;
326 Map.prp[2] = theCView.Mapping.ProjectionReferencePoint.z;
2166f0fa 327 if (!openglDisplay.IsNull() && !openglDisplay->Walkthrough())
bf75be98 328 Map.prp[2] += theCView.Mapping.FrontPlaneDistance;
2166f0fa 329
bf75be98 330 // view plane distance
331 Map.vpd = theCView.Mapping.ViewPlaneDistance;
2166f0fa 332
bf75be98 333 // back plane distance
334 Map.bpd = theCView.Mapping.BackPlaneDistance;
2166f0fa 335
bf75be98 336 // front plane distance
337 Map.fpd = theCView.Mapping.FrontPlaneDistance;
2166f0fa
SK
338
339 Tint err_ind = 0;
340
bf75be98 341 // use user-defined matrix
342 if (theCView.Mapping.IsCustomMatrix)
2166f0fa
SK
343 {
344 int i, j;
345 for( i = 0; i < 4; i++ )
346 for( j = 0; j < 4; j++ )
bf75be98 347 myMappingMatrix[i][j] = theCView.Mapping.ProjectionMatrix[i][j];
2166f0fa 348 }
bf75be98 349 else
2166f0fa
SK
350 TelEvalViewMappingMatrix( &Map, &err_ind, myMappingMatrix );
351
bf75be98 352 if (!err_ind)
2166f0fa
SK
353 myExtra.map = Map;
354}
355
356/*----------------------------------------------------------------------*/
357
358//call_togl_vieworientation
bf75be98 359void OpenGl_View::SetOrientation (const Graphic3d_CView& theCView)
2166f0fa
SK
360{
361 Tfloat Vrp[3];
362 Tfloat Vpn[3];
363 Tfloat Vup[3];
364 Tfloat ScaleFactors[3];
365
bf75be98 366 Vrp[0] = theCView.Orientation.ViewReferencePoint.x;
367 Vrp[1] = theCView.Orientation.ViewReferencePoint.y;
368 Vrp[2] = theCView.Orientation.ViewReferencePoint.z;
2166f0fa 369
bf75be98 370 Vpn[0] = theCView.Orientation.ViewReferencePlane.x;
371 Vpn[1] = theCView.Orientation.ViewReferencePlane.y;
372 Vpn[2] = theCView.Orientation.ViewReferencePlane.z;
2166f0fa 373
bf75be98 374 Vup[0] = theCView.Orientation.ViewReferenceUp.x;
375 Vup[1] = theCView.Orientation.ViewReferenceUp.y;
376 Vup[2] = theCView.Orientation.ViewReferenceUp.z;
2166f0fa 377
bf75be98 378 ScaleFactors[0] = theCView.Orientation.ViewScaleX;
379 ScaleFactors[1] = theCView.Orientation.ViewScaleY;
380 ScaleFactors[2] = theCView.Orientation.ViewScaleZ;
2166f0fa
SK
381
382 Tint err_ind = 0;
383
384 // use user-defined matrix
bf75be98 385 if (theCView.Orientation.IsCustomMatrix)
2166f0fa
SK
386 {
387 int i, j;
388 for( i = 0; i < 4; i++ )
389 for( j = 0; j < 4; j++ )
bf75be98 390 myOrientationMatrix[i][j] = theCView.Orientation.ModelViewMatrix[i][j];
2166f0fa
SK
391 }
392 else
bf75be98 393 {
394 TelEvalViewOrientationMatrix (Vrp, Vpn, Vup, ScaleFactors, &err_ind, myOrientationMatrix);
395 }
2166f0fa 396
bf75be98 397 if (!err_ind)
2166f0fa
SK
398 {
399 myExtra.vrp[0] = Vrp[0];
400 myExtra.vrp[1] = Vrp[1];
401 myExtra.vrp[2] = Vrp[2];
402
403 myExtra.vpn[0] = Vpn[0];
404 myExtra.vpn[1] = Vpn[1];
405 myExtra.vpn[2] = Vpn[2];
406
407 myExtra.vup[0] = Vup[0];
408 myExtra.vup[1] = Vup[1];
409 myExtra.vup[2] = Vup[2];
410
411 myExtra.scaleFactors[0] = ScaleFactors[0],
412 myExtra.scaleFactors[1] = ScaleFactors[1],
413 myExtra.scaleFactors[2] = ScaleFactors[2];
414 }
415}
416
417/*----------------------------------------------------------------------*/
418
bf75be98 419void OpenGl_View::SetFog (const Graphic3d_CView& theCView,
420 const Standard_Boolean theFlag)
2166f0fa 421{
bf75be98 422 if (!theFlag)
2166f0fa
SK
423 {
424 myFog.IsOn = Standard_False;
425 }
426 else
427 {
428 myFog.IsOn = Standard_True;
429
430 myFog.Front =
bf75be98 431 (theCView.Context.DepthFrontPlane - theCView.Mapping.BackPlaneDistance) /
432 (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
2166f0fa
SK
433
434 myFog.Back =
bf75be98 435 (theCView.Context.DepthBackPlane - theCView.Mapping.BackPlaneDistance) /
436 (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
2166f0fa
SK
437
438 if (myFog.Front < 0.F)
439 myFog.Front = 0.F;
440 else if (myFog.Front > 1.F)
441 myFog.Front = 1.F;
442
443 if (myFog.Back < 0.F)
444 myFog.Back = 0.F;
445 else if (myFog.Back > 1.F)
446 myFog.Back = 1.F;
447
448 if (myFog.Back > myFog.Front)
449 {
450 myFog.Front = 1.F;
451 myFog.Back = 0.F;
452 }
453
bf75be98 454 myFog.Color.rgb[0] = theCView.DefWindow.Background.r;
455 myFog.Color.rgb[1] = theCView.DefWindow.Background.g;
456 myFog.Color.rgb[2] = theCView.DefWindow.Background.b;
457 myFog.Color.rgb[3] = 1.0f;
2166f0fa
SK
458 }
459}
460
461/*----------------------------------------------------------------------*/
462
a174a3c5 463void OpenGl_View::TriedronDisplay (const Handle(OpenGl_Context)& theCtx,
464 const Aspect_TypeOfTriedronPosition thePosition,
465 const Quantity_NameOfColor theColor,
466 const Standard_Real theScale,
467 const Standard_Boolean theAsWireframe)
2166f0fa 468{
a174a3c5 469 OpenGl_Element::Destroy (theCtx, myTrihedron);
470 myTrihedron = new OpenGl_Trihedron (thePosition, theColor, theScale, theAsWireframe);
2166f0fa
SK
471}
472
473/*----------------------------------------------------------------------*/
474
a174a3c5 475void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx)
2166f0fa 476{
a174a3c5 477 OpenGl_Element::Destroy (theCtx, myTrihedron);
2166f0fa
SK
478}
479
480/*----------------------------------------------------------------------*/
481
a174a3c5 482void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
483 const Graphic3d_CGraduatedTrihedron& theData)
2166f0fa 484{
a174a3c5 485 OpenGl_Element::Destroy (theCtx, myGraduatedTrihedron);
486 myGraduatedTrihedron = new OpenGl_GraduatedTrihedron (theData);
2166f0fa
SK
487}
488
489/*----------------------------------------------------------------------*/
490
a174a3c5 491void OpenGl_View::GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx)
2166f0fa 492{
a174a3c5 493 OpenGl_Element::Destroy (theCtx, myGraduatedTrihedron);
2166f0fa
SK
494}
495
496/*----------------------------------------------------------------------*/
497
498//transform_persistence_end
c34dba32 499void OpenGl_View::EndTransformPersistence()
2166f0fa 500{
c34dba32 501 if (myIsTransPers)
2166f0fa 502 {
c34dba32 503 // restore matrix
2166f0fa 504 glMatrixMode (GL_PROJECTION);
c34dba32 505 glPopMatrix();
2166f0fa 506 glMatrixMode (GL_MODELVIEW);
c34dba32 507 glPopMatrix();
2166f0fa
SK
508 myIsTransPers = Standard_False;
509 }
bf75be98 510}
2166f0fa
SK
511
512/*----------------------------------------------------------------------*/
513
514//transform_persistence_begin
c34dba32 515const TEL_TRANSFORM_PERSISTENCE* OpenGl_View::BeginTransformPersistence (const TEL_TRANSFORM_PERSISTENCE* theTransPers)
2166f0fa 516{
c34dba32 517 const TEL_TRANSFORM_PERSISTENCE* aTransPersPrev = myTransPers;
518 myTransPers = theTransPers;
519 if (theTransPers->mode == 0)
2166f0fa
SK
520 {
521 EndTransformPersistence();
c34dba32 522 return aTransPersPrev;
2166f0fa
SK
523 }
524
c34dba32 525 GLint aViewport[4];
526 GLdouble aModelMatrix[4][4];
527 GLdouble aProjMatrix[4][4];
528 glGetIntegerv (GL_VIEWPORT, aViewport);
529 glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix);
530 glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble *)aProjMatrix);
531 const GLdouble aViewportW = (GLdouble )aViewport[2];
532 const GLdouble aViewportH = (GLdouble )aViewport[3];
2166f0fa 533
c34dba32 534 if (myIsTransPers)
2166f0fa 535 {
c34dba32 536 // pop matrix stack - it will be overridden later
2166f0fa 537 glMatrixMode (GL_PROJECTION);
c34dba32 538 glPopMatrix();
2166f0fa 539 glMatrixMode (GL_MODELVIEW);
c34dba32 540 glPopMatrix();
2166f0fa
SK
541 }
542 else
c34dba32 543 {
2166f0fa 544 myIsTransPers = Standard_True;
c34dba32 545 }
2166f0fa 546
c34dba32 547 // push matrices into stack and reset them
548 glMatrixMode (GL_MODELVIEW);
2166f0fa
SK
549 glPushMatrix();
550 glLoadIdentity();
551
c34dba32 552 glMatrixMode (GL_PROJECTION);
2166f0fa
SK
553 glPushMatrix();
554 glLoadIdentity();
555
c34dba32 556 // get the window's (fixed) coordinates for theTransPers->point before matrixes modifications
557 GLdouble aWinX = 0.0, aWinY = 0.0, aWinZ = 0.0;
558 if ((theTransPers->mode & TPF_PAN) != TPF_PAN)
2166f0fa 559 {
c34dba32 560 gluProject (theTransPers->pointX, theTransPers->pointY, theTransPers->pointZ,
561 (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport,
562 &aWinX, &aWinY, &aWinZ);
2166f0fa
SK
563 }
564
c34dba32 565 // prevent zooming
566 if ((theTransPers->mode & TPF_ZOOM)
567 || (theTransPers->mode == TPF_TRIEDRON))
2166f0fa 568 {
c34dba32 569 // compute fixed-zoom multiplier
570 // actually function works ugly with TelPerspective!
571 const GLdouble aDet2 = 0.002 / (aViewportW > aViewportH ? aProjMatrix[1][1] : aProjMatrix[0][0]);
572 aProjMatrix[0][0] *= aDet2;
573 aProjMatrix[1][1] *= aDet2;
574 aProjMatrix[2][2] *= aDet2;
2166f0fa
SK
575 }
576
c34dba32 577 // prevent translation - annulate translate matrix
578 if ((theTransPers->mode & TPF_PAN)
579 || (theTransPers->mode == TPF_TRIEDRON))
2166f0fa 580 {
c34dba32 581 aModelMatrix[3][0] = 0.0;
582 aModelMatrix[3][1] = 0.0;
583 aModelMatrix[3][2] = 0.0;
584 aProjMatrix [3][0] = 0.0;
585 aProjMatrix [3][1] = 0.0;
586 aProjMatrix [3][2] = 0.0;
2166f0fa 587 }
2166f0fa 588
c34dba32 589 // prevent scaling-on-axis
590 if (theTransPers->mode & TPF_ZOOM)
591 {
592 const double aScaleX = myExtra.scaleFactors[0];
593 const double aScaleY = myExtra.scaleFactors[1];
594 const double aScaleZ = myExtra.scaleFactors[2];
595 for (int i = 0; i < 3; ++i)
596 {
597 aModelMatrix[0][i] /= aScaleX;
598 aModelMatrix[1][i] /= aScaleY;
599 aModelMatrix[2][i] /= aScaleZ;
600 }
2166f0fa
SK
601 }
602
c34dba32 603 // prevent rotating - annulate rotate matrix
604 if (theTransPers->mode & TPF_ROTATE)
2166f0fa 605 {
c34dba32 606 aModelMatrix[0][0] = 1.0;
607 aModelMatrix[1][1] = 1.0;
608 aModelMatrix[2][2] = 1.0;
609
610 aModelMatrix[1][0] = 0.0;
611 aModelMatrix[2][0] = 0.0;
612 aModelMatrix[0][1] = 0.0;
613 aModelMatrix[2][1] = 0.0;
614 aModelMatrix[0][2] = 0.0;
615 aModelMatrix[1][2] = 0.0;
2166f0fa
SK
616 }
617
c34dba32 618 // load computed matrices
2166f0fa 619 glMatrixMode (GL_MODELVIEW);
c34dba32 620 glMultMatrixd ((GLdouble* )aModelMatrix);
2166f0fa
SK
621
622 glMatrixMode (GL_PROJECTION);
c34dba32 623 glMultMatrixd ((GLdouble* )aProjMatrix);
2166f0fa 624
c34dba32 625 if (theTransPers->mode == TPF_TRIEDRON)
2166f0fa 626 {
c34dba32 627 // move to the window corner
628 if (theTransPers->pointX != 0.0
629 && theTransPers->pointY != 0.0)
2166f0fa 630 {
c34dba32 631 GLdouble aW1, aH1, aW2, aH2, aDummy;
632 glMatrixMode (GL_PROJECTION);
633 gluUnProject ( 0.5 * aViewportW, 0.5 * aViewportH, 0.0,
634 (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport,
635 &aW1, &aH1, &aDummy);
636 gluUnProject (-0.5 * aViewportW, -0.5 * aViewportH, 0.0,
637 (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport,
638 &aW2, &aH2, &aDummy);
639 GLdouble aMoveX = 0.5 * (aW1 - aW2 - theTransPers->pointZ);
640 GLdouble aMoveY = 0.5 * (aH1 - aH2 - theTransPers->pointZ);
641 aMoveX = (theTransPers->pointX > 0.0) ? aMoveX : -aMoveX;
642 aMoveY = (theTransPers->pointY > 0.0) ? aMoveY : -aMoveY;
643 glTranslated (aMoveX, aMoveY, 0.0);
2166f0fa
SK
644 }
645 }
c34dba32 646 else if ((theTransPers->mode & TPF_PAN) != TPF_PAN)
647 {
648 // move to thePoint using saved win-coordinates ('marker-behaviour')
649 GLdouble aMoveX, aMoveY, aMoveZ;
650 glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix);
651 glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble* )aProjMatrix);
652 gluUnProject (aWinX, aWinY, aWinZ,
653 (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport,
654 &aMoveX, &aMoveY, &aMoveZ);
2166f0fa 655
c34dba32 656 glMatrixMode (GL_MODELVIEW);
657 glTranslated (aMoveX, aMoveY, aMoveZ);
658 }
2166f0fa 659
c34dba32 660 return aTransPersPrev;
661}