Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:twoviewlayout [2015/09/14] (current)
Line 1: Line 1:
 +======Two View Layout======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to create a two-view viewport layout.//
  
 +=====Question=====
 +I would like to create a "​2View"​ command that works like Rhino'​s **3View** and **4View** commands. I would like the left-most view to be a Top view and the right-most view to be Perspective. So far, I had not had much luck in creating such a command. Any suggestions or help would be appreciated.
 +
 +=====Answer=====
 +You can define own viewport layout using **CRhinoDoc::​ReplaceModelViews**. The trick is in being able to define the proper **ON_3dmView** objects. The following example command code does what you want, and it should be helpful in creating other "​xView"​ type commands.
 +
 +=====Example=====
 +<code c++>
 +CRhinoCommand::​result CCommand2View::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  ON_3dmView views[2];
 +  double def_size = 15.0;
 +  ON_BoundingBox bbox;
 +  bbox.m_min.Set( -def_size, -def_size, -def_size );
 +  bbox.m_max.Set( ​ def_size, def_size, def_size );
 +  ON_3dPoint target = ON_origin;
 +  const CRhinoAppViewSettings&​ view_settings = RhinoApp().AppSettings().ViewSettings();​
 +  ​
 +  // top view
 +  {
 +    views[0].m_name = L"​Top";​
 +    views[0].m_target = target;
 +    ON_3dVector dir( 0.0, 0.0, -100.0 );
 +    views[0].m_vp.SetCameraLocation( views[0].m_target - dir );
 +    views[0].m_vp.SetCameraDirection( dir );
 +    views[0].m_vp.SetCameraUp( ON_yaxis );
 +    views[0].m_vp.SetProjection( ON::​parallel_view );
 +    views[0].m_vp.SetScreenPort( 0, 100, 100, 0, 0, 1 );
 +    views[0].m_vp.Extents( atan(12.0 / view_settings.m_camera_lense_length),​ bbox );
 +    views[0].m_cplane.m_plane = ON_xy_plane;​
 +    views[0].m_position.m_wnd_left = 0.0;
 +    views[0].m_position.m_wnd_right = 0.5;
 +    views[0].m_position.m_wnd_top = 0.0;
 +    views[0].m_position.m_wnd_bottom = 1.0;
 +  }
 +
 +  // perspective view
 +  {
 +    views[1].m_name = L"​Perspective";​
 +    views[1].m_target = target;
 +    ON_3dVector dir( -43.30, 75.00, -50.00 );
 +    views[1].m_vp.SetCameraLocation( views[1].m_target - dir );
 +    views[1].m_vp.SetCameraDirection( dir );
 +    views[1].m_vp.SetCameraUp( ON_zaxis );
 +    views[1].m_vp.SetProjection( ON::​perspective_view );
 +    views[1].m_vp.SetScreenPort( 0, 100, 100, 0, 0, 1 );
 +    views[1].m_vp.Extents( atan(12.0 / view_settings.m_camera_lense_length),​ bbox );
 +    views[0].m_cplane.m_plane = ON_xy_plane;​
 +    views[1].m_position.m_wnd_left = 0.5;
 +    views[1].m_position.m_wnd_right = 1.0;
 +    views[1].m_position.m_wnd_top = 0.0;
 +    views[1].m_position.m_wnd_bottom = 1.0;
 +  }
 +  ​
 +  context.m_doc.ReplaceModelViews( 2, views );
 +  context.m_doc.Redraw();​
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
developer/sdksamples/twoviewlayout.txt ยท Last modified: 2015/09/14 (external edit)