Скачиваний:
9
Добавлен:
01.05.2014
Размер:
2.43 Кб
Скачать
// Copyright (C) 1991 - 1999 Rational Software Corporation
#include "stdafx.h"
#include "OurConstants.h"

#include "Triangle.h"

#include <math.h>

long Triangle::count_ID = 0;

//##ModelId=47092A4401A5
Triangle::Triangle(CPoint center, int size, COLORREF aColor):
ID(++count_ID)
{
	// TODO: Add your specialized code here.
	centerPoint = center;

	this->size=size;
	color = aColor;
	pen = DEFAULT_PEN;
	
	CPoint p1( 
		(int)(centerPoint.x - size*cos(PI/6.0) - GAP),
		(int)(centerPoint.y - size*sin(PI/6.0) - GAP)
		);
	CPoint p2(
		(int)(centerPoint.x + size*cos(PI/6.0) + GAP),
		(int)(centerPoint.y + size + GAP)
		);

	boundRect = CRect(p1,p2);
	boundRect.NormalizeRect();
}

//##ModelId=470A082E036B
Triangle::~Triangle()
{
//	cout << "Destructor: Triangle object ID: " << ID << endl;	
}

//##ModelId=470A1E4603B9
void Triangle::draw(CDC* pDC, COLORREF color, int pen=0) {

	// Create a pen for this object and
    // initialize it to the object color and line width of 1 pixel
	CPen aPen;
	COLORREF aColor = color;             // Initialize with element color
	if(!pen) pen = DEFAULT_PEN;
	if(!aPen.CreatePen(PS_SOLID, pen, aColor))
    {  
	  // Pen creation failed. Abort the program.
      AfxMessageBox("Pen creation failed drawing a line", MB_OK);
      AfxAbort();
    }

    CPen* pOldPen = pDC->SelectObject(&aPen);  // Select the pen

	CPoint p1(
		(int)(centerPoint.x - size*cos(PI/6)),
		(int)(centerPoint.y - size*sin(PI/6))
		);
	CPoint p2(
		(int)(centerPoint.x),
		(int)(centerPoint.y+size)
		);
	CPoint p3(
		(int)(centerPoint.x + size*cos(PI/6)),
		(int)(centerPoint.y - size*sin(PI/6))
		);

    // Now draw the triangle
    pDC->MoveTo(p1);
    pDC->LineTo(p2);
	pDC->MoveTo(p2);
	pDC->LineTo(p3);
	pDC->MoveTo(p3);
	pDC->LineTo(p1);

    pDC->SelectObject(pOldPen); // Restore the old pen

}

//##ModelId=472F355501F4
double Triangle::area() {
	return (3*size*size*cos(PI / 3)*sin(PI / 3));
}

//##ModelId=472F35550213
void Triangle::move(CSize& size) {
//	this->centerX = size.cx;
//	this->centerY = size.cy;

	centerPoint+=size;
//	CPoint p1( 
//		(int)(centerX - size*cos(PI/6.0) - GAP),
//		(int)(centerY - size*sin(PI/6.0) - GAP)
//		);
//	CPoint p2(
//		(int)(centerX + size*cos(PI/6.0) + GAP),
//		(int)(centerY + size + GAP)
//		);
//
//	boundRect = CRect(p1,p2);
	
	boundRect+=size;

}
Соседние файлы в папке Лабораторная работа 23