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 size of light visual #2947

Merged
merged 1 commit into from
Apr 15, 2021
Merged

Fix size of light visual #2947

merged 1 commit into from
Apr 15, 2021

Conversation

peci1
Copy link
Contributor

@peci1 peci1 commented Mar 11, 2021

Light visual is displayed wrong - it shows a cone corresponding to a light with double the angle than it should represent.

Example light:

<sdf version='1.6'>
  <world name='default'>
    <model name='lights'>
      <link name='link'>
        <light name='light_up' type='spot'>
          <attenuation>
            <range>60</range>
            <linear>0</linear>
            <constant>0.1</constant>
            <quadratic>0.0025</quadratic>
          </attenuation>
          <diffuse>0.8 0.8 0.5 1</diffuse>
          <specular>0.8 0.8 0.5 1</specular>
          <spot>
            <inner_angle>0.7</inner_angle> <!-- about 40 degrees -->
            <outer_angle>0.7</outer_angle>
            <falloff>1</falloff>
          </spot>
          <direction>0 0 -1</direction>
        </light>
        <kinematic>1</kinematic>
      </link>
    </model>
    <model name='unit_box'>
      <pose frame=''>0 0 -0.7 0 -0 0</pose>
      <link name='link'>
        <visual name='visual'>
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
          <material>
            <script>
              <name>Gazebo/Grey</name>
              <uri>file://media/materials/scripts/gazebo.material</uri>
            </script>
          </material>
        </visual>
        <kinematic>1</kinematic>
      </link>
    </model>
  </world>
</sdf>

default_gzclient_camera(1)-2021-03-11T23_12_09 882825

default_gzclient_camera(1)-2021-03-11T23_12_26 360157

It seems the math is just wrong in https://github.com/osrf/gazebo/blob/db40ad5e02f21e68e9924d725a49b3e107fecb45/gazebo/rendering/Light.cc#L314-L327

If we denote inner_angle by α, then the computation done in code to determine the corners of the pyramid is:

(±r*tan(α), ±r*tan(α), r)

Looking from a side, the situation is drawn here:

obrazek

It follows from the top half-triangle that tan(α) = (r*tan(α))/r = (angles[i]/r) and thus α = atan(angles[i]/r)... But as angles[i] is just a multiple of tan(α), it is apparent that the angle at the apex of the upper half-triangle is inner_angle. Then sum it up with the lower half-triangle, and you get angle at the apex of the light visual 2*inner_angle.

If I add a light with halved inner_angle, the borders of the visual match the circle of the light exactly:

default_gzclient_camera(1)-2021-03-11T23_22_54 013417

This PR just applies the halving of the angle to fix the visuals.

Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
@peci1
Copy link
Contributor Author

peci1 commented Mar 11, 2021

I also noticed the visual doesn't follow the direction specified in <direction> SDF tag. But I don't have an easy fix for that (although I'm sure it's just about constructing a rotation matrix and applying it to all the vertices; I don't have a Gazebo source build at hand to try that out).

@peci1
Copy link
Contributor Author

peci1 commented Mar 13, 2021

What's interesting is that if I add the light via GUI, until I click to finalize its placement, its size is correct. As soon as it gets attached to the world, the field of view doubles.

@scpeters scpeters merged commit f09ce61 into gazebosim:gazebo9 Apr 15, 2021
scpeters pushed a commit to scpeters/gazebo that referenced this pull request Apr 17, 2021
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
scpeters pushed a commit to scpeters/gazebo that referenced this pull request Apr 19, 2021
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
scpeters pushed a commit that referenced this pull request Apr 20, 2021
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
@peci1
Copy link
Contributor Author

peci1 commented Apr 22, 2021

Now it seems that the temporary light used when adding light interactively in GUI has wrong angle: #2981.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants