Click here to Skip to main content
Click here to Skip to main content

Basic Curves And Surfaces Modeler

By , 18 Apr 2012
Rate this:
Please Sign up or sign in to vote.

Sample Image - CadSurf.jpg

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:

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)
    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());
}

void CCadSurfView::OnMouseMove(...)
{
  .....
  myView->RotateView(....);
}

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

...CCadSurfView::OnDestroy(...)
{
  ...
  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

  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!

License

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

About the Author

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

Comments and Discussions

 
Question[My vote of 2] Weak as an article... PinmvpDave Kreskowiak24-Jul-13 2:01 
AnswerRe: [My vote of 2] Weak as an article... PinmemberSharjith24-Jul-13 18:23 
QuestionFixing the MFC and AERO issue? Pinmemberninpo12-Jun-13 6:12 
AnswerRe: Fixing the MFC and AERO issue? PinmemberSharjith12-Jun-13 18:16 
GeneralNice post PinmemberShahriar Iqbal Chowdhury19-Oct-12 11:09 
QuestionQuestion on 3D fit Pinmemberninpo14-Jun-12 7:10 
AnswerRe: Question on 3D fit PinmemberSharjith14-Jun-12 10:50 
GeneralRe: Question on 3D fit Pinmemberninpo14-Jun-12 13:43 
GeneralRe: Question on 3D fit PinmemberSharjith14-Jun-12 15:05 
GeneralRe: Question on 3D fit [modified] Pinmemberninpo14-Jun-12 18:14 
GeneralRe: Question on 3D fit PinmemberSharjith15-Jun-12 1:30 
GeneralMy vote of 5 PinmemberVolynsky Alex23-May-12 3:44 
GeneralMy vote of 3 PinmemberUnque23-Apr-12 20:52 
QuestionWho can tell me? PinmemberYangTze16-Apr-12 15:39 
AnswerRe: Who can tell me? PinmemberSharjith16-Apr-12 16:01 
GeneralRe: Who can tell me? [modified] PinmemberYangTze17-Apr-12 0:43 
GeneralRe: Who can tell me? PinmemberSharjith18-Apr-12 9:48 
GeneralRe: Who can tell me? PinmemberYangTze22-Apr-12 15:33 
Questioncan you tell me the usage of class in demo project?pdf file will be OK! Pinmembercpluspluswiser7-Feb-12 19:50 
AnswerRe: can you tell me the usage of class in demo project?pdf file will be OK! PinmemberSharjith8-Feb-12 1:08 
GeneralRe: can you tell me the usage of class in demo project?pdf file will be OK! PinmemberMember 915959-Feb-12 1:54 
GeneralRe: can you tell me the usage of class in demo project?pdf file will be OK! PinmemberSharjith9-Feb-12 16:35 
GeneralRe: can you tell me the usage of class in demo project?pdf file will be OK! PinmemberMember 9159522-Feb-12 15:30 
Questionplease help : how to draw BSpline by using mouse ??? Pinmembera04.lqd27-Nov-09 6:40 
AnswerRe: please help : how to draw BSpline by using mouse ??? PinmemberRichard MacCutchan27-Nov-09 7:15 

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 | Mobile
Web03 | 2.8.140415.2 | Last Updated 18 Apr 2012
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid