65.9K
CodeProject 正在变化。 阅读更多。
Home

3D 图表 ActiveX 控件

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.90/5 (94投票s)

2003年6月16日

MIT

3分钟阅读

viewsIcon

983623

downloadIcon

50200

基于 OpenGL 库的 ATL/STL ActiveX 控件,用于 3D 数据可视化

NTGraph3D -Sample Image

引言

这是一个基于 OpenGL 库的 ActiveX 控件,允许您绘制三维数据。该控件完全用 ATL/STL 编写,不链接 MFC 库。

该控件可以执行以下功能

  • 轴自定义,包括可自定义的字体、颜色和标题。
  • 绘制大量点,并在图表上用新数据更新一个或多个图,用新图替换旧图。
  • 绘制具有单独属性的多个元素,例如线条和点的颜色、线条粗细以及点的大小。
  • 光照
  • 绘图样式:{0 (线条); 1 (点); 2 (线点); 3 (曲面)}
  • 通过设置 Projection 属性,您可以更改视图:(0) 透视(近处的物体看起来更大),以及 (1) 正交(无论物体距离观察者的远近,其大小和角度都保持不变)。
  • 通过设置 TrackMode 属性,您可以执行:(1) 缩放,(2) 旋转,以及 (3) 运行时平移。

关于代码

要使用此控件,请将其嵌入支持 ActiveX 控件的应用程序中。Microsoft Visual Basic 应用程序、所有 MS Office 应用程序、HTA 或 Internet Explorer 应用程序中的 VBScript 和 JavaScript,以及使用 Microsoft Developer Studio 的 AppWizard 创建的应用程序都可以支持 ActiveX 控件的使用。

在开始之前,必须使用 Regsvr32.exe 将控件注册为 COM 组件。Regsvr32 接受一个参数,即要注册的 DLL 或控件,以及几个命令行开关,其中最值得注意的是 /u 用于卸载控件。默认情况下,即仅使用 dll 或 ocx 运行 Regsvr32.exe 时,它会注册该控件。

注意您必须在要使用该控件的每台计算机上执行此操作!

有关如何注册以及如何将控件包含在 VC 项目中的更多信息,请参阅我的文章 2D 图形 ActiveX 控件

下面是两个演示如何使用该控件绘制圆环的列表

C++

//
//
// Plot Torus
//
void CDemoDlg::OnButton1() 
{
   m_Graph3D.SetCaption ("Torus");
   m_Graph3D.ClearGraph(); // Clear all data
   m_Graph3D.AddElement(); // Add an element to element list

   m_Graph3D.SetElementLineColor(0, RGB(255,0,0));
   m_Graph3D.SetElementType(0, 3); // draw surface
   
   double x,y,z,ti,tj;
   
   for (int i = 0; i < 41; i++)
   {
      ti = (i - 20.0)/20.0 * 3.15;
      
      for (int j = 0; j < 41 ; j++) 
      {
	   tj = (j - 20.0)/20.0 * 3.15;
           
	   x = (cos(tj) + 3.0) * cos(ti);
	   y = sin(tj);
	   z = (cos(tj) + 3.0) * sin(ti);

           m_Graph3D.PlotXYZ(x,y,z,0); 
     }
   }

   //m_Graph3D.SetRange (-4, 4, -1, 1, -4, 4);
   m_Graph3D.AutoRange();
}

Visual Basic

'''''''''''''''''''''''''''''' 
' Look at the Demo3D.hta file 
' Double click on file to start the demo
'
' Plot Torus
'
Sub Torus

   With Graph3D
	.ClearGraph
  	.AddElement
        .Caption = "Torus"
	.ElementType(0) = 3 'Draw Surface

   For i = 0 To 41
    ti = (i - 20.0)/20.0 * 3.15

    For j = 0 To 41 
	
	tj = (j - 20.0)/20.0 * 3.15

	x = (cos(tj) + 3.0) * cos(ti)
	y = sin(tj)
	z = (cos(tj) + 3.0) * sin(ti)
	.PlotXYZ x,y,z,0
        
     Next
    Next
    	.Autorange
  End With
End Sub

控件属性列表

  •  short Appearance
  •  long BorderStyle
  •  VARIANT_BOOL BorderVisible
  •  BSTR Caption
  •  IFontDisp* Font
  •  OLE_COLOR BackColor
  •  OLE_COLOR CaptionColor
  •  short TrackMode
  •  short Projection
  •  BSTR XLabel
  •  BSTR YLabel
  •  BSTR ZLabel
  •  short XGridNumber
  •  short YGridNumber
  •  short ZGridNumber
  •  OLE_COLOR XGridColor
  •  OLE_COLOR YGridColor
  •  OLE_COLOR ZGridColor

    元素

  •  OLE_COLOR ElementLineColor(long ElementID, OLE_COLOR newVal)
  •  OLE_COLOR ElementPointColor(long ElementID, OLE_COLOR newVal)
  •  float ElementLineWidth(long ElementID, float newVal)
  •  float ElementPointSize(long ElementID, float newVal)
  •  short ElementType(long ElementID)
  •  BOOL ElementShow(long ElementID)
  •  BOOL ElementSurfaceFill(long ElementID)
  •  BOOL ElementSurfaceFlat(long ElementID)
  •  BOOL ElementLight(long ElementID
  •  short ElementLightingAmbient(long ElementID)
  •  short ElementLightingDiffuse(long ElementID)
  •  short ElementLightingSpecular(long ElementID)
  •  short ElementMaterialAmbient(long ElementID)
  •  short ElementMaterialDiffuse(long ElementID)
  •  short ElementMaterialSpecular(long ElementID)
  •  short ElementMaterialShinines(long ElementID)
  •  short ElementMaterialShinines(long ElementID)
  •  short ElementMaterialEmission(long ElementID)

控件方法列表

  •  void SetRange(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
  •  void AutoRange()
  •  void ShowPropertyPages()

    元素

  •  void AddElement()
  •  void DeleteElement(long ElementID)
  •  void ClearGraph()
  •  void PlotXYZ(double x, double y, double z, long ElementID)
  •  void SetLightCoordinates(long ElementID, float x, float y, float z)

价格:一瓶葡萄酒。 :-)

尽情享用!

注意我对 OpenGL 并不在行,因此所有关于改进该控件的良好建议、代码和帮助都非常欢迎!

如有关于本文的问题或意见,请发送电子邮件至 nteofilov@yahoo.de

历史

2003 年 6 月 16 日 - v1.0 首次发布

2003 年 6 月 22 日 - v2.0

  • 感谢 Alexander Chernosvitov 的精彩文章 3D 函数图形
  • 新增了许多属性(请参阅属性列表和演示文件)
  • ElementType = {0 (线条); 1 (点); 2 (线点); 3 (曲面)}
  • 新增了演示新功能的演示文件
  • 新属性 BOOL ElementShow(long ElementID)
2003 年 7 月 29 日 - v2.1
  • 一些绘图修复
  • 添加了 CopyToClipboard(仅适用于控件的发布版本!)
  • 添加了克莱因瓶
  • 演示项目更改
© . All rights reserved.