์ผ๋‹จ ์นœ๊ตฌํ•œํ…Œ ์กฐ์–ธ์„ ๊ตฌํ•˜๊ณ  ์žˆ์ง€๋งŒ ์—ญ์‹œ ๋‚ด ๋จธ๊ฐ€๋ฆฌ๋ก  ๋ชจ๋ฅด๊ฒ„์๋‹ˆ๋‹ค. ์•„์กฐ์”จ๋“ค ๋„์™€์กฐ์š”!


๊ธฐ์กด ์ง€์  (x1, y1)์—์„œ ์ง€์ •ํ•œ ์ง€์ ์œผ๋กœ (x2, y2). ๊ธฐ์กด ์ง€์ ์—์„œ ์ง€์ •ํ•œ ์ง€์ ์˜ ๋ฐฉํ–ฅ์œผ๋กœ, ์‹œ๊ฐ„์— ๋น„๋ก€ํ•ด ์†๋ ฅ๋งŒํผย ํ”Œ๋ ˆ์ด์–ด๋Š” ์›€์ง์ธ๋‹ค.

ย .. ๋‘ ์ง€์ ์˜ ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๊ฐ’์€ย sqrt((x1-x2)^2+(y1-y2)^2)ย 

ย .. ๊ฐ๋„๋Š”ย ฮธ ..ย degree = atan(dx / dy)๋กœ ํ•จ

ย .. ์ง€์ •๋œ ์†๋ ฅ๊ฐ’๊ณผ ์ง€๋‚œ ์‹œ๊ฐ„์— ๋”ฐ๋ผย ์ด๋™ํ•œ ๊ฐ’์ด ๋‚˜์˜ฌ ๊ฒƒ.

1์ดˆ๋งˆ๋‹ค ์›€์ง์ธ ํ›„์˜ ํ”Œ๋ ˆ์ด์–ด์˜ ์ขŒํ‘œ๊ฐ’์„ ๊ตฌํ•˜๋ ค ํ•˜๋Š”๋ฐ ..


์นœ๊ตฌ๋Š” (x1 + cosฮธยท(Vยทt), y1 + sinฮธยท(Vยทt)) = (x, y)๋ผ๊ณ  ํ•จ.

๋งž๋Š”์ง€ ๋ชฐ๊ฒƒ๋‹ค .. ์‹์— ๋งž์ถฐ์„œ ์งœ๋ดค๋Š”๋ฐ ๊ฐ’์ด ์ด์ƒํ•œ ๊ฐ’ ๋‚˜์˜จ๋‹ค. ์œผ์–ด์–พใ„ดใ…‡ใ„นใ„ทใ…ˆ


์•„๋ฌด๋ž˜๋„ ๋‚ด๊ฐ€ ์ฝ”๋“œ๋ฅผ ์ž˜๋ชป ์ง  ๊ฒƒ ๊ฐ™๋‹ค

๋ฌด์œผ๊ฐ€ ๋ฌธ์ œ์ง€


<!-- HTML generated using hilite.me -->
// Pawn.h /////////////////////// ///////////////////////////////// class Pawn { protected: //x, y, Speed, TP; double Speed, Length;//์†๋ ฅ๊ณผ ๊ฑฐ๋ฆฌ typedef struct Position { double x, y; } Pos; Pos NowPos; Pos FutPos; Pos PastPos[10]; public: Pawn() { PastPos[1].x = 0, PastPos[1].y = 0; } void SetPosition(double ax, double ay); void ToPosition(double ax, double ay); void SetSpeed(double aSpeed); void MovePer(); void CheckChange(int i); void TestReading(TCHAR *STR, int i); }; ////////////////////////////// //Pawn.cpp//////////////////// ////////////////////////////// void Pawn::SetPosition(double ax, double ay) { NowPos.x = ax; NowPos.y = ay; } void Pawn::ToPosition(double ax, double ay) { FutPos.x = ax; FutPos.y = ay; } void Pawn::SetSpeed(double aSpeed) { // "Speed"m/s .. Speed = aSpeed; } void Pawn::MovePer() { //ํ˜ธ์ถœํ•˜๋ฉด ๊ฑฐ๋ฆฌ๋ฅผ ๋”ํ•œ๋‹ค. Length += Speed; } void Pawn::CheckChange(int i) { double dx = NowPos.x - FutPos.x; double dy = NowPos.y - FutPos.y; double degree = atan(dx / dy); PastPos[i].x = NowPos.x + (cos(degree)*Length); PastPos[i].y = NowPos.y + (sin(degree)*Length); } void Pawn::TestReading(TCHAR *STR, int i) { wsprintf(STR, TEXT("X : %d, Y : %d"), PastPos[i].x, PastPos[i].y); }


์ผ๋‹จ ์“ฐ์ž˜๋ฐ๊ธฐ ์—†๋Š”๊ฑฐ ์ฃ„๋‹ค ์ƒ๋žตํ•˜๊ณ ย ์ •๋ฆฌํ•ด์„œ ์จ๋ด„ ..


<!-- HTML generated using hilite.me -->

static TCHAR Str2[30]; switch (message) { case WM_CREATE: SetTimer(hWnd, 1, 1000, NULL); //0.1์ดˆ. //์‹œ๊ฐ„ ์ฒดํฌ Now.TimeSet(Sec, Min, Hour); Now.WriteTick(Str1); SpeedSec = 5000; //5์ดˆ๋งˆ๋‹ค SetTimer(hWnd, 2, SpeedSec, NULL); //Pawn ์„ค์ • here.SetPosition(0, 0); here.ToPosition(300, 300); //์ž„์˜ ์ง€์ • here.SetSpeed(10); here.TestReading(Str2, 1); //์‚ฌ์ „ ํ‘œ๊ธฐ SendMessage(hWnd, WM_PAINT, 0, 0); return 0; ////////////////////////////////////// //////////์ƒ๋žต//////////////////////// ////////////////////////////////////// case WM_TIMER: switch (wParam) { case 1: Now.CheckTick(); Now.WriteTick(Str1); InvalidateRect(hWnd, NULL, TRUE); break; case 2: static int i = 0; here.MovePer(); here.CheckChange(i); here.TestReading(Str2, i); i++; } ////////////////////////////////////// //////////์ƒ๋žต//////////////////////// ////////////////////////////////////// case WM_PAINT: hdc = BeginPaint(hWnd, &ps); //ํฐํŠธ ์„ค์ • font = CreateFont(15, 0, 0, 0, 0, 0, 0, 0, HANGEUL_CHARSET, 0, 0, 0, 0, TEXT("๊ถ์„œ")); oldfont = (HFONT)SelectObject(hdc, font); SetTextColor(hdc, RGB(255, 255, 255)); SetBkMode(hdc, TRANSPARENT); //์ถœ๋ ฅ TextOut(hdc, 10, 10, Str1, lstrlen(Str1)); TextOut(hdc, 10, 30, Str2, lstrlen(Str2)); //์‚ญ์ œ SelectObject(hdc, oldfont); DeleteObject(font); EndPaint(hWnd, &ps); return 0;