McNeel Wiki
Rotate Objects Around Center
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
SummaryDemonstrates how rotate objects around the center point of their bounding box using the Rhino SDK.

Example

The following sample code demonstrates how rotate objects around the center point of their bounding box using the Rhino SDK.

  CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
  {
    // Select objects to rotate
    CRhinoGetObject go;
    go.SetCommandPrompt( L"Select objects to rotate" );
    go.GetObjects( 1, 0 );
    if( go.CommandResult() != success )
      return go.CommandResult();


    // Rotation angle (in degrees)
    CRhinoGetNumber gn;
    gn.SetCommandPrompt( L"Rotation angle" );
    gn.SetDefaultNumber( m_angle );
    gn.GetNumber();
    if( gn.CommandResult() != success )
      return gn.CommandResult();


    // Validate input
    double angle = gn.Number();
    if( angle == 0 )
      return nothing;


    m_angle = angle;


    // Get the active view's construction plane
    ON_Plane plane = RhinoActiveCPlane();


    // Do not split objects that get kinky 
    // when they are transformed.
    CRhinoKeepKinkySurfaces keep_kinky_srfs;


    int i;
    for( i = 0; i < go.ObjectCount(); i++ )
    {
      // Get an object reference
      const CRhinoObjRef& ref = go.Object(i);


      // Get the real object
      const CRhinoObject* obj = ref.Object();
      if( !obj )
        continue;


      // Get the object's tight bounding box
      ON_BoundingBox bbox;
      if( !obj->GetTightBoundingBox(bbox, false, 0) )
        continue;


      // Create transformation matrix
      ON_Xform xform;
      xform.Rotation( m_angle * ON_PI / 180.0, plane.zaxis, bbox.Center() );


      // Transform the object
      context.m_doc.TransformObject( obj, xform, true, true, true );
    }


    context.m_doc.Redraw();


    return success;
  }
rename · changes · history · subscriptions · lost and found · references · file upload