|
Thanks...appreciate it
|
|
|
|
|
You might have to do some digging around to find those old compilers.
'Lattice C' was the first C compiler I ever used. It was available for DOS and was used by NASA in the 1980s.
The first C++ compilers weren't really compilers. There were pre-compilers. They would convert the C++ code to C code, then you'd compile and link the C code it produced.
|
|
|
|
|
Google for 'turbo c++' There are lots of free downloads of the ancient Borland products, back to the days when the c++ standard was still evolving.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
I'm trying to find a 64-bit version of Turbo...none of them seem to work on my computer. (Compatbility problems...)
|
|
|
|
|
Turbo C++ 2.0 is still available on some websites to download.
But I am rather confused by this post. Why would you need the old compiler? and as for the unmanaged part, C++ modern compiler are unmanaged too. the CLI version of C++ is different. (just wondering)
|
|
|
|
|
The lower the version, the chanes of it working on any computer is increased.
|
|
|
|
|
It will/might work on computers of that era, but not on new computers.
You will need to have a DOS (16bit) virtual machine running. (have a look at dosbox)
Watched code never compiles.
|
|
|
|
|
Not true, most old compilers are designed for specific systems just the same. If you want a compiler that works anywhere then go for the GNU versions (gcc/g++) which need to be configured and built on the target system; of course this means you need a previous compiler to build it. You have not said which platform you are targeting so it's not easy to recommend anything else. However I would recommend any of the Express Editions[^] for Windows, gcc for Linux/Unix, and a straightjacket for Mac.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Rahul Rajat Singh wrote: Turbo C++ 2.0
Something tells me that wasn't the first C++ compiler...
|
|
|
|
|
Luc Pattyn wrote: that wasn't the first C++ compiler
No it isn't, but it compiles in standard C++. But your right on that part, who knows what was the very first native C++ compiler was...
|
|
|
|
|
Brandon T. H. wrote: I was wondering if any of you'll know any native compilers or compilers the use
the very, very first form/version of C++
The 'first' C++ compiler, CFront, actually produced C code as the output. Which might not be what you expect a compiler to do but which does fit the definition.
You can find source code for CFront. To compile CFront you will need some non-trivial knowledge of C and make files. You will also probably need to make modifications as C wasn't standarized at the time so the library APIs are likely different.
|
|
|
|
|
|
Big thanks
|
|
|
|
|
Would you do all this in a project? for CFront?
|
|
|
|
|
I am loading an extension dll from my mfc client application, when click on the menu first time the dll dialog is being loade and after i exit or close the dialog, and again clicking on the menu to load again it's giving error that "A required resource was unavailable". what could be the problem please help me to resolve this
[code]
void CTestRevApp ::On3DView()
{
typedef VOID (*MYPROC)(CString);
MYPROC ProcAdd;
BOOL fRunTimeLinkSuccess = FALSE;
hinstLib = LoadLibrary(L"C:\\Documents and Settings\\sdh\\My Documents\\REVOLUTIONPROJ_DB\\DllDialog\\package\\DllTest\\Release\\dlltest.dll");
if( hinstLib == NULL)
FreeLibrary(hinstLib);
ProcAdd = (MYPROC)GetProcAddress(hinstLib, "runAppli");
ProcAdd(NULL);
if(ProcAdd == NULL)
{
AfxMessageBox(L"Unable to get pointer to function runAppi()");
FreeLibrary(hinstLib);
hinstLib = NULL;
return;
}
return;
}
[/code]
|
|
|
|
|
Your code looks a little bit mixed up.
Try it this way. It should solve your problem:
CTestRevApp::CTestRevApp()
{
hinstLib = NULL;
}
CTestRevApp::~CTestRevApp()
{
if (hinstLib != NULL)
FreeLibrary(hinstLib);
}
void CTestRevApp::On3DView()
{
typedef VOID (*MYPROC)(CString);
MYPROC ProcAdd;
if (hinstLib == NULL)
{
hinstLib = LoadLibrary(L"C:\\Documents and Settings\\sdh\\My Documents\\REVOLUTIONPROJ_DB\\DllDialog\\package\\DllTest\\Release\\dlltest.dll");
if (hinstLib == NULL)
AfxMessageBox(L"Unable to load library");
}
if (hinstLib != NULL)
{
ProcAdd = (MYPROC)GetProcAddress(hinstLib, "runAppli");
if (ProcAdd == NULL)
AfxMessageBox(L"Unable to get pointer to function runAppi()");
else
ProcAdd(NULL);
}
}
|
|
|
|
|
It's not solving the problem. My Client application is still active when i am calling On3DView 2nd time, it's giving still error "A required resource was unavailable" and not laoding the dlg of the dll.
I have exactly copied your code it's still giving error.
|
|
|
|
|
The error is very probably in your DLL showing a dialog. Common sources are forgetting to release DCs and GDI objects.
|
|
|
|
|
how can i release them manually. Please help me
|
|
|
|
|
Do you have the source code? If not, you must contact the supplier of the DLL. If yes, you must check the code.
If the code uses GetDC() somewhere, ensure that ReleaseDC() is called when the CDC is no longer used.
|
|
|
|
|
I am releasing it in the ::OnDestroy() fucntion of the view
|
|
|
|
|
That's one place where you release a DC (in your app or the DLL?). If not in the DLL, you should concentrate on the DLL code. There may be multiple places in your code using DCs and GDI objects. If you miss any release call or forget to de-select GDI objcets out of context, the error may occcur.
I can't really help you without seeing the code. I can only guess.
Check this example code:
CDC *pDC = GetDC();
CPen NewPen(PS_SOLID, 0, m_Color);
CPen *pOldPen = pDC->SelectObject(&NewPen);
CFont *pOldFont = pDC->SelectObject(m_pMyFont);
...
pDC->SelectObject(pOldFont);
pDC->SelectObject(pOldPen);
ReleaseDC(pDC);
|
|
|
|
|
I am not able to delete the view it's crashing
delete m_pNewView;
It's crashing. how can I delete the view.????
|
|
|
|
|
I'm sorry, but without knowing your code, I can't really help. Also, is there a relation to the original question, or is it a new one? If it is a new one, you should open a new question.
Views are usually handled by the document class and the frame work. To close a view manually, the parent frame of the view must be closed.
|
|
|
|
|
this is my view class of the dll
[code]
// MyView.cpp : implementation file
//
#include "stdafx.h"
#include "DlgsViewDlg.h"
#include "MyView.h"
//////////////////////////////////////////////////////////////////////////
#include <windows.h> // Header File For Windows
#include <math.h> // Header File For Windows Math Library
#include <stdio.h> // Header File For Standard Input/Output
#include <stdarg.h> // Header File For Variable Argument Routines
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
//#include <afxcolordialog.h>
/////////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma comment (lib, "OpenGL32.lib")
#pragma comment (lib, "glu32.lib")
#define NOFPOINTSINARC 5
#define NSWEEP 60
#define DIB_HEADER_MARKER ((WORD) ('M' << 8) | 'B')
#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
/////////////////////////////////////////////////////////////////////////////
// CMyView
typedef enum state
{
NOMOVE = 0,
PAN ,
ZOOM,
ROTATE
} statemovement;
struct vec3{
float x, y, z;
};
GLfloat trans[3]; /* current translation */
GLfloat trans_axes[3];
GLfloat rot[3];
statemovement STATE;
GLfloat PI = 4 * atan(1.0);
////////////////////////
GLuint base; // Base Display List For The Font Set
GLfloat cnt1; // 1st Counter Used To Move Text & For Coloring
GLfloat cnt2; // 2nd Counter Used To Move Text & For Coloring
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
////////////////////////
double CMyView::left = -10.0f;
double CMyView::right = 10.0f;
double CMyView::top = -10.0f;
double CMyView::bottom = 10.0f;
double CMyView::znear = -100.0f;
double CMyView::zfar = 100.0f;
static float zoomFactor = 1.0f;
static bool colorChange=false;
static double iRed=1.0f;
static double iGreen=0.0f;
static double iBlue=0.0f;
IMPLEMENT_DYNCREATE(CMyView, CView)
CMyView::CMyView()
:object(0)
,startPoints(NULL)
,endPoints(NULL)
,arcs(NULL)
,pan(false)
,zoom(false)
,rotate(false)
,x(NULL)
,y(NULL)
,allX(NULL)
,allY(NULL)
,allZ(NULL)
,cx(0.0)
,cy(0.0)
,cz(0.0)
,isModel(false)
{
trans[0] = 0.0f;
trans[1] = 0.0f;
trans[2] = 0.0f;
rot[0] = 0.0f;
rot[1] = 0.0f;
rot[2] = 0.0f;
STATE = NOMOVE;
}
CMyView::~CMyView()
{
if(! m_points.IsEmpty()) {
POSITION pos = m_points.GetHeadPosition();
while(pos != NULL)
delete ((CMyPoint*) m_points.GetNext(pos));
};
if(x) {
delete [] x;
x=NULL;
}
if(y) {
delete [] y;
y=NULL;
}
if(allX) {
delete [] allX;
allX=NULL;
}
if(allY) {
delete [] allY;
allY=NULL;
}
if(allZ) {
delete [] allZ;
allZ=NULL;
}
if(startPoints)
{
delete [] startPoints;
startPoints=NULL;
}
if(endPoints)
{
delete [] endPoints;
endPoints=NULL;
}
if(arcs) {
delete [] arcs;
arcs=NULL;
}
}
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
// ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
ON_COMMAND(ID_UTILITY_LOADPROFILE, &CMyView::OnUtilityLoadprofile)
ON_COMMAND(ID_UTILITY_GENERATESURFACE, &CMyView::OnUtilityGeneratesurface)
ON_COMMAND(ID_UTILITY_DRAW1, &CMyView::OnUtilityDraw1)
ON_COMMAND(ID_UTILITY_DRAW3, &CMyView::OnUtilityDraw3)
ON_COMMAND(ID_UTILITY_SAVEASIMAGE, &CMyView::OnUtilitySaveasimage)
ON_COMMAND(ID_VIEW_WIREFRAME, &CMyView::OnViewWireframe)
ON_COMMAND(ID_VIEW_SHADE, &CMyView::OnViewShade)
ON_COMMAND(ID_VIEW_NORMAL, &CMyView::OnViewNormal)
ON_COMMAND(ID_VIEW_PAN, &CMyView::OnViewPan)
ON_COMMAND(ID_VIEW_ZOOM, &CMyView::OnViewZoom)
ON_COMMAND(ID_VIEW_ROTATE, &CMyView::OnViewRotate)
ON_COMMAND(ID_VIEW_TOPVIEW, &CMyView::OnViewTopview)
ON_COMMAND(ID_VIEW_FRONTVIEW, &CMyView::OnViewFrontview)
ON_COMMAND(ID_VIEW_SIDEVIEW, &CMyView::OnViewSideview)
ON_COMMAND(ID_VIEW_ISOMETRICVIEW, &CMyView::OnViewIsometricview)
ON_COMMAND(ID_VIEW_ISOMETRICVIEW32787, &CMyView::OnViewIsometricview32787)
ON_COMMAND(ID_VIEW_ISOMETRICVIEW32788, &CMyView::OnViewIsometricview32788)
ON_COMMAND(ID_VIEW_ISOMETRICVIEW32789, &CMyView::OnViewIsometricview32789)
ON_COMMAND(ID_VIEW_COLORMODEL, &CMyView::OnViewColormodel)
ON_COMMAND(ID_VIEW_FITTOSCREEN, &CMyView::OnViewFittoscreen)
ON_COMMAND(ID_HELP_MANUAL, &CMyView::OnHelpManual)
ON_COMMAND(ID_LOADPROFILE, &CMyView::OnLoadprofile)
ON_COMMAND(ID_GENERATESURFACE, &CMyView::OnGeneratesurface)
ON_COMMAND(ID_DRAWHALFSURFACE, &CMyView::OnDrawhalfsurface)
ON_COMMAND(ID_DRAWTHREEFOURTHSURFACE, &CMyView::OnDrawthreefourthsurface)
ON_COMMAND(ID_SAVEASIMAGE, &CMyView::OnSaveasimage)
ON_COMMAND(ID_WIREFRAME, &CMyView::OnWireframe)
ON_COMMAND(ID_SHADE, &CMyView::OnShade)
ON_COMMAND(ID_NORMAL, &CMyView::OnNormal)
ON_COMMAND(ID_PAN, &CMyView::OnPan)
ON_COMMAND(ID_ZOOM, &CMyView::OnZoom)
ON_COMMAND(ID_ROTATE, &CMyView::OnRotate)
ON_COMMAND(ID_TOP, &CMyView::OnTop)
ON_COMMAND(ID_FRONT, &CMyView::OnFront)
ON_COMMAND(ID_SIDE, &CMyView::OnSide)
ON_COMMAND(ID_ISOSOUTHWEST, &CMyView::OnIsosouthwest)
ON_COMMAND(ID_ISONORTHWEST, &CMyView::OnIsonorthwest)
ON_COMMAND(ID_ISOSOUTHEAST, &CMyView::OnIsosoutheast)
ON_COMMAND(ID_ISONORTHEAST, &CMyView::OnIsonortheast)
ON_COMMAND(ID_COLORMODEL, &CMyView::OnColormodel)
ON_COMMAND(ID_FITTOSCREEN, &CMyView::OnFittoscreen)
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_MOUSEWHEEL()
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_DESTROY()
END_MESSAGE_MAP()
GLvoid CMyView::BuildFont(GLvoid) // Build Our Bitmap Font
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping
base = glGenLists(96); // Storage For 96 Characters
font = CreateFont( -24, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
L"Courier New"); // Font Name
oldfont = (HFONT)SelectObject(pDC->m_hDC, font); // Selects The Font We Want
wglUseFontBitmaps(pDC->m_hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(pDC->m_hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
GLvoid CMyView::KillFont(GLvoid) // Delete The Font List
{
glDeleteLists(base, 96); // Delete All 96 Characters
}
GLvoid CMyView::glPrintX(const char *fmt, ...) // Custom GL "Print" Routine
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glRasterPos3f(5.0f, 0.0f, 0.0f);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
GLvoid CMyView::glPrintY(const char *fmt, ...) // Custom GL "Print" Routine
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glRasterPos3f(0.0f, 5.0f, 0.0f);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
GLvoid CMyView::glPrintZ(const char *fmt, ...) // Custom GL "Print" Routine
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There's No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glRasterPos3f(0.0f, 0.0f, 5.0f);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC,
::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
cs.dwExStyle = WS_EX_CLIENTEDGE;
return CView::PreCreateWindow(cs);
}
bool CMyView::CreateGLContext(CDC* pDC)
{
PIXELFORMATDESCRIPTOR pfd ;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.iLayerType = PFD_MAIN_PLANE;
int nPixelFormat = ChoosePixelFormat(pDC->m_hDC, &pfd);
if (nPixelFormat == 0) return false;
BOOL bResult = SetPixelFormat (pDC->m_hDC, nPixelFormat, &pfd);
if (!bResult) return false;
m_hrc = wglCreateContext(pDC->m_hDC);
if (!m_hrc) return false;
ReleaseDC(pDC);
return true;
}
void CMyView::drawAxes()
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
GLuint list= glGenLists(1);
glNewList(list, GL_COMPILE);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
glVertex3f(5.0f, 0.0f, 0.0f); // ending point of the
glEnd();
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
glVertex3f(0.0f, 5.0f, 0.0f); // ending point of the
glEnd();
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f); // origin of the line
glVertex3f(0.0f, 0.0f, 5.0f); // ending point of the
glEnd();
glEndList();
wglMakeCurrent(NULL,NULL);
axes = list;
ReleaseDC(pDC);
}
void CMyView::PrepareScene(CDC *pDC)
{
wglMakeCurrent(pDC->m_hDC, m_hrc);
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
drawAxes();
BuildFont();
wglMakeCurrent(NULL, NULL);
ReleaseDC(pDC);
}
void CMyView::DrawScene(CDC *pDC)
{
wglMakeCurrent(pDC->m_hDC, m_hrc);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (wd <= ht)
glOrtho(left, right, top*ht/wd, bottom*ht/wd, znear, zfar);
else
glOrtho(left*wd/ht, right*wd/ht, top, bottom, znear, zfar);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(trans[0], trans[1], trans[2]);
glRotatef(rot[0], 1.0f, 0.0f, 0.0f);
glRotatef(rot[1], 0.0f, 1.0f, 0.0f);
glRotatef(rot[2], 0.0f, 0.0f, 1.0f);
glTranslatef(cx,cy,cz);
glScalef(zoomFactor,zoomFactor,zoomFactor);
glTranslatef(-cx,-cy,-cz);
glCallList(object);
glCallList(axes);
glPrintX("X");
glPrintY("Y");
glPrintZ("Z");
glPopMatrix();
glFlush();
SwapBuffers(pDC->m_hDC);
wglMakeCurrent(NULL, NULL);
ReleaseDC(pDC);
}
void CMyView::Reshape(CDC *pDC, int w, int h)
{
wglMakeCurrent(pDC->m_hDC, m_hrc);
AR = (double)w/(double)h;
wd = w;
ht = h;
if (h==0) // Prevent A Divide By Zero By
{
h=1; // Making Height Equal One
}
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (wd <= ht)
glOrtho(left, right, top*ht/wd, bottom*ht/wd, znear, zfar);
else
glOrtho(left*wd/ht, right*wd/ht, top, bottom, znear, zfar);
Invalidate();
wglMakeCurrent(NULL, NULL);
ReleaseDC(pDC);
}
void CMyView::DestroyScene(CDC *pDC)
{
wglMakeCurrent(pDC->m_hDC, m_hrc);
//---------------------------------
//---------------------------------
wglMakeCurrent(NULL,NULL);
if(m_hrc)
{
wglDeleteContext(m_hrc);
m_hrc = NULL;
}
ReleaseDC(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
DrawScene(pDC);
ReleaseDC(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
newP = point;
// TODO: Add your message handler code here and/or call default
int dx = oldP.x - newP.x;
int dy = newP.y - oldP.y;
switch(STATE)
{
case PAN:
{
trans[0] -= dx;
trans[1] -= dy;
Invalidate();
}
break;
case ZOOM:
{
if(newP.y < oldP.y)
{
zoomFactor /= (0.75);
}
else
{
zoomFactor *= (0.75);
}
Invalidate();
}
break;
case ROTATE:
{
rot[0] += (dy * 180.0f) / 500.0f;
rot[1] -= (dx * 180.0f) / 500.0f;
#define clamp(x) x = x > 360.0f ? x-360.0f : x < -360.0f ? x+=360.0f : x
clamp(rot[0]);
clamp(rot[1]);
Invalidate();
}
break;
}
oldP = newP;
CView::OnMouseMove(nFlags, point);
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnUtilityLoadprofile()
{
// TODO: Add your command handler code here
OnLoadprofile();
}
void CMyView::OnUtilityGeneratesurface()
{
// TODO: Add your command handler code here
OnGeneratesurface();
}
void CMyView::OnUtilityDraw1()
{
// TODO: Add your command handler code here
OnDrawhalfsurface();
}
void CMyView::OnUtilityDraw3()
{
// TODO: Add your command handler code here
OnDrawthreefourthsurface();
}
void CMyView::OnUtilitySaveasimage()
{
// TODO: Add your command handler code here
OnSaveasimage();
}
void CMyView::OnViewWireframe()
{
// TODO: Add your command handler code here
OnWireframe();
}
void CMyView::OnViewShade()
{
// TODO: Add your command handler code here
OnShade();
}
void CMyView::OnViewNormal()
{
// TODO: Add your command handler code here
OnNormal();
}
void CMyView::OnViewPan()
{
// TODO: Add your command handler code here
if(STATE==NOMOVE)
STATE = PAN;
else
STATE = NOMOVE;
}
void CMyView::OnViewZoom()
{
// TODO: Add your command handler code here
if(STATE==NOMOVE)
STATE = ZOOM;
else
STATE = NOMOVE;
}
void CMyView::OnViewRotate()
{
// TODO: Add your command handler code here
if(STATE==NOMOVE)
STATE = ROTATE;
else
STATE = NOMOVE;
}
void CMyView::OnViewTopview()
{
// TODO: Add your command handler code here
OnTop();
}
void CMyView::OnViewFrontview()
{
// TODO: Add your command handler code here
OnFront();
}
void CMyView::OnViewSideview()
{
// TODO: Add your command handler code here
OnSide();
}
void CMyView::OnViewIsometricview()
{
// TODO: Add your command handler code here
OnIsosouthwest();
}
void CMyView::OnViewIsometricview32787()
{
// TODO: Add your command handler code here
OnIsonorthwest();
}
void CMyView::OnViewIsometricview32788()
{
// TODO: Add your command handler code here
OnIsosoutheast();
}
void CMyView::OnViewIsometricview32789()
{
// TODO: Add your command handler code here
OnIsonortheast();
}
void CMyView::OnViewColormodel()
{
// TODO: Add your command handler code here
OnColormodel();
}
void CMyView::OnViewFittoscreen()
{
// TODO: Add your command handler code here
OnFittoscreen();
}
void CMyView::OnHelpManual()
{
// TODO: Add your command handler code here
HINSTANCE hInst = ShellExecute(0,
L"open", // Operation to perform
L"RevolutionProject Documentation.docx", // Application name
0, // Additional parameters
0, // Default directory
SW_SHOW);
}
////////////////////TOOLBAR/////////////////////
void CMyView::OnLoadprofile()
{
// TODO: Add your command handler code here
if(x) {
delete [] x;
x=NULL;
}
if(y) {
delete [] y;
y=NULL;
}
if(allX)
{
delete [] allX;
allX=NULL;
}
if(allY)
{
delete [] allY;
allY=NULL;
}
if(allZ)
{
delete [] allZ;
allZ=NULL;
}
// TODO: Add your command handler code here
CString filename;
CFileDialog file( true,
NULL,
NULL,
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
NULL,
NULL,
0
);
if(file.DoModal()==IDOK) {
filename = file.GetFileName();
}
if(filename.IsEmpty())
return;
loadProfile(filename);
domainSetUpForProfile();
drawLines();
drawArcs();
drawProfile();
isModel=true;
}
void CMyView::domainSetUpForProfile()
{
zoomFactor = 1.0f;
trans[0] = 0.0f;
trans[1] = 0.0f;
trans[2] = 0.0f;
rot[0] = 0.0f;
rot[1] = 0.0f;
rot[2] = 0.0f;
x = new double[(count1*2)+(count2*NOFPOINTSINARC)];
y = new double[(count1*2)+(count2*NOFPOINTSINARC)];
int cnt1=0;
for(int i=0; i<count1; i++)
="" {
="" x[cnt1]="startPoints[i].x;
" x[cnt1+1]="endPoints[i].x;
" y[cnt1]="startPoints[i].y;
" y[cnt1+1]="endPoints[i].y;
" cnt1+="2;
" }
="" int="" cnt2="0;
" for(int="" i="0;" i<count2;="" p="0;
" j="0;" j<nofpointsinarc;="" j++)="" x[cnt1+cnt2]="arcs[i].vertices[p];
" y[cnt1+cnt2]="arcs[i].vertices[p+1];
" cnt2++;
="" p+="3;
" selectionsort(x,(count1*2="" +="" count2="" *="" nofpointsinarc));
="" selectionsort(y,(count1*2="" middlex="((x[(count1*2)+(count2*NOFPOINTSINARC)-1]-x[0])/2.0)" x[0];
="" middley="((y[(count1*2)+(count2*NOFPOINTSINARC)-1]-y[0])/2.0)" y[0];
="" cx="middleX;
" cy="middleY;
" cz="0.0;
" double="" dom;
="" *domainprof="new" double[4];
="" dom1="x[(count1*2)+(count2*NOFPOINTSINARC)-1]" -="" dom2="y[(count1*2)+(count2*NOFPOINTSINARC)-1]" if(dom1="">dom2)
dom = dom1;
else
dom=dom2;
dom=dom/2;
domainProf[0] = middleX-dom;
domainProf[1] = middleX+dom;
double wid = domainProf[1] - domainProf[0];
domainProf[2] = middleY-dom;
domainProf[3] = middleY+dom;
double hei = domainProf[3] - domainProf[2];
double aspect = wid/hei;
if(aspect>1) {
left = domainProf[0]/aspect;
right = domainProf[1]/aspect;
top = domainProf[2];
bottom = domainProf[3];
}
else
{
left = domainProf[0];
right = domainProf[1];
top = domainProf[2]*aspect;
bottom = domainProf[3]*aspect;
}
trans[0] = left + ((wid)/2);
znear = - (wid*1000.0f);
zfar = (wid*1000.0f);
delete [] domainProf;
domainProf=NULL;
}
void CMyView::drawLines()
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
GLuint list= glGenLists(1);
glNewList(list, GL_COMPILE);
for(int i=0; i<count1; i++)="" {
="" glbegin(gl_lines);
="" glvertex2f(startpoints[i].x,="" startpoints[i].y);
="" glvertex2f(endpoints[i].x,="" endpoints[i].y);
="" glend();
="" }
="" glendlist();
="" object1="list;
" wglmakecurrent(null,null);
="" releasedc(pdc);
}
void="" cmyview::drawarcs()="" {
="" cdc*="" pdc="GetDC();
" wglmakecurrent(pdc-="">m_hDC, m_hrc);
GLuint list= glGenLists(1);
glNewList(list, GL_COMPILE);
for(int i=0; i<count2; i++)="" {
="" glenableclientstate(gl_vertex_array);
="" glvertexpointer(3,="" gl_float,="" 0,="" arcs[i].vertices="" );
="" gldrawarrays(gl_line_strip,0,nofpointsinarc);
="" }
="" glendlist();
="" object2="list;
" wglmakecurrent(null,null);=""
="" releasedc(pdc);
}
void="" cmyview::drawprofile()
{
="" object="0;
" cdc*="" pdc="GetDC();
" wglmakecurrent(pdc-="">m_hDC, m_hrc);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glColor3f(1.0f,1.0f,1.0f);
Invalidate();
GLuint list= glGenLists(1);
glNewList(list, GL_COMPILE);
if(object1)
glCallList(object1);
if(object2)
glCallList(object2);
glEndList();
object = list;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnGeneratesurface()
{
// TODO: Add your command handler code here
//m_wndStatusBar.SetPaneText(0,L"Drawing the surface the selected profile...");
//I have x and y points;
//count1 = numberof points
//theta = 0 to 360 degs.
//nsweep = number of sweeps. 360/nsweep = each angle;
nsweep=NSWEEP;
//no of profiles = nsweep + 1...
//each profile will have count1 no of lines...so count1 startpoints and count1 endPoints...
//so...total startPoints and endPoints for (nsweep+1) profiles = (nsweep+1) * count1...
POINT3D *totalStartPoints, *totalEndPoints;
POINT3D ***totalArcPoints;
totalStartPoints = new POINT3D[(nsweep+1)*count1];
totalEndPoints = new POINT3D[(nsweep+1)*count1];
totalArcPoints = new POINT3D**[(nsweep+1)];
allX = new double[(2*(nsweep+1)*count1) +((nsweep+1)*(count2)*NOFPOINTSINARC)];
allY = new double[(2*(nsweep+1)*count1) +((nsweep+1)*count2*NOFPOINTSINARC)];
allZ = new double[(2*(nsweep+1)*count1) +((nsweep+1)*count2*NOFPOINTSINARC)];
int cnt1=0;
int m=0;
v =0;
double theta, inter;
inter = (360/nsweep) * (PI/180.00);
theta = 0;
int i=0;
while(i<(nsweep+1))
{
totalArcPoints[i] = new POINT3D*[count2];
int j=0;
while(j<count1)
{
="" totalstartpoints[cnt1].x="startPoints[j].x;
" totalstartpoints[cnt1].y="startPoints[j].y" *="" cos(theta)="" -="" startpoints[j].z="" sin(theta);
="" totalstartpoints[cnt1].z="startPoints[j].y" sin(theta)="" +="" cos(theta);
="" totalendpoints[cnt1].x="endPoints[j].x;
" totalendpoints[cnt1].y="endPoints[j].y" endpoints[j].z="" totalendpoints[cnt1].z="endPoints[j].y" allx[v]="totalStartPoints[cnt1].x;"
="" allx[v+1]="totalEndPoints[cnt1].x;
" ally[v]="totalStartPoints[cnt1].y;
" ally[v+1]="totalEndPoints[cnt1].y;
" allz[v]="totalStartPoints[cnt1].z;
" allz[v+1]="totalEndPoints[cnt1].z;
" cnt1++;
="" v="v" 2;
="" j++;
="" }
="" int="" k="0;
" while(k<count2)
="" m="0;
" totalarcpoints[i][k]="new" point3d[nofpointsinarc];
="" p="0;
" while(p<nofpointsinarc)
="" totalarcpoints[i][k][p].x="arcs[k].vertices[m];
" totalarcpoints[i][k][p].y="arcs[k].vertices[m+1]" arcs[k].vertices[m+2]="" ;
="" totalarcpoints[i][k][p].z="arcs[k].vertices[m+1]" 1;
="" p++;
="" }
="" k++;
="" theta="theta" inter;
="" i++;
="" cnt1="0;
" cdc*="" pdc="GetDC();
" wglmakecurrent(pdc-="">m_hDC, m_hrc);
GLuint list= glGenLists(1);
glNewList(list, GL_COMPILE);
for(int i=0; i<nsweep; i++)
="" {
="" for(int="" j="0;" j<count1;="" j++)="" {
="" point3d="" vec1,="" vec2,="" vec3,="" vec4,="" vec5,="" vec6,="" vec7,="" vec8;
="" glfloat="" *normal1,="" *normal2,="" *normal3,="" *normal4;
="" normal1="new" glfloat[3];
="" normal2="new" normal3="new" normal4="new" *v0,="" *v1,="" *v2,="" *v3;
=""
="" v0="new" v1="new" v2="new" v3="new" v0[0]="totalStartPoints[cnt1].x;
" v0[1]="totalStartPoints[cnt1].y;
" v0[2]="totalStartPoints[cnt1].z;
" v1[0]="totalEndPoints[cnt1].x;
" v1[1]="totalEndPoints[cnt1].y;
" v1[2]="totalEndPoints[cnt1].z;
" v2[0]="totalEndPoints[cnt1+count1].x;
" v2[1]="totalEndPoints[cnt1+count1].y;
" v2[2]="totalEndPoints[cnt1+count1].z;
" v3[0]="totalStartPoints[cnt1+count1].x;
" v3[1]="totalStartPoints[cnt1+count1].y;
" v3[2]="totalStartPoints[cnt1+count1].z;
" vec1.x="v1[0]" -="" v0[0];
="" vec1.y="v1[1]" v0[1];
="" vec1.z="v1[2]" v0[2];
="" vec2.x="v3[0]" vec2.y="v3[1]" vec2.z="v3[2]" normal1[0]="((vec1.y" *="" vec2.z)-(vec1.z="" vec2.y));
="" normal1[1]="((vec1.z" vec2.x)-(vec1.x="" vec2.z));
="" normal1[2]="((vec1.x" vec2.y)-(vec1.y="" vec2.x));
="" len="sqrt((normal1[0]*normal1[0])" +="" (normal1[1]*normal1[1])="" (normal1[2]*normal1[2]));
="" =="" len;
="" len;
="" normal2
="" vec3.x="v1[0]" vec3.y="v1[1]" vec3.z="v1[2]" vec4.x="v2[0]" v1[0];
="" vec4.y="v2[1]" v1[1];
="" vec4.z="v2[2]" v1[2];
="" normal2[0]="((vec3.y" vec4.z)-(vec3.z="" vec4.y));
="" normal2[1]="((vec3.z" vec4.x)-(vec3.x="" vec4.z));
="" normal2[2]="((vec3.x" vec4.y)-(vec3.y="" vec4.x));
="" (normal2[1]*normal2[1])="" (normal2[2]*normal2[2]));
="" normal3
="" vec5.x="v2[0]" vec5.y="v2[1]" vec5.z="v2[2]" vec6.x="v3[0]" v2[0];
="" vec6.y="v3[1]" v2[1];
="" vec6.z="v3[2]" v2[2];
="" normal3[0]="((vec5.y" vec6.z)-(vec5.z="" vec6.y));
="" normal3[1]="((vec5.z" vec6.x)-(vec5.x="" vec6.z));
="" normal3[2]="((vec5.x" vec6.y)-(vec5.y="" vec6.x));
="" (normal3[1]*normal3[1])="" (normal3[2]*normal3[2]));
="" vec7.x="v3[0]" vec7.y="v3[1]" vec7.z="v3[2]" vec8.x="v3[0]" vec8.y="v3[1]" vec8.z="v3[2]" normal4[0]="((vec7.y" vec8.z)-(vec7.z="" vec8.y));
="" normal4[1]="((vec7.z" vec8.x)-(vec7.x="" vec8.z));
="" normal4[2]="((vec7.x" vec8.y)-(vec7.y="" vec8.x));
="" (normal4[1]*normal4[1])="" (normal4[2]*normal4[2]));
=""
="" glbegin(gl_quads);="" glnormal3f(normal1[0],normal1[1],normal1[2]);
="" glvertex3fv(v0);="" glnormal3f(normal2[0],normal2[1],normal2[2]);
="" glvertex3fv(v1);
="" glnormal3f(normal3[0],normal3[1],normal3[2]);
="" glvertex3fv(v2);
="" glnormal3f(normal4[0],normal4[1],normal4[2]);
="" glvertex3fv(v3);
="" glend();
="" delete="" []="" v0;
="" v1;
="" v2;
="" v3;
="" normal1;
="" normal2;
="" normal3;
="" normal4;
="" cnt1++;
="" }
="" j<count2;="" p="0;" p<nofpointsinarc-1;="" p++)="" glfloat[3];
="" }
="" selectionsort(allx,v);
="" selectionsort(ally,v);
="" selectionsort(allz,v);
="" glendlist();
="" object="list;
" onfittoscreen();
="" wglmakecurrent(null,null);="" releasedc(pdc);
="" totalstartpoints;
="" totalstartpoints="NULL;
" totalendpoints;
="" totalendpoints="NULL;
" totalarcpoints;
="" totalarcpoints="NULL;
"
}
void="" cmyview::ondrawhalfsurface()
{
="" todo:="" add="" your="" command="" handler="" code="" here
="" pframe-="">m_wndStatusBar.SetPaneText(0,L"Drawing the surface the selected profile...");
//I have x and y points;
//count1 = numberof points
//theta = 0 to 360 degs.
//nsweep = number of sweeps. 360/nsweep = each angle;
int nsweep=NSWEEP;
//no of profiles = nsweep + 1...
//each profile will have count1 no of lines...so count1 startpoints and count1 endPoints...
//so...total startPoints and endPoints for (nsweep+1) profiles = (nsweep+1) * count1...
POINT3D *totalStartPoints, *totalEndPoints;
POINT3D ***totalArcPoints;
totalStartPoints = new POINT3D[(nsweep+1)*count1];
totalEndPoints = new POINT3D[(nsweep+1)*count1];
totalArcPoints = new POINT3D**[(nsweep+1)];
allX = new double[(2*(nsweep+1)*count1) +((nsweep+1)*(count2)*NOFPOINTSINARC)];
allY = new double[(2*(nsweep+1)*count1) +((nsweep+1)*count2*NOFPOINTSINARC)];
allZ = new double[(2*(nsweep+1)*count1) +((nsweep+1)*count2*NOFPOINTSINARC)];
int cnt1=0;
int m=0;
v = 0;
double theta, inter;
inter = (180/nsweep) * (PI/180.00);
theta = 0;
for(int i=0; i<(nsweep+1); i++)
{
totalArcPoints[i] = new POINT3D*[count2];
for(int j=0; j<count1; j++)
="" {
="" totalstartpoints[cnt1].x="startPoints[j].x;
" totalstartpoints[cnt1].y="startPoints[j].y" *="" cos(theta)="" -="" startpoints[j].z="" sin(theta);
="" totalstartpoints[cnt1].z="startPoints[j].y" sin(theta)="" +="" cos(theta);
="" totalendpoints[cnt1].x="endPoints[j].x;
" totalendpoints[cnt1].y="endPoints[j].y" endpoints[j].z="" totalendpoints[cnt1].z="endPoints[j].y" allx[v]="totalStartPoints[cnt1].x;"
="" allx[v+1]="totalEndPoints[cnt1].x;
" ally[v]="totalStartPoints[cnt1].y;
" ally[v+1]="totalEndPoints[cnt1].y;
" allz[v]="totalStartPoints[cnt1].z;
" allz[v+1]="totalEndPoints[cnt1].z;
" cnt1++;
="" v="v" 2;
="" }
="" for(int="" k="0;" k<count2;="" k++)
="" m="0;
" totalarcpoints[i][k]="new" point3d[nofpointsinarc];
="" p="0;" p<nofpointsinarc;="" p++)
="" totalarcpoints[i][k][p].x="arcs[k].vertices[m];
" totalarcpoints[i][k][p].y="arcs[k].vertices[m+1]" arcs[k].vertices[m+2]="" ;
="" totalarcpoints[i][k][p].z="arcs[k].vertices[m+1]" 1;
="" }
="" theta="theta" inter;
="" cnt1="0;
" cdc*="" pdc="GetDC();
" wglmakecurrent(pdc-="">m_hDC, m_hrc);
GLuint list= glGenLists(1);
glNewList(list, GL_COMPILE);
for(int i=0; i<nsweep; i++)
="" {
="" for(int="" j="0;" j<count1;="" j++)="" point3d="" vec1,="" vec2,="" vec3,="" vec4,="" vec5,="" vec6,="" vec7,="" vec8;
="" glfloat="" *normal1,="" *normal2,="" *normal3,="" *normal4;
="" normal1="new" glfloat[3];
="" normal2="new" normal3="new" normal4="new" *v0,="" *v1,="" *v2,="" *v3;
="" v0="new" v1="new" v2="new" v3="new"
="" v0[0]="totalStartPoints[cnt1].x;
" v0[1]="totalStartPoints[cnt1].y;
" v0[2]="totalStartPoints[cnt1].z;
" v1[0]="totalEndPoints[cnt1].x;
" v1[1]="totalEndPoints[cnt1].y;
" v1[2]="totalEndPoints[cnt1].z;
" v2[0]="totalEndPoints[cnt1+count1].x;
" v2[1]="totalEndPoints[cnt1+count1].y;
" v2[2]="totalEndPoints[cnt1+count1].z;
" v3[0]="totalStartPoints[cnt1+count1].x;
" v3[1]="totalStartPoints[cnt1+count1].y;
" v3[2]="totalStartPoints[cnt1+count1].z;
" vec1.x="v1[0]" -="" v0[0];
="" vec1.y="v1[1]" v0[1];
="" vec1.z="v1[2]" v0[2];
="" vec2.x="v3[0]" vec2.y="v3[1]" vec2.z="v3[2]" normal1[0]="((vec1.y" *="" vec2.z)-(vec1.z="" vec2.y));
="" normal1[1]="((vec1.z" vec2.x)-(vec1.x="" vec2.z));
="" normal1[2]="((vec1.x" vec2.y)-(vec1.y="" vec2.x));
="" len="sqrt((normal1[0]*normal1[0])" +="" (normal1[1]*normal1[1])="" (normal1[2]*normal1[2]));
="" =="" len;
="" len;
="" normal2
="" vec3.x="v1[0]" vec3.y="v1[1]" vec3.z="v1[2]" vec4.x="v2[0]" v1[0];
="" vec4.y="v2[1]" v1[1];
="" vec4.z="v2[2]" v1[2];
="" normal2[0]="((vec3.y" vec4.z)-(vec3.z="" vec4.y));
="" normal2[1]="((vec3.z" vec4.x)-(vec3.x="" vec4.z));
="" normal2[2]="((vec3.x" vec4.y)-(vec3.y="" vec4.x));
="" (normal2[1]*normal2[1])="" (normal2[2]*normal2[2]));
="" normal3
="" vec5.x="v2[0]" vec5.y="v2[1]" vec5.z="v2[2]" vec6.x="v3[0]" v2[0];
="" vec6.y="v3[1]" v2[1];
="" vec6.z="v3[2]" v2[2];
="" normal3[0]="((vec5.y" vec6.z)-(vec5.z="" vec6.y));
="" normal3[1]="((vec5.z" vec6.x)-(vec5.x="" vec6.z));
="" normal3[2]="((vec5.x" vec6.y)-(vec5.y="" vec6.x));
="" (normal3[1]*normal3[1])="" (normal3[2]*normal3[2]));
="" vec7.x="v3[0]" vec7.y="v3[1]" vec7.z="v3[2]" vec8.x="v3[0]" vec8.y="v3[1]" vec8.z="v3[2]" normal4[0]="((vec7.y" vec8.z)-(vec7.z="" vec8.y));
="" normal4[1]="((vec7.z" vec8.x)-(vec7.x="" vec8.z));
="" normal4[2]="((vec7.x" vec8.y)-(vec7.y="" vec8.x));
="" (normal4[1]*normal4[1])="" (normal4[2]*normal4[2]));
=""
="" glbegin(gl_quads);="" draw="" a="" cube="" with="" 6="" quads
="" glnormal3f(normal1[0],normal1[1],normal1[2]);
="" glvertex3fv(v0);="" front="" face
="" glnormal3f(normal2[0],normal2[1],normal2[2]);
="" glvertex3fv(v1);
="" glnormal3f(normal3[0],normal3[1],normal3[2]);
="" glvertex3fv(v2);
="" glnormal3f(normal4[0],normal4[1],normal4[2]);
="" glvertex3fv(v3);
="" glend();
="" delete="" []="" v0;
="" v1;
="" v2;
="" v3;
="" cnt1++;
="" }
="" j<count2;="" {
="" p="0;" p<nofpointsinarc-1;="" p++)="" glfloat[3];
="" }
="" selectionsort(allx,v);
="" selectionsort(ally,v);
="" selectionsort(allz,v);
="" glendlist();
="" object="list;
" onfittoscreen();
="" wglmakecurrent(null,null);
="" releasedc(pdc);
="" totalstartpoints;
="" totalstartpoints="NULL;
" totalendpoints;
="" totalendpoints="NULL;
" totalarcpoints;
="" totalarcpoints="NULL;
}
void" cmyview::ondrawthreefourthsurface()
{
="" todo:="" add="" your="" command="" handler="" code="" here
="" pframe-="">m_wndStatusBar.SetPaneText(0,L"Drawing the surface the selected profile...");
//I have x and y points;
//count1 = numberof points
//theta = 0 to 360 degs.
//nsweep = number of sweeps. 360/nsweep = each angle;
int nsweep=NSWEEP;
//no of profiles = nsweep + 1...
//each profile will have count1 no of lines...so count1 startpoints and count1 endPoints...
//so...total startPoints and endPoints for (nsweep+1) profiles = (nsweep+1) * count1...
POINT3D *totalStartPoints, *totalEndPoints;
POINT3D ***totalArcPoints;
totalStartPoints = new POINT3D[(nsweep+1)*count1];
totalEndPoints = new POINT3D[(nsweep+1)*count1];
totalArcPoints = new POINT3D**[(nsweep+1)];
allX = new double[(2*(nsweep+1)*count1) +((nsweep+1)*(count2)*NOFPOINTSINARC)];
allY = new double[(2*(nsweep+1)*count1) +((nsweep+1)*count2*NOFPOINTSINARC)];
allZ = new double[(2*(nsweep+1)*count1) +((nsweep+1)*count2*NOFPOINTSINARC)];
int cnt1=0;
int m=0;
v = 0;
double theta, inter;
inter = (270/nsweep) * (PI/180.00);
theta = 0;
for(int i=0; i<(nsweep+1); i++)
{
totalArcPoints[i] = new POINT3D*[count2];
for(int j=0; j<count1; j++)
="" {
="" totalstartpoints[cnt1].x="startPoints[j].x;
" totalstartpoints[cnt1].y="startPoints[j].y" *="" cos(theta)="" -="" startpoints[j].z="" sin(theta);
="" totalstartpoints[cnt1].z="startPoints[j].y" sin(theta)="" +="" cos(theta);
="" totalendpoints[cnt1].x="endPoints[j].x;
" totalendpoints[cnt1].y="endPoints[j].y" endpoints[j].z="" totalendpoints[cnt1].z="endPoints[j].y" cos(theta);
="" allx[v]="totalStartPoints[cnt1].x;"
="" allx[v+1]="totalEndPoints[cnt1].x;
" ally[v]="totalStartPoints[cnt1].y;
" ally[v+1]="totalEndPoints[cnt1].y;
" allz[v]="totalStartPoints[cnt1].z;
" allz[v+1]="totalEndPoints[cnt1].z;
" cnt1++;
="" v="v" 2;
="" }
="" for(int="" k="0;" k<count2;="" k++)
="" m="0;
" totalarcpoints[i][k]="new" point3d[nofpointsinarc];
="" p="0;" p<nofpointsinarc;="" p++)
="" totalarcpoints[i][k][p].x="arcs[k].vertices[m];
" totalarcpoints[i][k][p].y="arcs[k].vertices[m+1]" arcs[k].vertices[m+2]="" ;
="" totalarcpoints[i][k][p].z="arcs[k].vertices[m+1]" 1;
="" }
="" theta="theta" inter;
="" cnt1="0;
" cdc*="" pdc="GetDC();
" wglmakecurrent(pdc-="">m_hDC, m_hrc);
GLuint list= glGenLists(1);
glNewList(list, GL_COMPILE);
for(int i=0; i<nsweep; i++)
="" {
="" for(int="" j="0;" j<count1;="" j++)="" point3d="" vec1,="" vec2,="" vec3,="" vec4,="" vec5,="" vec6,="" vec7,="" vec8;
="" glfloat="" *normal1,="" *normal2,="" *normal3,="" *normal4;
="" normal1="new" glfloat[3];
="" normal2="new" normal3="new" normal4="new" *v0,="" *v1,="" *v2,="" *v3;
="" v0="new" v1="new" v2="new" v3="new"
="" v0[0]="totalStartPoints[cnt1].x;
" v0[1]="totalStartPoints[cnt1].y;
" v0[2]="totalStartPoints[cnt1].z;
" v1[0]="totalEndPoints[cnt1].x;
" v1[1]="totalEndPoints[cnt1].y;
" v1[2]="totalEndPoints[cnt1].z;
" v2[0]="totalEndPoints[cnt1+count1].x;
" v2[1]="totalEndPoints[cnt1+count1].y;
" v2[2]="totalEndPoints[cnt1+count1].z;
" v3[0]="totalStartPoints[cnt1+count1].x;
" v3[1]="totalStartPoints[cnt1+count1].y;
" v3[2]="totalStartPoints[cnt1+count1].z;
" vec1.x="v1[0]" -="" v0[0];
="" vec1.y="v1[1]" v0[1];
="" vec1.z="v1[2]" v0[2];
="" vec2.x="v3[0]" vec2.y="v3[1]" vec2.z="v3[2]" normal1[0]="((vec1.y" *="" vec2.z)-(vec1.z="" vec2.y));
="" normal1[1]="((vec1.z" vec2.x)-(vec1.x="" vec2.z));
="" normal1[2]="((vec1.x" vec2.y)-(vec1.y="" vec2.x));
="" len="sqrt((normal1[0]*normal1[0])" +="" (normal1[1]*normal1[1])="" (normal1[2]*normal1[2]));
="" =="" len;
="" len;
="" normal2
="" vec3.x="v1[0]" vec3.y="v1[1]" vec3.z="v1[2]" vec4.x="v2[0]" v1[0];
="" vec4.y="v2[1]" v1[1];
="" vec4.z="v2[2]" v1[2];
="" normal2[0]="((vec3.y" vec4.z)-(vec3.z="" vec4.y));
="" normal2[1]="((vec3.z" vec4.x)-(vec3.x="" vec4.z));
="" normal2[2]="((vec3.x" vec4.y)-(vec3.y="" vec4.x));
="" (normal2[1]*normal2[1])="" (normal2[2]*normal2[2]));
="" normal3
="" vec5.x="v2[0]" vec5.y="v2[1]" vec5.z="v2[2]" vec6.x="v3[0]" v2[0];
="" vec6.y="v3[1]" v2[1];
="" vec6.z="v3[2]" v2[2];
="" normal3[0]="((vec5.y" vec6.z)-(vec5.z="" vec6.y));
="" normal3[1]="((vec5.z" vec6.x)-(vec5.x="" vec6.z));
="" normal3[2]="((vec5.x" vec6.y)-(vec5.y="" vec6.x));
="" (normal3[1]*normal3[1])="" (normal3[2]*normal3[2]));
="" vec7.x="v3[0]" vec7.y="v3[1]" vec7.z="v3[2]" vec8.x="v3[0]" vec8.y="v3[1]" vec8.z="v3[2]" normal4[0]="((vec7.y" vec8.z)-(vec7.z="" vec8.y));
="" normal4[1]="((vec7.z" vec8.x)-(vec7.x="" vec8.z));
="" normal4[2]="((vec7.x" vec8.y)-(vec7.y="" vec8.x));
="" (normal4[1]*normal4[1])="" (normal4[2]*normal4[2]));
=""
="" glbegin(gl_quads);="" draw="" a="" cube="" with="" 6="" quads
="" glnormal3f(normal1[0],normal1[1],normal1[2]);
="" glvertex3fv(v0);="" front="" face
="" glnormal3f(normal2[0],normal2[1],normal2[2]);
="" glvertex3fv(v1);
="" glnormal3f(normal3[0],normal3[1],normal3[2]);
="" glvertex3fv(v2);
="" glnormal3f(normal4[0],normal4[1],normal4[2]);
="" glvertex3fv(v3);
="" glend();
="" delete="" []="" v0;
="" v1;
="" v2;
="" v3;
="" cnt1++;
="" }
="" j<count2;="" {
="" p="0;" p<nofpointsinarc-1;="" p++)="" glfloat[3];
="" }
="" selectionsort(allx,v);
="" selectionsort(ally,v);
="" selectionsort(allz,v);
="" glendlist();
="" object="list;
" onfittoscreen();
="" wglmakecurrent(null,null);
="" releasedc(pdc);
="" totalstartpoints;
="" totalstartpoints="NULL;
" totalendpoints;
="" totalendpoints="NULL;
" totalarcpoints;
="" totalarcpoints="NULL;
}
void" cmyview::onsaveasimage()
{
="" todo:="" add="" your="" command="" handler="" code="" here
="" m_wndstatusbar.setpanetext(0,l"save="" as="" image");
="" hbitmap="" cwnd="" *wnd="AfxGetMainWnd();
" rect="" rectclient;="" point="" pt1,="" pt2;="" get="" client="" dimensions="" wnd-="">GetClientRect(&rectClient); // convert client coords to screen coords
pt1.x = rectClient.left;
pt1.y = rectClient.top;
pt2.x = rectClient.right;
pt2.y = rectClient.bottom;
wnd->ClientToScreen(&pt1);
wnd->ClientToScreen(&pt2);
rectClient.left = pt1.x;
rectClient.top = pt1.y;
rectClient.right = pt2.x;
rectClient.bottom = pt2.y;
// get the bitmap of the client area by calling
// CopyScreenToBitmap and passing it the client rect
BOOL ret = CopyScreenToBitmap(&rectClient);
}
BOOL CMyView::CopyScreenToBitmap(const CRect& rect)
{
CImage image;
// detach and destroy the old bitmap if any attached
image.Destroy();
// create a screen and a memory device context
HDC hDCScreen = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
HDC hDCMem = ::CreateCompatibleDC(hDCScreen);
// create a compatible bitmap and select it in the memory DC
HBITMAP hBitmap =
::CreateCompatibleBitmap(hDCScreen, rect.Width(), rect.Height());
HBITMAP hBmpOld = (HBITMAP)::SelectObject(hDCMem, hBitmap);
// bit-blit from screen to memory device context
// note: CAPTUREBLT flag is required to capture layered windows
DWORD dwRop = SRCCOPY | CAPTUREBLT;
BOOL bRet = ::BitBlt(hDCMem, 0, 0, rect.Width(), rect.Height(),
hDCScreen, rect.left, rect.top, dwRop);
// attach bitmap handle to this object
// Attach(hBitmap);
image.Attach(hBitmap);
CFile f;
this->UpdateData();
LPCTSTR strFilter = {L"JPG Files(*.jpg)|*.jpg |PNG Files(*.png)|*.png |All Files (*.*)|*.*||" };
CFileDialog FileDlg(FALSE, L".jpg", NULL, 0, strFilter);
if( FileDlg.DoModal() == IDOK )
{
f.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
}
else
return false;
f.Close();
image.Save(FileDlg.GetFileName());
// restore the memory DC and perform cleanup
::SelectObject(hDCMem, hBmpOld);
::DeleteDC(hDCMem);
::DeleteDC(hDCScreen);
// clean up
return bRet;
}
void CMyView::OnWireframe()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnShade()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
glMatrixMode(GL_MODELVIEW);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glEnable(GL_LIGHT3);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable(GL_NORMALIZE);
GLfloat ambientLight0[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight0[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat specularLight0[] = { 0.0f, 0.0f, 1.0f, 1.0f };
GLfloat emissionLight0[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat position0[] = {0.0f,0.0f,allZ[0]-1000.0f,1.0f};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
glLightfv(GL_LIGHT0, GL_EMISSION, emissionLight0);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
GLfloat ambientLight1[] = { 0.15f, 0.15f, 0.15f, 1.0f };
GLfloat diffuseLight1[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat specularLight1[] = { 0.0f, 0.0f, 1.0f, 1.0f };
GLfloat emissionLight1[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat position1[] = {0.0f,0.0f, allZ[v-1]+1000.0,1.0f};
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight1);
glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight1);
glLightfv(GL_LIGHT1, GL_EMISSION, emissionLight1);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
GLfloat ambientLight2[] = { 0.06f, 0.06f, 0.06f, 1.0f };
GLfloat diffuseLight2[] = { 0.07f, 0.07f, 0.07f, 1.0f };
GLfloat specularLight2[] = { 0.0f, 0.0f, 1.0f, 1.0f };
GLfloat emissionLight2[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat position2[] = {0.0f,0.0f,allZ[v-1]+10000.0f,1.0f};
glLightfv(GL_LIGHT2, GL_AMBIENT, ambientLight2);
glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuseLight2);
glLightfv(GL_LIGHT2, GL_SPECULAR, specularLight2);
glLightfv(GL_LIGHT2, GL_EMISSION, emissionLight2);
glLightfv(GL_LIGHT2, GL_POSITION, position2);
GLfloat ambientLight3[] = { 0.06f, 0.06f, 0.06f, 1.0f };
GLfloat diffuseLight3[] = { 0.07f, 0.07f, 0.07f, 1.0f };
GLfloat specularLight3[] = { 0.0f, 0.0f, 1.0f, 1.0f };
GLfloat emissionLight3[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat position3[] = {0.0f,0.0f, allZ[0]-10000.0,1.0f};
glLightfv(GL_LIGHT3, GL_AMBIENT, ambientLight3);
glLightfv(GL_LIGHT3, GL_DIFFUSE, diffuseLight3);
glLightfv(GL_LIGHT3, GL_SPECULAR, specularLight3);
glLightfv(GL_LIGHT3, GL_EMISSION, emissionLight3);
glLightfv(GL_LIGHT3, GL_POSITION, position3);
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnNormal()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
glColor3f(1.0,0.0,0.0);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnPan()
{
// TODO: Add your command handler code here
if(!pan)
pan = true;
else
pan = false;
}
void CMyView::OnZoom()
{
// TODO: Add your command handler code here
if(!zoom)
zoom = true;
else
zoom = false;
}
void CMyView::OnRotate()
{
// TODO: Add your command handler code here
if(!rotate)
rotate=true;
else
rotate=false;
}
void CMyView::OnTop()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
rot[0] = 0.0f;
rot[1] = 0.0f;
rot[2] = 0.0f;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnFront()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
rot[0] = -90.0f;
rot[1] = 0.0f;
rot[2] = -90.0f;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnSide()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
rot[0] = -90.0f;
rot[1] = 0.0f;
rot[2] = 0.0f;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnIsosouthwest()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
rot[0] = -45.0;
rot[1] = -45.0;
rot[2] = 0.0;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnIsonorthwest()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
rot[0] = 45.0;
rot[1] = -45.0;
rot[2] = 0.0;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnIsosoutheast()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
rot[0] = -135.0;
rot[1] = -135.0;
rot[2] = 0.0;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnIsonortheast()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
rot[0] = 135.0;
rot[1] = -135.0;
rot[2] = 0.0;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnColormodel()
{
// TODO: Add your command handler code here
COLORREF color;
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
{
color = dlg.GetColor();
}
iRed = GetRValue(color)/255.0f;
iBlue = GetBValue(color)/255.0f;
iGreen = GetGValue(color)/255.0f;
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
colorChange = true;
glColor3f(iRed,iGreen,iBlue);
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
}
void CMyView::OnFittoscreen()
{
// TODO: Add your command handler code here
if(!isModel)
return;
trans[0] = 0.0f;
trans[1] = 0.0f;
trans[2] = 0.0f;
zoomFactor = 1.0f;
// TODO: Add your command handler code here
if(allX!=NULL && allY!=NULL && allZ!=NULL) {
double midX = (allX[v-1]-allX[0])/2 + allX[0];
double midY = (allY[v-1]-allY[0])/2 + allY[0];
double midZ = (allZ[v-1]-allZ[0])/2 + allZ[0];
cx = midX;
cy = midY;
cz = midZ;
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
double dom;
double *domain = new double[4];
double dom1 = allX[v-1] - allX[0];
double dom2 = allY[v-1] - allY[0];
if(dom1>dom2)
dom = dom1;
else
dom = dom2;
dom = dom/4;
domain[0] = (allX[0])-dom;
domain[1] = (allX[v-1])+dom;
domain[2] = allY[0]-dom;
domain[3] = allY[v-1]+dom;
double wid = domain[1] - domain[0];
double hei = domain[3] - domain[2];
double aspect = wid/hei;
if(aspect>1) {
left = domain[0];
right = domain[1];
top = domain[2]*aspect;
bottom = domain[3]*aspect;
}
else
{
left = domain[0]/aspect;
right = domain[1]/aspect;
top = domain[2];
bottom = domain[3];
}
znear = allZ[0]- wid * 1000.0f;
zfar = allZ[v-1]+ wid * 1000.0f;
trans[0] = left + wid/2;
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
delete [] domain;
domain=NULL;
return;
}
else
{
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
domainSetUpForProfile();
Invalidate();
wglMakeCurrent(NULL,NULL);
ReleaseDC(pDC);
return;
}
}
void CMyView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = PAN;
CView::OnLButtonDblClk(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = NOMOVE;
CView::OnLButtonUp(nFlags, point);
}
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(pan)
STATE = PAN;
else if(zoom)
STATE = ZOOM;
else if(rotate)
STATE = ROTATE;
else
STATE = NOMOVE;
oldP = point;
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnMButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = PAN;
CView::OnMButtonDown(nFlags, point);
}
void CMyView::OnMButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = NOMOVE;
CView::OnMButtonUp(nFlags, point);
}
void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = ROTATE;
CView::OnRButtonDown(nFlags, point);
}
void CMyView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
STATE = NOMOVE;
CView::OnRButtonUp(nFlags, point);
}
BOOL CMyView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
if(zDelta > 0)
{
zoomFactor /= (0.75);
}
else
{
zoomFactor *= (0.75);
}
Invalidate();
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
void CMyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CDC* pDC = GetDC();
PrepareScene(pDC);
ReleaseDC(pDC);
}
BOOL CMyView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return CView::OnEraseBkgnd(pDC);
}
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CDC* pDC = GetDC();
Reshape(pDC, cx, cy);
ReleaseDC(pDC);
}
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CDC* pDC = GetDC();
CreateGLContext(pDC);
ReleaseDC(pDC);
return 0;
}
void CMyView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
CDC* pDC = GetDC();
DestroyScene(pDC);
ReleaseDC(pDC);
}
void CMyView::selectionSort(double arr[], int size)
{
int indexOfMin, pass, j;
for (pass = 0; pass < size - 1; pass++)
{
indexOfMin = pass;
for (j = pass + 1; j < size; j++)
if (arr[j] < arr[indexOfMin])
indexOfMin = j;
swap(arr[pass], arr[indexOfMin]);
}
}
void CMyView::loadProfile(CString filename)
{
// pFrame->m_wndStatusBar.SetPaneText(0,L"Load-Profile !!");
if(startPoints) {
delete [] startPoints;
startPoints=NULL;
}
if(endPoints) {
delete [] endPoints;
endPoints=NULL;
}
if(arcs) {
delete [] arcs;
arcs=NULL;
}
// profile to be drawn
//file needs be open
double startPX, startPY, endPX, endPY;
double cenX, cenY, rad, startA, endA;
ifstream indata; // indata is like cin
int id, dir; // variable for input value
indata.open(filename); // opens the file
if(!indata) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
count1=0;
count2=0;
int n1;
while(!indata.eof()){ // keep reading until end-of-file
indata >> id;
cout << "The id is " << id << endl;
if(id==1)
{
indata >> startPX >> startPY >> endPX >> endPY;
if(count1==0)
{
startPoints = (POINT3D *)malloc(sizeof(POINT3D));
endPoints = (POINT3D *)malloc(sizeof(POINT3D));
}
else
{
startPoints = (POINT3D *)realloc(startPoints,sizeof(POINT3D)*(count1+1));
endPoints = (POINT3D *)realloc(endPoints,sizeof(POINT3D) * (count1+1));
}
startPoints[count1].x = startPX;
startPoints[count1].y = startPY;
startPoints[count1].z = 0.0f;
endPoints[count1].x = endPX;
endPoints[count1].y = endPY;
endPoints[count1].z = 0.0f;
count1++;
}
else
{
indata >> dir >> cenX >> cenY >> rad >> startA >> endA;
if(count2==0)
arcs = (ARC *)malloc(sizeof(ARC));
else
arcs = (ARC *)realloc(arcs,sizeof(ARC)*(count2+1));
arcs[count2].vertices = new float[3 * NOFPOINTSINARC];
arcs[count2].vertices = getArcVerts(cenX,cenY,rad,startA,endA,NOFPOINTSINARC);
// DrawArc(cenX,cenY,rad,startA,endA,NOFPOINTSINARC-1);
count2++;
}
}
if(id==1)
count1--;
else
count2--;
indata.close();
cout << "End-of-file reached.." << endl;
}
float* CMyView::getArcVerts(float pos_x, float pos_y,
float radius,
float angle_start, float angle_end,
unsigned int detail_level)
{
float* verts = (float *)malloc(sizeof(float) * 3 * detail_level);
float angle_delta = (angle_end - angle_start);
if(angle_delta < - 180.0)
{
angle_delta = 360 + angle_delta;
}
float angle_step = angle_delta / (detail_level - 1);
float angle = angle_start;
int cnt=0;
while(detail_level){
verts[cnt] = pos_x + radius * cosf(angle * PI/180.0);
verts[cnt+1] = pos_y + radius * sinf(angle * PI/180.0);
verts[cnt+2] = 0.0f;
angle += angle_step;
cnt+=3;
--detail_level;
}
return verts;
}
[/code]
|
|
|
|
|