96d5ae90df5dd52c98fa5a73583569fa80ef396b
[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-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_Texture1Dsegment.ixx>
18 #include <Graphic3d_TypeOfTextureMode.hxx>
19 #include <Graphic3d_TextureParams.hxx>
20
21 // =======================================================================
22 // function : Graphic3d_Texture1Dsegment
23 // purpose  :
24 // =======================================================================
25 Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const TCollection_AsciiString& theFileName)
26 : Graphic3d_Texture1D (theFileName, Graphic3d_TOT_1D),
27   myX1 (0.0f),
28   myY1 (0.0f),
29   myZ1 (0.0f),
30   myX2 (0.0f),
31   myY2 (0.0f),
32   myZ2 (0.0f)
33 {
34   myParams->SetRepeat (Standard_True);
35   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
36                         Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
37                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
38 }
39
40 // =======================================================================
41 // function : Graphic3d_Texture1Dsegment
42 // purpose  :
43 // =======================================================================
44 Graphic3d_Texture1Dsegment::Graphic3d_Texture1Dsegment (const Graphic3d_NameOfTexture1D theNOT)
45 : Graphic3d_Texture1D (theNOT, Graphic3d_TOT_1D),
46   myX1 (0.0f),
47   myY1 (0.0f),
48   myZ1 (0.0f),
49   myX2 (0.0f),
50   myY2 (0.0f),
51   myZ2 (0.0f)
52 {
53   myParams->SetRepeat (Standard_True);
54   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
55                         Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f),
56                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
57 }
58
59 // =======================================================================
60 // function : SetSegment
61 // purpose  :
62 // =======================================================================
63 void Graphic3d_Texture1Dsegment::SetSegment (const Standard_ShortReal X1,
64                                              const Standard_ShortReal Y1,
65                                              const Standard_ShortReal Z1,
66                                              const Standard_ShortReal X2,
67                                              const Standard_ShortReal Y2,
68                                              const Standard_ShortReal Z2)
69 {
70   myX1 = X1;
71   myY1 = Y1;
72   myZ1 = Z1;
73   myX2 = X2;
74   myY2 = Y2;
75   myZ2 = Z2;
76   Graphic3d_Vec4 aPlaneX (X2 - X1, Y2 - Y1, Z2 - Z1, 0.0f);
77
78   Standard_ShortReal aSqNorm = aPlaneX.x() * aPlaneX.x()
79                              + aPlaneX.y() * aPlaneX.y()
80                              + aPlaneX.z() * aPlaneX.z();
81   aPlaneX.x() /= aSqNorm;
82   aPlaneX.y() /= aSqNorm;
83   aPlaneX.z() /= aSqNorm;
84   aPlaneX.w() = -aPlaneX.x() * X1
85                 -aPlaneX.y() * Y1
86                             -aPlaneX.z() * Z1;
87
88   myParams->SetGenMode (Graphic3d_TOTM_OBJECT,
89                         aPlaneX,
90                         Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
91 }
92
93 // =======================================================================
94 // function : Segment
95 // purpose  :
96 // =======================================================================
97 void Graphic3d_Texture1Dsegment::Segment (Standard_ShortReal& X1,
98                                           Standard_ShortReal& Y1,
99                                           Standard_ShortReal& Z1,
100                                           Standard_ShortReal& X2,
101                                           Standard_ShortReal& Y2,
102                                           Standard_ShortReal& Z2) const
103 {
104   X1 = myX1;
105   Y1 = myY1;
106   Z1 = myZ1;
107   X2 = myX2;
108   Y2 = myY2;
109   Z2 = myZ2;
110 }