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

Basic Curves And Surfaces Modeler

By , 18 Apr 2012
 

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 Inc
United States United States
Member
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: can you tell me the usage of class in demo project?pdf file will be OK!memberSharjith9 Feb '12 - 16:35 
My friend, I am more than ready to help you but please explain which class and methods are you using. Your explanation doesn't give me an accurate picture of what you are trying to do and where you are getting stuck.
RegardsSmile | :)
N. Sharjith

GeneralRe: can you tell me the usage of class in demo project?pdf file will be OK!memberMember 9159522 Feb '12 - 15:30 
How do adjust the direction of the x,y,z Axis.Now three Axis lines are displayed in the center of window,How can i modify the angle between x and y Axis.
Questionplease help : how to draw BSpline by using mouse ???membera04.lqd27 Nov '09 - 6:40 
then save the curve.
 
it is hard exercise for me.... Dead | X|
 
please help !!!
 
thank very much.
AnswerRe: please help : how to draw BSpline by using mouse ???memberRichard MacCutchan27 Nov '09 - 7:15 
So even using someone else's code you are incapable of completing the exercise given by your teacher. How you expect to pass your course is a mystery.
GeneralCompilation errormemberguims377009 Jul '08 - 6:45 
I would like to operate this sofware but when I build, I get this error(I use Visual C++ 6):
 
Linking...
LINK : fatal error LNK1104: cannot open file "VKGeom.lib"
Error executing link.exe.
 

CadSurf.exe - 1 error(s), 0 warning(s)
 
Could anyone help me?
 
Guims37700
GeneralMaterialDlg.cpp compilation errormemberhumorstar16 Sep '07 - 17:02 
When I open the cadsurf project in Visual C++ 2005, it has one compilation error in materialDlg.cpp as follows:
 
cadsurf\materialdlg.cpp(39) : error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMaterialDlg::* )(UINT)' to 'BOOL (__thiscall CCmdTarget::* )(UINT)'
None of the functions with this name in scope match the target type
 
How to fix this problem?
 
Thanks for the nice work,

AnswerRe: MaterialDlg.cpp compilation errormemberSharjith20 Sep '07 - 4:43 
Stricter C++ adherence in (MFC) Visual Studio 2005 will not allow compilation unless many changes are made to the code. Please use Visual C++ 6 for building
 
Regds
N. SharjithSmile | :)
QuestionProblem in toolbar icon??memberHienBK992 Jan '07 - 14:54 
When I open this program and click some shape icons, this program will be stop immediately,is anyone same to me???
AnswerRe: Problem in toolbar icon??memberandyliujun5 Apr '07 - 2:28 
I also can't run it !Why not someone give the answer?

QuestionHave you used OpenCasCade?memberninja120 Apr '06 - 20:27 
Hi Sharjith
 
Have you ever experimented with OpenCasCade? Any comments on the same.
 
Nitin
GeneralCAD/CAM SoftwaresussStéphan15 Sep '05 - 22:35 
I'm all alone to do my own CAD/CAM software, and I would appreciate some kind of help.
If you are interrested to work on this kind of project please contact me.
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox?memberwerter13 May '04 - 21:16 

How to run 2 different(or same) OpenGL objects in one DialogBox?
IDC_STATIC1 is a first OpenGL objects Scene window.
IDC_STATIC2 is a second OpenGL objects Scene window.
IDC_STATIC1 and IDC_STATIC2 ,they are placed on IDD_DIALOG1.
 
code:
pclStatic = (CStatic *)GetDlgItem(IDC_OpenGL_Window);
pclGlView = new CGlView(pclStatic);
pclGlView->OnCreate();
pclGlView->InitGL();
pclGlView->DrawGLScene();
 
pclStatic1 = (CStatic *)GetDlgItem(IDC_OpenGL_Window);
pclGlView1 = new CGlView(pclStatic1);
pclGlView1->OnCreate();
pclGlView1->InitGL();
pclGlView1->DrawGLScene();
 
Will not involve both windows (IDC_STATIC2,IDC_STATIC1)
Generalit is an example developed based on opencascadememberxazdw24 Mar '04 - 23:02 
If you are interested in it,please click www.opencascade.com to down the opencascade that is a large 3D modeling platform in CAD/CAM. the new version
is 5.1;);PBig Grin | :-D Smile | :)
 
