"ON_Xform::TranslationTransformation() "has a bug?


(yeye) #1

Hi

TranslationTransformation Regardless of your movement value, it will be at the (0,0,0)
QQ%E6%88%AA%E5%9B%BE20180308194202
The test code is as follows:

CRhinoGetObject go;
  go.SetCommandPrompt(L"Select grips to move");
  go.SetGeometryFilter(CRhinoGetObject::grip_object);
  go.GetObjects(1, 0);
  if (go.CommandResult() != success)
    return go.CommandResult();

  CRhinoXformObjectList list;
  if (list.AddObjects(go, true) < 1)
    return CRhinoCommand::failure;

  CRhinoGetPoint gp;
  gp.SetCommandPrompt(L"Point to move from");
  gp.GetPoint();
  if (gp.CommandResult() != success)
    return gp.CommandResult();

  ON_3dPoint from = gp.Point();

  gp.SetCommandPrompt(L"Point to move to");
  gp.SetBasePoint(from);
  gp.DrawLineFromPoint(from, TRUE);
  gp.GetPoint();
  if (gp.CommandResult() != success)
    return gp.CommandResult();

  ON_3dPoint to = gp.Point();

  ON_Xform xform;   
  xform.TranslationTransformation(to - from);
  if (xform.IsValid())
  {
    // Transform the grip objects
    int i;
    for (i = 0; i < list.m_grips.Count(); i++)
    {
      CRhinoGripObject* grip = list.m_grips[i];
      if (grip)
        grip->MoveGrip(xform);
    }

    // Replace the old owner with a new one
    for (i = 0; i < list.m_grip_owners.Count(); i++)
    {
      RhinoUpdateGripOwner(list.m_grip_owners[i], false, 0);
    }

    context.m_doc.Redraw();
  }

  return CRhinoCommand::success;

(Dale Fugier) #2

Hi @yeye

ON_Xform::TranslationTransformation is a static function.

So instead of this:

ON_Xform xform;   
xform.TranslationTransformation(to - from);

Do this:

ON_Xform xform = ON_Xform::TranslationTransformation(to - from);

Does this help?

– Dale


(yeye) #3

Thanks, Dale. That worked.

I also saw the update of the “https://github.com/mcneel/rhino-developer-samples/blob/6/cpp/SampleCommands/cmdSampleMoveGrips.cpp” website

Very helpful.