Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

3D Graph ActiveX Control

, 2 Aug 2003
An ATL/STL ActiveX control based on OpenGL library for 3D data visualization
ntgraph3d_bin.zip
NTGraph3D.dll
ntgraph3d_demo.zip
NTGraph3D_demo
Demo3D
Demo.aps
Demo.clw
Demo.dsp
Demo.dsw
Demo.ncb
Demo.opt
Demo.plg
res
Demo.ico
Demo3D.hta
Torus
res
Torus.ico
Torus.aps
Torus.clw
Torus.dsp
Torus.dsw
Torus.ncb
Torus.opt
Torus.plg
ntgraph3d_src.zip
NTGraph3D_src
graphctl.bmp
GraphCtl.rgs
NTGraph3D.aps
NTGraph3D.def
NTGraph3D.dsp
NTGraph3D.dsw
NTGraph3D.ncb
NTGraph3D.opt
NTGraph3D.plg
NTGraph3D.tlb
NTGraph3Dps.def
NTGraph3Dps.mk
ReleaseMinSize
Test.dsm
ntgraph_bin.zip
NTGraph3D.dll
// TorusDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Torus.h"
#include "TorusDlg.h"

#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTorusDlg dialog

CTorusDlg::CTorusDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTorusDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTorusDlg)
	m_bProjection = FALSE;
	m_nDefformation = 100;
	m_nAmbient = 60;
	m_nAmbMat = 0;
	m_nDiffMat = 0;
	m_nDiffuse = 20;
	m_nEmission = 10;
	m_nShine = 0;
	m_nSpecMat = 0;
	m_nSpecular = 0;
	m_nPosX = 37;
	m_nPosY = 100;
	m_nPosZ = 46;
	m_strAmbient = _T("");
	m_strAmbMat = _T("");
	m_strDiffMat = _T("");
	m_strDiffuse = _T("");
	m_strEmission = _T("");
	m_strShine = _T("");
	m_strSpecMat = _T("");
	m_strSpecular = _T("");
	m_strPosX = _T("");
	m_strPosY = _T("");
	m_strPosZ = _T("");
	m_bFill = FALSE;
	m_bFlat = FALSE;
	m_bLights = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTorusDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTorusDlg)
	DDX_Control(pDX, IDC_COMBO_MODE, m_cmbTrackMode);
	DDX_Check(pDX, IDC_CHECK_PROJ, m_bProjection);
	DDX_Control(pDX, IDC_NTGRAPH3D1, m_Graph3D);
	DDX_Slider(pDX, IDC_DEFFORMATION, m_nDefformation);
	DDX_Slider(pDX, IDC_AMBIENT, m_nAmbient);
	DDX_Slider(pDX, IDC_AMBMAT, m_nAmbMat);
	DDX_Slider(pDX, IDC_DIFFMAT, m_nDiffMat);
	DDX_Slider(pDX, IDC_DIFFUSE, m_nDiffuse);
	DDX_Slider(pDX, IDC_EMISSION, m_nEmission);
	DDX_Slider(pDX, IDC_SHINE, m_nShine);
	DDX_Slider(pDX, IDC_SPECMAT, m_nSpecMat);
	DDX_Slider(pDX, IDC_SPECULAR, m_nSpecular);
	DDX_Slider(pDX, IDC_XPOS, m_nPosX);
	DDX_Slider(pDX, IDC_YPOS, m_nPosY);
	DDX_Slider(pDX, IDC_ZPOS, m_nPosZ);
	DDX_Text(pDX, IDC_AMB_TEXT, m_strAmbient);
	DDX_Text(pDX, IDC_AMBMAT_TEXT, m_strAmbMat);
	DDX_Text(pDX, IDC_DIFFMAT_TEXT, m_strDiffMat);
	DDX_Text(pDX, IDC_DIFFUSE_TEXT, m_strDiffuse);
	DDX_Text(pDX, IDC_EMISSION_TEXT, m_strEmission);
	DDX_Text(pDX, IDC_SHINE_TEXT, m_strShine);
	DDX_Text(pDX, IDC_SPECMAT_TEXT, m_strSpecMat);
	DDX_Text(pDX, IDC_SPECULAR_TEXT, m_strSpecular);
	DDX_Text(pDX, IDC_XPOS_TEXT, m_strPosX);
	DDX_Text(pDX, IDC_YPOS_TEXT, m_strPosY);
	DDX_Text(pDX, IDC_ZPOS_TEXT, m_strPosZ);
	DDX_Check(pDX, IDC_FILL, m_bFill);
	DDX_Check(pDX, IDC_FLAT, m_bFlat);
	DDX_Check(pDX, IDC_LIGHTS, m_bLights);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTorusDlg, CDialog)
	//{{AFX_MSG_MAP(CTorusDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CHECK_PROJ, OnCheckProjection)
	ON_CBN_CLOSEUP(IDC_COMBO_MODE, OnCloseupComboMode)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_FILL, OnFillSurface)
	ON_BN_CLICKED(IDC_FLAT, OnFlatSurface)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTorusDlg message handlers

