1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /***********************************************************************
22 Classe V3d_SpotLight :
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods)
28 IMP230300: GG Add SetColor() and Color() methods
29 IMP231100: GG Add IsDisplayed() method
31 ************************************************************************/
33 /*----------------------------------------------------------------------*/
39 #include <V3d_Light.ixx>
46 //-Global data definitions
48 //-Local data definitions
52 V3d_Light::V3d_Light(const Handle(V3d_Viewer)& VM) {
54 MyType = V3d_AMBIENT ;
60 Handle(Visual3d_Light) V3d_Light::Light() const {
65 void V3d_Light::SetColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
66 Standard_Real V1 = v1 ;
67 Standard_Real V2 = v2 ;
68 Standard_Real V3 = v3 ;
70 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
71 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
72 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
75 Quantity_Color C(V1,V2,V3,Type) ;
76 MyLight->SetColor(C) ;
79 void V3d_Light::SetColor(const Quantity_NameOfColor Name) {
80 Quantity_Color C(Name) ;
81 MyLight->SetColor(C) ;
84 void V3d_Light::SetColor(const Quantity_Color& aColor) {
85 MyLight->SetColor(aColor) ;
88 void V3d_Light::Color(const Quantity_TypeOfColor Type, Standard_Real& V1, Standard_Real& V2, Standard_Real& V3) const {
91 C = MyLight->Color() ;
92 C.Values(V1,V2,V3,Type) ;
95 void V3d_Light::Color(Quantity_NameOfColor& Name) const{
98 C = MyLight->Color() ;
102 Quantity_Color V3d_Light::Color() const{
104 return MyLight->Color();
107 V3d_TypeOfLight V3d_Light::Type() const {
113 Standard_Boolean V3d_Light::Headlight() const {
114 return MyLight->Headlight();
117 void 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 Standard_Real X0,Y0,Z0,XP,YP,ZP;
120 Standard_Real PXP,PYP,DeltaX,DeltaY,DeltaZ;
121 Standard_Real A,B,C,Delta,Lambda;
122 Standard_Integer IPX,IPY;
124 Center.Coord(X0,Y0,Z0);
125 aPoint.Coord(XP,YP,ZP);
126 aView->Project(XP,YP,ZP,PXP,PYP);
127 aView->Convert(PXP,PYP,IPX,IPY);
128 aView->ProjReferenceAxe(IPX,IPY,X,Y,Z,VX,VY,VZ);
133 // The point of intersection of straight lines defined by :
134 // - Straight line passing by the point of projection and the eye
135 // if this is a perspective, parralel to the normal of the view
136 // if this is an axonometric view.
137 // position in the view is parallel to the normal of the view
138 // - The distance position of the target camera is equal to the radius.
140 A = VX*VX + VY*VY + VZ*VZ ;
141 B = -2. * (VX*DeltaX + VY*DeltaY + VZ*DeltaZ);
142 C = DeltaX*DeltaX + DeltaY*DeltaY + DeltaZ*DeltaZ
144 Delta = B*B - 4.*A*C;
146 Lambda = (-B + Sqrt(Delta))/(2.*A);
147 if ( Lambda >= -0.0001 && Lambda <= 0.0001 )
148 Lambda = (-B - Sqrt(Delta))/(2.*A);
154 X = XP; Y = YP; Z = ZP;
158 Standard_Boolean V3d_Light::IsDisplayed() const {
159 if( MyGraphicStructure.IsNull() ) return Standard_False;
160 return MyGraphicStructure->IsDisplayed();