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   
GeneralMy vote of 2 Pinmemberibyk3015 Jun '11 - 14:25 
incomeplete, lacks essential features, not working correctly, abandonware
GeneralRe: My vote of 2 Pinmemberxrg_soft@163.com28 Jun '11 - 23:28 
GeneralRe: My vote of 2 Pinmemberelha5818 Oct '11 - 22:18 
Questionsetting element color Pinmemberibyk3030 May '11 - 7:02 
i am trying to plot surface graph (similar to example "double sine" but solid) and set color of surface based on Z value.
am not sure if i use this properly but i am having some problems. so far i am still playing with the code trying to see how to use it.
for example right now i just use lineplot (modified from "double sine" example) and while plot looks fine, it is next to impossible to see anything because everything is same color.
i can change color but is always applied to entire graph not just line i am ploting.
i expect that after each ".AddElement", and it's ".ElementLineColor(n)=RGB(100 + (n mod 128), 0,0)" i color set for only that element (".PlotXYZ X, Y, Z, n").
for some reason it does not work (or maybe I am not understanding how this is supposed to be used).
 
any help is greatly appreciated.
GeneralMy vote of 5 PinmemberRedDK15 Apr '11 - 8:39 
Eight years old and still seriously wawesome!
Questionvisual studio 2010 ? PinmemberroboticEDAR29 Mar '11 - 10:45 
tried to register it on win 7 and then add it to com from C# it worked but then tried to pull in from toolbox and then vs crashed .
any ideas?
QuestionIs the src project is supposed to generate an ActiveX control ? PinmemberMichael B Pliam31 Jan '11 - 11:47 
I am confused by this project. After spending many hours locating and correcting errors and
 
eliminating myriad warnings so that the NTGraph3D_src project would compile on Visual Studion
 
2008, I find there remain a couple of unresolved issues.
 
1) if this is supposed to generate an ActiveX control, why is no OCX file generated ?
2) the only library files generated are the NTGraph3D.dll and the associated NTGraph3D.lib
3) a Custom Build error occurs in every configuration
4) it is not possible to register the NTGraph3D.dll using regsvr32.exe
When attempts are made to do so using regsvr32.exe NTGraph3D.dll, the following message is
 
posted:
 
The NTGraph3D.dll was loaded, but the DLLRegisterServer entry point was not found.
This file cannot be registered.
 
Further, when the src project generated NTGraph3D.dll is placed in the root directory of the demo project, an Assertion Violation is encountered:
 
Debug Assertion Failed!
 
Program: this
File: f:\dd\vctools\vc7libs\ship
atlmfc\src\mfc\occont.cpp
Line 926

ASSERT(IsWindow(pTemp->m_hWnd));
 
This problem can occur when the ActiveX controls are not properly registered on the deployment machine.
http://support.microsoft.com/kb/949107
 

If anyone would like my compilable version of NTGraph3D_src project, send me an email:
 
mbpliam@pliatech.com
 
If anyone has any idea how to get this project and the demos to work, please post your comments
 
here where we can all appreciate your brilliance. Smile | :)
AnswerRe: Is the src project is supposed to generate an ActiveX control ? PinmemberMichael B Pliam26 Feb '11 - 9:01 
QuestionWould be nice if this were NOT an ActiveX Control ? PinmemberMichael B Pliam30 Jan '11 - 20:34 
I fail to see how making Alexander Chernosvitov 's code into an ActiveX control adds much utility. I believe that ActiveX controls have fallen out of fashion. It would be nice if the author would update this code without involving ActiveX. Then it would be extremely useful to many. As it is, it is full of errors and warnings when one attempts to compile it in VS 2008. While I certainly appreciate the effort the author put into this, I hope he or someone can update it. Still gets a 5 from me, but it's now too long in the tooth. Smile | :)
AnswerRe: Would be nice if this were NOT an ActiveX Control ? Pinmembernguyenvanhauk510 Jul '12 - 20:41 
GeneralUsing this library in C++ PinmemberVi_Ter5 Oct '09 - 4:40 
I can't run this demos (Demo3D and Torus) from C++ Builder 6. Please, tell me step by step what I must to do.
Generalgetting errors for data types(error: C2664) Pinmemberhituhoney16 Jul '09 - 2:16 
error C2664: 'CGraphCtl::SetLight' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'CElement *'
error C2664: 'CGraphCtl::PtInRange' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'CPoint3D *'
error C2664: 'CGraphCtl::Corrdinate' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'CPoint3D *'
error C2664: 'CGraphCtl::PtInRange' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'CPoint3D *'
error C2664: 'CGraphCtl::Corrdinate' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'CPoint3D *'
error C2668: 'sqrt' : ambiguous call to overloaded function
 

