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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Question3D-Graph DrawingmemberRaheel Anwar12 Jul '08 - 9:51 
I want to move a point(x,y,z) on straight or curved path in NTGraph3D control. Should I use line drawing function to draw curved path? Can Grid in background be made invisible? I only need 3-Axis in background. Is there anyother free 3D-Graph Drawing Actvx control like NTGraph3D? Thanks Raheel
GeneralSurface Plot Not Workingmemberrob10011 Jul '08 - 23:41 
Anyone got the surface plot and associated properties to work or is it disabled? Any idea on how to get the release version? No valid contact details are available for the author here.
GeneralRe: Surface Plot Not WorkingmemberLarsLiden17 Feb '09 - 15:00 
I can get the surface to draw but it doesn't draw correctly. It seems to create a bunch of spurious points.   were you able to get it to work?
GeneralRe: Surface Plot Not Working [modified]memberrob100111 Mar '09 - 17:39 
Hello,   Yes, I got the activex working. Just make sure you set the data points correctly for each axis when you use Graph3D.PlotXYX   If the x,y and z data points do not correspond to the correct axes you will get points plotted that make no sense. I had to swap the y and z axes...
Generalprintingmemberdanandu21 Apr '08 - 2:48 
I want to have print option for 3D Graphs plotted using this ActiveX control . Can anyone help me in this. There is one in 2D ActiveX, but he has not provided in this control - 3D ActiveX.   Thanks in advance.
QuestionHow to use NTGraph3D in c#?memberxiachunmin28 Nov '07 - 2:32 
I found this 3D Graph ActiveX Control in this website, but I don't konw how to use it? what is m_Graph3D then? it seems to be a instance of the class. Any one who has used it, please give me one hint.   thanks.
AnswerRe: How to use NTGraph3D in c#?memberroboticEDAR29 Mar '11 - 10:34 
did you ever figure out how to use it ?
Questionupdate surface fastermemberOlaf Petersen25 Oct '07 - 3:36 
Hi   I tryed your code in an MFC DLL and it worked, but very slow. I have to show every 12Hz new 3D images. Now i can display 1 Image per second and this will bring the CPU to 100%.   Ok what i have done is calling an function from the Dialog with this code:   ...
Generalplease help me soonmemberkian_beh16 Oct '07 - 1:56 
Hi I registerd this dll and ntgraoh.ocx in win 3000 server but when I want to put it on my prog not only a new form it takes a long time and my prog can not be started my prog is in vc++.net windows form application . please help me to say what can I do?
QuestionDoes any changes needed to use NTGraph3D in VISTA [modified]memberSai Ravi16 Jul '07 - 23:00 
Hi All, Can anyone tell me what changes required other than registering dll, i have to made while using NTGraph3D dll in Vista system     -- modified at 4:22 Friday 17th August, 2007   NSRS
QuestionRe: Does any changes needed to use NTGraph3D in VISTAmemberSai Ravi15 Aug '07 - 19:01 
I have found in some sites that i have to install some drivers to support OpenGL, Can any one suggest the relevant driver   NSRS
AnswerRe: Does any changes needed to use NTGraph3D in VISTAmemberrob100111 Mar '09 - 17:45 
All you need is a graphics accelerator that supports OpenGL. All modern graphics accelerators do this. Vista has no problems with OpenGL provided it is supported by the graphics accelerator
GeneralElements not appearingmembergrandmasterphat1 Apr '07 - 16:49 
Hey all, sorry i'm pretty average at this VB business, currently using VB6 though. Downloaded the NTGraph3D binary and registered it using regsvr32 and all went well. However after adding as a component in VB only NTGraph3D's properties show up, the elements (ie ClearGraph, AddElement,...
Generalonly plotting cornersmemberop46645 Mar '07 - 13:36 
Hi, first off, thanks for making this, its been really helpful. i have been having problems plotting an iterative sequence of a lattice like structure using a scatter diagram. while the program is running only the corners of the cube appear then the rest is plotted at the end. yet if the code...
GeneralNTGraph3D in Accessmemberbakerjw2 Jan '07 - 9:14 
Is anything other than registering NTGraph3D.dll required to get the control to work in Access?   I have it registered adn working with Excel. Right now Access is a no go though.   Any help will be greatly appreciated
Generalneed draw arc member functionmemberhoward200625 Aug '06 - 7:42 
Good code, I hope to embedded our project,as a preview 3D motion track component, could you tell me how can draw a arc by pssing center plot ,start plot and direct?   anyway, studying your code let me master lots of experiences.   coolman
QuestionUsing this Code to Draw Surface DrawingmemberNMGajjar16 Jul '06 - 19:53 
Dear Friends can any body help in usin this 3D control in VB I want to Plot the Graph from my Data Table my Table Consist of X = Columns Y = Rows Z = Values in that Row.   Can any body help in to plot the Drawing.   Z contains the Values which needs to be Ploted. help...
QuestionCANNOT compile using VSNET2003!memberRedDK26 Jun '06 - 18:39 
Aside from scores of warnings about "possible loss of data", C2664 is keeping me from compiling this code in anything but VC++ 6.0. Would someone please post a method to "convert"? The code to convert, not just "oh great, it works now! Because I casted!" or "dude, you gotta cast". Thanx. ...
AnswerRe: CANNOT compile using VSNET2003!memberhytleung21 May '07 - 22:25 
I had the same problem trying to compile the dll in VS C++ 2005.   CElement (and other iterators alike in the erring code) is a pointer which is different to an iterator. Hence you have to dereference it first then get its address before you can pass it through. This converts the...
GeneralRe: CANNOT compile using VSNET2003! ... dereferencing ... coolmemberRedDK15 Apr '11 - 8:25 
Thanks hytleung!   Neat trick. It's 2011 and I'm using VS2010 now (back when I posted this message was using VS2005, as you noted).   Aside from sqrt((double)..., your fix made the compiler get to the last error. Only a linker error here.   And quickly finding a missing .lib...
QuestionThis control in C#memberbuzzy845 Jun '06 - 22:29 
Hy guys, I need to implement in my C# app same things that control does, just like 3d surfaces and points visualization. How can I perform this?By wrap the *.dll?And if true why? Thankyou a lot. Mirko
AnswerRe: This control in C#memberLarsLiden17 Feb '09 - 15:02 
I'm using it in c#. It's pretty easy. Just go to your tools bar on the left hand side, right click, select "Choose Items" and then browse to the .dll. Then a new item for this control should appear in your tools bar.   I am having problems getting it to draw surfaces correctly though.
GeneralRe: This control in C#membervakulsr22 Apr '09 - 3:55 
Thanks man. it was a gr8 help
GeneralProperty PagesmemberJairo Alonso12 Mar '06 - 21:51 
I cannot add property pages because the compiler said "windows.h already include" or similar. Anybody can help me? Thank you.
GeneralI want to create a 3D gamemembervikas amin15 Sep '05 - 0:47 
I want to develope a 3D game with vc++ can anyone help me for using opengl , is there any simple example present on the net free to download. If anyone in the same field can help me ok take care   Vikas Amin Embin Technology Bombay vikas.amin@embin.com

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

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