Click here to Skip to main content
Click here to Skip to main content

3D Graph ActiveX Control

By , 2 Aug 2003
 
Prize winner in Competition "MFC/C++ May 2003"

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++

//
//
// 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

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nikolai Teofilov
Researcher
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralNTGraph3D in Access Pinmembermbojanks27 Oct '08 - 2:43 
Generalntgraph Pinmemberabhinav bhorkar16 Oct '08 - 3:51 
GeneralCompile Error in Excel PinmemberBonnie Douglas14 Oct '08 - 20:42 
GeneralDirect3D [modified] PinmemberRaheel Anwar3 Sep '08 - 7:38 
Question3D-Graph Drawing PinmemberRaheel Anwar12 Jul '08 - 9:51 
GeneralSurface Plot Not Working Pinmemberrob10011 Jul '08 - 23:41 
Generalprinting Pinmemberdanandu21 Apr '08 - 2:48 
QuestionHow to use NTGraph3D in c#? Pinmemberxiachunmin28 Nov '07 - 2:32 
Questionupdate surface faster PinmemberOlaf Petersen25 Oct '07 - 3:36 
Generalplease help me soon Pinmemberkian_beh16 Oct '07 - 1:56 
QuestionDoes any changes needed to use NTGraph3D in VISTA [modified] PinmemberSai Ravi16 Jul '07 - 23:00 
GeneralElements not appearing Pinmembergrandmasterphat1 Apr '07 - 16:49 
Generalonly plotting corners Pinmemberop46645 Mar '07 - 13:36 
GeneralNTGraph3D in Access Pinmemberbakerjw2 Jan '07 - 9:14 
Generalneed draw arc member function Pinmemberhoward200625 Aug '06 - 7:42 
QuestionUsing this Code to Draw Surface Drawing PinmemberNMGajjar16 Jul '06 - 19:53 
QuestionCANNOT compile using VSNET2003! PinmemberRedDK26 Jun '06 - 18:39 
QuestionThis control in C# Pinmemberbuzzy845 Jun '06 - 22:29 
GeneralProperty Pages PinmemberJairo Alonso12 Mar '06 - 21:51 
GeneralI want to create a 3D game Pinmembervikas amin15 Sep '05 - 0:47 
GeneralBug fix 2 Pinmembermerckel23 Aug '05 - 16:30 
GeneralBug fix Pinmembermerckel19 Aug '05 - 0:04 
Questiondrawing a surface?!? PinmemberyouCanCallMeAl2 Apr '05 - 2:16 
Questionrotate the graph by pressing a button? PinmemberyouCanCallMeAl1 Apr '05 - 0:39 
GeneralMaking a surface PinmemberGeorgi Petrov2 Feb '05 - 1:33 
GeneralThis is magic PinmemberGeorgi Petrov1 Feb '05 - 2:29 
GeneralHelp with regsvr32 and Win2k Pinmembereng874516 Nov '04 - 5:52 
GeneralHelp with regsvr32 and Win2k Pinmembereng874516 Nov '04 - 5:51 
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pinmemberwerter15 Jun '04 - 21:50 
GeneralSelection of vertices PinmemberJain Mohit25 May '04 - 21:19 
GeneralBuilding on Microsoft Visual Studio .NET 2003 PinmemberB129309132318 May '04 - 14:38 
GeneralSetting line color in C# PinmemberM3 Dave15 May '04 - 5:06 
QuestionStretching a particular axis? Pinmember1dp10 May '04 - 4:40 
Generalproblem with placing it in WTL app Pinmembernadszyszkownik11 Apr '04 - 12:09 
GeneralI want help PinmemberAl_Shakhly1 Apr '04 - 14:37 
QuestionWhen can I available a 3D printing? PinmemberYoung-heum.Han31 Mar '04 - 21:25 
GeneralError in downloading source code Pinmemberzxb041212 Mar '04 - 1:59 
GeneralMeaningless error messages PinsussUserID1532435 Mar '04 - 4:49 
GeneralTest Pinsussdhan750255 Jan '04 - 12:38 
QuestionHow to draw 3d graph using VB6 Pinsusssyahadda31 Oct '03 - 4:56 
GeneralI Need a 3D graphics library PinsussHesham M. Al_Masaeed13 Sep '03 - 23:08 
GeneralI need 3D library Pinmemberalmentar13 Sep '03 - 23:03 
QuestionSave to File? Pinmemberrjahrman31 Aug '03 - 6:18 
GeneralRedrawing without re-rendering PinmemberPhil Atkin29 Aug '03 - 1:58 
GeneralExceptions and using namespace std PinsussMårten R7 Aug '03 - 1:55 
Questionhow to draw button on ocx control? Pinmemberxnew22 Jul '03 - 5:16 
GeneralHELP! CAN'T CREATE OBJECT! PinmemberBSMAN18 Jul '03 - 20:02 
GeneralglData PinsussAnonymous1 Jul '03 - 14:37 
GeneralAn idea PinmemberTom Mason24 Jun '03 - 1:20 
GeneralCool PinmemberNikolai Teofilov21 Jun '03 - 4:24 
GeneralButterfly PinmemberColin Davies20 Jun '03 - 23:59 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 3 Aug 2003
Article Copyright 2003 by Nikolai Teofilov
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid