您现在的位置:网站首页 > 经验分享 > 基于Rhino的三维鞋业CAD软件开发[
设计师介绍:

昵称:烦夫子
类别:界面/平面设计师
年龄:38
现所在地:北京

查看该设计师的主页>>

关注好友

统计中心

主页浏览总数:24260
总积分:89
文章数:88
作品数:70

基于Rhino的三维鞋业CAD软件开发[

作者:烦夫子  更新时间: 2007-11-19   浏览人数:18188  评论:0  
分享到:
开放源码:
                            RHINO三维图形开发平台
                                     [10]
 
// 自定义三维物体旋转
// The one and only instance of a CCommandrotate3Object class. 
// Do NOT create any other instance of a CCommandrotate3Object class.
static class CCommandrotate3Object therotate3ObjectCommand;
CRhinoscrīptCommand::result CCommandrotate3Object::RunCommand( const CRhinoCommandContext& context )
{
 
 int i;
 CRhinoGetObject go;
 go.SetCommandPrompt( L"Select curve" );
 go.SetGeometryFilter( CRhinoGetObject::curve_object );
 go.EnableSubObjectSelect( FALSE );
 go.GetObjects( 1, 1 );
 if( go.CommandResult() != CRhinoCommand::success )
  return go.CommandResult();
 
 CRhinoObjRef ōbjref = go.Object(0);
 const ON_Curve* pC = objref.Curve();
 if( !pC )
  return CRhinoCommand::failure;
 
 CRhinoGetPoint gp;
 gp.SetCommandPrompt( L"Point on curve" );
 gp.Constrain( *pC );
 gp.GetPoint();
 if( gp.CommandResult() != CRhinoCommand::success )
  return gp.CommandResult();
 
 ON_3dPoint pt = gp.Point();
 
 double t = 0.0;
 if( !pC->GetClosestPoint(pt, &t) )
  return CRhinoCommand::failure;
 
 ON_3dVector xaxis = pC->TangentAt( t );
 xaxis.Unitize();
 
 ON_3dVector zaxis = gp.View()->Viewport().ConstructionPlane().m_plane.zaxis;
 zaxis.Unitize();
 
 ON_3dVector yaxis = ON_CrossProduct( zaxis, xaxis );
 yaxis.Unitize();
 
 ON_Plane plane( pt, xaxis, yaxis );
 
    //通过重新定义一点来对垂直线进行加长
 ON_3dVector mypoint,m_pointonend,m_pointonend2;
 mypoint.x=4;
 mypoint.y=4;
 
 //得到垂直线的端点
 m_pointonend=pt - plane.yaxis - mypoint;
 m_pointonend2=pt + plane.yaxis + mypoint;
 //AfxMessageBox(m_pointonend.x);
 context.m_doc.UnselectAll();
 context.m_doc.Redraw();
 
 //第二次选取
 //c_tmp0为对称直线的一端的移动到的坐标
    ON_wString c_tmp0,c_tmp1,c_tmp2,c_tmp3;
    c_tmp0.Format("move ");
    c_tmp1.Format("%g,%g %g,%g",pt.x,pt.y,m_pointonend.x,m_pointonend.y);
    c_tmp0=c_tmp0+c_tmp1;
 //c_tmp2为对称直线的另一端的移动到的坐标
    c_tmp2.Format("move ");
    c_tmp3.Format("%g,%g %g,%g",pt.x,pt.y,m_pointonend2.x,m_pointonend2.y);
    c_tmp2=c_tmp2+c_tmp3;

 go.SetCommandPrompt( L"请依次选取外曲线以便进行旋转" );
 go.SetGeometryFilter( CRhinoGetObject::curve_object );
 CRhinoGet::result res2 = go.GetObjects( 1, 0 );
 if( res2 != CRhinoGet::object )
  return CRhinoCommand::cancel;
 
 
 for( i = 0; i < go.ObjectCount(); i++ )
 {
  
  const CRhinoObject *obj_ref2 = go.Object(i).Object();
  
        obj_ref2->Select();
  RhinoApp().Runscrīpt(c_tmp0);
  //  const ON_Curve* crv2 = obj_ref2.Curve();
  //  if( crv2 )
  //   crv_array2.Append( crv2 );
  //  
  //      
 }
 go.ClearObjects();
 context.m_doc.UnselectAll();
 context.m_doc.Redraw();
 
 //第三次选取
 go.SetCommandPrompt( L"请依次选取外曲线以便进行旋转" );
 go.SetGeometryFilter( CRhinoGetObject::curve_object );
 CRhinoGet::result res3 = go.GetObjects( 1, 0 );
 if( res3 != CRhinoGet::object )
  return CRhinoCommand::cancel;
 
 // ON_SimpleArray crv_array3( go.ObjectCount() );
 for( i = 0; i < go.ObjectCount(); i++ )
 {
  
  const CRhinoObject *obj_ref3 = go.Object(i).Object();
  
  //  const ON_Curve* crv2 = obj_ref2.Curve();
  //  if( crv2 )
  //   crv_array2.Append( crv2 );
  //  obj_ref2.m_pHeader->SetSelected(-1);
        obj_ref3->Select();
  RhinoApp().Runscrīpt(c_tmp2);
 }
 go.ClearObjects();
 
 return CRhinoCommand::success;
}
//
// END rotate3Object command
//
(目前有0人发表看法,  我要发表评论
我要评论:
  只有登录后才能评论!
评论者: 匿名游客    (立即登录 或 注册)