Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:addclippingplane [2015/09/14] (current)
Line 1: Line 1:
 +====== Adding Clipping Plane Objects ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to add a viewport clipping plane object using the Rhino 4.0 SDK.//
 +
 +=====Question=====
 +I would like to write a command to add clipping planes to a viewport so that I can easily cut sections of the model. I have seen the **CRhinoClippingPlaneObject** class, but I am not sure how to use it. Could I see an example?
 +
 +=====Answer=====
 +The following sample code demonstrates how to add a viewport clipping plane object.
 +
 +===== C++ =====
 +<code c++>
 +
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  // Define the corners of the clipping plane
 +  CArgsRhinoGetPlane args;
 +  ON_3dPoint corners[4];
 +  CRhinoHistory history( *this );
 +  CRhinoCommand::​result rc = RhinoGetRectangle( args, corners, &​history );
 +  if( rc != CRhinoCommand::​success )
 +    return rc;
 +
 +  // Get the active view
 +  CRhinoView* view = RhinoApp().ActiveView();​
 +  if( 0 == view  )
 +    return CRhinoCommand::​failure;​
 +
 +  const ON_3dPoint&​ p0 = corners[0];
 +  const ON_3dPoint&​ p1 = corners[1];
 +  const ON_3dPoint&​ p2 = corners[2];
 +  const ON_3dPoint&​ p3 = corners[3];
 +
 +  ON_Interval domain0, domain1;
 +  domain0.Set( 0.0, p0.DistanceTo(p1) );
 +  domain1.Set( 0.0, p0.DistanceTo(p3) );
 +
 +  // Create a plane from the corner points
 +  ON_Plane plane( p0, p1, p3);
 +
 +  // Create a plane surface
 +  ON_PlaneSurface plane_srf( plane );
 +  plane_srf.SetExtents( 0, domain0, true );
 +  plane_srf.SetExtents( 1, domain1, true );
 +  plane_srf.SetDomain( 0, domain0.Min(),​ domain0.Max() );
 +  plane_srf.SetDomain( 1, domain1.Min(),​ domain1.Max() );
 +
 +  // Create a clipping plane object
 +  rc = CRhinoCommand::​failure;​
 +  CRhinoClippingPlaneObject* plane_obj = new CRhinoClippingPlaneObject();​
 +  if( plane_obj )
 +  {
 +    plane_obj->​SetPlaneSurface( plane_srf );
 +
 +    // Add the clipping plane
 +    if( plane_obj->​AddClipViewport(view->​ActiveViewport().ViewportId()) )
 +    {
 +      context.m_doc.AddObject( plane_obj );
 +      context.m_doc.Regen();​
 +      rc = CRhinoCommand::​success;​
 +    }
 +    else
 +    {
 +      delete plane_obj;
 +      plane_obj = 0;
 +    }
 +  }
 +
 +  return rc;
 +}
 +
 +
 +
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/addclippingplane.txt ยท Last modified: 2015/09/14 (external edit)