Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added to light if the light is on or off #851

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/sdf/Light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ namespace sdf
/// \param[in] _cast True to indicate that the light casts shadows.
public: void SetCastShadows(const bool _cast);

/// \brief Get if the light is on
/// \return True if the light is on.
public: bool LightOn() const;

/// \brief Set if the light is ON/OFF
/// \param[in] _cast True to indicate that the light is on, False otherwise.
public: void SetLightOn(const bool _isLightOn);

/// \brief Get the light intensity
/// \return The light intensity
public: double Intensity() const;
Expand Down
4 changes: 4 additions & 0 deletions sdf/1.8/light.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<description>When true, the light will cast shadows.</description>
</element>

<element name="light_on" type="bool" default="true" required="0">
<description>When true, the light is on.</description>
</element>

<element name="intensity" type="double" default="1" required="0">
<description>Scale factor to set the relative power of a light.</description>
</element>
Expand Down
18 changes: 18 additions & 0 deletions src/Light.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class sdf::Light::Implementation

/// \brief Spot light falloff.
public: double spotFalloff = 0.0;

/// \brief Is light on ?
public: bool isLightOn = true;
};

/////////////////////////////////////////////////
Expand Down Expand Up @@ -141,6 +144,9 @@ Errors Light::Load(ElementPtr _sdf)
// Load the pose. Ignore the return value since the light pose is optional.
loadPose(_sdf, this->dataPtr->pose, this->dataPtr->poseRelativeTo);

this->dataPtr->isLightOn = _sdf->Get<bool>("light_on",
this->dataPtr->isLightOn).first;

this->dataPtr->castShadows = _sdf->Get<bool>("cast_shadows",
this->dataPtr->castShadows).first;

Expand Down Expand Up @@ -316,6 +322,18 @@ void Light::SetCastShadows(const bool _cast)
this->dataPtr->castShadows = _cast;
}

/////////////////////////////////////////////////
bool Light::LightOn() const
{
return this->dataPtr->isLightOn;
}

/////////////////////////////////////////////////
void Light::SetLightOn(const bool _isLightOn)
{
this->dataPtr->isLightOn = _isLightOn;
}

/////////////////////////////////////////////////
ignition::math::Color Light::Diffuse() const
{
Expand Down
12 changes: 12 additions & 0 deletions src/Light_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ TEST(DOMLight, DefaultConstruction)
EXPECT_FALSE(semanticPose.Resolve(pose).empty());
}

EXPECT_TRUE(light.LightOn());
light.SetLightOn(false);
EXPECT_FALSE(light.LightOn());

EXPECT_FALSE(light.CastShadows());
light.SetCastShadows(true);
EXPECT_TRUE(light.CastShadows());
Expand Down Expand Up @@ -113,6 +117,7 @@ TEST(DOMLight, CopyConstructor)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -131,6 +136,7 @@ TEST(DOMLight, CopyConstructor)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand All @@ -153,6 +159,7 @@ TEST(DOMLight, CopyAssignmentOperator)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -172,6 +179,7 @@ TEST(DOMLight, CopyAssignmentOperator)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand All @@ -194,6 +202,7 @@ TEST(DOMLight, MoveConstructor)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -212,6 +221,7 @@ TEST(DOMLight, MoveConstructor)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand All @@ -234,6 +244,7 @@ TEST(DOMLight, MoveAssignment)
light.SetRawPose({3, 2, 1, 0, IGN_PI, 0});
light.SetPoseRelativeTo("ground_plane");
light.SetCastShadows(true);
light.SetLightOn(false);
light.SetDiffuse(ignition::math::Color(0.4f, 0.5f, 0.6f, 1.0));
light.SetSpecular(ignition::math::Color(0.8f, 0.9f, 0.1f, 1.0));
light.SetAttenuationRange(3.2);
Expand All @@ -253,6 +264,7 @@ TEST(DOMLight, MoveAssignment)
EXPECT_EQ(ignition::math::Pose3d(3, 2, 1, 0, IGN_PI, 0), light2.RawPose());
EXPECT_EQ("ground_plane", light2.PoseRelativeTo());
EXPECT_TRUE(light2.CastShadows());
EXPECT_FALSE(light2.LightOn());
EXPECT_EQ(ignition::math::Color(0.4f, 0.5f, 0.6f, 1), light2.Diffuse());
EXPECT_EQ(ignition::math::Color(0.8f, 0.9f, 0.1f, 1), light2.Specular());
EXPECT_DOUBLE_EQ(3.2, light2.AttenuationRange());
Expand Down