Click here to Skip to main content
11,412,833 members (77,579 online)
Click here to Skip to main content

3D Graph ActiveX Control

, 2 Aug 2003 MIT
Rate this:
Please Sign up or sign in to vote.
An ATL/STL ActiveX control based on OpenGL library for 3D data visualization
<!--P>You can take a look on live demo.

NTGraph3D -Sample Image

<STYLE> <!-- li.property { list-style-image: url(NTGraph3D_ATL/prop.gif) } li.method { list-style-image: url(NTGraph3D_ATL/gmethod.gif) } --> </STYLE>

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. Smile | :)

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

Share

About the Author

Nikolai Teofilov
Researcher
Germany Germany
No Biography provided

Comments and Discussions

 
QuestionCANNOT compile using VSNET2003! Pin
RedDK at 26-Jun-06 19:39
memberRedDK26-Jun-06 19:39 
AnswerRe: CANNOT compile using VSNET2003! Pin
hytleung at 21-May-07 23:25
memberhytleung21-May-07 23:25 
GeneralRe: CANNOT compile using VSNET2003! ... dereferencing ... cool Pin
RedDK at 15-Apr-11 9:25
memberRedDK15-Apr-11 9:25 
QuestionThis control in C# Pin
buzzy84 at 5-Jun-06 23:29
memberbuzzy845-Jun-06 23:29 
AnswerRe: This control in C# Pin
LarsLiden at 17-Feb-09 16:02
memberLarsLiden17-Feb-09 16:02 
GeneralRe: This control in C# Pin
vakulsr at 22-Apr-09 4:55
membervakulsr22-Apr-09 4:55 
GeneralProperty Pages Pin
Jairo Alonso at 12-Mar-06 22:51
memberJairo Alonso12-Mar-06 22:51 
GeneralI want to create a 3D game Pin
vikas amin at 15-Sep-05 1:47
membervikas amin15-Sep-05 1: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
GeneralRe: I found one Pin
vikas amin at 15-Sep-05 1:55
membervikas amin15-Sep-05 1:55 
GeneralBug fix 2 Pin
merckel at 23-Aug-05 17:30
membermerckel23-Aug-05 17:30 
GeneralBug fix Pin
merckel at 19-Aug-05 1:04
membermerckel19-Aug-05 1:04 
Questiondrawing a surface?!? Pin
youCanCallMeAl at 2-Apr-05 3:16
memberyouCanCallMeAl2-Apr-05 3:16 
AnswerRe: drawing a surface?!? Pin
Georgi Petrov at 7-Jun-05 12:33
memberGeorgi Petrov7-Jun-05 12:33 
GeneralRe: drawing a surface?!? Pin
chen_zd at 17-May-07 5:54
memberchen_zd17-May-07 5:54 
AnswerRe: drawing a surface?!? Pin
LarsLiden at 17-Feb-09 18:51
memberLarsLiden17-Feb-09 18:51 
Questionrotate the graph by pressing a button? Pin
youCanCallMeAl at 1-Apr-05 1:39
memberyouCanCallMeAl1-Apr-05 1:39 
AnswerRe: rotate the graph by pressing a button? Pin
Ujwal Manandhar at 18-May-07 9:11
memberUjwal Manandhar18-May-07 9:11 
GeneralMaking a surface Pin
Georgi Petrov at 2-Feb-05 2:33
memberGeorgi Petrov2-Feb-05 2:33 
GeneralThis is magic Pin
Georgi Petrov at 1-Feb-05 3:29
memberGeorgi Petrov1-Feb-05 3:29 
GeneralHelp with regsvr32 and Win2k Pin
eng8745 at 16-Nov-04 6:52
membereng874516-Nov-04 6:52 
GeneralRe: Help with regsvr32 and Win2k Pin
Dennis C. Dietrich at 16-Nov-04 7:22
memberDennis C. Dietrich16-Nov-04 7:22 
GeneralRe: Help with regsvr32 and Win2k Pin
eng8745 at 16-Nov-04 22:19
membereng874516-Nov-04 22:19 
GeneralGeneral regsvr32 tip Pin
Robert Bielik at 15-Dec-04 22:34
memberRobert Bielik15-Dec-04 22:34 
GeneralRe: General regsvr32 tip Pin
eng8745 at 4-Jan-05 7:59
membereng87454-Jan-05 7:59 
GeneralHelp with regsvr32 and Win2k Pin
eng8745 at 16-Nov-04 6:51
membereng874516-Nov-04 6:51 
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
werter1 at 5-Jun-04 22:50
memberwerter15-Jun-04 22:50 
GeneralSelection of vertices Pin
Jain Mohit at 25-May-04 22:19
memberJain Mohit25-May-04 22:19 
GeneralBuilding on Microsoft Visual Studio .NET 2003 Pin
B1293091323 at 18-May-04 15:38
memberB129309132318-May-04 15:38 
GeneralWorks! Pin
jhwurmbach at 6-Feb-06 23:11
memberjhwurmbach6-Feb-06 23:11 
GeneralSetting line color in C# Pin
M3 Dave at 15-May-04 6:06
memberM3 Dave15-May-04 6:06 
GeneralRe: Setting line color in C# Pin
BenDi at 29-Jan-05 11:51
memberBenDi29-Jan-05 11:51 
QuestionStretching a particular axis? Pin
1dp at 10-May-04 5:40
member1dp10-May-04 5:40 
Generalproblem with placing it in WTL app Pin
nadszyszkownik at 11-Apr-04 13:09
membernadszyszkownik11-Apr-04 13:09 
GeneralI want help Pin
Al_Shakhly at 1-Apr-04 15:37
memberAl_Shakhly1-Apr-04 15:37 
QuestionWhen can I available a 3D printing? Pin
Young-heum.Han at 31-Mar-04 22:25
memberYoung-heum.Han31-Mar-04 22:25 
GeneralError in downloading source code Pin
zxb0412 at 12-Mar-04 2:59
memberzxb041212-Mar-04 2:59 
GeneralMeaningless error messages Pin
UserID153243 at 5-Mar-04 5:49
sussUserID1532435-Mar-04 5:49 
GeneralTest Pin
dhan75025 at 5-Jan-04 13:38
sussdhan750255-Jan-04 13:38 
QuestionHow to draw 3d graph using VB6 Pin
syahadda at 31-Oct-03 5:56
susssyahadda31-Oct-03 5:56 
GeneralI Need a 3D graphics library Pin
Hesham M. Al_Masaeed at 14-Sep-03 0:08
sussHesham M. Al_Masaeed14-Sep-03 0:08 
GeneralRe: I Need a 3D graphics library Pin
Vacindak at 25-May-04 3:51
memberVacindak25-May-04 3:51 
GeneralI need 3D library Pin
almentar at 14-Sep-03 0:03
memberalmentar14-Sep-03 0:03 
QuestionSave to File? Pin
rjahrman at 31-Aug-03 7:18
memberrjahrman31-Aug-03 7:18 
GeneralRedrawing without re-rendering Pin
Phil Atkin at 29-Aug-03 2:58
memberPhil Atkin29-Aug-03 2:58 
GeneralRe: Redrawing without re-rendering Pin
Alex Scripnik at 4-Dec-03 1:31
memberAlex Scripnik4-Dec-03 1:31 
GeneralExceptions and using namespace std Pin
Mårten R at 7-Aug-03 2:55
sussMårten R7-Aug-03 2:55 
GeneralRe: Exceptions and using namespace std Pin
Nikolai Teofilov at 7-Aug-03 4:45
memberNikolai Teofilov7-Aug-03 4:45 
Questionhow to draw button on ocx control? Pin
xnew at 22-Jul-03 6:16
memberxnew22-Jul-03 6:16 
GeneralHELP! CAN'T CREATE OBJECT! Pin
BSMAN at 18-Jul-03 21:02
memberBSMAN18-Jul-03 21:02 
GeneralRe: HELP! CAN'T CREATE OBJECT! Pin
Antony M Kancidrowski at 5-Aug-03 3:01
memberAntony M Kancidrowski5-Aug-03 3:01 

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

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

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