0024530: TKMesh - remove unused package IntPoly
[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//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
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/***********************************************************************
15
16 FONCTION :
17 ----------
18 Classe V3d_SpotLight :
19
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 00-09-92 : GG ; Creation.
7fd59977 23 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods)
24 IMP230300: GG Add SetColor() and Color() methods
25 IMP231100: GG Add IsDisplayed() method
26
27************************************************************************/
28
29/*----------------------------------------------------------------------*/
30/*
31 * Includes
32 */
33
34#include <V3d.hxx>
35#include <V3d_Light.ixx>
36
37//-Declarations
38
39
40//-Aliases
41
42//-Global data definitions
43
44//-Local data definitions
45
46//-Constructors
47
48V3d_Light::V3d_Light(const Handle(V3d_Viewer)& VM) {
49
50 MyType = V3d_AMBIENT ;
51 VM->AddLight(this) ;
52}
53
54//-Methods, in order
55
56Handle(Visual3d_Light) V3d_Light::Light() const {
57
58 return MyLight ;
59}
60
61void V3d_Light::SetColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
62 Standard_Real V1 = v1 ;
63 Standard_Real V2 = v2 ;
64 Standard_Real V3 = v3 ;
65
66 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
67 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
68 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
69
70
71 Quantity_Color C(V1,V2,V3,Type) ;
72 MyLight->SetColor(C) ;
73}
74
75void V3d_Light::SetColor(const Quantity_NameOfColor Name) {
76 Quantity_Color C(Name) ;
77 MyLight->SetColor(C) ;
78}
79
80void V3d_Light::SetColor(const Quantity_Color& aColor) {
81 MyLight->SetColor(aColor) ;
82}
83
84void V3d_Light::Color(const Quantity_TypeOfColor Type, Standard_Real& V1, Standard_Real& V2, Standard_Real& V3) const {
85
86 Quantity_Color C ;
87 C = MyLight->Color() ;
88 C.Values(V1,V2,V3,Type) ;
89}
90
91void V3d_Light::Color(Quantity_NameOfColor& Name) const{
92
93 Quantity_Color C ;
94 C = MyLight->Color() ;
95 Name = C.Name();
96}
97
98Quantity_Color V3d_Light::Color() const{
99
100 return MyLight->Color();
101}
102
103V3d_TypeOfLight V3d_Light::Type() const {
104
105 return MyType;
106}
107
108
109Standard_Boolean V3d_Light::Headlight() const {
110 return MyLight->Headlight();
111}
112
12381341 113void V3d_Light::SetHeadlight (const Standard_Boolean theValue)
114{
115 MyLight->SetHeadlight (theValue);
116}
117
7fd59977 118void 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 ) {
119
120 Standard_Real X0,Y0,Z0,XP,YP,ZP;
121 Standard_Real PXP,PYP,DeltaX,DeltaY,DeltaZ;
122 Standard_Real A,B,C,Delta,Lambda;
123 Standard_Integer IPX,IPY;
124
125 Center.Coord(X0,Y0,Z0);
126 aPoint.Coord(XP,YP,ZP);
127 aView->Project(XP,YP,ZP,PXP,PYP);
128 aView->Convert(PXP,PYP,IPX,IPY);
129 aView->ProjReferenceAxe(IPX,IPY,X,Y,Z,VX,VY,VZ);
130 DeltaX = X0 - XP;
131 DeltaY = Y0 - YP;
132 DeltaZ = Z0 - ZP;
133
81bba717 134// The point of intersection of straight lines defined by :
135// - Straight line passing by the point of projection and the eye
136// if this is a perspective, parralel to the normal of the view
137// if this is an axonometric view.
138// position in the view is parallel to the normal of the view
139// - The distance position of the target camera is equal to the radius.
7fd59977 140
141 A = VX*VX + VY*VY + VZ*VZ ;
142 B = -2. * (VX*DeltaX + VY*DeltaY + VZ*DeltaZ);
143 C = DeltaX*DeltaX + DeltaY*DeltaY + DeltaZ*DeltaZ
144 - Rayon*Rayon ;
145 Delta = B*B - 4.*A*C;
146 if ( Delta >= 0 ) {
147 Lambda = (-B + Sqrt(Delta))/(2.*A);
148 if ( Lambda >= -0.0001 && Lambda <= 0.0001 )
149 Lambda = (-B - Sqrt(Delta))/(2.*A);
150 X = XP + Lambda*VX;
151 Y = YP + Lambda*VY;
152 Z = ZP + Lambda*VZ;
153 }
154 else {
155 X = XP; Y = YP; Z = ZP;
156 }
157}
158
159Standard_Boolean V3d_Light::IsDisplayed() const {
160 if( MyGraphicStructure.IsNull() ) return Standard_False;
161 return MyGraphicStructure->IsDisplayed();
162}