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

Fix light_control example and update tutorial #2149

Merged
merged 4 commits into from
Sep 15, 2023
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
2 changes: 2 additions & 0 deletions examples/standalone/light_control/light_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void createLight()

entityFactoryRequest.mutable_light()->set_name("point");
entityFactoryRequest.mutable_light()->set_range(4);
entityFactoryRequest.mutable_light()->set_intensity(1);
entityFactoryRequest.mutable_light()->set_attenuation_linear(0.5);
entityFactoryRequest.mutable_light()->set_attenuation_constant(0.2);
entityFactoryRequest.mutable_light()->set_attenuation_quadratic(0.01);
Expand Down Expand Up @@ -149,6 +150,7 @@ int main(int argc, char **argv)
//! [modify light]
lightRequest.set_name("point");
lightRequest.set_range(4);
lightRequest.set_intensity(1);
lightRequest.set_attenuation_linear(0.5);
lightRequest.set_attenuation_constant(0.2);
lightRequest.set_attenuation_quadratic(0.01);
Expand Down
9 changes: 6 additions & 3 deletions tutorials/light_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ This service will allow to modify lights in the scene.

To modify lights inside the scene we need to use the service `/world/<world name>/light_config` and
fill the message [`gz::msgs::Light`](https://gazebosim.org/api/msgs/9/classgz_1_1msgs_1_1Light.html).
In particular this example modifies the point light that we introduced with the function `createLight()`.

This tutorial describes the code in the `examples/standalone/light_control` example.

First we create a point light with the function `createLight()`:

\snippet examples/standalone/light_control/light_control.cc create light

**NOTE:**: You can check the [entity creation](entity_creation.html) tutorial to learn how to include models and lights in the scene.

As you can see in the snippet we modify the specular and diffuse colors of the light in the scene.
As you can see in the snippet below, we then modify the specular and diffuse colors of the point light in the scene.

\snippet examples/standalone/light_control/light_control.cc modify light

In this case we are creating random numbers to fill the diffuse and specular.
The `r`, `g`, `b` components of the light diffuse and specular colors are randomly generated and constantly changing:

\snippet examples/standalone/light_control/light_control.cc random numbers

Expand Down