Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:conduitboundingbox [2015/09/14] (current)
Line 1: Line 1:
 +====== Adjusting Clipping Planes from a Conduit ======
 +> **Version:​** //Rhino 4//
 +
 +=====Question=====
 +I believe I need to change Rhino'​s Z-Buffer range because when I draw using my CRhinoDisplayConduit class, objects that are far from Rhino'​s objects are being clipped. Is this true?
 +
 +=====Answer=====
 +The Z-Buffer range has nothing to do with whether or not objects get culled, or clipped, from the viewing frustum. What you are talking about has to do with Rhino'​s near and far clipping planes. Rhino'​s clipping planes are adjusted dynamically in order to maximize the precision within the Z-Buffer. And, Rhino does this by placing the near plane as close to the closest visible object in the frustum, and the far plane as far as the furthest visible object in the frustum.
 +
 +If you are adding or drawing objects that Rhino does not know about - that are not in the drawing database - then they will not be included in those calculations. Thus, you must also implement the SC_CALCBOUNDINGBOX channel inside your conduit and add to the overall scene bounding box. This will make Rhino adjust its clipping planes to include your objects.
 +
 +===== C++ =====
 +<code c++>
 +class CTestDisplayConduit : public CRhinoDisplayConduit
 +{
 +public:
 +  CTestDisplayConduit();​
 +
 +  bool ExecConduit(
 +    CRhinoDisplayPipeline&​ dp,
 +    UINT nChannel,
 +    bool& bTerminate
 +    );
 +
 +  // TODO: add other methods and members here
 +};
 +
 +CTestDisplayConduit::​CTestDisplayConduit() ​
 +: CRhinoDisplayConduit(CSupportChannels::​SC_PREDRAWOBJECTS|CSupportChannels::​SC_CALCBOUNDINGBOX)
 +{
 +  // TODO: initialize members here
 +}
 +
 +bool CTestDisplayConduit::​ExecConduit(
 +    CRhinoDisplayPipeline&​ dp,
 +    UINT nChannel,
 +    bool& bTerminate
 +    )
 +{
 +  switch( nChannel )
 +  {
 +    case CSupportChannels::​SC_CALCBOUNDINGBOX:​
 +    {
 +      m_pChannelAttrs->​m_BoundingBox.Union( /​*YOUR_OBJECTS_BOUNDING_BOXES*/​ );
 +      break;
 +    }
 +    case CSupportChannels::​SC_PREDRAWOBJECTS:​
 +    {
 +      // TODO: add drawing code here
 +      break;
 +    }
 +  }
 +  return true;
 +}
 +
 +</​code>​
 +===== C# =====
 +<code c#>
 +public class CSTestDisplayConduit : MRhinoDisplayConduit
 +{
 +  public CSTestDisplayConduit()
 +  :base(new MSupportChannels(MSupportChannels.SC_CALCBOUNDINGBOX | MSupportChannels.SC_PREDRAWOBJECTS))
 +  {
 +  }
 +
 +  public override bool ExecConduit(ref MRhinoDisplayPipeline pipeline, uint channel, ref bool terminate)
 +  {
 +    if (channel == MSupportChannels.SC_CALCBOUNDINGBOX)
 +    {
 +      OnBoundingBox bbox = new OnBoundingBox();​
 +      // bbox = YOUR_OBJECTS_BOUNDING_BOXES
 +      m_pChannelAttrs.m_BoundingBox.Union(bbox);​
 +    }
 +    else if (channel == MSupportChannels.SC_PREDRAWOBJECTS)
 +    {
 +      // TODO: add drawing code here
 +    }
 +    return true;
 +  }
 +}
 +
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class CSTestDisplayConduit
 +  Inherits MRhinoDisplayConduit
 +
 +  Public Sub New()
 +    MyBase.New(New MSupportChannels(MSupportChannels.SC_CALCBOUNDINGBOX Or MSupportChannels.SC_PREDRAWOBJECTS))
 +  End Sub
 +
 +  Public Overrides Function ExecConduit(ByRef pipeline As RMA.Rhino.MRhinoDisplayPipeline,​ _
 +    ByVal channel As UInteger, ByRef terminate As Boolean) As Boolean
 +    If (channel = MSupportChannels.SC_CALCBOUNDINGBOX) Then
 +      Dim bbox As New OnBoundingBox()
 +      ' bbox = YOUR_OBJECTS_BOUNDING_BOXES
 +      m_pChannelAttrs.m_BoundingBox.Union(bbox)
 +    ElseIf (channel = MSupportChannels.SC_PREDRAWOBJECTS) Then
 +      ' TODO: add drawing code here
 +    End If
 +    Return True
 +  End Function
 +End Class
 +
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/conduitboundingbox.txt ยท Last modified: 2015/09/14 (external edit)