2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
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
24 // IMP240100 //GG -> Activates WalkThrough model.
41 #include <V3d_View.hxx>
42 #include <V3d_PerspectiveView.ixx>
43 #include <Visual3d_View.hxx>
44 #include <V3d_BadValue.hxx>
46 V3d_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() ;
54 V3d_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() ;
62 V3d_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() ;
69 Handle(V3d_PerspectiveView) V3d_PerspectiveView::Copy() const {
70 return new V3d_PerspectiveView(this->Viewer(),this);}
74 void V3d_PerspectiveView::SetAngle(const Standard_Real Angle) {
76 Standard_Real focale,Umin,Vmin,Umax,Vmax,Dxv,Dyv,Rap,Xrp,Yrp;
78 V3d_BadValue_Raise_if ( Angle <= 0. || Angle >= M_PI, "V3d_PerspectiveView::SetAngle, bad angle");
80 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
81 Dxv = Abs(Umax - Umin)/2. ; Dyv = Abs(Vmax - Vmin)/2.;
83 Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
86 Dyv = Abs(focale * tan(Angle/2.)) ;
89 Dxv = Abs(focale * tan(Angle/2.)) ;
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) ;
99 Standard_Real V3d_PerspectiveView::Angle()const {
101 // Graphic3d_Vertex Prp ;
102 Standard_Real focale,Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
103 Standard_Real angle = M_PI ;
105 MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
107 Dxv = (Umax - Umin)/2. ; Dyv = (Vmax - Vmin)/2. ;
110 angle = 2.*atan(Dyv/focale) ;
112 angle = 2.*atan(Dxv/focale) ;
119 void V3d_PerspectiveView::SetPerspective(const Standard_Real Angle, const Standard_Real UVRatio,
120 const Standard_Real ZNear, const Standard_Real ZFar)
122 Standard_Real Umin,Vmin,Umax,Vmax,Yrp,Zrp,du,dv;
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");
127 Graphic3d_Vertex PRP = MyViewMapping.ProjectionReferencePoint() ;
130 PRP.SetCoord(Zrp, Yrp, Zrp);
131 MyViewMapping.SetProjectionReferencePoint(PRP);
133 Standard_Real size = (ZFar - ZNear) / 2.;
135 MyViewMapping.SetFrontPlaneDistance(size);
136 MyViewMapping.SetBackPlaneDistance(-size);
137 MyViewMapping.SetViewPlaneDistance(size);
139 // recompute window limits by mapping to view plane
140 dv = Abs(ZNear * tan(Angle/2.));
142 Umin = -du; Umax = du;
143 Vmin = -dv; Vmax = dv;
144 MyViewMapping.SetWindowLimit(Umin, Vmin, Umax, Vmax);
146 MyView->SetViewMapping(MyViewMapping) ;