Skip to content

Commit

Permalink
Fix light_control example and update tutorial (#2149)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Sep 15, 2023
1 parent c8d16bf commit b504e5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit b504e5c

Please sign in to comment.