7fd59977 |
1 | |
2 | // File Visual3d_ViewOrientation.cxx |
3 | // Created Fevrier 1992 |
4 | // Author NW,JPB,CAL |
5 | |
6 | //-Copyright MatraDatavision 1991,1992 |
7 | |
8 | //-Version |
9 | |
81bba717 |
10 | //-Design Declaration of variables specific to the orientation of views |
7fd59977 |
11 | |
81bba717 |
12 | //-Warning The view orientation is defined by : |
13 | // - the point of origin of the reference mark |
14 | // - the normal vector to the visualisation plane |
15 | // - the vertical vector of the viewer |
7fd59977 |
16 | |
17 | //-References |
18 | |
19 | //-Language C++ 2.0 |
20 | |
21 | //-Declarations |
22 | |
23 | // for the class |
24 | #include <Visual3d_ViewOrientation.ixx> |
25 | |
26 | //-Aliases |
27 | |
28 | //-Global data definitions |
29 | |
30 | // -- le point origine du repere |
31 | // MyViewReferencePoint : Vertex; |
32 | |
33 | // -- le vecteur normal au plan de visualisation |
34 | // MyViewPlaneNormal : Vector; |
35 | |
36 | // -- le vecteur vertical de l'observateur |
37 | // MyViewUpVector : Vector; |
38 | |
39 | //-Constructors |
40 | |
41 | //-Destructors |
42 | |
43 | //-Methods, in order |
44 | |
45 | Visual3d_ViewOrientation::Visual3d_ViewOrientation (): |
46 | MyViewReferencePoint (0.0, 0.0, 0.0), |
47 | MyViewPlaneNormal (0.0, 0.0, 1.0), |
48 | MyViewUpVector (0.0, 1.0, 0.0), |
49 | MyScaleX(1.0), |
50 | MyScaleY(1.0), |
51 | MyScaleZ(1.0) { |
52 | } |
53 | |
54 | Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Graphic3d_Vector& VPN, const Graphic3d_Vector& VUP): |
55 | MyViewReferencePoint (VRP), |
56 | MyViewPlaneNormal (VPN), |
57 | MyViewUpVector (VUP), |
58 | MyScaleX(1.0), |
59 | MyScaleY(1.0), |
60 | MyScaleZ(1.0) { |
61 | |
62 | if (Graphic3d_Vector::NormeOf (VPN) == 0.0) |
63 | Visual3d_ViewOrientationDefinitionError::Raise |
64 | ("Bad value for ViewPlaneNormal"); |
65 | |
66 | if (Graphic3d_Vector::NormeOf (VUP) == 0.0) |
67 | Visual3d_ViewOrientationDefinitionError::Raise |
68 | ("Bad value for ViewUpVector"); |
69 | |
70 | if (Graphic3d_Vector::IsParallel (VPN, VUP)) |
71 | Visual3d_ViewOrientationDefinitionError::Raise |
72 | ("ViewPlaneNormal and ViewUpVector are parallel"); |
73 | |
74 | } |
75 | |
76 | Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Graphic3d_Vector& VPN, const Standard_Real Twist) { |
77 | |
78 | if (Graphic3d_Vector::NormeOf (VPN) == 0.0) |
79 | Visual3d_ViewOrientationDefinitionError::Raise |
80 | ("Bad value for ViewPlaneNormal"); |
81 | |
82 | cout << "\nVisual3d_ViewOrientation : Not Yet Implemented\n\n" << flush; |
83 | |
84 | MyViewReferencePoint = VRP; |
85 | MyViewPlaneNormal = VPN; |
86 | |
87 | } |
88 | |
89 | Visual3d_ViewOrientation::Visual3d_ViewOrientation (const Graphic3d_Vertex& VRP, const Standard_Real Azim, const Standard_Real Inc, const Standard_Real Twist) { |
90 | |
91 | cout << "\nVisual3d_ViewOrientation : Not Yet Implemented\n\n" << flush; |
92 | |
93 | MyViewReferencePoint = VRP; |
94 | |
95 | } |
96 | |
97 | void Visual3d_ViewOrientation::SetViewReferencePoint (const Graphic3d_Vertex& VRP) { |
98 | |
99 | MyViewReferencePoint = VRP; |
100 | |
101 | } |
102 | |
103 | Graphic3d_Vertex Visual3d_ViewOrientation::ViewReferencePoint () const { |
104 | |
105 | return (MyViewReferencePoint); |
106 | |
107 | } |
108 | |
109 | void Visual3d_ViewOrientation::SetViewReferencePlane (const Graphic3d_Vector& VPN) { |
110 | |
111 | if (Graphic3d_Vector::NormeOf (VPN) == 0.0) |
112 | Visual3d_ViewOrientationDefinitionError::Raise |
113 | ("Bad value for ViewPlaneNormal"); |
114 | |
115 | MyViewPlaneNormal = VPN; |
116 | |
117 | } |
118 | |
119 | Graphic3d_Vector Visual3d_ViewOrientation::ViewReferencePlane () const { |
120 | |
121 | return (MyViewPlaneNormal); |
122 | |
123 | } |
124 | |
125 | void Visual3d_ViewOrientation::SetViewReferenceUp (const Graphic3d_Vector& VUP) { |
126 | |
127 | if (Graphic3d_Vector::NormeOf (VUP) == 0.0) |
128 | Visual3d_ViewOrientationDefinitionError::Raise |
129 | ("Bad value for ViewUpVector"); |
130 | |
131 | MyViewUpVector = VUP; |
132 | |
133 | } |
134 | |
135 | void Visual3d_ViewOrientation::SetAxialScale (const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz) { |
136 | if ( Sx <= 0. || Sy <= 0. || Sz <= 0. ) |
137 | Visual3d_ViewOrientationDefinitionError::Raise |
138 | ("Bad value for ViewUpVector"); |
139 | MyScaleX = Sx; |
140 | MyScaleY = Sy; |
141 | MyScaleZ = Sz; |
142 | } |
143 | |
144 | Graphic3d_Vector Visual3d_ViewOrientation::ViewReferenceUp () const { |
145 | |
146 | return (MyViewUpVector); |
147 | |
148 | } |
149 | |
150 | void Visual3d_ViewOrientation::Assign (const Visual3d_ViewOrientation& Other) { |
151 | |
152 | Standard_Real X, Y, Z; |
153 | |
154 | (Other.ViewReferencePoint ()).Coord (X, Y, Z); |
155 | MyViewReferencePoint.SetCoord (X, Y, Z); |
156 | |
157 | (Other.ViewReferencePlane ()).Coord (X, Y, Z); |
158 | MyViewPlaneNormal.SetCoord (X, Y, Z); |
159 | |
160 | (Other.ViewReferenceUp ()).Coord (X, Y, Z); |
161 | MyViewUpVector.SetCoord (X, Y, Z); |
162 | |
163 | if ( Other.IsCustomMatrix() ) { |
164 | MyModelViewMatrix = new TColStd_HArray2OfReal( 0, 3, 0, 3); |
165 | for (Standard_Integer i = 0; i < 4; i++) |
166 | for (Standard_Integer j = 0; j < 4; j++) |
167 | MyModelViewMatrix->SetValue( i, j, Other.MyModelViewMatrix->Value(i, j) ); |
168 | } |
169 | else |
170 | MyModelViewMatrix.Nullify(); |
171 | } |
172 | |
173 | Standard_Real Visual3d_ViewOrientation::Twist () const { |
174 | |
175 | cout << "\nVisual3d_ViewOrientation::Twist : Not Yet Implemented\n\n" << flush; |
176 | |
177 | #ifdef OK |
178 | Standard_Real Xrp, Yrp, Zrp; |
179 | Standard_Real Xpn, Ypn, Zpn; |
180 | Standard_Real Xup, Yup, Zup; |
181 | Standard_Real a1, b1, c1, a2, b2, c2; |
182 | Standard_Real pvx, pvy, pvz; |
183 | Standard_Real an1, an2; |
184 | Standard_Real pvn, sca, angle; |
185 | |
186 | MyViewReferencePoint.Coord (Xrp, Yrp, Zrp) ; |
187 | MyViewPlaneNormal.Coord (Xpn, Ypn, Zpn) ; |
188 | MyViewUpVector.Coord (Xup, Yup, Zup) ; |
189 | |
190 | Xrp -= Xpn ; Yrp -= Ypn ; Zrp -= Zpn ; |
191 | Xup -= Xpn ; Yup -= Ypn ; Zup -= Zpn ; |
192 | /* Compute Plane Normal EYE, AT, UP */ |
193 | a1 = Yrp*Zup - Yup*Zrp ; |
194 | b1 = Zrp*Xup - Zup*Xrp ; |
195 | c1 = Xrp*Yup - Xup*Yrp ; |
196 | /* Compute Plane Normal EYE, AT, YAXIS */ |
197 | a2 = -Zrp ; |
198 | b2 = 0. ; |
199 | c2 = Xrp ; |
200 | /* Compute Cross Vector from 2 last Normals */ |
201 | pvx = b1*c2 - c1*b2 ; |
202 | pvy = c1*a2 - a1*c2 ; |
203 | pvz = a1*b2 - b1*a2 ; |
204 | /* Normalize vectors */ |
205 | an1 = a1*a1 + b1*b1 + c1*c1 ; |
206 | an2 = a2*a2 + b2*b2 + c2*c2 ; |
207 | pvn = pvx*pvx + pvy*pvy + pvz*pvz ; |
208 | /* Compute Angle */ |
209 | if (angle > 1.) angle = 1. ; |
210 | else if ( angle < -1. ) angle = -1. ; |
211 | angle = asin (angle)/Standard_PI180 ; |
212 | sca = a1*a2 + b1*b2 + c1*c2 ; |
213 | if (sca < 0.) angle = 180. - angle ; |
214 | if ( (angle > 0.) && (angle < 180.) ) { |
215 | sca = - (pvx*Xrp + pvy*Yrp + pvz*Zrp) ; |
216 | if (sca > 0.) angle = 360. - angle ; |
217 | } |
218 | |
219 | return (angle*Standard_PI/180.0); |
220 | #else |
221 | return (Standard_PI/180.0); |
222 | #endif |
223 | |
224 | } |
225 | |
226 | void Visual3d_ViewOrientation::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const { |
227 | Sx = MyScaleX; |
228 | Sy = MyScaleY; |
229 | Sz = MyScaleZ; |
230 | } |
231 | |
232 | |
233 | void Visual3d_ViewOrientation::SetCustomModelViewMatrix(const Handle(TColStd_HArray2OfReal)& Mat) |
234 | { |
235 | MyModelViewMatrix = Mat; |
236 | } |
237 | |
238 | Standard_Boolean Visual3d_ViewOrientation::IsCustomMatrix() const |
239 | { |
240 | return !MyModelViewMatrix.IsNull() |
241 | && MyModelViewMatrix->LowerRow() == 0 |
242 | && MyModelViewMatrix->LowerCol() == 0 |
243 | && MyModelViewMatrix->UpperRow() == 3 |
244 | && MyModelViewMatrix->UpperCol() == 3; |
245 | } |