I come from Xi'an Jiaotong university.
www.xjtu.edu.cn
GeneralHelp mememberrockers13 Apr '03 - 6:58 
How to draw line3D or cycle 3D by Mouse

GeneralRe: Help memembersataoa20 Apr '06 - 20:43 
Hello,
To do the things more positively. Just started u r coding and ask if the problem.
GeneralIt crash for me toosussAnonymous26 Feb '03 - 7: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...
GeneralRe: It crash for me toosussAnonymous26 Feb '03 - 16:27 
Sleepy | :zzz: Sleepy | :zzz: Poke tongue | ;-P
GeneralRe: It crash for me toomemberSharjith27 Feb '03 - 22:52 
Hi,
Thanks for the feedback, the problem is probably with the graphics card u have. Please let me know your systems config.
 
Regards
N.Sharjith
GeneralStill crashingmemberpochadri25 Feb '03 - 19:07 
It is still crashing.please upload the correct version soon
 
Thank you

GeneralRe: Still crashingmemberSharjith27 Feb '03 - 23:03 
Hi,
Please try running the pogram after recompiling by commenting out the code parts for displaying the fonts in all the geometry creation tasks in the CCadSurfDoc events.
The fonts give trouble on graphic cards with no OpenGL support and low vram. The culprit is probably wglFonts.
 
I recommend a graphics card with full OpenGL drivers loaded and a vram of atleast 32mb.
 
Regards
N.Sharjith
 


GeneralcrashmemberJon19 Feb '03 - 1:00 
If you run the exe and drag a selection over the axes the program crashes.
GeneralRe: crashmemberSharjith24 Feb '03 - 23:55 
Hi Jon,
Thankyou for the feedback. I think it is some thing related to the graphics card you have. I have come across the problems like selection not happening, crashing if fonts displayed etc. on other computers with no AGP cards or low level cards. The graphics card must have full OpenGL support and enough video memory. The project is updated now. You may download the fresh one. All the best!
 
Regards
N. SharjithSmile | :)
GeneralBig Honking PicturememberEd Gadziemski18 Feb '03 - 4:08 
That must be the largest screenshot ever in a CodeProject article. The source code downloads are huge, too. Are you seeking the award for biggest picture and files?
GeneralRe: Big Honking PicturememberRick York18 Feb '03 - 6:41 
This is what happens when the .APS, .NCB, and .OPT files are included in the archive which is unnecessary since they are all regeneratable.
 
Sharjith : you should add the height and width attributes to the img tag so that the image is displayed at the correct size.
 

The Ten Commandments For C Programmers

GeneralRe: Big Honking PicturesussAnonymous26 Feb '03 - 16:26 
Dead | X| Confused | :confused:
GeneralRe: Big Honking PicturememberChopper18 Feb '03 - 6:52 
And I bet the line with Windows Task Bar is conceptually necessary.... Smile | :)

 
Ultimate all-in-one XP-Style UI multiplatform solution: Tooltips, XP Menus, Hyperlinks, Drawing Graphics and formatted documents, plus powerful binary resource reuse. All Free 100%, visit www.tooltips.net now. It can be used in VC++, C#, Java, VB, Delphi, Borland C++, Borland C++ Builder, as well as any COM-compatible platform.
GeneralRe: Big Honking PicturememberClaudius Mokler19 Feb '03 - 1:36 
Yeah, pressing the "Print" key is that much cooler than pressing "Alt" + "Print" keys together ...
GeneralRe: Big Honking PicturememberLars Wadefalk26 Feb '03 - 1:22 
Dead | X|
If he WOULD have pressed the "Print" key only, he would have got the entire screen in the dump (which he obviously didn't).
I can't see what's wrong in doing a sufficiently large application dump in the article.
 
It gives you a better idea of what everything is all about...don't you think?

 
Lars Wadefalk
Siemens Laser Analytics

GeneralRe: Big Honking PicturememberClaudius Mokler27 Feb '03 - 0:18 
> If he WOULD have pressed the "Print" key only, he would have got the entire screen in the dump (which he obviously didn't).
He did so originally, but has updated his article since.
 
> I can't see what's wrong in doing a sufficiently large application dump in the article.
No? Who's interested in *your* computer's task bar and why should something that can be said with, say 640x480 pixels done so with a XGA or even UXGA image?
 


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

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