Can anybody please help me to solve these errors???
GeneralRe: getting errors for data types(error: C2664) PinmemberMember 389846914 Nov '09 - 4:52 
GeneralOpen GL PinmemberMyron Langer16 Apr '09 - 6:32 
Does anyone have a complete VB example of how to get this demo working in a VB project?
GeneralRe: Open GL Pinmemberibyk301 Jun '11 - 5:05 
GeneralRe: Open GL Pinmemberibyk301 Jun '11 - 5:26 
GeneralUsing this library in С# Pinmembergetbraine20 Feb '09 - 23:42 
Hi!
Could you write some examples how to use this library in my С# -project?Thx for help!
GeneralRe: Using this library in С# Pinmembermaslbl425 Aug '10 - 4:51 
GeneralRe: Using this library in С# PinmemberroboticEDAR29 Mar '11 - 10:34 
GeneralNTGraph3D in Access Pinmembermbojanks27 Oct '08 - 2:43 
Have you checked the exact name of the control in Access? If yes, have you then tried writing NTGraph3D0.Object instead of just NTGraph3D0 (or whatever your control`s name was) in the With line of the Torus example? Torus example with this .Object modification works fine in Access for me.
Generalntgraph Pinmemberabhinav bhorkar16 Oct '08 - 3:51 
please tell me how to change the grid distances of x & y axis in ntgraph activex control.
 
abhinav bhorkar
GeneralCompile Error in Excel PinmemberBonnie Douglas14 Oct '08 - 20:42 
Hi,
I've been using VBA for some time but have never worked with ActiveX controls.
I am trying to use this ActiveX Control in Excel.
I have registered the dll using REGSVR32.
I created an ActiveX control using NTGraph3D class.
I can see the empty x,y,z axis in the control.
I double-clicked on the control to add code.
I have ensured that I've ticked "NTGraph3D 1.0 Type Library" in my project References.
I can see the NTGraph3D objects when I open the object browser.
 
I have created the following test code:
 
Sub TstTorus()
 
Dim Gr As OLEObject
Dim WS As Worksheet
 
Set WS = Worksheets("Sheet1")
WS.OLEObject("NTGraph3D").ClearGraph
End Sub

 
I keep getting the same compile error:
Object library invalid or contains references to object definitions that could not be found.
 
Is there some step that I've missed? I would greatly appreciate help!
bd
GeneralDirect3D [modified] PinmemberRaheel Anwar3 Sep '08 - 7:38 
I want to use 2d capabilities of Direct3D. I have different bitmaps and need to blit these directly on 'Backbuffer of device'. I created a surface using IDirect3Device::CreateOffScreenPlainSurface() then I blit bitmap on this surfsace using GetDC() function of surface. Then I used IDirect3Device::GetBackBuffer() method to get backbuffer surface and using IDirect3Device::StretchRect(), did blit on backbuffer surfaceBut It did not work. Kindly guide me in this regard.
Raheel
 
modified on Saturday, September 6, 2008 7:46 AM

Question3D-Graph Drawing PinmemberRaheel 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 Working Pinmemberrob10011 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.

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