-// File: OpenGl_View.cxx
-// Created: 20 September 2011
-// Author: Sergey ZERCHANINOV
-// Copyright: OPEN CASCADE 2011
+// Created on: 2011-09-20
+// Created by: Sergey ZERCHANINOV
+// Copyright (c) 2011-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#include <OpenGl_GlCore11.hxx>
#include <OpenGl_View.hxx>
-
+#include <OpenGl_Context.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_Display.hxx>
-#include <OpenGl_tgl_all.hxx>
-#include <GL/gl.h>
-
-#include <OpenGl_Display.hxx>
+#include <OpenGl_Texture.hxx>
#include <OpenGl_Trihedron.hxx>
#include <OpenGl_GraduatedTrihedron.hxx>
#include <OpenGl_transform_persistence.hxx>
+#include <Graphic3d_TextureEnv.hxx>
+
+#include <GL/glu.h> // gluUnProject()
+
IMPLEMENT_STANDARD_HANDLE(OpenGl_View,MMgt_TShared)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared)
static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } };
static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F };
+static const GLdouble THE_IDENTITY_MATRIX[4][4] =
+{
+ {1.0, 0.0, 0.0, 0.0},
+ {0.0, 1.0, 0.0, 0.0},
+ {0.0, 0.0, 1.0, 0.0},
+ {0.0, 0.0, 0.0, 1.0}
+};
/*----------------------------------------------------------------------*/
OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext)
-: myTextureEnv(0),
- mySurfaceDetail(Visual3d_TOD_NONE),
+: mySurfaceDetail(Visual3d_TOD_NONE),
myBackfacing(0),
myBgTexture(myDefaultBgTexture),
myBgGradient(myDefaultBgGradient),
OpenGl_View::~OpenGl_View ()
{
+ ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
+}
+
+void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
+{
+ if (!myTextureEnv.IsNull())
+ {
+ theCtx->DelayedRelease (myTextureEnv);
+ myTextureEnv.Nullify();
+ }
+ if (myBgTexture.TexId != 0)
+ {
+ glDeleteTextures (1, (GLuint*)&(myBgTexture.TexId));
+ myBgTexture.TexId = 0;
+ }
if (myAnimationListIndex)
- glDeleteLists((GLuint)myAnimationListIndex,1);
+ {
+ glDeleteLists ((GLuint )myAnimationListIndex, 1);
+ myAnimationListIndex = 0;
+ }
+}
+
+void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
+ const Handle(Graphic3d_TextureEnv)& theTexture)
+{
+ if (!myTextureEnv.IsNull())
+ {
+ theCtx->DelayedRelease (myTextureEnv);
+ myTextureEnv.Nullify();
+ }
+
+ if (theTexture.IsNull())
+ {
+ return;
+ }
- if ( myBgTexture.TexId != 0 )
- glDeleteTextures( 1, (GLuint*)&(myBgTexture.TexId) );
+ myTextureEnv = new OpenGl_Texture (theTexture->GetParams());
+ Handle(Image_PixMap) anImage = theTexture->GetImage();
+ myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type());
}
/*----------------------------------------------------------------------*/
{
// clear clipping planes information
myClippingPlanes.Clear();
- // update information
+ // update information
int i = 0;
for (; i < AContext.NbActivePlane; i++)
{
/*----------------------------------------------------------------------*/
//call_togl_cliplimit
-void OpenGl_View::SetClipLimit (const CALL_DEF_VIEW &ACView)
+void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView)
{
myZClip.Back.Limit =
- ( ACView.Context.ZClipBackPlane - ACView.Mapping.BackPlaneDistance ) /
- ( ACView.Mapping.FrontPlaneDistance - ACView.Mapping.BackPlaneDistance );
+ (theCView.Context.ZClipBackPlane - theCView.Mapping.BackPlaneDistance) /
+ (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
myZClip.Front.Limit =
- ( ACView.Context.ZClipFrontPlane - ACView.Mapping.BackPlaneDistance ) /
- ( ACView.Mapping.FrontPlaneDistance - ACView.Mapping.BackPlaneDistance );
- if ( myZClip.Back.Limit < 0.F )
- myZClip.Back.Limit = 0.F;
- if ( myZClip.Front.Limit > 1.F )
- myZClip.Front.Limit = 1.F;
- if ( myZClip.Back.Limit > myZClip.Front.Limit )
+ (theCView.Context.ZClipFrontPlane - theCView.Mapping.BackPlaneDistance) /
+ (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
+ if (myZClip.Back.Limit < 0.0f)
+ myZClip.Back.Limit = 0.0f;
+ if (myZClip.Front.Limit > 1.0f)
+ myZClip.Front.Limit = 1.0f;
+ if (myZClip.Back.Limit > myZClip.Front.Limit)
{
- myZClip.Back.Limit = 0.F;
- myZClip.Front.Limit = 1.F;
+ myZClip.Back.Limit = 0.0f;
+ myZClip.Front.Limit = 1.0f;
}
- myZClip.Back.IsOn = (ACView.Context.BackZClipping != 0);
- myZClip.Front.IsOn = (ACView.Context.FrontZClipping != 0);
+ myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0);
+ myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0);
}
/*----------------------------------------------------------------------*/
//call_togl_viewmapping
-void OpenGl_View::SetMapping (const CALL_DEF_VIEW &ACView)
+void OpenGl_View::SetMapping (const Graphic3d_CView& theCView)
{
- const float ratio = ACView.DefWindow.dy / ACView.DefWindow.dx;
- const float r_ratio = ACView.DefWindow.dx / ACView.DefWindow.dy;
+ const float ratio = theCView.DefWindow.dy / theCView.DefWindow.dx;
+ const float r_ratio = theCView.DefWindow.dx / theCView.DefWindow.dy;
TEL_VIEW_MAPPING Map;
- Map.window.xmin = ACView.Mapping.WindowLimit.um;
- Map.window.ymin = ACView.Mapping.WindowLimit.vm;
- Map.window.xmax = ACView.Mapping.WindowLimit.uM;
- Map.window.ymax = ACView.Mapping.WindowLimit.vM;
+ Map.window.xmin = theCView.Mapping.WindowLimit.um;
+ Map.window.ymin = theCView.Mapping.WindowLimit.vm;
+ Map.window.xmax = theCView.Mapping.WindowLimit.uM;
+ Map.window.ymax = theCView.Mapping.WindowLimit.vM;
Map.viewport.xmin = 0.F;
Map.viewport.xmax = ( 1.F < r_ratio ? 1.F : r_ratio );
Map.viewport.zmin = 0.F;
Map.viewport.zmax = 1.F;
- /* projection type */
- switch( ACView.Mapping.Projection )
+ // projection type
+ switch (theCView.Mapping.Projection)
{
case 0 :
Map.proj = TelPerspective;
break;
}
- /* projection reference point */
- Map.prp[0] = ACView.Mapping.ProjectionReferencePoint.x;
- Map.prp[1] = ACView.Mapping.ProjectionReferencePoint.y;
- Map.prp[2] = ACView.Mapping.ProjectionReferencePoint.z;
+ // projection reference point
+ Map.prp[0] = theCView.Mapping.ProjectionReferencePoint.x;
+ Map.prp[1] = theCView.Mapping.ProjectionReferencePoint.y;
+ Map.prp[2] = theCView.Mapping.ProjectionReferencePoint.z;
if (!openglDisplay.IsNull() && !openglDisplay->Walkthrough())
- Map.prp[2] += ACView.Mapping.FrontPlaneDistance;
+ Map.prp[2] += theCView.Mapping.FrontPlaneDistance;
- /* view plane distance */
- Map.vpd = ACView.Mapping.ViewPlaneDistance;
+ // view plane distance
+ Map.vpd = theCView.Mapping.ViewPlaneDistance;
- /* back plane distance */
- Map.bpd = ACView.Mapping.BackPlaneDistance;
+ // back plane distance
+ Map.bpd = theCView.Mapping.BackPlaneDistance;
- /* front plane distance */
- Map.fpd = ACView.Mapping.FrontPlaneDistance;
+ // front plane distance
+ Map.fpd = theCView.Mapping.FrontPlaneDistance;
Tint err_ind = 0;
- /* use user-defined matrix */
- if ( ACView.Mapping.IsCustomMatrix )
+ // use user-defined matrix
+ if (theCView.Mapping.IsCustomMatrix)
{
int i, j;
for( i = 0; i < 4; i++ )
for( j = 0; j < 4; j++ )
- myMappingMatrix[i][j] = ACView.Mapping.ProjectionMatrix[i][j];
+ myMappingMatrix[i][j] = theCView.Mapping.ProjectionMatrix[i][j];
}
- else
+ else
TelEvalViewMappingMatrix( &Map, &err_ind, myMappingMatrix );
- if ( !err_ind )
+ if (!err_ind)
myExtra.map = Map;
}
/*----------------------------------------------------------------------*/
//call_togl_vieworientation
-void OpenGl_View::SetOrientation (const CALL_DEF_VIEW &ACView)
+void OpenGl_View::SetOrientation (const Graphic3d_CView& theCView)
{
Tfloat Vrp[3];
Tfloat Vpn[3];
Tfloat Vup[3];
Tfloat ScaleFactors[3];
- Vrp[0] = ACView.Orientation.ViewReferencePoint.x;
- Vrp[1] = ACView.Orientation.ViewReferencePoint.y;
- Vrp[2] = ACView.Orientation.ViewReferencePoint.z;
+ Vrp[0] = theCView.Orientation.ViewReferencePoint.x;
+ Vrp[1] = theCView.Orientation.ViewReferencePoint.y;
+ Vrp[2] = theCView.Orientation.ViewReferencePoint.z;
- Vpn[0] = ACView.Orientation.ViewReferencePlane.x;
- Vpn[1] = ACView.Orientation.ViewReferencePlane.y;
- Vpn[2] = ACView.Orientation.ViewReferencePlane.z;
+ Vpn[0] = theCView.Orientation.ViewReferencePlane.x;
+ Vpn[1] = theCView.Orientation.ViewReferencePlane.y;
+ Vpn[2] = theCView.Orientation.ViewReferencePlane.z;
- Vup[0] = ACView.Orientation.ViewReferenceUp.x;
- Vup[1] = ACView.Orientation.ViewReferenceUp.y;
- Vup[2] = ACView.Orientation.ViewReferenceUp.z;
+ Vup[0] = theCView.Orientation.ViewReferenceUp.x;
+ Vup[1] = theCView.Orientation.ViewReferenceUp.y;
+ Vup[2] = theCView.Orientation.ViewReferenceUp.z;
- ScaleFactors[0] = ACView.Orientation.ViewScaleX;
- ScaleFactors[1] = ACView.Orientation.ViewScaleY;
- ScaleFactors[2] = ACView.Orientation.ViewScaleZ;
+ ScaleFactors[0] = theCView.Orientation.ViewScaleX;
+ ScaleFactors[1] = theCView.Orientation.ViewScaleY;
+ ScaleFactors[2] = theCView.Orientation.ViewScaleZ;
Tint err_ind = 0;
// use user-defined matrix
- if ( ACView.Orientation.IsCustomMatrix )
+ if (theCView.Orientation.IsCustomMatrix)
{
int i, j;
for( i = 0; i < 4; i++ )
for( j = 0; j < 4; j++ )
- myOrientationMatrix[i][j] = ACView.Orientation.ModelViewMatrix[i][j];
+ myOrientationMatrix[i][j] = theCView.Orientation.ModelViewMatrix[i][j];
}
else
- TelEvalViewOrientationMatrix( Vrp, Vpn, Vup, ScaleFactors, &err_ind, myOrientationMatrix );
+ {
+ TelEvalViewOrientationMatrix (Vrp, Vpn, Vup, ScaleFactors, &err_ind, myOrientationMatrix);
+ }
- if ( !err_ind )
+ if (!err_ind)
{
myExtra.vrp[0] = Vrp[0];
myExtra.vrp[1] = Vrp[1];
/*----------------------------------------------------------------------*/
-void OpenGl_View::SetFog (const CALL_DEF_VIEW &ACView, const Standard_Boolean AFlag)
+void OpenGl_View::SetFog (const Graphic3d_CView& theCView,
+ const Standard_Boolean theFlag)
{
- if( !AFlag )
+ if (!theFlag)
{
myFog.IsOn = Standard_False;
}
myFog.IsOn = Standard_True;
myFog.Front =
- (ACView.Context.DepthFrontPlane - ACView.Mapping.BackPlaneDistance) /
- (ACView.Mapping.FrontPlaneDistance - ACView.Mapping.BackPlaneDistance);
+ (theCView.Context.DepthFrontPlane - theCView.Mapping.BackPlaneDistance) /
+ (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
myFog.Back =
- (ACView.Context.DepthBackPlane - ACView.Mapping.BackPlaneDistance) /
- (ACView.Mapping.FrontPlaneDistance - ACView.Mapping.BackPlaneDistance);
+ (theCView.Context.DepthBackPlane - theCView.Mapping.BackPlaneDistance) /
+ (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance);
if (myFog.Front < 0.F)
myFog.Front = 0.F;
myFog.Back = 0.F;
}
- myFog.Color.rgb[0] = ACView.DefWindow.Background.r;
- myFog.Color.rgb[1] = ACView.DefWindow.Background.g;
- myFog.Color.rgb[2] = ACView.DefWindow.Background.b;
- myFog.Color.rgb[3] = 1.F;
+ myFog.Color.rgb[0] = theCView.DefWindow.Background.r;
+ myFog.Color.rgb[1] = theCView.DefWindow.Background.g;
+ myFog.Color.rgb[2] = theCView.DefWindow.Background.b;
+ myFog.Color.rgb[3] = 1.0f;
}
}
/*----------------------------------------------------------------------*/
//transform_persistence_end
-void OpenGl_View::EndTransformPersistence ()
+void OpenGl_View::EndTransformPersistence()
{
- if ( myIsTransPers )
+ if (myIsTransPers)
{
- /* restore matrix */
+ // restore matrix
glMatrixMode (GL_PROJECTION);
- glPopMatrix ();
+ glPopMatrix();
glMatrixMode (GL_MODELVIEW);
- glPopMatrix ();
+ glPopMatrix();
myIsTransPers = Standard_False;
}
-}
+}
/*----------------------------------------------------------------------*/
//transform_persistence_begin
-const TEL_TRANSFORM_PERSISTENCE * OpenGl_View::BeginTransformPersistence (const TEL_TRANSFORM_PERSISTENCE *ATransPers)
+const TEL_TRANSFORM_PERSISTENCE* OpenGl_View::BeginTransformPersistence (const TEL_TRANSFORM_PERSISTENCE* theTransPers)
{
- const TEL_TRANSFORM_PERSISTENCE *TransPers_old = myTransPers;
-
- if ( ATransPers->mode == 0 )
+ const TEL_TRANSFORM_PERSISTENCE* aTransPersPrev = myTransPers;
+ myTransPers = theTransPers;
+ if (theTransPers->mode == 0)
{
EndTransformPersistence();
- return TransPers_old;
+ return aTransPersPrev;
}
- myTransPers = ATransPers;
-
- GLint viewport[4];
- glGetIntegerv (GL_VIEWPORT, viewport);
- GLdouble modelMatrix[4][4];
- glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix );
- GLdouble projMatrix[4][4];
- glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
-
- double W = viewport[2];
- double H = viewport[3];
+ GLint aViewport[4];
+ GLdouble aModelMatrix[4][4];
+ GLdouble aProjMatrix[4][4];
+ glGetIntegerv (GL_VIEWPORT, aViewport);
+ glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix);
+ glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble *)aProjMatrix);
+ const GLdouble aViewportW = (GLdouble )aViewport[2];
+ const GLdouble aViewportH = (GLdouble )aViewport[3];
- if ( myIsTransPers )
+ if (myIsTransPers)
{
- /* restore matrix */
+ // pop matrix stack - it will be overridden later
glMatrixMode (GL_PROJECTION);
- glPopMatrix ();
+ glPopMatrix();
glMatrixMode (GL_MODELVIEW);
- glPopMatrix ();
+ glPopMatrix();
}
else
+ {
myIsTransPers = Standard_True;
+ }
- glMatrixMode( GL_MODELVIEW );
+ // push matrices into stack and reset them
+ glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
- glMatrixMode( GL_PROJECTION );
+ glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
- /*pre loading matrix*/
- if( ATransPers->mode & TPF_PAN )
- /* Annulate translate matrix */
+ // get the window's (fixed) coordinates for theTransPers->point before matrixes modifications
+ GLdouble aWinX = 0.0, aWinY = 0.0, aWinZ = 0.0;
+ if ((theTransPers->mode & TPF_PAN) != TPF_PAN)
{
- modelMatrix[3][0] = 0.;
- modelMatrix[3][1] = 0.;
- modelMatrix[3][2] = 0.;
- projMatrix[3][0] = 0.;
- projMatrix[3][1] = 0.;
- projMatrix[3][2] = 0.;
+ gluProject (theTransPers->pointX, theTransPers->pointY, theTransPers->pointZ,
+ (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport,
+ &aWinX, &aWinY, &aWinZ);
}
- if( ATransPers->mode & TPF_ZOOM )
- /* Annulate zoom matrix */
+ // prevent zooming
+ if ((theTransPers->mode & TPF_ZOOM)
+ || (theTransPers->mode == TPF_TRIEDRON))
{
- const double scaleX = myExtra.scaleFactors[0];
- const double scaleY = myExtra.scaleFactors[1];
- const double scaleZ = myExtra.scaleFactors[2];
-
- for (int i = 0; i < 3; ++i)
- {
- modelMatrix[0][i] /= scaleX;
- modelMatrix[1][i] /= scaleY;
- modelMatrix[2][i] /= scaleZ;
- }
-
- const double det2 = 0.002 / ( W > H ? projMatrix[1][1] : projMatrix[0][0]);
- projMatrix[0][0] *= det2;
- projMatrix[1][1] *= det2;
+ // compute fixed-zoom multiplier
+ // actually function works ugly with TelPerspective!
+ const GLdouble aDet2 = 0.002 / (aViewportW > aViewportH ? aProjMatrix[1][1] : aProjMatrix[0][0]);
+ aProjMatrix[0][0] *= aDet2;
+ aProjMatrix[1][1] *= aDet2;
+ aProjMatrix[2][2] *= aDet2;
}
- if( ATransPers->mode & TPF_ROTATE )
- /* Annulate rotate matrix */
+ // prevent translation - annulate translate matrix
+ if ((theTransPers->mode & TPF_PAN)
+ || (theTransPers->mode == TPF_TRIEDRON))
{
- modelMatrix[0][0] = 1.;
- modelMatrix[1][1] = 1.;
- modelMatrix[2][2] = 1.;
-
- modelMatrix[1][0] = 0.;
- modelMatrix[2][0] = 0.;
- modelMatrix[0][1] = 0.;
- modelMatrix[2][1] = 0.;
- modelMatrix[0][2] = 0.;
- modelMatrix[1][2] = 0.;
+ aModelMatrix[3][0] = 0.0;
+ aModelMatrix[3][1] = 0.0;
+ aModelMatrix[3][2] = 0.0;
+ aProjMatrix [3][0] = 0.0;
+ aProjMatrix [3][1] = 0.0;
+ aProjMatrix [3][2] = 0.0;
}
- else if( ATransPers->mode & TPF_RELATIVE_ROTATE )
- /* Initialize relative rotate matrix*/
- {
- modelMatrix[3][0] = 0.;
- modelMatrix[3][1] = 0.;
- modelMatrix[3][2] = 0.;
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- glTranslated( ATransPers->pointX, ATransPers->pointY, ATransPers->pointZ );
+ // prevent scaling-on-axis
+ if (theTransPers->mode & TPF_ZOOM)
+ {
+ const double aScaleX = myExtra.scaleFactors[0];
+ const double aScaleY = myExtra.scaleFactors[1];
+ const double aScaleZ = myExtra.scaleFactors[2];
+ for (int i = 0; i < 3; ++i)
+ {
+ aModelMatrix[0][i] /= aScaleX;
+ aModelMatrix[1][i] /= aScaleY;
+ aModelMatrix[2][i] /= aScaleZ;
+ }
}
- if( ATransPers->mode == TPF_TRIEDRON )
+ // prevent rotating - annulate rotate matrix
+ if (theTransPers->mode & TPF_ROTATE)
{
- /* Annulate translation matrix */
- modelMatrix[3][0] = 0.;
- modelMatrix[3][1] = 0.;
- modelMatrix[3][2] = 0.;
-
- projMatrix[3][0] = 0.;
- projMatrix[3][1] = 0.;
- projMatrix[3][2] = 0.;
-
- const double det2 = 0.002 / ( W > H ? projMatrix[1][1] : projMatrix[0][0]);
- projMatrix[0][0] *= det2;
- projMatrix[1][1] *= det2;
+ aModelMatrix[0][0] = 1.0;
+ aModelMatrix[1][1] = 1.0;
+ aModelMatrix[2][2] = 1.0;
+
+ aModelMatrix[1][0] = 0.0;
+ aModelMatrix[2][0] = 0.0;
+ aModelMatrix[0][1] = 0.0;
+ aModelMatrix[2][1] = 0.0;
+ aModelMatrix[0][2] = 0.0;
+ aModelMatrix[1][2] = 0.0;
}
- /* load matrix */
+ // load computed matrices
glMatrixMode (GL_MODELVIEW);
- glMultMatrixd ((GLdouble *) modelMatrix);
+ glMultMatrixd ((GLdouble* )aModelMatrix);
glMatrixMode (GL_PROJECTION);
- glMultMatrixd ((GLdouble *) projMatrix);
+ glMultMatrixd ((GLdouble* )aProjMatrix);
- /*post loading matrix*/
- if( ATransPers->mode == TPF_TRIEDRON )
+ if (theTransPers->mode == TPF_TRIEDRON)
{
- glMatrixMode( GL_PROJECTION );
-
- double winx, winy, winz;
- const GLdouble idenMatrix[4][4] = { {1.,0.,0.,0.}, {0.,1.,0.,0.}, {0.,0.,1.,0.}, {0.,0.,0.,1.} };
-
- gluUnProject( W/2., H/2., 0., (GLdouble*)idenMatrix, (GLdouble*)projMatrix, (GLint*)viewport, &winx, &winy, &winz);
- double W1, H1;
- W1 = winx;
- H1 = winy;
- gluUnProject( -W/2., -H/2., 0., (GLdouble*)idenMatrix, (GLdouble*)projMatrix, (GLint*)viewport, &winx, &winy, &winz);
- double W2, H2;
- W2 = winx;
- H2 = winy;
-
- if( ATransPers->pointX == 0. && ATransPers->pointY == 0. )
- {
- /*center*/
- }
- else if( ATransPers->pointX > 0. && ATransPers->pointY > 0. )
- {
- /*right upper*/
- glTranslated( 0.5*(W1 - W2 - ATransPers->pointZ), 0.5*(H1 - H2 - ATransPers->pointZ), 0. );
- }
- else if( ATransPers->pointX > 0. && ATransPers->pointY < 0. )
- {
- /*right lower*/
- glTranslated( 0.5*(W1 - W2 - ATransPers->pointZ), 0.5*(H2 - H1 + ATransPers->pointZ), 0. );
- }
- else if( ATransPers->pointX < 0. && ATransPers->pointY > 0. )
+ // move to the window corner
+ if (theTransPers->pointX != 0.0
+ && theTransPers->pointY != 0.0)
{
- /*left upper*/
- glTranslated( 0.5*(W2 - W1 + ATransPers->pointZ), 0.5*(H1 - H2 - ATransPers->pointZ), 0. );
- }
- else if( ATransPers->pointX < 0 && ATransPers->pointY < 0 )
- {
- /*left lower*/
- glTranslated( -(W1 - W2)/2. + ATransPers->pointZ/2., -(H1-H2)/2. + ATransPers->pointZ/2., 0. );
+ GLdouble aW1, aH1, aW2, aH2, aDummy;
+ glMatrixMode (GL_PROJECTION);
+ gluUnProject ( 0.5 * aViewportW, 0.5 * aViewportH, 0.0,
+ (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport,
+ &aW1, &aH1, &aDummy);
+ gluUnProject (-0.5 * aViewportW, -0.5 * aViewportH, 0.0,
+ (GLdouble* )THE_IDENTITY_MATRIX, (GLdouble* )aProjMatrix, aViewport,
+ &aW2, &aH2, &aDummy);
+ GLdouble aMoveX = 0.5 * (aW1 - aW2 - theTransPers->pointZ);
+ GLdouble aMoveY = 0.5 * (aH1 - aH2 - theTransPers->pointZ);
+ aMoveX = (theTransPers->pointX > 0.0) ? aMoveX : -aMoveX;
+ aMoveY = (theTransPers->pointY > 0.0) ? aMoveY : -aMoveY;
+ glTranslated (aMoveX, aMoveY, 0.0);
}
}
+ else if ((theTransPers->mode & TPF_PAN) != TPF_PAN)
+ {
+ // move to thePoint using saved win-coordinates ('marker-behaviour')
+ GLdouble aMoveX, aMoveY, aMoveZ;
+ glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble* )aModelMatrix);
+ glGetDoublev (GL_PROJECTION_MATRIX, (GLdouble* )aProjMatrix);
+ gluUnProject (aWinX, aWinY, aWinZ,
+ (GLdouble* )aModelMatrix, (GLdouble* )aProjMatrix, aViewport,
+ &aMoveX, &aMoveY, &aMoveZ);
- return TransPers_old;
-}
+ glMatrixMode (GL_MODELVIEW);
+ glTranslated (aMoveX, aMoveY, aMoveZ);
+ }
-/*----------------------------------------------------------------------*/
+ return aTransPersPrev;
+}