b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
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. |
7 | // |
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. |
10 | // |
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. |
17 | |
7fd59977 |
18 | /*********************************************************************** |
19 | |
20 | FONCTION : |
21 | ---------- |
22 | Classe V3d_View_3.cxx : |
23 | |
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. |
31 | |
32 | ************************************************************************/ |
33 | |
34 | #define IMP020300 //GG Don't use ZFitAll in during Rotation |
35 | // for perf improvment |
36 | |
37 | /*----------------------------------------------------------------------*/ |
38 | /* |
39 | * Includes |
40 | */ |
41 | |
42 | #include <V3d_View.jxx> |
43 | #include <V3d_Static.hxx> |
44 | |
45 | #define Zmargin 1. |
46 | |
47 | /*----------------------------------------------------------------------*/ |
48 | |
49 | void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) { |
50 | |
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 ; |
55 | |
56 | if( Start ) { |
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"); |
64 | } |
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"); |
75 | #ifdef DEB |
76 | Standard_Real focale = |
77 | #endif |
78 | 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) ; |
85 | |
86 | // Check ZClipping planes |
87 | #ifdef IMP020300 |
88 | MyView->SetViewMapping(MyViewMapping) ; |
89 | SetZSize(0.); |
90 | #else |
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) ; |
98 | } else { |
99 | if( MyType == V3d_PERSPECTIVE ) { |
100 | SetFocale(focale) ; |
101 | } |
102 | MyView->SetViewMapping(MyViewMapping) ; |
103 | } |
104 | #endif |
105 | ImmediateUpdate(); |
106 | } |
107 | |
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 ; |
113 | if( Start ) { |
114 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; |
115 | MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ; |
116 | MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ; |
117 | } |
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"); |
126 | |
127 | #ifdef DEB |
128 | Standard_Real focale = |
129 | #endif |
130 | 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) ; |
137 | |
138 | #ifdef IMP020300 |
139 | MyView->SetViewMapping(MyViewMapping) ; |
140 | SetZSize(0.); |
141 | #else |
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) ; |
150 | } else { |
151 | if( MyType == V3d_PERSPECTIVE ) { |
152 | SetFocale(focale) ; |
153 | } |
154 | MyView->SetViewMapping(MyViewMapping) ; |
155 | } |
156 | #endif |
157 | ImmediateUpdate(); |
158 | } |
159 | |
160 | void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) { |
161 | |
162 | |
163 | switch (Axe) { |
164 | case V3d_X : |
165 | Move(Length,0.,0.,Start); |
166 | break ; |
167 | case V3d_Y : |
168 | Move(0.,Length,0.,Start); |
169 | break ; |
170 | case V3d_Z : |
171 | Move(0.,0.,Length,Start); |
172 | break ; |
173 | } |
174 | } |
175 | |
176 | void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) { |
177 | |
178 | Graphic3d_Vertex Vrp ; |
179 | Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ; |
180 | Standard_Real Xat,Yat,Zat ; |
181 | if( Start ) { |
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"); |
189 | } |
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) ; |
200 | #ifdef IMP020300 |
201 | SetZSize(0.); |
202 | #else |
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) ; |
213 | } |
214 | #endif |
215 | ImmediateUpdate(); |
216 | } |
217 | |
218 | void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) { |
219 | |
220 | switch (Axe) { |
221 | case V3d_X : |
222 | Translate(Length,0.,0., Start); |
223 | break ; |
224 | case V3d_Y : |
225 | Translate(0.,Length,0., Start); |
226 | break ; |
227 | case V3d_Z : |
228 | Translate(0.,0.,Length, Start); |
229 | break ; |
230 | } |
231 | } |
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; |
236 | Center(xpos,ypos); |
237 | Convert(xpos,ypos,xc,yc); |
238 | Pan(xc-ix,iy-yc,aZoomFactor/Scale()); |
239 | } |
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 ; |
243 | if( Start ) { |
244 | MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ; |
245 | } |
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) ; |
252 | |
253 | #ifdef IMP020300 |
254 | SetZSize(0.); |
255 | #else |
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) ; |
266 | } |
267 | #endif |
268 | ImmediateUpdate(); |
269 | } |