0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Vrml / Vrml_DirectionalLight.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <gp_Vec.hxx>
16 #include <Quantity_Color.hxx>
17 #include <Vrml_DirectionalLight.hxx>
18
19 Vrml_DirectionalLight::Vrml_DirectionalLight():
20   myOnOff(Standard_True),
21   myIntensity(1),
22   myColor (Quantity_NOC_WHITE),
23   myDirection (0, 0, -1)
24 {
25   //
26 }
27
28  Vrml_DirectionalLight::Vrml_DirectionalLight(const Standard_Boolean aOnOff, 
29                                               const Standard_Real aIntensity, 
30                                               const Quantity_Color& aColor, 
31                                               const gp_Vec& aDirection)
32 {
33   myOnOff = aOnOff;
34   if (aIntensity < 0. || aIntensity > 1.)
35     {
36       throw Standard_Failure("Error : Light intensity must be in the range 0.0 to 1.0, inclusive.");
37     }
38   myIntensity = aIntensity;
39   myColor = aColor;
40   myDirection = aDirection;
41 }
42
43 void Vrml_DirectionalLight::SetOnOff(const Standard_Boolean aOnOff)
44 {
45   myOnOff = aOnOff;
46 }
47
48 Standard_Boolean Vrml_DirectionalLight::OnOff() const 
49 {
50   return myOnOff;
51 }
52
53 void Vrml_DirectionalLight::SetIntensity(const Standard_Real aIntensity)
54 {
55   if (aIntensity < 0. || aIntensity > 1.)
56     {
57       throw Standard_Failure("Error : Light intensity must be in the range 0.0 to 1.0, inclusive.");
58     }
59   myIntensity = aIntensity;
60 }
61
62 Standard_Real Vrml_DirectionalLight::Intensity() const 
63 {
64   return myIntensity;
65 }
66
67 void Vrml_DirectionalLight::SetColor(const Quantity_Color& aColor)
68 {
69   myColor = aColor;
70 }
71
72 Quantity_Color Vrml_DirectionalLight::Color() const 
73 {
74   return  myColor;
75 }
76
77 void Vrml_DirectionalLight::SetDirection(const gp_Vec& aDirection)
78 {
79   myDirection = aDirection;
80 }
81
82 gp_Vec Vrml_DirectionalLight::Direction() const 
83 {
84   return myDirection;
85 }
86
87 Standard_OStream& Vrml_DirectionalLight::Print(Standard_OStream& anOStream) const 
88 {
89  anOStream  << "DirectionalLight {\n";
90
91  if ( myOnOff != Standard_True )
92    {
93     anOStream  << "    on\t\tFALSE\n";
94 //    anOStream << myOnOff << "\n";
95    }
96
97  if ( Abs(myIntensity - 1) > 0.0001 )
98    {
99     anOStream  << "    intensity\t";
100     anOStream << myIntensity << "\n";
101    }
102
103  if ( Abs(myColor.Red() - 1) > 0.0001 || 
104       Abs(myColor.Green() - 1) > 0.0001 || 
105       Abs(myColor.Blue() - 1) > 0.0001 )
106    {
107     NCollection_Vec3<Standard_Real> aColor_sRGB;
108     myColor.Values (aColor_sRGB.r(), aColor_sRGB.g(), aColor_sRGB.b(), Quantity_TOC_sRGB);
109     anOStream  << "    color\t";
110     anOStream << aColor_sRGB.r() << " " << aColor_sRGB.g() << " " << aColor_sRGB.b() << "\n";
111    }
112
113  if ( Abs(myDirection.X() - 0) > 0.0001 || 
114      Abs(myDirection.Y() - 0) > 0.0001 || 
115      Abs(myDirection.Z() + 1) > 0.0001 ) 
116    {
117     anOStream  << "    direction" << '\t';
118     anOStream << myDirection.X() << " " << myDirection.Y() << " " << myDirection.Z() << "\n";
119    }
120
121  anOStream  << "}\n";
122  return anOStream;
123 }