TexGen
CustomInteractorStyle.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#include "PrecompiledHeaders.h"
22
23#include "vtkMath.h"
24#include "vtkObjectFactory.h"
25
27
29{
30 if (this->CurrentRenderer == NULL)
31 {
32 return;
33 }
34
35 vtkRenderWindowInteractor *rwi = this->Interactor;
36
37 int dx = - (rwi->GetEventPosition()[0] - rwi->GetLastEventPosition()[0]);
38 int dy = - (rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1]);
39
40 int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
41
42 double a = (double)dx / (double)size[0] * (double)180.0;
43 double e = (double)dy / (double)size[1] * (double)180.0;
44
45 if (rwi->GetShiftKey())
46 {
47 if (fabs((double)dx) >= fabs((double)dy))
48 {
49 e = (double)0.0;
50 }
51 else
52 {
53 a = (double)0.0;
54 }
55 }
56
57 // Move the camera.
58 // Make sure that we don't hit the north pole singularity.
59
60 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
61 camera->Azimuth(a);
62
63 double dop[3], vup[3];
64
65 camera->GetDirectionOfProjection(dop);
66 vtkMath::Normalize(dop);
67 camera->GetViewUp(vup);
68 vtkMath::Normalize(vup);
69
70 const double dAngleLimit = 5.0;
71
72 double angle = acos(vtkMath::Dot(dop, vup)) / vtkMath::RadiansFromDegrees( 1.0 );
73 if ((angle + e) > 180.0-dAngleLimit)
74 {
75 e = 180.0-dAngleLimit-angle;
76 }
77 else if ((angle + e) < dAngleLimit)
78 {
79 e = dAngleLimit-angle;
80 }
81
82 camera->Elevation(e);
83 if (this->AutoAdjustCameraClippingRange)
84 {
85 this->CurrentRenderer->ResetCameraClippingRange();
86 }
87
88 rwi->Render();
89}
90
91
92
93
94
95
96
97
vtkStandardNewMacro(CCustomInteractorStyle)
#define NULL
Definition: ShinyConfig.h:50