summaryrefslogtreecommitdiff
path: root/src/V3d/V3d_View_3.cxx
blob: 8b48ee79f55d1a4f0597d948662d3147e175e660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/***********************************************************************
 
     FONCTION :
     ----------
        Classe V3d_View_3.cxx :
 
     HISTORIQUE DES MODIFICATIONS   :
     --------------------------------
     00-09-92 : GG  ; Creation.
     24-12-97 : FMN ; Suppression de GEOMLITE
     13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guide)
     22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
     IMP240100: GG -> Activates WalkThrough model.

************************************************************************/

#define IMP020300       //GG Don't use ZFitAll in during Rotation
//                      for perf improvment

/*----------------------------------------------------------------------*/
/*
 * Includes
 */

#include <V3d_View.jxx>
#include <V3d_Static.hxx>

#define Zmargin 1.

/*----------------------------------------------------------------------*/

void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {

  Graphic3d_Vertex Prp ;
  Graphic3d_Vector Vpn ;
  Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
  Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
  
  if( Start ) {
    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
    if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
		MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
	Viewer_BadValue::Raise ("V3d_View::Move, alignment of Eye,At,Up");
  }
  MyXscreenAxis.Coord(XX,XY,XZ) ; 
  MyYscreenAxis.Coord(YX,YY,YZ) ; 
  MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
  Xeye = Zrp*Xpn + Dx*XX + Dy*YX + Dz*ZX ;
  Yeye = Zrp*Ypn + Dx*XY + Dy*YY + Dz*ZY ;
  Zeye = Zrp*Zpn + Dx*XZ + Dy*YZ + Dz*ZZ ;
  Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
  Viewer_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
  Prp.SetCoord(Xrp,Yrp,Zrp) ;
  MyViewMapping.SetProjectionReferencePoint(Prp) ;
  Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
  Vpn.SetCoord(Xpn,Ypn,Zpn) ;   
  MyViewOrientation.SetViewReferencePlane(Vpn) ;
  MyView->SetViewOrientation(MyViewOrientation) ; 
  
  // Check ZClipping planes
#ifdef IMP020300
  MyView->SetViewMapping(MyViewMapping) ; 
  SetZSize(0.);
#else
  Standard_Real Zmax,Xat,Yat,Zat ;
  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
  Xeye += Xat ; Yeye += Yat ; Zeye += Zat ;
  Zmax = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
	MyProjModel == V3d_TPM_SCREEN ) {
    SetZSize(2.*Zmax+Zmax*Zmargin) ;
  } else {
    if( MyType == V3d_PERSPECTIVE ) {
      SetFocale(focale) ;
    }
    MyView->SetViewMapping(MyViewMapping) ; 
  }
#endif
  ImmediateUpdate();
}

void V3d_View::Move(const Standard_Real Length, const Standard_Boolean Start) {
  Graphic3d_Vertex Prp ;
  Graphic3d_Vector Vpn ;
  Standard_Real Vx,Vy,Vz ;
  Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
  if( Start ) {
    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
  }
  MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
  Xeye = Zrp*Xpn + Vx*Length ; 
  Yeye = Zrp*Ypn + Vy*Length ; 
  Zeye = Zrp*Zpn + Vz*Length ;
  Zrp = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
  Viewer_BadValue_Raise_if( Zrp <= 0. ,"V3d_View::Move:: Eye,At are Confused");
  
  Prp.SetCoord(Xrp,Yrp,Zrp) ;
  MyViewMapping.SetProjectionReferencePoint(Prp) ;
  Xpn = Xeye / Zrp ; Ypn = Yeye / Zrp ; Zpn = Zeye / Zrp ;
  Vpn.SetCoord(Xpn,Ypn,Zpn) ;
  MyViewOrientation.SetViewReferencePlane(Vpn) ;
  MyView->SetViewOrientation(MyViewOrientation) ; 

#ifdef IMP020300
  MyView->SetViewMapping(MyViewMapping) ; 
  SetZSize(0.);
#else
  // Check ZClipping planes
  Standard_Real Zmax,Xat,Yat,Zat ;
  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
  Xeye += Xat ; Yeye += Yat ; Zeye += Zat ;
  Zmax = sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ;
  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
	MyProjModel == V3d_TPM_SCREEN ) {
    SetZSize(2.*Zmax+Zmax*Zmargin) ;
  } else {
    if( MyType == V3d_PERSPECTIVE ) {
      SetFocale(focale) ;
    }
    MyView->SetViewMapping(MyViewMapping) ; 
  }
