0024510: Remove unused local variables
[occt.git] / src / V3d / V3d_PerspectiveView.cxx
CommitLineData
b311480e 1// Created by: GG
2// Copyright (c) 1991-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// Modified 07-10-96 : CQ ; correction PRO4522
17// Modified 23-02-98 : FMN ; Replace PI by Standard_PI
18// Modified 25-02-98 : FMN ; PERF.27: Optimisation of view creation from an existing view
19// Modified 02-09-98 : FMN ; Correction problem of angle calculation in V3d_PerspectiveView::Angle().
20// Modified 23-11-98 : FMN ; PRO14896: Correction of the management of the perspective (cf Programming Guide)
21// If the angle is modified the WindowLimit changes not the focal.
22// 22-12-98 : FMN ; Rename CSF_WALKTHROW into CSF_WALKTHROUGH
23
24// IMP240100 //GG -> Activates WalkThrough model.
25
7fd59977 26
27//-Version
28
29//-Design
30
31//-Warning
32
33//-References
34
35//-Language C++ 2.1
36
37
38// for Test method
39
40// for the class
41#include <V3d_View.hxx>
42#include <V3d_PerspectiveView.ixx>
43#include <Visual3d_View.hxx>
6942f04a 44#include <V3d_BadValue.hxx>
7fd59977 45
46V3d_PerspectiveView::V3d_PerspectiveView (const Handle(V3d_Viewer)& VM):V3d_View (VM,V3d_PERSPECTIVE) {
47 MyViewMapping.SetProjection(Visual3d_TOP_PERSPECTIVE) ;
48 SetAngle(VM->DefaultAngle()) ;
49// SetZoom(10.0, Standard_True);
50 SetViewMappingDefault() ;
51 SetViewOrientationDefault() ;
52}
53
54V3d_PerspectiveView::V3d_PerspectiveView (const Handle(V3d_Viewer)& VM, const Handle(V3d_OrthographicView)& V):V3d_View (VM,V,V3d_PERSPECTIVE) {
55 MyViewMapping.SetProjection(Visual3d_TOP_PERSPECTIVE) ;
56 SetAngle(VM->DefaultAngle()) ;
57// SetZoom(10.0, Standard_True);
58 SetViewMappingDefault() ;
59 SetViewOrientationDefault() ;
60}
61
62V3d_PerspectiveView::V3d_PerspectiveView (const Handle(V3d_Viewer)& VM, const Handle(V3d_PerspectiveView)& V):V3d_View (VM,V,V3d_PERSPECTIVE) {
63 MyViewMapping.SetProjection(Visual3d_TOP_PERSPECTIVE) ;
64// SetZoom(10.0, Standard_True);
65 SetViewMappingDefault() ;
66 SetViewOrientationDefault() ;
67}
68
69Handle(V3d_PerspectiveView) V3d_PerspectiveView::Copy() const {
70 return new V3d_PerspectiveView(this->Viewer(),this);}
71
72//-Methods, in order
73
74void V3d_PerspectiveView::SetAngle(const Standard_Real Angle) {
75
76 Standard_Real focale,Umin,Vmin,Umax,Vmax,Dxv,Dyv,Rap,Xrp,Yrp;
77
6942f04a 78 V3d_BadValue_Raise_if ( Angle <= 0. || Angle >= M_PI, "V3d_PerspectiveView::SetAngle, bad angle");
7fd59977 79
80 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
81 Dxv = Abs(Umax - Umin)/2. ; Dyv = Abs(Vmax - Vmin)/2.;
82 focale = Focale();
83 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
84 Rap = Dxv / Dyv;
85 if( Dxv >= Dyv ) {
86 Dyv = Abs(focale * tan(Angle/2.)) ;
87 Dxv = Rap * Dyv;
88 } else {
89 Dxv = Abs(focale * tan(Angle/2.)) ;
90 Dyv = Dxv / Rap;
91 }
92 Umin = Xrp - Dxv ; Umax = Xrp + Dxv ;
93 Vmin = Yrp - Dyv ; Vmax = Yrp + Dyv ;
94 MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
95 MyView->SetViewMapping(MyViewMapping) ;
96 ImmediateUpdate();
97}
98
99Standard_Real V3d_PerspectiveView::Angle()const {
100
101// Graphic3d_Vertex Prp ;
102 Standard_Real focale,Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
c6541a0c 103 Standard_Real angle = M_PI ;
7fd59977 104
105 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
106 focale = Focale() ;
107 Dxv = (Umax - Umin)/2. ; Dyv = (Vmax - Vmin)/2. ;
108 if( focale > 0. ) {
109 if( Dxv >= Dyv ) {
110 angle = 2.*atan(Dyv/focale) ;
111 } else {
112 angle = 2.*atan(Dxv/focale) ;
113 }
114 }
115
116 return angle ;
117}
118
119void V3d_PerspectiveView::SetPerspective(const Standard_Real Angle, const Standard_Real UVRatio,
120 const Standard_Real ZNear, const Standard_Real ZFar)
121{
96a95605 122 Standard_Real Umin,Vmin,Umax,Vmax,Yrp,Zrp,du,dv;
7fd59977 123
6942f04a 124 V3d_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_PerspectiveView::SetPerspective, bad distances");
125 V3d_BadValue_Raise_if ( Angle <= 0. || Angle >= M_PI, "V3d_PerspectiveView::SetAngle, bad angle");
7fd59977 126
127 Graphic3d_Vertex PRP = MyViewMapping.ProjectionReferencePoint() ;
96a95605 128 Yrp = Zrp = 0.;
7fd59977 129
130 PRP.SetCoord(Zrp, Yrp, Zrp);
131 MyViewMapping.SetProjectionReferencePoint(PRP);
132
133 Standard_Real size = (ZFar - ZNear) / 2.;
134
135 MyViewMapping.SetFrontPlaneDistance(size);
136 MyViewMapping.SetBackPlaneDistance(-size);
137 MyViewMapping.SetViewPlaneDistance(size);
138
139 // recompute window limits by mapping to view plane
140 dv = Abs(ZNear * tan(Angle/2.));
141 du = dv * UVRatio;
142 Umin = -du; Umax = du;
143 Vmin = -dv; Vmax = dv;
144 MyViewMapping.SetWindowLimit(Umin, Vmin, Umax, Vmax);
145
146 MyView->SetViewMapping(MyViewMapping) ;
147 ImmediateUpdate();
148}