Esempio n. 1
1
File: main.cpp Progetto: CCJY/coliru
int main()
{
Shape *shape = new Circle;
shape->Draw();

Circle *circle = dynamic_cast<Circle*>(shape);
circle->Draw();

Circle *oneMore = Dynamic_Cast<Circle*,Shape*>(shape); 
oneMore->Draw();

Circle *nope = Dynamic_Cast<Circle*,Shape*>(shape); // <-- Fix this line from Circle *nope = dynamic_cast<Circle*,Shape*>(shape);
//system("pause");
}
Esempio n. 2
0
int main()
{

	Shape s;
	s.Move(100, 100);
	s.Draw();

	Rectangle r;
	r.Move(200, 100);
	r.Resize( 50, 50);
	r.Draw();

	Circle c;
	c.Move( 300, 100);
	c.SetRadius(30);
	c.Draw();

	return 0;
}
void CalcDist::Excute()
{
	
	m_cursor = LoadCursor(g_hInst, MAKEINTRESOURCE(IDC_CURSOR2));
	m_oldCursor = SetCursor(m_cursor);

	HDC	hdc = GetDC(m_hWnd);
	HDC memoryDC = CreateCompatibleDC(hdc);
	HBITMAP memoryBitmap = CreateCompatibleBitmap(hdc, m_maxWidth, m_maxHeight);
	HBITMAP oldBitmap = (HBITMAP)SelectObject(memoryDC, memoryBitmap);
	WCHAR temp[100] = { 0, };
	Rectangle(memoryDC, 0, 0, m_maxWidth, m_maxHeight); //흰색 바탕 칠하기

	/* line 그리기 */
	// y = ax + b
	// ax - y + b = 0;
	double x1 = 550, y1 = -100, x2 = 250, y2 = 900;
	double angle = (y2 - y1) / (x2 - x1); // a
	double b = -angle * x2 + y2; // b
	double distance = abs(angle * g_mousex - g_mousey + b) / sqrt(angle*angle + 1);
	MoveToEx(memoryDC, x1, y1, PS_SOLID);
	LineTo(memoryDC, x2, y2);

	/*법선그리기*/
	double crossAngle = -1 / angle; //법선 기울기
	// ax + b = y
	// b = y - ax
	double crossB = g_mousey - crossAngle * g_mousex;
	double crossX = -(b - crossB) / (angle - crossAngle);
	double crossY = crossX * crossAngle + crossB;
	MoveToEx(memoryDC, crossX, crossY, PS_SOLID);
	LineTo(memoryDC, g_mousex, g_mousey);

	Circle myCircle = Circle(g_mousex, g_mousey, 20.0);
	Circle targetCircle = Circle(500, 300, 60);
	RECT targetRect = RECT();
	targetRect.bottom = 350;
	targetRect.top = 250;
	targetRect.left = 100;
	targetRect.right = 200;
	
	COLORREF targetRectColor;
	if (CollideChecker::IsCollision(targetRect, myCircle))
		targetRectColor = RGB(255, 0, 0);
	else
		targetRectColor = RGB(0, 0, 255);

	COLORREF targetCircleColor;
	if (CollideChecker::IsCollision(myCircle, targetCircle))
		targetCircleColor = RGB(200, 200, 0);
	else
		targetCircleColor = RGB(0, 200, 200);

	COLORREF myColor = RGB(20, 100, 100);

	DrawRectWithColor(memoryDC, targetRect, targetRectColor);
	targetCircle.Draw(memoryDC, targetCircleColor);
	myCircle.Draw(memoryDC, myColor);
	MoveToEx(memoryDC, targetCircle.m_cx, targetCircle.m_cy, PS_SOLID);
	LineTo(memoryDC, myCircle.m_cx, myCircle.m_cy);

	wsprintf(temp, L"X : %d", (int)g_mousex);
	TextOut(memoryDC, 10, 10, temp, lstrlen(temp));
	wsprintf(temp, L"Y : %d", (int)g_mousey);
	TextOut(memoryDC, 10, 30, temp, lstrlen(temp));
	wsprintf(temp, L"Distance : %d", (int)distance);
	TextOut(memoryDC, 10, 50, temp, lstrlen(temp));

	//memoryDC에 버퍼링된 이미지 그리기.
	BitBlt(hdc, 0, 0, m_maxWidth, m_maxHeight, memoryDC, 0, 0, SRCCOPY);

	/* 리소스 반환 */
	//memoryDC 제거
	SelectObject(memoryDC, oldBitmap);
	DeleteDC(memoryDC);
	DeleteObject(memoryBitmap);

	ReleaseDC(m_hWnd, hdc);
}