BOOL CTorusDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	PlotTorus();
	m_cmbTrackMode.SetCurSel(0);
	SetTimer(1,33,0);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTorusDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTorusDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTorusDlg::OnCheckProjection() 
{
	UpdateData();
	if (m_bProjection) {
		m_Graph3D.SetProjection (1);
	    m_Graph3D.SetCaption ("Orthographic");
	} else {
		m_Graph3D.SetProjection (0);
		m_Graph3D.SetCaption ("Perspective");
	}	
}

void CTorusDlg::OnCloseupComboMode() 
{
    m_Graph3D.SetTrackMode(m_cmbTrackMode.GetCurSel());	
}



void CTorusDlg::PlotTorus()
{
	m_Graph3D.SetCaption ("Torus");
	m_Graph3D.ClearGraph();
	m_Graph3D.AddElement();
	
    m_Graph3D.SetElementLineColor(0, RGB(255,0,0));
	m_Graph3D.SetElementType(0, 3); // draw surface
	m_Graph3D.SetElementSurfaceFill(0,m_bFill);
	m_Graph3D.SetElementSurfaceFlat(0,m_bFlat);
	m_Graph3D.SetLighting(0,m_bLights);

	float a = m_nDefformation/100.0;     

	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 = (a*cos(tj) + 3.0) * cos(ti);
			y = a*sin(tj);
			z = (a*cos(tj) + 3.0) * sin(ti);

			m_Graph3D.PlotXYZ(x,y,z,0);
		}
	}

	m_Graph3D.AutoRange();
}

void CTorusDlg::OnTimer(UINT nIDEvent) 
{
    UpdateData();

	PlotTorus();

	m_Graph3D.SetElementLight(0,TRUE); // Enable Lighting
    m_Graph3D.SetElementLightingAmbient(0,m_nAmbient);
    m_Graph3D.SetElementLightingDiffuse(0,m_nDiffuse);
	m_Graph3D.SetElementLightingSpecular(0,m_nSpecular);
	m_Graph3D.SetElementMaterialAmbient(0,m_nAmbMat);
    m_Graph3D.SetElementMaterialDiffuse(0,m_nDiffMat);
	m_Graph3D.SetElementMaterialSpecular(0,m_nSpecMat);
	m_Graph3D.SetElementMaterialEmission(0,m_nEmission);
	m_Graph3D.SetElementMaterialShinines(0,m_nShine);
	m_Graph3D.SetLightCoordinates(0,(float)m_nPosX,(float)m_nPosY,(float)m_nPosZ);

	CString str;

	str.Format("%d",m_nAmbient);
	m_strAmbient = str;

	str.Format("%d",m_nDiffuse);
	m_strDiffuse = str;

	str.Format("%d",m_nSpecular);
	m_strSpecular = str;

	str.Format("%d",m_nAmbMat);
	m_strAmbMat = str;

	str.Format("%d",m_nDiffMat);
	m_strDiffMat = str;

	str.Format("%d",m_nSpecMat);
	m_strSpecMat = str;

	str.Format("%d",m_nEmission);
	m_strEmission = str;

	str.Format("%d",m_nShine);
	m_strShine = str;

	str.Format("%d",m_nPosX);
	m_strPosX = str;
	str.Format("%d",m_nPosY);
	m_strPosY = str;
	str.Format("%d",m_nPosZ);
	m_strPosZ = str;



	UpdateData(FALSE);

	CDialog::OnTimer(nIDEvent);
}


void CTorusDlg::OnFillSurface() 
{
	UpdateData();
	m_Graph3D.SetElementSurfaceFill(0,m_bFill);
	
}

void CTorusDlg::OnFlatSurface() 
{
	UpdateData();
	m_Graph3D.SetElementSurfaceFlat(0,m_bFlat);
	
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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

Share

About the Author

Nikolai Teofilov
Researcher
Germany Germany
No Biography provided

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