0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Vrml / Vrml_SpotLight.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <gp_Vec.hxx>
16#include <Quantity_Color.hxx>
17#include <Vrml_SpotLight.hxx>
7fd59977 18
19Vrml_SpotLight::Vrml_SpotLight():
20 myOnOff(Standard_True),
21 myIntensity(1),
ba00aab7 22 myColor (Quantity_NOC_WHITE),
23 myLocation (0, 0, 1),
24 myDirection (0, 0, -1),
7fd59977 25 myDropOffRate(0),
26 myCutOffAngle(0.785398)
27{
ba00aab7 28 //
7fd59977 29}
30
31 Vrml_SpotLight::Vrml_SpotLight( const Standard_Boolean aOnOff,
32 const Standard_Real aIntensity,
33 const Quantity_Color& aColor,
34 const gp_Vec& aLocation,
35 const gp_Vec& aDirection,
36 const Standard_Real aDropOffRate,
37 const Standard_Real aCutOffAngle)
38{
39 myOnOff = aOnOff;
40 if (aIntensity < 0. || aIntensity > 1.)
41 {
9775fa61 42 throw Standard_Failure("Error : Light intensity must be in the range 0.0 to 1.0, inclusive.");
7fd59977 43 }
44 myIntensity = aIntensity;
45 myColor = aColor;
46 myLocation = aLocation;
47 myDirection = aDirection;
48 myDropOffRate = aDropOffRate;
49 myCutOffAngle = aCutOffAngle;
50}
51
52void Vrml_SpotLight::SetOnOff(const Standard_Boolean aOnOff)
53{
54 myOnOff = aOnOff;
55}
56
57Standard_Boolean Vrml_SpotLight::OnOff() const
58{
59 return myOnOff;
60}
61
62void Vrml_SpotLight::SetIntensity(const Standard_Real aIntensity)
63{
64 if (aIntensity < 0. || aIntensity > 1.)
65 {
9775fa61 66 throw Standard_Failure("Error : Light intensity must be in the range 0.0 to 1.0, inclusive.");
7fd59977 67 }
68 myIntensity = aIntensity;
69}
70
71Standard_Real Vrml_SpotLight::Intensity() const
72{
73 return myIntensity;
74}
75
76void Vrml_SpotLight::SetColor(const Quantity_Color& aColor)
77{
78 myColor = aColor;
79}
80
81Quantity_Color Vrml_SpotLight::Color() const
82{
83 return myColor;
84}
85
86void Vrml_SpotLight::SetLocation(const gp_Vec& aLocation)
87{
88 myLocation = aLocation;
89}
90
91gp_Vec Vrml_SpotLight::Location() const
92{
93 return myLocation;
94}
95
96void Vrml_SpotLight::SetDirection(const gp_Vec& aDirection)
97{
98 myDirection = aDirection;
99}
100
101gp_Vec Vrml_SpotLight::Direction() const
102{
103 return myDirection;
104}
105
106void Vrml_SpotLight::SetDropOffRate(const Standard_Real aDropOffRate)
107{
108 myDropOffRate = aDropOffRate;
109}
110
111Standard_Real Vrml_SpotLight::DropOffRate() const
112{
113 return myDropOffRate;
114}
115
116void Vrml_SpotLight::SetCutOffAngle(const Standard_Real aCutOffAngle)
117{
118 myCutOffAngle = aCutOffAngle;
119}
120
121Standard_Real Vrml_SpotLight::CutOffAngle() const
122{
123 return myCutOffAngle;
124}
125
126Standard_OStream& Vrml_SpotLight::Print(Standard_OStream& anOStream) const
127{
586db386 128 anOStream << "SpotLight {\n";
7fd59977 129
130 if ( myOnOff != Standard_True )
131 {
586db386 132 anOStream << " on\t\tFALSE\n";
133// anOStream << myOnOff << "\n";
7fd59977 134 }
135
136 if ( Abs(myIntensity - 1) > 0.0001 )
137 {
586db386 138 anOStream << " intensity\t";
139 anOStream << myIntensity << "\n";
7fd59977 140 }
141
142 if ( Abs(myColor.Red() - 1) > 0.0001 ||
143 Abs(myColor.Green() - 1) > 0.0001 ||
144 Abs(myColor.Blue() - 1) > 0.0001 )
145 {
ba00aab7 146 NCollection_Vec3<Standard_Real> aColor_sRGB;
147 myColor.Values (aColor_sRGB.r(), aColor_sRGB.g(), aColor_sRGB.b(), Quantity_TOC_sRGB);
586db386 148 anOStream << " color\t";
ba00aab7 149 anOStream << aColor_sRGB.r() << " " << aColor_sRGB.g() << " " << aColor_sRGB.b() << "\n";
7fd59977 150 }
151
152 if ( Abs(myLocation.X() - 0) > 0.0001 ||
153 Abs(myLocation.Y() - 0) > 0.0001 ||
154 Abs(myLocation.Z() - 1) > 0.0001 )
155 {
586db386 156 anOStream << " location\t";
157 anOStream << myLocation.X() << " " << myLocation.Y() << " " << myLocation.Z() << "\n";
7fd59977 158 }
159
160 if ( Abs(myDirection.X() - 0) > 0.0001 ||
161 Abs(myDirection.Y() - 0) > 0.0001 ||
162 Abs(myDirection.Z() + 1) > 0.0001 )
163 {
586db386 164 anOStream << " direction\t";
165 anOStream << myDirection.X() << " " << myDirection.Y() << " " << myDirection.Z() << "\n";
7fd59977 166 }
167
168 if ( Abs(myDropOffRate - 0) > 0.0001 )
169 {
586db386 170 anOStream << " dropOffRate\t";
171 anOStream << myDropOffRate << "\n";
7fd59977 172 }
173
174 if ( Abs(myCutOffAngle - 0.785398) > 0.0000001 )
175 {
586db386 176 anOStream << " cutOffAngle\t";
177 anOStream << myCutOffAngle << "\n";
7fd59977 178 }
179
586db386 180 anOStream << "}\n";
7fd59977 181 return anOStream;
182}