Creating an ARCore powered indoor navigation application in Unity | Raccoons
위 링크 따라해보기 : QR코드로 초기점 인식해서 AR 실내 내비게이션 만드는 과정
- XR 패키지매니저들 깔고, 빌드 설정 하는건 ARfoundation 기초 유튜브 참고
- Plane에 Map 텍스처 넣고
- Sphere로 Indicator 만들고
- MiniMapCamera 하나 만들어서 Indicator에 링크 (카메라 설정은 사진 참고)
-
HelloARController.cs
- CameraTarget(Indicator)의 초기 위치를 AR카메라의 초기위치로 설정하고, 그 이후부터는 프레임마다(Update) FirstPersonCamera(ARcamera)가 움직이는 정도(deltaPosition)을 구해서 CameraTarget의 위치를 움직여주는 스크립트
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR; // EmptyGameObject1에 넣어둠 // MiniMapCamera가 Indicator를 따라가게 만드는 스크립트 public class HelloARController : MonoBehaviour { public Camera FirstPersonCamera; // 1인칭 카메라(AR카메라?) public GameObject CameraTarget; // 카메라 위치 따라갈 타깃 (Indicator) private Vector3 PrevARPosePosition; // AR카메라 위치 private bool Tracking = false; // Start is called before the first frame update void Start() { // 초기 포지션 잡기 PrevARPosePosition = Vector3.zero; } // Update에서 카메라의 이전 위치와 현재 위치 간의 차이를 계산하여 Indicator 위치를 업데이트 하는 데에 사용 void Update() { // UpdateApplicationLifecycle(); -> 이거 뭐야 암것도 없다는데;; // Indicator를 AR카메라 포지션에 따라 움직이게 만들기 Vector3 currentARPosition = FirstPersonCamera.transform.position; // --------------Frame.Pose.position 해야되는데 Frame이라는게 없음 if (!Tracking) { Tracking = true; PrevARPosePosition = FirstPersonCamera.transform.position; // --------------Frame.Pose.position 해야되는데 Frame이라는게 없음 } // Remember the previous position so we can apply deltas Vector3 deltaPosition = currentARPosition - PrevARPosePosition; PrevARPosePosition = currentARPosition; if (CameraTarget != null) { // The initial forward vector of the sphere must be aligned with the initial camera direction in the XZ plane. // We apply translation only in the XZ plane. CameraTarget.transform.Translate(deltaPosition.x, 0.0f, deltaPosition.z); // Set the pose rotation to be used in the CameraFollow script : 화살표 방향 // FirstPersonCamera.GetComponent<ArrowDirection>().targetRot = FirstPersonCamera.transform.rotation; } } }
-
코드 설명
- UpdateApplicationLifecycle(); 를 넣으면 오류 떠서 그냥 지움
- Frame.Pose.position 의 Frame이 옛날 버전 ARCore에만 있던 클래스라 못씀
- 그냥 transform 써서 AR카메라의 위치를 가져옴
-
결과


