Rotate the camera around the X axis of Cplane

HI;
I want the camera to rotate around the X-axis of the Cplane (0-360 degrees).
But when I run my code the X-axis will be reversed and after 180 degrees, the rotation direction will be reversed.
How do I solve them.

CRhinoViewport& viewport = RhinoApp().ActiveView()->ActiveViewport();
ON_Xform rot;
ON_3dVector axis = RhinoApp().ActiveView()->Viewport().ConstructionPlane().m_plane.xaxis;
ON_3dPoint or  = RhinoApp().ActiveView()->Viewport().ConstructionPlane().m_plane.origin;
double angle = (-5.0 / 360.0) * 2 * ON_PI;
rot.Rotation(angle, axis, or);
ON_3dVector camx = viewport.VP().CameraX();
ON_3dPoint location = viewport.VP().CameraLocation();
ON_3dPoint target = viewport.VP().TargetPoint();
viewport.SetTargetAndCameraLocation(rot * target, rot * location, true);

Hi @suc_kiet,

Does this help?

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  CRhinoView* pView = RhinoApp().ActiveView();
  if (nullptr == pView)
    return CRhinoCommand::failure;

  CRhinoViewport* pViewport = &(pView->ActiveViewport());
  if (pViewport->View().m_bLockedProjection)
    pViewport = &(pView->MainViewport());
  if (!pViewport->VP().IsPerspectiveProjection())
    return CRhinoCommand::nothing;

  const ON_Viewport& vp_in = pViewport->VP();
  ON_3dPoint camLoc;
  ON_3dVector camX, camY, camZ;
  if (!vp_in.GetCameraFrame(camLoc, camX, camY, camZ))
    return CRhinoCommand::failure;

  const CRhinoAppViewSettings& view_settings = RhinoApp().AppSettings().ViewSettings();
  double angle = 2.0 * ON_PI / view_settings.m_rotate_circle_increment;
  double target_distance = (camLoc - pViewport->Target()) * camZ;

  // Rotate about cplane x-axis
  ON_3dVector axis = pViewport->View().m_cplane.m_plane.xaxis;

  ON_Xform rot;
  rot.Rotation(angle, axis, ON_origin);
  const ON_3dVector camUp = rot * camY;
  const ON_3dVector camDir = -(rot * camZ);

  ON_3dPoint target = camLoc + target_distance * camDir;
  pViewport->SetTarget(target, true);

  ON_Viewport vp_out = vp_in;
  vp_out.SetCameraLocation(camLoc);
  vp_out.SetCameraDirection(camDir);
  vp_out.SetCameraUp(camUp);

  pViewport->SetVP(vp_out, FALSE);
  pView->Redraw();

  return CRhinoCommand::success;
}

– Dale

Hi@dale;
Thank you, it is very helpful