#endif
  ImmediateUpdate();
}

void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) {


  switch (Axe) {
  case V3d_X :
    Move(Length,0.,0.,Start);
    break ;
  case V3d_Y :
    Move(0.,Length,0.,Start);
    break ;
  case V3d_Z :
    Move(0.,0.,Length,Start);
    break ;
  }
}

void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) {

  Graphic3d_Vertex Vrp ;
  Standard_Real XX,XY,XZ,YX,YY,YZ,ZX,ZY,ZZ ;
  Standard_Real Xat,Yat,Zat ;
  if( Start ) {
    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
    if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
		MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
	Viewer_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
  }
  MyXscreenAxis.Coord(XX,XY,XZ) ; 
  MyYscreenAxis.Coord(YX,YY,YZ) ; 
  MyZscreenAxis.Coord(ZX,ZY,ZZ) ;
  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
  Xat -= Dx*XX + Dy*YX + Dz*ZX ;
  Yat -= Dx*XY + Dy*YY + Dz*ZY ;
  Zat -= Dx*XZ + Dy*YZ + Dz*ZZ ;
  Vrp.SetCoord(Xat,Yat,Zat) ;
  MyViewOrientation.SetViewReferencePoint(Vrp) ;
  MyView->SetViewOrientation(MyViewOrientation) ; 
#ifdef IMP020300
  SetZSize(0.);
#else
  // Check ZClipping planes
  Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
  Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
  Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
	     sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
	MyProjModel == V3d_TPM_SCREEN ) {
    SetZSize(2.*Zmax+Zmax*Zmargin) ;
  }
#endif
  ImmediateUpdate();
}

void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) {

  switch (Axe) {
  case V3d_X :
    Translate(Length,0.,0., Start);
    break ;
  case V3d_Y :
    Translate(0.,Length,0., Start);
    break ;
  case V3d_Z :
    Translate(0.,0.,Length, Start);
    break ;
  }
}
void V3d_View::Place (const Standard_Integer ix, const Standard_Integer iy,
		      const Quantity_Factor aZoomFactor) {
  Standard_Real xpos,ypos;
  Standard_Integer xc,yc;
  Center(xpos,ypos);
  Convert(xpos,ypos,xc,yc);
  Pan(xc-ix,iy-yc,aZoomFactor/Scale());
}
void V3d_View::Translate(const Standard_Real Length,const Standard_Boolean Start) {
  Graphic3d_Vertex Vrp ;
  Standard_Real Xat,Yat,Zat,Vx,Vy,Vz ;
  if( Start ) {
    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
  }
  MyDefaultViewAxis.Coord(Vx,Vy,Vz) ;
  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
  Xat -= Vx*Length ; Yat -= Vy*Length ; Zat -= Vz*Length ;
  Vrp.SetCoord(Xat,Yat,Zat) ;
  MyViewOrientation.SetViewReferencePoint(Vrp) ;
  MyView->SetViewOrientation(MyViewOrientation) ; 
  
#ifdef IMP020300
  SetZSize(0.);
#else
  // Check ZClipping planes
  Standard_Real Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye,Zmax ;
  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
  Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
  Zmax = Max(sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye ) ,
	     sqrt( Xat*Xat + Yat*Yat + Zat*Zat )) ;
  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
	MyProjModel == V3d_TPM_SCREEN ) {
    SetZSize(2.*Zmax+Zmax*Zmargin) ;
  }
#endif
  ImmediateUpdate();
}