ON_Light world_rectangular_light creation

Similar to my previous question, if I create a light using user commands:

Command: RectangularLight
Rectangular light corner (Target):1,1
Rectangular light length:5,2
Rectangular light width:1
Choose rectangle < picked a point on screen

Here is my attempt in code, which is close, but not quite right:

void makeRectangularLight(CRhinoDoc * rDoc)
  ON_Light light;

  ON_3dPoint start(1, 1, 0);
  ON_3dPoint end(5, 2, 0);
  ON_3dVector dirVec(end[0] - start[0], end[1] - start[1], end[2] - start[2]);

  double length = start.DistanceTo(end);


  if (light.IsValid())
    CRhinoLightTable& light_table = rDoc->m_light_table;

Hi @mgraham,

Here is a example that creates light like the RectangularLight command.

cmdTestMgraham.cpp (2.7 KB)

Also, there is some good info in opennurbs_light.h that describe how the data members work.

  ON_3dVector m_direction; // ignored for "point" and "ambient" lights
  ON_3dPoint  m_location;  // ignored for "directional" and "ambient" lights
  ON_3dVector m_length;    // only for linear and rectangular lights
                           // ends of linear lights are m_location and m_location+m_length
  ON_3dVector m_width;     // only for rectangular lights
                           // corners of rectangular lights are m_location, m_location+m_length,
                           // m_location+m_width, m_location+m_width+m_length

Hope this helps.

– Dale