Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа №44 / laba4_fact / laba4_factView
.cpp// laba4_factView.cpp : implementation of the Claba4_factView class
//
#include "stdafx.h"
#include "laba4_fact.h"
#include "laba4_factDoc.h"
#include "laba4_factView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Claba4_factView
IMPLEMENT_DYNCREATE(Claba4_factView, CView)
BEGIN_MESSAGE_MAP(Claba4_factView, CView)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_COMMAND(ID_EDIT_SETPARAMETERS, &Claba4_factView::OnEditSetparameters)
END_MESSAGE_MAP()
// Claba4_factView construction/destruction
Claba4_factView::Claba4_factView(): x1(0), y1(0), Radius(300),MinRad(50)
{
// TODO: add construction code here
}
Claba4_factView::~Claba4_factView()
{
}
BOOL Claba4_factView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
return CView::PreCreateWindow(cs);
}
// Claba4_factView drawing
void Claba4_factView::OnDraw(CDC* pDC)
{
Claba4_factDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
wglMakeCurrent(pDC->m_hDC, m_hRC);
DrawWithOpenGL();
wglMakeCurrent(pDC->m_hDC, NULL);
}
// Claba4_factView diagnostics
#ifdef _DEBUG
void Claba4_factView::AssertValid() const
{
CView::AssertValid();
}
void Claba4_factView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
Claba4_factDoc* Claba4_factView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Claba4_factDoc)));
return (Claba4_factDoc*)m_pDocument;
}
#endif //_DEBUG
// Claba4_factView message handlers
int Claba4_factView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // Structure size.
1, // Structure version number.
PFD_DRAW_TO_WINDOW | // Property flags.
PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24, // 24-bit color.
0, 0, 0, 0, 0, 0, // Not concerned with these.
0, 0, 0, 0, 0, 0, 0, // No alpha or accum buffer.
32, // 32-bit depth buffer.
0, 0, // No stencil or aux buffer.
PFD_MAIN_PLANE, // Main layer type.
0, // Reserved.
0, 0, 0 // Unsupported.
};
CClientDC clientDC(this);
int pixelFormat =
ChoosePixelFormat(clientDC.m_hDC, &pfd);
BOOL success =
SetPixelFormat(clientDC.m_hDC, pixelFormat, &pfd);
m_hRC = wglCreateContext(clientDC.m_hDC);
return 0;
}
void Claba4_factView::OnDestroy()
{
CView::OnDestroy();
wglDeleteContext(m_hRC);
}
void Claba4_factView::DrawWithOpenGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
Circle(0.0f,0.0f,Radius);
KochCircle(0.0f,0.0f,Radius,MinRad);
glFlush();
}
void Claba4_factView::KochCircle( float x, float y, float R, float q )
{
Circle(x,y,(float)R/3);
if( (R/3) >= q )
KochCircle(x,y,(float)R/3,q);
float x0 = x;
float y0 = y;
y -= -(2*R)/3;
for(int i=0; i<=4; i++){
float alpha = i*72* Pi/180;
x1 = x * cos(alpha) - y * sin(alpha) - x0*(cos(alpha)-1)+y0*sin(alpha);
y1 = x * sin(alpha) + y * cos(alpha) - x0*sin(alpha)-y0*(cos(alpha)-1);
Circle(x1,y1, R/3);
if( (R/3) >= q )
KochCircle(x1,y1,(float)R/3,q);
}
}//KochCircle
void Claba4_factView::Circle(float x, float y, float radius)
{
float y1 =(y + radius)/640;
float x1 = x/640;
glBegin(GL_LINE_STRIP);
for(double angle=0.0f;angle<=(2.0f*3.14159);angle+=0.01f)
{
float x2=x+(radius*(float)sin((float)angle));
float y2=y+(radius*(float)cos((float)angle));
glVertex2d(x1,y1);
y1=y2/640;
x1=x2/640;
}
glEnd();
}//Circle
void Claba4_factView::OnEditSetparameters()
{
MyDialog dlg;
dlg.DoModal();
Radius = dlg.vRadius;
MinRad = dlg.vMinRad;
Invalidate();
// TODO: Add your command handler code here
}
Соседние файлы в папке laba4_fact