1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Aspect_GradientBackground.hxx>
16 #include <Aspect_Grid.hxx>
17 #include <Aspect_Window.hxx>
18 #include <Bnd_Box.hxx>
21 #include <Graphic3d_Group.hxx>
22 #include <Graphic3d_Structure.hxx>
23 #include <Graphic3d_TextureEnv.hxx>
24 #include <Graphic3d_Vector.hxx>
25 #include <Quantity_Color.hxx>
26 #include <Standard_MultiplyDefined.hxx>
27 #include <Standard_TypeMismatch.hxx>
28 #include <V3d_BadValue.hxx>
29 #include <V3d_Light.hxx>
30 #include <V3d_UnMapped.hxx>
31 #include <V3d_View.hxx>
32 #include <V3d_Viewer.hxx>
34 //=============================================================================
37 //=============================================================================
38 void V3d_View::Move (const Standard_Real Dx,
39 const Standard_Real Dy,
40 const Standard_Real Dz,
41 const Standard_Boolean Start)
43 Handle(Graphic3d_Camera) aCamera = Camera();
47 myCamStartOpEye = aCamera->Eye();
49 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
50 gp_Dir anUp (aCamera->Up());
51 if (!ScreenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
53 V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
57 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
59 myXscreenAxis.Coord (XX,XY,XZ);
60 myYscreenAxis.Coord (YX,YY,YZ);
61 myZscreenAxis.Coord (ZX,ZY,ZZ);
63 aCamera->SetEye (myCamStartOpEye);
65 aCamera->SetEye (aCamera->Eye().XYZ()
66 + Dx * gp_Pnt (XX, XY, XZ).XYZ()
67 + Dy * gp_Pnt (YX, YY, YZ).XYZ()
68 + Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
76 //=============================================================================
79 //=============================================================================
80 void V3d_View::Move (const Standard_Real Length, const Standard_Boolean Start)
82 Handle(Graphic3d_Camera) aCamera = Camera();
86 myCamStartOpEye = aCamera->Eye();
88 aCamera->SetEye (myCamStartOpEye);
90 Standard_Real Vx, Vy, Vz;
91 MyDefaultViewAxis.Coord (Vx, Vy, Vz) ;
93 aCamera->SetEye (aCamera->Eye().XYZ() + Length * gp_Pnt (Vx, Vy, Vz).XYZ());
100 //=============================================================================
103 //=============================================================================
104 void V3d_View::Move (const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start)
108 Move(Length,0.,0.,Start);
111 Move(0.,Length,0.,Start);
114 Move(0.,0.,Length,Start);
119 //=============================================================================
120 //function : Translate
122 //=============================================================================
123 void V3d_View::Translate (const Standard_Real Dx,
124 const Standard_Real Dy,
125 const Standard_Real Dz,
126 const Standard_Boolean Start)
128 Handle(Graphic3d_Camera) aCamera = Camera();
132 myCamStartOpEye = aCamera->Eye();
133 myCamStartOpCenter = aCamera->Center();
135 gp_Dir aReferencePlane (aCamera->Direction().Reversed());
136 gp_Dir anUp (aCamera->Up());
137 if (!ScreenAxis (aReferencePlane, anUp,
138 myXscreenAxis,myYscreenAxis,myZscreenAxis))
139 V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up");
142 Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
144 myXscreenAxis.Coord (XX,XY,XZ);
145 myYscreenAxis.Coord (YX,YY,YZ);
146 myZscreenAxis.Coord (ZX,ZY,ZZ);
148 aCamera->SetEye (myCamStartOpEye);
149 aCamera->SetCenter (myCamStartOpCenter);
151 aCamera->SetCenter (aCamera->Center().XYZ()
152 - Dx * gp_Pnt (XX, XY, XZ).XYZ()
153 - Dy * gp_Pnt (YX, YY, YZ).XYZ()
154 - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
157 aCamera->SetEye (aCamera->Eye().XYZ()
158 - Dx * gp_Pnt (XX, XY, XZ).XYZ()
159 - Dy * gp_Pnt (YX, YY, YZ).XYZ()
160 - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ()
168 //=============================================================================
169 //function : Translate
171 //=============================================================================
172 void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) {
176 Translate(Length,0.,0., Start);
179 Translate(0.,Length,0., Start);
182 Translate(0.,0.,Length, Start);
187 //=======================================================================
190 //=======================================================================
191 void V3d_View::Place (const Standard_Integer theXp,
192 const Standard_Integer theYp,
193 const Quantity_Factor theZoomFactor)
195 Standard_Integer aWinWidth = 0;
196 Standard_Integer aWinHeight = 0;
197 View()->Window()->Size (aWinWidth, aWinHeight);
199 Standard_Integer aWinCXp = aWinWidth / 2;
200 Standard_Integer aWinCYp = aWinHeight / 2;
201 Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale());
204 //=======================================================================
207 //=======================================================================
208 void V3d_View::Translate (const Standard_Real theLength, const Standard_Boolean theStart)
210 Handle(Graphic3d_Camera) aCamera = Camera();
212 Standard_Real aVx, aVy, aVz;
215 myCamStartOpCenter = aCamera->Center() ;
217 MyDefaultViewAxis.Coord (aVx, aVy, aVz);
218 gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - gp_Pnt (aVx, aVy, aVz).XYZ() * theLength);
219 aCamera->SetCenter (aNewCenter);