Click here to Skip to main content
13,398,090 members (40,476 online)
Click here to Skip to main content
Add your own
alternative version


115 bookmarked
Posted 17 Feb 2003

Basic Curves And Surfaces Modeler

, 18 Apr 2012
Rate this:
Please Sign up or sign in to vote.
A basic demo of modeling curves and surfaces in OpenGL.

Sample Image - CadSurf.jpg


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:

Some where in your project file you create your own derived classes' headers and source files...

//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)
    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:

  myView = new CGLView(this, GetDocument()->DisplayContext());

void CCadSurfView::OnMouseMove(...)

void CCadSurfView::OnSize(...)
  myView->Resize(cx, cy);

  delete myView;

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

void CCadSurfView::OnMouseMove(...)

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.


27 March 2007: I have split project into two parts

  1. Cadsurf Application,
  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!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

You may also be interested in...


Comments and Discussions

QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
werter13-May-04 22:16
memberwerter13-May-04 22:16 
Generalit is an example developed based on opencascade Pin
xazdw25-Mar-04 0:02
memberxazdw25-Mar-04 0:02 
GeneralHelp me Pin
rockers13-Apr-03 7:58
memberrockers13-Apr-03 7:58 
GeneralRe: Help me Pin
sataoa20-Apr-06 21:43
membersataoa20-Apr-06 21:43 
GeneralIt crash for me too Pin
Anonymous26-Feb-03 8:14
sussAnonymous26-Feb-03 8:14 
GeneralRe: It crash for me too Pin
Anonymous26-Feb-03 17:27
sussAnonymous26-Feb-03 17:27 
GeneralRe: It crash for me too Pin
Sharjith27-Feb-03 23:52
memberSharjith27-Feb-03 23:52 
GeneralStill crashing Pin
pochadri25-Feb-03 20:07
memberpochadri25-Feb-03 20:07 
It is still crashing.please upload the correct version soon

Thank you

GeneralRe: Still crashing Pin
Sharjith28-Feb-03 0:03
memberSharjith28-Feb-03 0:03 
Generalcrash Pin
Jon19-Feb-03 2:00
memberJon19-Feb-03 2:00 
GeneralRe: crash Pin
Sharjith25-Feb-03 0:55
memberSharjith25-Feb-03 0:55 
GeneralBig Honking Picture Pin
Ed Gadziemski18-Feb-03 5:08
memberEd Gadziemski18-Feb-03 5:08 
GeneralRe: Big Honking Picture Pin
Rick York18-Feb-03 7:41
memberRick York18-Feb-03 7:41 
GeneralRe: Big Honking Picture Pin
Anonymous26-Feb-03 17:26
sussAnonymous26-Feb-03 17:26 
GeneralRe: Big Honking Picture Pin
Chopper18-Feb-03 7:52
memberChopper18-Feb-03 7:52 
GeneralRe: Big Honking Picture Pin
Claudius Mokler19-Feb-03 2:36
memberClaudius Mokler19-Feb-03 2:36 
GeneralRe: Big Honking Picture Pin
Lars Wadefalk26-Feb-03 2:22
memberLars Wadefalk26-Feb-03 2:22 
GeneralRe: Big Honking Picture Pin
Claudius Mokler27-Feb-03 1:18
memberClaudius Mokler27-Feb-03 1:18 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180216.1 | Last Updated 18 Apr 2012
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid