Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа №46 / alab4 / rlab4View
.cpp// rlab4View.cpp : implementation of the CRlab4View class
//
#include "stdafx.h"
#include "rlab4.h"
#include "rlab4Doc.h"
#include "rlab4View.h"
#include <cmath>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRlab4View
IMPLEMENT_DYNCREATE(CRlab4View, CView)
BEGIN_MESSAGE_MAP(CRlab4View, CView)
//{{AFX_MSG_MAP(CRlab4View)
ON_WM_CREATE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRlab4View construction/destruction
CRlab4View::CRlab4View()
{
// TODO: add construction code here
}
CRlab4View::~CRlab4View()
{
}
BOOL CRlab4View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CRlab4View drawing
void CRlab4View::OnDraw(CDC* pDC)
{
CRlab4Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
wglMakeCurrent(pDC->m_hDC, m_hrc);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
glColor3f(1, 1, 0);
DrawCircle(0, 0, 0.3);
Draw();
wglMakeCurrent(NULL, NULL);
}
/////////////////////////////////////////////////////////////////////////////
// CRlab4View diagnostics
#ifdef _DEBUG
void CRlab4View::AssertValid() const
{
CView::AssertValid();
}
void CRlab4View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CRlab4Doc* CRlab4View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRlab4Doc)));
return (CRlab4Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRlab4View message handlers
int CRlab4View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CClientDC dc(this);
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE ;
int nPixelFormat = ChoosePixelFormat(dc.m_hDC, &pfd);
if (nPixelFormat == 0)
return -1;
BOOL bResult = SetPixelFormat(dc.m_hDC, nPixelFormat, &pfd);
if (!bResult)
return -1;
m_hrc = wglCreateContext(dc.m_hDC);
if (!m_hrc)
return -1;
return 0;
}
void CRlab4View::OnInitialUpdate()
{
CView::OnInitialUpdate();
CClientDC dc(this);
wglMakeCurrent(dc.m_hDC, m_hrc);
glViewport(0, 0, 500, 500);
glClearColor(0.3, 0.3, 0.5, 0.0);
wglMakeCurrent(NULL, NULL);
}
void CRlab4View::OnDestroy()
{
CView::OnDestroy();
wglDeleteContext(m_hrc);
}
void CRlab4View::DrawCircle(double x, double y, double r)
{
double xx, yy, angle;
glBegin(GL_LINE_STRIP);
for (int i = 0; i <= 30; i++)
{
angle = 3.14 * i / 15;
xx = cos(angle) * r + x;
yy = sin(angle) * r + y;
glVertex2d(xx , yy);
}
glEnd();
}
void CRlab4View::Draw()
{
double x, y, angle;
for (int i = 72; i <= 360; i += 72) {
angle = 3.14 * i / 180;
x = cos(angle) * 0.45;
y = sin(angle) * 0.45;
Draw5(x, y, angle);
}
}
void CRlab4View::Draw5(double x, double y, double angle)
{
double xx, yy, angle2;
glColor3f(1, 0, 0);
DrawCircle(x, y, 0.1);
glColor3f(0, 1, 0);
xx = cos(angle) * 0.16 + x;
yy = sin(angle) * 0.16 + y;
DrawCircle(xx, yy, 0.04);
xx = cos(angle - 1) * 0.16 + x;
yy = sin(angle - 1) * 0.16 + y;
DrawCircle(xx, yy, 0.04);
xx = cos(angle + 1) * 0.16 + x;
yy = sin(angle + 1) * 0.16 + y;
DrawCircle(xx, yy, 0.04);
}
Соседние файлы в папке alab4