#include <iostream>
#include <math.h>
using namespace std;

struct vec2 {
public:
	float x;
	float y;

	vec2() {

	}
	vec2(float x, float y) {
		this->x = x;
		this->y = y;
	}
};

//      (시작점)--------------------------------------->(끝점)

int main() {
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	
	vec2 posStart(0,0);// 시작점
	vec2 posEnd(10,10);// 끝점

	vec2 arrow1(0, 0);// 화살표 1
	vec2 arrow2(0, 0);// 화살표 2

	float width = 1;  // 너비
	float length = 3; // 길이

	float distance = sqrtf(powf(posEnd.x - posStart.x, 2) + powf(posEnd.y - posStart.y, 2));
	cout << "distance : " << distance << '\n';

	//float th = atan2f(pend.x - pstart.x, pend.y - pstart.y) * (180 / 3.14f);
	float th = atan2f(posEnd.y - posStart.y, posEnd.x - posStart.x);
	cout << "th : " << th << '\n';

	arrow1.x = (distance - length) * cosf(th) - (width / 2.f) * sinf(th) + posStart.x;
	arrow1.y = (distance - length) * sinf(th) + (width / 2.f) * cosf(th) + posStart.y;

	arrow2.x = (distance - length) * cosf(th) + (width / 2.f) * sinf(th) + posStart.x;
	arrow2.y = (distance - length) * sinf(th) - (width / 2.f) * cosf(th) + posStart.y;

	cout << "arrow1 x : " << arrow1.x << ", y : " << arrow1.y << '\n';
	cout << "arrow2 x : " << arrow2.x << ", y : " << arrow2.y << '\n';

	return 0;
}

'게임 개발 > C++ console' 카테고리의 다른 글

배열 안에서 숫자 움직이기 (MBCS, WBCS 연습 겸)  (0) 2021.01.13
빙고게임2 (MBCS,WBCS 연습겸)  (0) 2021.01.13
미디 키보드 건반 프로그램  (0) 2020.01.14
마리오게임  (0) 2019.12.03
TextRPG  (0) 2019.11.12

+ Recent posts