Click here to Skip to main content
15,861,125 members
Articles / Desktop Programming / ATL
Article

3D Graph ActiveX Control

Rate me:
Please Sign up or sign in to vote.
4.90/5 (100 votes)
2 Aug 2003MIT3 min read 766.2K   50K   284   111
An ATL/STL ActiveX control based on OpenGL library for 3D data visualization

NTGraph3D -Sample Image

Introduction

This is an ActiveX control based on the OpenGL library, which allows you to plot three-dimensional data. The control is entirely written on ATL/STL, and does not link to MFC libraries.

The control can perform the following functions:

  • Axis customization, including customizable font, colors, and titles.
  • Plot a large number of points and updating one or more plots on the graph with new data, replacing the old plot with the new plot.
  • Plot the multiple elements with individual properties such as line and point color, line width, and point size.
  • Lighting
  • Plot styles: {0 (Lines); 1 (Points); 2 (LinePoint); 3 (Surface)}
  • By setting the Projection property you should be able to change the viewing to: (0) Perspective (in which objects that are closer appear larger), and (1) Orthographic (in which the sizes and angles between objects are maintained no matter what their distance from the viewer).
  • By setting the TrackMode property you should be able to do: (1) Zooming, (2) Rotation, and (3) Panning at runtime.

About the Code

To use this control, embed it in an application that supports the use of ActiveX controls. Microsoft Visual Basic applications, all MS Office applications, VBScript and JavaScript in the HTA or Internet Explorer applications, and applications created with the Microsoft Developer Studio’s AppWizard can support the use of ActiveX controls.

Before you start, the control must be register as a COM component using Regsvr32.exe. Regsvr32 takes one argument the DLL or control to register and any of several command-line switches, the most notable of which is /u to uninstall a control. By default that is, when run with only a dll or ocx Regsvr32.exe registers the control.

Note: you must do this on every computer that you are going to use the control!

For more information on how to register and how to include the control in a VC Project, refer to my article 2D Graph ActiveX Control.

Bellow are two listings that demonstrates how to use the control to draw a Torus:

C++

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

VBScript
'''''''''''''''''''''''''''''' 
' 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

List of Control Properties:

    Graph

  •  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

    Elements

  •  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)

List of Control Methods:

    Graph

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

    Elements

  •  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)

Cost: One bottle wine. :-)

Enjoy!

Note: I am not expert on OpenGL, therefore all good suggestions, code and help for imporving the control are welcome!

Send mail to nteofilov@yahoo.de with questions or comments about this article.

History

16 Jun 2003 - v1.0 Initial release

22 Jun 2003 - v2.0

  • Thanks to Alexander Chernosvitov for the Excellent article Function graphics in 3D.
  • Lot’s of new properties (see property list and demo files)
  • ElementType = {0 (Lines); 1 (Points); 2 (LinePoint); 3 (Surface)}
  • Added new demo file that demonstrate the new features
  • New Property BOOL ElementShow(long ElementID)
29 Jul 2003 - v2.1
  • Some drawing fixes
  • Added CopyToClipboard (Works only with release versions of the control! )
  • Added Klein Bottle
  • Changes to the Demo Projects

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Researcher
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSetting line color in C# Pin
Member 109716115-May-04 5:06
Member 109716115-May-04 5:06 
GeneralRe: Setting line color in C# Pin
BenDi29-Jan-05 10:51
BenDi29-Jan-05 10:51 
QuestionStretching a particular axis? Pin
1dp10-May-04 4:40
1dp10-May-04 4:40 
Generalproblem with placing it in WTL app Pin
nadszyszkownik11-Apr-04 12:09
nadszyszkownik11-Apr-04 12:09 
GeneralI want help Pin
Al_Shakhly1-Apr-04 14:37
Al_Shakhly1-Apr-04 14:37 
QuestionWhen can I available a 3D printing? Pin
Young-heum.Han31-Mar-04 21:25
Young-heum.Han31-Mar-04 21:25 
GeneralError in downloading source code Pin
zxb041212-Mar-04 1:59
zxb041212-Mar-04 1:59 
GeneralMeaningless error messages Pin
Mark Kinsley5-Mar-04 4:49
Mark Kinsley5-Mar-04 4:49 
GeneralTest Pin
dhan750255-Jan-04 12:38
sussdhan750255-Jan-04 12:38 
QuestionHow to draw 3d graph using VB6 Pin
suhaida31-Oct-03 4:56
suhaida31-Oct-03 4:56 
GeneralI Need a 3D graphics library Pin
Hesham M. Al_Masaeed13-Sep-03 23:08
sussHesham M. Al_Masaeed13-Sep-03 23:08 
GeneralRe: I Need a 3D graphics library Pin
Bob Aman25-May-04 2:51
Bob Aman25-May-04 2:51 
GeneralI need 3D library Pin
Hesham Al_Masaeed13-Sep-03 23:03
Hesham Al_Masaeed13-Sep-03 23:03 
QuestionSave to File? Pin
rjahrman31-Aug-03 6:18
rjahrman31-Aug-03 6:18 
GeneralRedrawing without re-rendering Pin
Phil Atkin29-Aug-03 1:58
Phil Atkin29-Aug-03 1:58 
GeneralRe: Redrawing without re-rendering Pin
Alex Scripnik4-Dec-03 0:31
Alex Scripnik4-Dec-03 0:31 
GeneralExceptions and using namespace std Pin
Mårten R7-Aug-03 1:55
Mårten R7-Aug-03 1:55 
GeneralRe: Exceptions and using namespace std Pin
Nikolai Teofilov7-Aug-03 3:45
Nikolai Teofilov7-Aug-03 3:45 
Questionhow to draw button on ocx control? Pin
xnew22-Jul-03 5:16
xnew22-Jul-03 5:16 
GeneralHELP! CAN'T CREATE OBJECT! Pin
BSMAN18-Jul-03 20:02
BSMAN18-Jul-03 20:02 
GeneralRe: HELP! CAN'T CREATE OBJECT! Pin
Antony M Kancidrowski5-Aug-03 2:01
Antony M Kancidrowski5-Aug-03 2:01 
GeneralglData Pin
Anonymous1-Jul-03 14:37
Anonymous1-Jul-03 14:37 
GeneralRe: glData Pin
Nikolai Teofilov1-Jul-03 19:33
Nikolai Teofilov1-Jul-03 19:33 
GeneralAn idea Pin
Tom Mason24-Jun-03 1:20
Tom Mason24-Jun-03 1:20 
GeneralRe: An idea Pin
Nikolai Teofilov24-Jun-03 2:37
Nikolai Teofilov24-Jun-03 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.