11,411,840 members (65,092 online)

# Basic Curves And Surfaces Modeler

, 18 Apr 2012 CPOL
 Rate this:
A basic demo of modeling curves and surfaces in OpenGL.

## Introduction

This is a basic surface modeler made using MFC and OpenGL on VC6. The geometry interface and graphics interface are separated so that you can simply define your curve or surface without worrying about the display. The display is in a generalized form i.e. if you derive your own curve from `CCurve` and override the `PointAtPara` and `NormalAt` methods along with other mandatory methods, you can create an OpenGL curve as follows:

```//header file
#include "Curve.h"
class myCurve : public CCurve
{
....
};

//cpp file
#include "myCurve.h"
CPoint3D myCurve::PointAtPara(double upar)
{
double x, y, z;
x = 2*sin(uPar)......
y = .......
z = .....
CPoint3D P(x,y,z);
return P;
}```

Some where in your `CDocument` code...

```#include "myCurve.h"
void CMyProjDoc::OnCurve()
{
myCurve crv(...);
CGLCurve* myglCurve = new CGLCurve(&crv)
dContext->Display(myglCurve);
delete myglCurve;
}```

Now `dContext` is the display context object (`CGLDisplayContext`) that manages all the display functions, so this is created in the constructor of the document. Similarly for surfaces also. There are currently almost all the general curves and surfaces implemented. Curves are: line, circle, ellipse, parabola, hyperbola, Bezier and bspline. Surfaces are: plane, cylinder, cone, sphere, torus, extruded, revolved, ruled and pipe.

The display of all curves are managed by the `CGLCurve` class and that of surfaces are by the `CGLSurface` class. Points and other geometric helpers like axes, coordinate systems etc. are also modeled. This is implemented in non interactive mode for demo. You can modify the source to make an interactive application.

There are some modifications, dated 23/2/2003, made in the `CGLView` class which is the basic class for OpenGL viewing. Earlier it was derived from `CView` and the `CCadSurfView` class was derived from `CGLView`. The OpenGL manipulation methods were called from the `CCadSurfView` class's methods. e.g. mouse implementations etc. Like this: `CGLView::RotateView()`. Some how, I felt that there is no isolation for the OpenGL view. Hence with a better Object Oriented approach, I made the `CGLView` class, an independent class and the constructor of the class is passed with pointer to `CWnd`. The private data member in `CGLView` is the pointer to the `CWnd` which is initialized with OpenGL settings in the c'tor. Now an object of this `CGLView` is private member for `CCadSurfView` class which is dynamically initialized in the `OnCreate()` method of `CCadSurfView` and is deleted in `OnDestroy()` method. Now the methods are called using the object of the `CGLView` class instead of calling it directly as base class methods.--Like this:

```CCadSurfView::OnCreate(...)
{
myView = new CGLView(this, GetDocument()->DisplayContext());
}

{
.....
myView->RotateView(....);
}

{
...
myView->Resize(cx, cy);
...
}

{
...
delete myView;
...
}
```

Whereas when it was derived earlier from `CView`, the calls were like this:

```void CCadSurfView::OnMouseMove(...)
{
...
CGLView::RotateView(...);
...
}```

This application has been developed on a PIII 800Mhz m/c with 256MB RAM, RIVA TNT 32MB VRAM AGP and W2K. Not tested on other platforms. Graphics is heavy and requires good graphics card. This is not just a tutorial but an ongoing project development! Contributions are also welcome. Best Of Luck and please do let me know about comments and suggestions. Thank You.

## History

27 March 2007: I have split project into two parts

2. VKernel (VKGeom.dll and VKGraphic.dll DLLs). There are now two separate DLLs for geometry and graphics.

18th April 2012: Added solution for VS2008.

Added an additional demo of user defined surface showing Klein Bottle variant. The UserSurface.h and .cpp file in the CadSurf project shows the real implementation of Object Oriented Programming. And much more!

## Share

Engineer Tata Technologies Ltd
India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

 First Prev Next
 [My vote of 2] Weak as an article... Dave Kreskowiak 24-Jul-13 3:01
 Re: [My vote of 2] Weak as an article... Sharjith 24-Jul-13 19:23
 Fixing the MFC and AERO issue? ninpo 12-Jun-13 7:12
 Re: Fixing the MFC and AERO issue? Sharjith 12-Jun-13 19:16
 Nice post Shahriar Iqbal Chowdhury 19-Oct-12 12:09
 Question on 3D fit ninpo 14-Jun-12 8:10
 Re: Question on 3D fit Sharjith 14-Jun-12 11:50
 Re: Question on 3D fit ninpo 14-Jun-12 14:43
 Re: Question on 3D fit Sharjith 14-Jun-12 16:05
 Re: Question on 3D fit [modified] ninpo 14-Jun-12 19:14
 Re: Question on 3D fit Sharjith 15-Jun-12 2:30
 My vote of 5 Volynsky Alex 23-May-12 4:44
 My vote of 3 Unque 23-Apr-12 21:52
 Who can tell me? YangTze 16-Apr-12 16:39
 Re: Who can tell me? Sharjith 16-Apr-12 17:01
 Re: Who can tell me? [modified] YangTze 17-Apr-12 1:43
 Re: Who can tell me? Sharjith 18-Apr-12 10:48
 Re: Who can tell me? YangTze 22-Apr-12 16:33
 Compilation error guims37700 9-Jul-08 7:45
 MaterialDlg.cpp compilation error humorstar 16-Sep-07 18:02
 Re: MaterialDlg.cpp compilation error Sharjith 20-Sep-07 5:43
 Problem in toolbar icon?? HienBK99 2-Jan-07 15:54
 Re: Problem in toolbar icon?? andyliujun 5-Apr-07 3:28
 Have you used OpenCasCade? ninja1 20-Apr-06 21:27
 it is an example developed based on opencascade xazdw 25-Mar-04 0:02
 Help me rockers 13-Apr-03 7:58
 Re: Help me sataoa 20-Apr-06 21:43
 It crash for me too Anonymous 26-Feb-03 8:14
 If you start drawing something the program crash. For example choosing the icon points cause the program to crash in DefineDisplay at glDisable (GL_POINT_SMOOTH); However it looks as a very good piece of code. I'm looking forward for the full working version...
 Re: It crash for me too Anonymous 26-Feb-03 17:27
 Re: It crash for me too Sharjith 27-Feb-03 23:52
 Re: Still crashing Sharjith 28-Feb-03 0:03
 crash Jon 19-Feb-03 2:00
 Re: crash Sharjith 25-Feb-03 0:55
 Big Honking Picture Ed Gadziemski 18-Feb-03 5:08
 Re: Big Honking Picture Rick York 18-Feb-03 7:41
 Re: Big Honking Picture Anonymous 26-Feb-03 17:26
 Re: Big Honking Picture Chopper 18-Feb-03 7:52
 Re: Big Honking Picture Claudius Mokler 19-Feb-03 2:36
 Re: Big Honking Picture Lars Wadefalk 26-Feb-03 2:22
 Re: Big Honking Picture Claudius Mokler 27-Feb-03 1:18
 Last Visit: 31-Dec-99 19:00     Last Update: 26-Apr-15 7:54 Refresh 1