0024224: Suspicious logics in changing clipping planes at OpenGl_Structure
[occt.git] / src / Graphic3d / Graphic3d_Texture1Dsegment.cxx
1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 #include <Graphic3d_Texture1Dsegment.ixx>
22 #include <Graphic3d_TypeOfTextureMode.hxx>
23 #include <Graphic3d_TextureParams.hxx>
24
25 // =======================================================================
26 // function : Graphic3d_Texture1Dsegment
27 // purpose  :
28 // =======================================================================
29 Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const TCollection_AsciiString& theFileName)
30 : Graphic3d_Texture1D (theFileName, Graphic3d_TOT_1D),
31   myX1 (0.0f),
32   myY1 (0.0f),
33   myZ1 (0.0f),
34   myX2 (0.0f),
35   myY2 (0.0f),
36   myZ2 (0.0f)
37 {
38   myParams->SetRepeat (Standard_True);
39   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
40                         Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
41                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
42 }
43
44 // =======================================================================
45 // function : Graphic3d_Texture1Dsegment
46 // purpose  :
47 // =======================================================================
48 Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTexture1D theNOT)
49 : Graphic3d_Texture1D (theNOT, Graphic3d_TOT_1D),
50   myX1 (0.0f),
51   myY1 (0.0f),
52   myZ1 (0.0f),
53   myX2 (0.0f),
54   myY2 (0.0f),
55   myZ2 (0.0f)
56 {
57   myParams->SetRepeat (Standard_True);
58   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
59                         Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
60                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
61 }
62
63 // =======================================================================
64 // function : SetSegment
65 // purpose  :
66 // =======================================================================
67 void Graphic3d_Texture1Dsegment::SetSegment (const Standard_ShortReal X1,
68                                              const Standard_ShortReal Y1,
69                                              const Standard_ShortReal Z1,
70                                              const Standard_ShortReal X2,
71                                              const Standard_ShortReal Y2,
72                                              const Standard_ShortReal Z2)
73 {
74   myX1 = X1;
75   myY1 = Y1;
76   myZ1 = Z1;
77   myX2 = X2;
78   myY2 = Y2;
79   myZ2 = Z2;
80   Graphic3d_Vec4 aPlaneX (X2 - X1, Y2 - Y1, Z2 - Z1, 0.0f);
81
82   Standard_ShortReal aSqNorm = aPlaneX.x() * aPlaneX.x()
83                              + aPlaneX.y() * aPlaneX.y()
84                              + aPlaneX.z() * aPlaneX.z();
85   aPlaneX.x() /= aSqNorm;
86   aPlaneX.y() /= aSqNorm;
87   aPlaneX.z() /= aSqNorm;
88   aPlaneX.w() = -aPlaneX.x() * X1
89                 -aPlaneX.y() * Y1
90                             -aPlaneX.z() * Z1;
91
92   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
93                         aPlaneX,
94                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
95 }
96
97 // =======================================================================
98 // function : Segment
99 // purpose  :
100 // =======================================================================
101 void Graphic3d_Texture1Dsegment::Segment (Standard_ShortReal& X1,
102                                           Standard_ShortReal& Y1,
103                                           Standard_ShortReal& Z1,
104                                           Standard_ShortReal& X2,
105                                           Standard_ShortReal& Y2,
106                                           Standard_ShortReal& Z2) const
107 {
108   X1 = myX1;
109   Y1 = myY1;
110   Z1 = myZ1;
111   X2 = myX2;
112   Y2 = myY2;
113   Z2 = myZ2;
114 }