0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / V3d / V3d_Light.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
7fd59977 14/***********************************************************************
7fd59977 15 FONCTION :
16 ----------
17 Classe V3d_SpotLight :
7fd59977 18 HISTORIQUE DES MODIFICATIONS :
19 --------------------------------
20 00-09-92 : GG ; Creation.
7fd59977 21************************************************************************/
7fd59977 22/*----------------------------------------------------------------------*/
23/*
24 * Includes
25 */
26
42cf5bc1 27#include <Graphic3d_Structure.hxx>
28#include <Quantity_Color.hxx>
29#include <Standard_Type.hxx>
7fd59977 30#include <V3d.hxx>
42cf5bc1 31#include <V3d_BadValue.hxx>
32#include <V3d_Light.hxx>
33#include <V3d_View.hxx>
34#include <V3d_Viewer.hxx>
7fd59977 35
92efcf78 36IMPLEMENT_STANDARD_RTTIEXT(V3d_Light,MMgt_TShared)
37
c357e426 38// =======================================================================
39// function : V3d_Light
40// purpose :
41// =======================================================================
42V3d_Light::V3d_Light (const Handle(V3d_Viewer)& theViewer)
43{
44 SetType (V3d_AMBIENT);
45 theViewer->AddLight (this);
7fd59977 46}
47
c357e426 48// =======================================================================
49// function : SetType
50// purpose :
51// =======================================================================
52void V3d_Light::SetType (const V3d_TypeOfLight theType)
53{
54 myLight.Type = (Graphic3d_TypeOfLightSource)theType;
7fd59977 55}
56
c357e426 57// =======================================================================
58// function : SetColor
59// purpose :
60// =======================================================================
c357e426 61void V3d_Light::SetColor (const Quantity_Color& theColor)
62{
63 myLight.Color.r() = static_cast<Standard_ShortReal> (theColor.Red());
64 myLight.Color.g() = static_cast<Standard_ShortReal> (theColor.Green());
65 myLight.Color.b() = static_cast<Standard_ShortReal> (theColor.Blue());
7fd59977 66}
67
c357e426 68// =======================================================================
c357e426 69// function : Type
70// purpose :
71// =======================================================================
72V3d_TypeOfLight V3d_Light::Type() const
73{
74 return (V3d_TypeOfLight)myLight.Type;
7fd59977 75}
76
189f85a3 77// =======================================================================
78// function : SetIntensity
79// purpose :
80// =======================================================================
81void V3d_Light::SetIntensity (const Standard_Real theValue)
82{
c357e426 83 Standard_ASSERT_RAISE (theValue > 0.,
84 "V3d_Light::SetIntensity, "
85 "Negative value for intensity");
86
87 myLight.Intensity = static_cast<Standard_ShortReal> (theValue);
189f85a3 88}
89
90// =======================================================================
91// function : Intensity
92// purpose :
93// =======================================================================
94Standard_Real V3d_Light::Intensity() const
95{
c357e426 96 return myLight.Intensity;
189f85a3 97}
98
99// =======================================================================
100// function : Smoothness
101// purpose :
102// =======================================================================
103Standard_Real V3d_Light::Smoothness() const
104{
c357e426 105 return myLight.Smoothness;
189f85a3 106}
7fd59977 107
c357e426 108// =======================================================================
109// function : Headlight
110// purpose :
111// =======================================================================
112Standard_Boolean V3d_Light::Headlight() const
113{
114 return myLight.IsHeadlight;
7fd59977 115}
116
c357e426 117// =======================================================================
118// function : SetHeadlight
119// purpose :
120// =======================================================================
12381341 121void V3d_Light::SetHeadlight (const Standard_Boolean theValue)
122{
c357e426 123 myLight.IsHeadlight = theValue;
12381341 124}
125
c357e426 126// =======================================================================
127// function : SymetricPointOnSphere
128// purpose :
129// =======================================================================
7fd59977 130void V3d_Light::SymetricPointOnSphere (const Handle(V3d_View)& aView, const Graphic3d_Vertex &Center, const Graphic3d_Vertex &aPoint, const Standard_Real Rayon, Standard_Real& X, Standard_Real& Y, Standard_Real& Z, Standard_Real& VX, Standard_Real& VY, Standard_Real& VZ ) {
131
132 Standard_Real X0,Y0,Z0,XP,YP,ZP;
133 Standard_Real PXP,PYP,DeltaX,DeltaY,DeltaZ;
134 Standard_Real A,B,C,Delta,Lambda;
135 Standard_Integer IPX,IPY;
136
137 Center.Coord(X0,Y0,Z0);
138 aPoint.Coord(XP,YP,ZP);
139 aView->Project(XP,YP,ZP,PXP,PYP);
140 aView->Convert(PXP,PYP,IPX,IPY);
141 aView->ProjReferenceAxe(IPX,IPY,X,Y,Z,VX,VY,VZ);
142 DeltaX = X0 - XP;
143 DeltaY = Y0 - YP;
144 DeltaZ = Z0 - ZP;
145
81bba717 146// The point of intersection of straight lines defined by :
147// - Straight line passing by the point of projection and the eye
148// if this is a perspective, parralel to the normal of the view
149// if this is an axonometric view.
150// position in the view is parallel to the normal of the view
151// - The distance position of the target camera is equal to the radius.
7fd59977 152
153 A = VX*VX + VY*VY + VZ*VZ ;
154 B = -2. * (VX*DeltaX + VY*DeltaY + VZ*DeltaZ);
155 C = DeltaX*DeltaX + DeltaY*DeltaY + DeltaZ*DeltaZ
156 - Rayon*Rayon ;
157 Delta = B*B - 4.*A*C;
158 if ( Delta >= 0 ) {
159 Lambda = (-B + Sqrt(Delta))/(2.*A);
160 if ( Lambda >= -0.0001 && Lambda <= 0.0001 )
161 Lambda = (-B - Sqrt(Delta))/(2.*A);
162 X = XP + Lambda*VX;
163 Y = YP + Lambda*VY;
164 Z = ZP + Lambda*VZ;
165 }
166 else {
167 X = XP; Y = YP; Z = ZP;
168 }
169}
170
c357e426 171// =======================================================================
172// function : IsDisplayed
173// purpose :
174// =======================================================================
175Standard_Boolean V3d_Light::IsDisplayed() const
176{
177 if (myGraphicStructure.IsNull())
178 {
179 return Standard_False;
180 }
181
182 return myGraphicStructure->IsDisplayed();
7fd59977 183}