์ผ๋จ ์น๊ตฌํํ
์กฐ์ธ์ ๊ตฌํ๊ณ ์์ง๋ง ์ญ์ ๋ด ๋จธ๊ฐ๋ฆฌ๋ก ๋ชจ๋ฅด๊ฒ์๋๋ค. ์์กฐ์จ๋ค ๋์์กฐ์!
๊ธฐ์กด ์ง์ (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;
V๊ฐ ์๋ ฅ, t๊ฐ ์๊ฐ์ด๋ผ MovePer๋ก ๋ฐ๋ก ๋ง๋๋ฌ์ ..
X : %d๋ก ํ๊ฒ ์๋ชป๋๊ฒ ์๋๊น!
y๊ฐ cos ์๋?
๋๋ ค๋ณธ๊ฒฐ๊ณผ ์๋ฌ๋ ์ข ๋ง์์ผ ๊ฒ์ฆ์ด๋์ ธ
http://forums.codeguru.com/showthread.php?528367-wsprintf()-Function-how-to-read-Double-Variable
์ฐธ์กฐํด์ ํ์๊ฐ ๋๋๋ก ๋ฐ๊ฟ์ ์ผ๋จ ์ค์๊ฐ ํ๊ธฐ๋๋๋ก ํจ. ๊ทธ๋์ (0, 0)์์ (300, 300)์ผ๋ก 10๋ฅผ 5์ด ๊ฐ๊ฒฉ์ผ๋ก ์ด๋ํด์, ์ฒ์ ๋์จ ๊ฐ์ด 7.071068 ์ธ๋ฐ .. ์์ด ๋ง๋์ง ๋ชจ๋ฅด๊ฒ ๋ค. ์ผ๋จ ์จ๋ด์ผ์ง.