using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Chapter03 : MonoBehaviour {
public float rotateSpeed = 1f;
public float scrollSpeed = 200f;
public Transform pivot;
[System.Serializable]
public class SphericalCoordinates
{
public float _radius, _azimuth, _elevation;
public float radius
{
get { return _radius; }
private set
{
_radius = Mathf.Clamp( value, _minRadius, _maxRadius );
}
}
public float azimuth
{
get { return _azimuth; }
private set
{
_azimuth = Mathf.Repeat( value, _maxAzimuth - _minAzimuth );
}
}
public float elevation
{
get{ return _elevation; }
private set
{
_elevation = Mathf.Clamp( value, _minElevation, _maxElevation );
}
}
public float _minRadius = 3f;
public float _maxRadius = 20f;
public float minAzimuth = 0f;
private float _minAzimuth;
public float maxAzimuth = 360f;
private float _maxAzimuth;
public float minElevation = 0f;
private float _minElevation;
public float maxElevation = 90f;
private float _maxElevation;
public SphericalCoordinates(){}
public SphericalCoordinates(Vector3 cartesianCoordinate)
{
_minAzimuth = Mathf.Deg2Rad * minAzimuth;
_maxAzimuth = Mathf.Deg2Rad * maxAzimuth;
_minElevation = Mathf.Deg2Rad * minElevation;
_maxElevation = Mathf.Deg2Rad * maxElevation;
radius = cartesianCoordinate.magnitude;
azimuth = Mathf.Atan2(cartesianCoordinate.z, cartesianCoordinate.x);
elevation = Mathf.Asin(cartesianCoordinate.y / radius);
}
public Vector3 toCartesian
{
get
{
float t = radius * Mathf.Cos(elevation);
return new Vector3(t * Mathf.Cos(azimuth), radius * Mathf.Sin(elevation), t * Mathf.Sin(azimuth));
}
}
public SphericalCoordinates Rotate(float newAzimuth, float newElevation){
azimuth += newAzimuth;
elevation += newElevation;
return this;
}
public SphericalCoordinates TranslateRadius(float x) {
radius += x;
return this;
}
}
public SphericalCoordinates sphericalCoordinates;
private List<Vector3> triangleVertices = new List<Vector3>();
void Start () {
sphericalCoordinates = new SphericalCoordinates(transform.position);
transform.position = sphericalCoordinates.toCartesian + pivot.position;
Mesh mesh = pivot.gameObject.GetComponent<MeshFilter>().mesh;
for (int i = 0; i < mesh.vertices.Length; i++)
{
if (triangleVertices.Count < 3) {
triangleVertices.Add(mesh.vertices[i]);
}
}
}
void Update () {
DrawCameraLine ();
float kh, kv, mh, mv, h, v;
kh = Input.GetAxis( "Horizontal" );
kv = Input.GetAxis( "Vertical" );
bool anyMouseButton = Input.GetMouseButton(0) | Input.GetMouseButton(1) | Input.GetMouseButton(2);
mh = anyMouseButton ? Input.GetAxis( "Mouse X" ) : 0f;
mv = anyMouseButton ? Input.GetAxis( "Mouse Y" ) : 0f;
h = kh * kh > mh * mh ? kh : mh;
v = kv * kv > mv * mv ? kv : mv;
if (h * h > Mathf.Epsilon || v * v > Mathf.Epsilon) {
transform.position
= sphericalCoordinates.Rotate(h * rotateSpeed * Time.deltaTime, v * rotateSpeed * Time.deltaTime).toCartesian + pivot.position;
}
float sw = -Input.GetAxis("Mouse ScrollWheel");
if (sw * sw > Mathf.Epsilon) {
transform.position = sphericalCoordinates.TranslateRadius(sw * Time.deltaTime * scrollSpeed).toCartesian + pivot.position;
}
transform.LookAt(pivot.position);
}
void DrawCameraLine() {
Debug.DrawLine(pivot.position, pivot.transform.forward * 2, Color.blue);
Vector3 cameraPoint = transform.position + transform.forward * 5;
Vector3 edge1 = triangleVertices [1] - triangleVertices [0];
Vector3 edge2 = cameraPoint - triangleVertices [1];
Vector3 edge3 = triangleVertices [2] - triangleVertices [1];
Vector3 edge4 = cameraPoint - triangleVertices [2];
Vector3 edge5 = triangleVertices [0] - triangleVertices [2];
Vector3 edge6 = cameraPoint - triangleVertices [0];
Vector3 cp1 = Vector3.Cross (edge1, edge2);
Vector3 cp2 = Vector3.Cross (edge3, edge4);
Vector3 cp3 = Vector3.Cross (edge5, edge6);
if (Vector3.Dot (cp1, cp2) > 0 && Vector3.Dot (cp1, cp3) > 0) {
Debug.DrawLine (transform.position, cameraPoint, Color.red);
} else {
Debug.DrawLine (transform.position, cameraPoint, Color.green);
}
}
}
이게 그 카메라 너희들이 온라인겜할때 화면 돌리는 코드다
이 정도하면서 개발 한다고 말하는거지 너희들?
ㅋㅋㅋ
당연한 걸 ㅇㅅㅇ
올~
azimuth 가 뭐죠?
방위각
pitch roll yaw 는?
그건 저도 잘
아 그거 ㅋㅋ 3방향 회전
ellipsoid 의 표면 좌표 거리 구할 수 있음?
삼각함수 돌려서 하는건 다 할수 있을듯. 용어는 나도 이제 막 배우는 입장이라 모름
응 아냐.
아직도 수학 많이 남았는데 나오것지 뭐
안나올껄? ㅋㅋ
게임에서 쓰이는거면 나오지 않을까?
게임에 안쓰이는건 없지만, 잘 안쓰이는건 있지. 그런건 안나와.
니가 게임프로그래밍의 고수가 된다면 ( 물론 그럴리는 없겠지만 ) 깨닫게 되겠지... 이정도면 지구정복도 가능할것 같은데... 그런거임.
뭐 배우면 다 아는거지
키둑키둑.
소년이로학난성이라오.
몰라 그런 한자어
니가 34년을 놀고 먹은것보다 앞으로 34년을 놀고 먹기 더 좋단 말임.
왜냐하면 시간이 흐르는 체감속도가 훨씬 빨라지거든.
아하 그래
엥 뭐지 PC 버전이랑 모바일이랑 XSS 필터가 다르게 적용되네? 진짜 병신같다 ㅋㅋ
복붙만하고 이해를 못하는데 뭔 ㅋㅋ
착각일수도 있으니 이따 실험해봐야징
아니 라이브러리 메뉴얼 펼처서 함수 명개만 알면 10줄이내로 되는건 니같은 취미생활하는애가 젤 짜증나.
아하 저게 라이브러리로 되있음?
엔진엔 저런거 라이브러리화 되있지 않나, 여튼