Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа №23 / Laba2 / Laba2View
.cpp// Laba2View.cpp : implementation of the CLaba2View class
//
#include "stdafx.h"
#include "Laba2.h"
#include "Laba2Doc.h"
#include "Laba2View.h"
#include "cParabSpline.h"
#include ".\laba2view.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define POINTS_COUNT 1000
// CLaba2View
IMPLEMENT_DYNCREATE(CLaba2View, CView)
BEGIN_MESSAGE_MAP(CLaba2View, CView)
END_MESSAGE_MAP()
// CLaba2View construction/destruction
CLaba2View::CLaba2View()
{
// TODO: add construction code here
}
CLaba2View::~CLaba2View()
{
}
BOOL CLaba2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CLaba2View drawing
void CLaba2View::OnDraw(CDC* pDC)
{
CLaba2Doc* pDoc = GetDocument();
CRect Rect;
CWnd* pWnd;
int CentrX, CentrY;
ASSERT_VALID(pDoc);
if (!pDoc)
return;
pWnd=pDC->GetWindow();
pWnd->GetClientRect(&Rect);
CentrX=(Rect.right + Rect.left)/2;
CentrY=(Rect.bottom + Rect.top)/2;
pDC->MoveTo(CentrX, 10);
pDC->LineTo(CentrX, Rect.bottom-10);
pDC->MoveTo(10, CentrY);
pDC->LineTo(Rect.right-10, CentrY);
if (theApp.Init == 2)
{
cParabSpline Spline1(theApp.T1, theApp.T2, theApp.T3);
cParabSpline Spline2(theApp.T2, theApp.T3, theApp.T4);
cParabSpline Spline3(theApp.T3, theApp.T4, theApp.T5);
POINT Point1;
cVector3D tmpVect1, tmpVect2;
float i,j,k;
int tx, ty;
float step1, step2;
// draw points
tmpVect1 = Spline1.GetGSK(Spline1.GetT1());
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
pDC->Ellipse(CentrX-tx-4, CentrY-ty-4, CentrX-tx+4, CentrY-ty+4);
tmpVect1 = Spline1.GetGSK(0);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
pDC->Ellipse(CentrX-tx-4, CentrY-ty-4, CentrX-tx+4, CentrY-ty+4);
tmpVect1 = Spline2.GetGSK(0);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
pDC->Ellipse(CentrX-tx-4, CentrY-ty-4, CentrX-tx+4, CentrY-ty+4);
tmpVect1 = Spline3.GetGSK(0);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
pDC->Ellipse(CentrX-tx-4, CentrY-ty-4, CentrX-tx+4, CentrY-ty+4);
tmpVect1 = Spline3.GetGSK(Spline3.GetT3());
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
pDC->Ellipse(CentrX-tx-4, CentrY-ty-4, CentrX-tx+4, CentrY-ty+4);
if(theApp.VivodSplain == 1)
{
step1 = (0 - Spline1.GetT1())/POINTS_COUNT;
for(k=0,i=Spline1.GetT1(); k<POINTS_COUNT; k++,i+=step1)
{
tmpVect1 = Spline1.GetGSK(i);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
Point1.x = CentrX-tx;
Point1.y = CentrY-ty;
pDC->SetPixel(Point1, RGB(200, 200, 200));
}
step1 = (Spline1.GetT3() - 0)/POINTS_COUNT;
step2 = (0 - Spline2.GetT1())/POINTS_COUNT;
for(k=0,i=0,j=Spline2.GetT1(); k<POINTS_COUNT; k++,i+=step1,j+=step2)
{
tmpVect1 = Spline1.GetGSK(i);
tmpVect2 = Spline2.GetGSK(j);
tmpVect1*(1-k/POINTS_COUNT);
tmpVect2*(k/POINTS_COUNT);
tmpVect1+tmpVect2;
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
Point1.x = CentrX-tx;
Point1.y = CentrY-ty;
pDC->SetPixel(Point1, RGB(200, 200, 200));
}
step1 = (Spline2.GetT3() - 0)/POINTS_COUNT;
step2 = (0 - Spline3.GetT1())/POINTS_COUNT;
for(k=0,i=0,j=Spline3.GetT1(); k<POINTS_COUNT; k++,i+=step1,j+=step2)
{
tmpVect1 = Spline2.GetGSK(i);
tmpVect2 = Spline3.GetGSK(j);
tmpVect1*(1-k/POINTS_COUNT);
tmpVect2*(k/POINTS_COUNT);
tmpVect1+tmpVect2;
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
Point1.x = CentrX-tx;
Point1.y = CentrY-ty;
pDC->SetPixel(Point1, RGB(200, 200, 200));
}
step1 = (Spline3.GetT3() - 0)/POINTS_COUNT;
for(k=0,i=0; k<POINTS_COUNT; k++,i+=step1)
{
tmpVect1 = Spline3.GetGSK(i);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
Point1.x = CentrX-tx;
Point1.y = CentrY-ty;
pDC->SetPixel(Point1, RGB(200, 200, 200));
}
}
else
{
step1 = (Spline1.GetT3() - Spline1.GetT1())/(2*POINTS_COUNT);
for(i=Spline1.GetT1(); i<Spline1.GetT3();i+=step1)
{
tmpVect1=Spline1.GetGSK(i);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
Point1.x = CentrX-tx;
Point1.y = CentrY-ty;
pDC->SetPixel(Point1, RGB(100, 100, 100));
}
step1 = (Spline2.GetT3() - Spline2.GetT1())/(2*POINTS_COUNT);
for(i=Spline2.GetT1(); i<Spline2.GetT3();i+=step1)
{
tmpVect1=Spline2.GetGSK(i);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
Point1.x = CentrX-tx;
Point1.y = CentrY-ty;
pDC->SetPixel(Point1, RGB(100, 100, 100));
}
step1 = (Spline3.GetT3() - Spline3.GetT1())/(2*POINTS_COUNT);
for(i=Spline3.GetT1(); i<Spline3.GetT3();i+=step1)
{
tmpVect1=Spline3.GetGSK(i);
tx = GetVectX(tmpVect1, theApp.OutOsi);
ty = GetVectY(tmpVect1, theApp.OutOsi);
Point1.x = CentrX-tx;
Point1.y = CentrY-ty;
pDC->SetPixel(Point1, RGB(100, 100, 100));
}
}
}
}
// CLaba2View diagnostics
#ifdef _DEBUG
void CLaba2View::AssertValid() const
{
CView::AssertValid();
}
void CLaba2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CLaba2Doc* CLaba2View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLaba2Doc)));
return (CLaba2Doc*)m_pDocument;
}
#endif //_DEBUG
// CLaba2View message handlers
int CLaba2View::GetVectX(cVector3D& Vect, int Regim)
{
switch(Regim)
{
case 1: return (int)Vect.X;
case 2: return (int)Vect.Y;
case 3: return (int)Vect.X;
}
return 0;
}
int CLaba2View::GetVectY(cVector3D& Vect, int Regim)
{
switch(Regim)
{
case 1: return (int)Vect.Y;
case 2: return (int)Vect.Z;
case 3: return (int)Vect.Z;
}
return 0;
}
Соседние файлы в папке Laba2