1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /***********************************************************************
22 Classe V3d_View_3.cxx :
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 24-12-97 : FMN ; Suppression de GEOMLITE
28 13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guide)
29 22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
30 IMP240100: GG -> Activates WalkThrough model.
32 ************************************************************************/
34 #define IMP020300 //GG Don't use ZFitAll in during Rotation
35 // for perf improvment
37 /*----------------------------------------------------------------------*/
42 #include <V3d_View.jxx>
43 #include <V3d_Static.hxx>
47 /*----------------------------------------------------------------------*/
49 void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
51 Graphic3d_Vertex Prp ;
52 Graphic3d_Vector Vpn ;
53 Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
54 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
57 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
58 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
59 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
60 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
61 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
62 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
63 Viewer_BadValue::Raise ("V3d_View::Move, alignment of Eye,At,Up");
65 MyXscreenAxis.Coord(XX,XY,XZ) ;
66 MyYscreenAxis.Coord(YX,YY,YZ) ;
67 MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
68 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
69 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
70 Xeye = Zrp*Xpn + Dx*XX + Dy*YX + Dz*ZX ;
71 Yeye = Zrp*Ypn + Dx*XY + Dy*YY + Dz*ZY ;
72 Zeye = Zrp*Zpn + Dx*XZ + Dy*YZ + Dz*ZZ ;
73 Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
74 Viewer_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
76 Standard_Real focale =
79 Prp.SetCoord(Xrp,Yrp,Zrp) ;
80 MyViewMapping.SetProjectionReferencePoint(Prp) ;
81 Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
82 Vpn.SetCoord(Xpn,Ypn,Zpn) ;
83 MyViewOrientation.SetViewReferencePlane(Vpn) ;
84 MyView->SetViewOrientation(MyViewOrientation) ;
86 // Check ZClipping planes
88 MyView->SetViewMapping(MyViewMapping) ;
91 Standard_Real Zmax,Xat,Yat,Zat ;
92 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
93 Xeye += Xat ; Yeye += Yat ; Zeye += Zat ;
94 Zmax = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
95 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
96 MyProjModel == V3d_TPM_SCREEN ) {
97 SetZSize(2.*Zmax+Zmax*Zmargin) ;
99 if( MyType == V3d_PERSPECTIVE ) {
102 MyView->SetViewMapping(MyViewMapping) ;
108 void V3d_View::Move(const Standard_Real Length, const Standard_Boolean Start) {
109 Graphic3d_Vertex Prp ;
110 Graphic3d_Vector Vpn ;
111 Standard_Real Vx,Vy,Vz ;
112 Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
114 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
115 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
116 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
118 MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
119 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
120 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
121 Xeye = Zrp*Xpn + Vx*Length ;
122 Yeye = Zrp*Ypn + Vy*Length ;
123 Zeye = Zrp*Zpn + Vz*Length ;
124 Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
125 Viewer_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
128 Standard_Real focale =
131 Prp.SetCoord(Xrp,Yrp,Zrp) ;
132 MyViewMapping.SetProjectionReferencePoint(Prp) ;
133 Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
134 Vpn.SetCoord(Xpn,Ypn,Zpn) ;
135 MyViewOrientation.SetViewReferencePlane(Vpn) ;
136 MyView->SetViewOrientation(MyViewOrientation) ;
139 MyView->SetViewMapping(MyViewMapping) ;
142 // Check ZClipping planes
143 Standard_Real Zmax,Xat,Yat,Zat ;
144 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
145 Xeye += Xat ; Yeye += Yat ; Zeye += Zat ;
146 Zmax = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
147 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
148 MyProjModel == V3d_TPM_SCREEN ) {
149 SetZSize(2.*Zmax+Zmax*Zmargin) ;
151 if( MyType == V3d_PERSPECTIVE ) {
154 MyView->SetViewMapping(MyViewMapping) ;
160 void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) {
165 Move(Length,0.,0.,Start);
168 Move(0.,Length,0.,Start);
171 Move(0.,0.,Length,Start);
176 void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {
178 Graphic3d_Vertex Vrp ;
179 Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
180 Standard_Real Xat,Yat,Zat ;
182 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
183 MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
184 MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
185 MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
186 if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
187 MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
188 Viewer_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
190 MyXscreenAxis.Coord(XX,XY,XZ) ;
191 MyYscreenAxis.Coord(YX,YY,YZ) ;
192 MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
193 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
194 Xat -= Dx*XX + Dy*YX + Dz*ZX ;
195 Yat -= Dx*XY + Dy*YY + Dz*ZY ;
196 Zat -= Dx*XZ + Dy*YZ + Dz*ZZ ;
197 Vrp.SetCoord(Xat,Yat,Zat) ;
198 MyViewOrientation.SetViewReferencePoint(Vrp) ;
199 MyView->SetViewOrientation(MyViewOrientation) ;
203 // Check ZClipping planes
204 Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
205 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
206 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
207 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
208 Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
209 sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
210 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
211 MyProjModel == V3d_TPM_SCREEN ) {
212 SetZSize(2.*Zmax+Zmax*Zmargin) ;
218 void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) {
222 Translate(Length,0.,0., Start);
225 Translate(0.,Length,0., Start);
228 Translate(0.,0.,Length, Start);
232 void V3d_View::Place (const Standard_Integer ix, const Standard_Integer iy,
233 const Quantity_Factor aZoomFactor) {
234 Standard_Real xpos,ypos;
235 Standard_Integer xc,yc;
237 Convert(xpos,ypos,xc,yc);
238 Pan(xc-ix,iy-yc,aZoomFactor/Scale());
240 void V3d_View::Translate(const Standard_Real Length,const Standard_Boolean Start) {
241 Graphic3d_Vertex Vrp ;
242 Standard_Real Xat,Yat,Zat,Vx,Vy,Vz ;
244 MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
246 MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
247 MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
248 Xat -= Vx*Length ; Yat -= Vy*Length ; Zat -= Vz*Length ;
249 Vrp.SetCoord(Xat,Yat,Zat) ;
250 MyViewOrientation.SetViewReferencePoint(Vrp) ;
251 MyView->SetViewOrientation(MyViewOrientation) ;
256 // Check ZClipping planes
257 Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
258 MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
259 MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
260 Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
261 Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
262 sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
263 if( Zmax > MyViewMapping.FrontPlaneDistance() &&
264 MyProjModel == V3d_TPM_SCREEN ) {
265 SetZSize(2.*Zmax+Zmax*Zmargin) ;