e1b78420ec758f66a9cdf6349e46b4008d1fac21
[occt.git] / src / Graphic3d / Graphic3d_Texture2Dplane.cxx
1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Graphic3d_Texture2Dplane.ixx>
18 #include <Graphic3d_TypeOfTextureMode.hxx>
19 #include <Graphic3d_TextureParams.hxx>
20
21 // =======================================================================
22 // function : Graphic3d_Texture2Dplane
23 // purpose  :
24 // =======================================================================
25 Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const TCollection_AsciiString& theFileName)
26 : Graphic3d_Texture2D (theFileName, Graphic3d_TOT_2D_MIPMAP)
27 {
28   myParams->SetModulate (Standard_True);
29   myParams->SetRepeat   (Standard_True);
30   myParams->SetFilter   (Graphic3d_TOTF_TRILINEAR);
31   myParams->SetGenMode  (Graphic3d_TOTM_OBJECT,
32                          Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
33                          Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
34 }
35
36 // =======================================================================
37 // function : Graphic3d_Texture2Dplane
38 // purpose  :
39 // =======================================================================
40 Graphic3d_Texture2Dplane::Graphic3d_Texture2Dplane (const Graphic3d_NameOfTexture2D theNOT)
41 : Graphic3d_Texture2D (theNOT, Graphic3d_TOT_2D_MIPMAP)
42 {
43   myParams->SetModulate (Standard_True);
44   myParams->SetRepeat   (Standard_True);
45   myParams->SetFilter   (Graphic3d_TOTF_TRILINEAR);
46   myParams->SetGenMode  (Graphic3d_TOTM_OBJECT,
47                          Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
48                          Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
49 }
50
51 // =======================================================================
52 // function : SetPlaneS
53 // purpose  :
54 // =======================================================================
55 void Graphic3d_Texture2Dplane::SetPlaneS (const Standard_ShortReal theA,
56                                           const Standard_ShortReal theB,
57                                           const Standard_ShortReal theC,
58                                           const Standard_ShortReal theD)
59 {
60   const Graphic3d_Vec4 aPlaneS (theA, theB, theC, theD);
61   const Graphic3d_Vec4 aPlaneT = myParams->GenPlaneT();
62   myParams->SetGenMode (Graphic3d_TOTM_OBJECT, aPlaneS, aPlaneT);
63   myPlaneName = Graphic3d_NOTP_UNKNOWN;
64 }
65
66 // =======================================================================
67 // function : SetPlaneT
68 // purpose  :
69 // =======================================================================
70 void Graphic3d_Texture2Dplane::SetPlaneT (const Standard_ShortReal theA,
71                                           const Standard_ShortReal theB,
72                                           const Standard_ShortReal theC,
73                                           const Standard_ShortReal theD)
74 {
75   const Graphic3d_Vec4 aPlaneS = myParams->GenPlaneS();
76   const Graphic3d_Vec4 aPlaneT (theA, theB, theC, theD);
77   myParams->SetGenMode (Graphic3d_TOTM_OBJECT, aPlaneS, aPlaneT);
78   myPlaneName = Graphic3d_NOTP_UNKNOWN;
79 }
80
81 // =======================================================================
82 // function : SetPlane
83 // purpose  :
84 // =======================================================================
85 void Graphic3d_Texture2Dplane::SetPlane (const Graphic3d_NameOfTexturePlane thePlane)
86 {
87   switch (thePlane)
88   {
89     case Graphic3d_NOTP_XY:
90     {
91       myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
92                             Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f),
93                             Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
94       break;
95     }
96     case Graphic3d_NOTP_YZ:
97     {
98       myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
99                             Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f),
100                             Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
101       break;
102     }
103     case Graphic3d_NOTP_ZX:
104     {
105       myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
106                             Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
107                             Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
108       break;
109     }
110     default: break;
111   }
112
113   myPlaneName = thePlane;
114 }
115
116 // =======================================================================
117 // function : SetScaleS
118 // purpose  :
119 // =======================================================================
120 void Graphic3d_Texture2Dplane::SetScaleS (const Standard_ShortReal theVal)
121 {
122   Graphic3d_Vec2 aScale = myParams->Scale();
123   aScale.x() = theVal;
124   myParams->SetScale (aScale);
125 }
126
127 // =======================================================================
128 // function : SetScaleT
129 // purpose  :
130 // =======================================================================
131 void Graphic3d_Texture2Dplane::SetScaleT (const Standard_ShortReal theVal)
132 {
133   Graphic3d_Vec2 aScale = myParams->Scale();
134   aScale.y() = theVal;
135   myParams->SetScale (aScale);
136 }
137
138 // =======================================================================
139 // function : SetTranslateS
140 // purpose  :
141 // =======================================================================
142 void Graphic3d_Texture2Dplane::SetTranslateS (const Standard_ShortReal theVal)
143 {
144   Graphic3d_Vec2 aVec = myParams->Translation();
145   aVec.x() = theVal;
146   myParams->SetTranslation (aVec);
147 }
148
149 // =======================================================================
150 // function : SetTranslateT
151 // purpose  :
152 // =======================================================================
153 void Graphic3d_Texture2Dplane::SetTranslateT (const Standard_ShortReal theVal)
154 {
155   Graphic3d_Vec2 aVec = myParams->Translation();
156   aVec.y() = theVal;
157   myParams->SetTranslation (aVec);
158 }
159
160 // =======================================================================
161 // function : SetRotation
162 // purpose  :
163 // =======================================================================
164 void Graphic3d_Texture2Dplane::SetRotation (const Standard_ShortReal theAngleDegrees)
165 {
166   myParams->SetRotation (theAngleDegrees);
167 }
168
169 // =======================================================================
170 // function : PlaneS
171 // purpose  :
172 // =======================================================================
173 void Graphic3d_Texture2Dplane::PlaneS (Standard_ShortReal& theA,
174                                        Standard_ShortReal& theB,
175                                        Standard_ShortReal& theC,
176                                        Standard_ShortReal& theD) const
177 {
178   const Graphic3d_Vec4& aPlaneS = myParams->GenPlaneS();
179   theA = aPlaneS.x();
180   theB = aPlaneS.y();
181   theC = aPlaneS.z();
182   theD = aPlaneS.w();
183 }
184
185 // =======================================================================
186 // function : PlaneT
187 // purpose  :
188 // =======================================================================
189 void Graphic3d_Texture2Dplane::PlaneT (Standard_ShortReal& theA,
190                                        Standard_ShortReal& theB,
191                                        Standard_ShortReal& theC,
192                                        Standard_ShortReal& theD) const
193 {
194   const Graphic3d_Vec4& aPlaneT = myParams->GenPlaneT();
195   theA = aPlaneT.x();
196   theB = aPlaneT.y();
197   theC = aPlaneT.z();
198   theD = aPlaneT.w();
199 }
200
201 // =======================================================================
202 // function : TranslateS
203 // purpose  :
204 // =======================================================================
205 void Graphic3d_Texture2Dplane::TranslateS (Standard_ShortReal& theVal) const
206 {
207   theVal = myParams->Translation().x();
208 }
209
210 // =======================================================================
211 // function : TranslateT
212 // purpose  :
213 // =======================================================================
214 void Graphic3d_Texture2Dplane::TranslateT (Standard_ShortReal& theVal) const
215 {
216   theVal = myParams->Translation().y();
217 }
218
219 // =======================================================================
220 // function : Rotation
221 // purpose  :
222 // =======================================================================
223 void Graphic3d_Texture2Dplane::Rotation (Standard_ShortReal& theVal) const
224 {
225   theVal = myParams->Rotation();
226 }
227
228 // =======================================================================
229 // function : Plane
230 // purpose  :
231 // =======================================================================
232 Graphic3d_NameOfTexturePlane Graphic3d_Texture2Dplane::Plane() const
233 {
234   return myPlaneName;
235 }
236
237 // =======================================================================
238 // function : ScaleS
239 // purpose  :
240 // =======================================================================
241 void Graphic3d_Texture2Dplane::ScaleS (Standard_ShortReal& theVal) const
242 {
243   theVal = myParams->Scale().x();
244 }
245
246 // =======================================================================
247 // function : ScaleT
248 // purpose  :
249 // =======================================================================
250 void Graphic3d_Texture2Dplane::ScaleT (Standard_ShortReal& theVal) const
251 {
252   theVal = myParams->Scale().y();
253 }