[유니티로 배우는 게임 수학] (1)

5409 단어 studystudy

1. 삼각함수

  • 삼각형
  • 직각삼각형
  • 피타고라스의 정리
  • 사인, 코사인, 탄젠트
  • 삼각함수의 주기성

예제

  1. 화면의 임의의 점을 클릭하면 캡슐의 끝이 클릭한 위치를 향한다
Vector3 selfScreenPoint = Camera.main.WorldToScreenPoint(capsule.transform.position);
Vector3 diff = mousePosition - selfScreenPoint;
		
float angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
Debug.Log (string.Format("angle: {0:f}", angle));

float finalAngle = angle - 90f;
Debug.Log (string.Format("finalAngle: {0:f}", finalAngle));

return finalAngle;

위의 함수식을 통해 -β와 일치하는 α-90 값을 구할 수 있다.
/ + Atan2 함수 : 가로, 세로의 길이를 통해 탄젠트 값을 반환한다.
Atan 함수와 달리 두번째 인수가 0이 되어 tan 값을 구할 수 없을 경우 적절한 각(π/2 정도)를 반환한다

  1. 화면의 임의의 점을 클릭하면 그 위치에 구체가 나타나면서 화면 중앙을 바운드하듯이 움직인다.
sphere.transform.position = new Vector3(sphere.transform.position.x 
			+ (capsule.transform.position.x - sphere.transform.position.x) 
            		* Time.deltaTime * sphereMagnitudeX,
			Mathf.Abs(Mathf.Sin ((Time.time - buttonDownTime) * (Mathf.PI * 2) 
            * sphereFrequency) * sphereMagnitudeY),
			    0
			);

y값에 sin 함수를 적용함으로써 바운스되도록 할 수 있다.
그 값에 Magnitude 값을 곱하여 튀기는 정도를 조정한다.

/+ sphereMagnitudeY : 이동량 조정을 위한 수치. 튀기는 정도


2. 직교좌표계

  • 2D 좌표계
  • 3D 좌표계
  • 극좌표계

예제

좋은 웹페이지 즐겨찾기