- implementation for Positional light only.
else
{
aTrsfPers.Nullify();
+ if (myLightSource->Is2DPers() && myLightSource->Type() == Graphic3d_TOLS_POSITIONAL)
+ {
+ aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER,
+ Graphic3d_Vec2i(myLightSource->Position().X(), myLightSource->Position().Y()));
+ }
}
break;
}
if (myIsZoomable)
{
gp_Trsf aTrsf;
- aTrsf.SetTranslation (gp::Origin(), myLightSource->Position());
+ if (!myLightSource->Is2DPers())
+ {
+ aTrsf.SetTranslation (gp::Origin(), myLightSource->Position());
+ }
myLocalTransformation = new TopLoc_Datum3D (aTrsf);
}
break;
myType (theType),
myRevision (0),
myIsHeadlight(false),
+ myIs2DPers(false),
myIsEnabled (true),
myToCastShadows (false)
{
myIsHeadlight = theValue;
}
+// =======================================================================
+// function : SetIs2DPers
+// purpose :
+// =======================================================================
+void Graphic3d_CLight::SetIs2DPers (Standard_Boolean theValue)
+{
+ if (myType == Graphic3d_TOLS_AMBIENT)
+ {
+ throw Standard_ProgramError ("Graphic3d_CLight::SetIs2DPers() is not applicable to ambient light");
+ }
+ myIs2DPers = theValue;
+}
+
// =======================================================================
// function : SetDirection
// purpose :
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myType)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myRevision)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsHeadlight)
+ OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIs2DPers)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsEnabled)
}
//! Setup headlight flag.
Standard_EXPORT void SetHeadlight (Standard_Boolean theValue);
+ //! Returns true if the light is positioned in 2D persistence; FALSE by default.
+ //! Headlight flag means that light position/direction are defined not in a World coordinate system, but relative to the camera orientation.
+ Standard_Boolean Is2DPers() const { return myIs2DPers; }
+
+ //! Setup 2D persistence for positioning light.
+ Standard_EXPORT void SetIs2DPers (Standard_Boolean theValue);
+
//! @name positional/spot light properties
public:
const Graphic3d_TypeOfLightSource myType; //!< Graphic3d_TypeOfLightSource enumeration
Standard_Size myRevision; //!< modification counter
Standard_Boolean myIsHeadlight; //!< flag to mark head light
+ Standard_Boolean myIs2DPers; //!< flag to mark head light position in 2D persistence
Standard_Boolean myIsEnabled; //!< enabled state
Standard_Boolean myToCastShadows;//!< casting shadows is requested
myWorldViewState.Update();
}
+// =======================================================================
+// function : convertTo2DPersPosition
+// purpose :
+// =======================================================================
+gp_Pnt OpenGl_ShaderManager::convertTo2DPersPosition (const gp_Pnt& thePosition) const
+{
+ OpenGl_Mat4 aProjMat = myContext->ProjectionState.Current();
+ OpenGl_Mat4 aModelMat = myContext->ModelWorldState.Current() * myContext->WorldViewState.Current();
+
+ Standard_ShortReal aX, anY, aZ;
+ Graphic3d_TransformUtils::UnProject<Standard_ShortReal> (thePosition.X(), thePosition.Y(), 0,
+ aModelMat, aProjMat, myContext->Viewport(),
+ aX, anY, aZ);
+ return gp_Pnt(aX, anY, aZ);
+}
+
// =======================================================================
// function : pushLightSourceState
// purpose :
const Graphic3d_Mat4& anOrientInv = myWorldViewState.WorldViewMatrixInverse();
aLightParams.Position = anOrientInv * Graphic3d_Vec4 (aLightParams.Position.xyz(), 1.0f);
}
+ else if (aLight.Is2DPers())
+ {
+ gp_Pnt aPosition = convertTo2DPersPosition (aLight.Position());
+
+ aLightParams.Position.x() = static_cast<float>(aPosition.X());
+ aLightParams.Position.y() = static_cast<float>(aPosition.Y());
+ aLightParams.Position.z() = static_cast<float>(aPosition.Z());
+ aLightParams.Position.w() = 0.0f;
+ }
else
{
aLightParams.Position.x() = static_cast<float>(aLight.Position().X() - myLocalOrigin.X());
//! Invalidate state of OCCT light sources.
Standard_EXPORT void UpdateLightSourceState();
+ //! Converts position to 3D point in 2D pesistence.
+ gp_Pnt convertTo2DPersPosition (const gp_Pnt& thePosition) const;
+
//! Pushes current state of OCCT light sources to specified program (only on state change).
//! Note that light sources definition depends also on WorldViewState.
void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const
}
aLightCurr->SetHeadlight (isHeadLight);
}
+ else if (anArgCase.IsEqual ("2DPERS") ||
+ anArgCase.IsEqual ("-2DPERS"))
+ {
+ if (aLightCurr.IsNull()
+ || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
+ {
+ Message::SendFail() << "Syntax error at argument '" << anArg << "'";
+ return 1;
+ }
+
+ Standard_Boolean is2DPers = Standard_False;
+ if (anArgIt + 1 < theArgsNb
+ && Draw::ParseOnOff (theArgVec[anArgIt + 1], is2DPers))
+ {
+ ++anArgIt;
+ }
+ aLightCurr->SetIs2DPers (is2DPers);
+ }
else if (anArgCase.IsEqual ("NAME")
|| anArgCase.IsEqual ("-NAME"))
{
"\n -{dir}ection X Y Z (for directional light or for spotlight)"
"\n -color colorName"
"\n -{head}light 0|1"
+ "\n -2dpers 0|1"
"\n -castShadows 0|1"
"\n -{sm}oothness value"
"\n -{int}ensity value"
--- /dev/null
+puts "================================="
+puts "0032325: Visualization - Possibility to use fixed positioned light source"
+puts "================================="
+
+pload MODELING VISUALIZATION
+vclear
+vinit View1
+vlight -clear
+
+vbackground -color GRAY
+vrenderparams -shadingModel PHONG
+vlight -add ambient -COLOR WHITE -intensity 0.1
+
+box b 10 10 10 30 30 30
+vdisplay b -dispMode 1
+vaspects b -material Brass
+vfit
+
+puts "=== Check headlight option with positional light ==="
+vlight -add positional -2dpers 1 -color WHITE -display Light1 -pos 30 20 0
+
+vlight -add positional -2dpers 1 -color WHITE -display Light2 -pos 380 370 0
+
+vlight -add positional -2dpers 1 -color WHITE -display Light3 -pos 30 380 0
+
+vdump $imagedir/${casename}_1.png
+
+vrotate 10 0 0
+vdump $imagedir/${casename}_2.png
+
+vpan -60 0
+vdump $imagedir/${casename}_3.png