0Rae / CapstoneViewer1.7

1 stars 0 forks source link

기술조사4. Unity Raycasters #7

Open 0Rae opened 7 years ago

0Rae commented 7 years ago

The Event System needs a method for detecting where current input events need to be sent to, and this is provided by the Raycasters. Given a screen space position they will collect all potential targets, figure out if they are under the given position, and then return the object that is closest to the screen. There are a few types of Raycasters that are provided: EventSystem이 현재의 입력 이벤트를 보내야 하는 경우, 이를 검출하는 수단이 필요하며, 이것은 Raycasters에 의해 제공됩니다. 이러한 모든 잠재적인 대상을 수집하는 화면 공간 위치를 받아, 그것이 주어진 위치 하에 있는지를 파악하고, 그 후, 스크린에 가장 가까운 오브젝트를 반환합니다. 제공되는 Raycasters에는 몇 가지 종류가 있습니다:

0Rae commented 7 years ago

Graphic Raycaster - Used for UI elements, lives on a Canvas and searches within the canvas GraphicRaycaster - UI 요소로 사용하며, 캔버스에서 활용되어 캔버스 안을 검색합니다

Physics 2D Raycaster - Used for 2D physics elements Physics2DRaycaster - 2D 물리 요소에 사용됩니다

Physics Raycaster - Used for 3D physics elements PhysicsRaycaster - 3D 물리 요소에 사용됩니다

When a Raycaster is present and enabled in the scene it will be used by the Event System whenever a query is issued from an Input Module. Raycaster이 씬에 존재하고 활성화되어 있는 경우에는 쿼리가 InputModule에서 발행될 때마다 EventSystem을 사용합니다.

If multiple Raycasters are used then they will all have casting happen against them and the results will be sorted based on distance to the elements. 여러 Raycasters는 그 후 사용될 때 모든 캐스팅이 그들에게 대하여 실행되어야 하며, 그 결과는 요소까지의 거리에 따라 정렬됩니다.

0Rae commented 7 years ago

Physics Raycaster 물리적인 레이캐스터

The Raycaster raycasts against 3D objects in the scene. This allows messages to be sent to 3D physics objects that implement event interfaces. 이 Raycaster는 장면에서 3D 오브젝트에 대해 레이캐스팅(raycasting)합니다. 이를 이용하여 이벤트 인터페이스를 구현하고 있는 3D 물리 오브젝트에 메시지를 보낼 수 있습니다.

Properties 프로퍼티

Property: Function: 프로퍼티: 함수:

Depth Get the depth of the configured camera. 깊이 구성된 카메라의 깊이를 구합니다.

Event Camera Get the camera that is used for this module. 이벤트 카메라 이 모듈에 사용되는 카메라를 가져옵니다.

Event Mask Logical and of Camera mask and eventMask. 이벤트 마스크 카메라 마스크와 eventMask의 논리.

Final Event Mask Logical and of Camera mask and eventMask. 최종 이벤트 마스크 카메라 마스크와 eventMask의 논리.

0Rae commented 7 years ago

Mobile Device Input 모바일 장치 입력

On mobile devices, the Input class offers access to touchscreen, accelerometer and geographical/location input. 모바일 장치에서 입력 클래스는 터치 스크린, 가속도계 및 지리적/위치 입력에 대한 액세스를 제공합니다.

Access to keyboard on mobile devices is provided via the iOS keyboard. iOS 키보드를 통해 모바일 장치의 키보드에 액세스를 할 수 있습니다.

Multi-Touch Screen 멀티-터치 스크린

The iPhone and iPod Touch devices are capable of tracking up to five fingers touching the screen simultaneously. You can retrieve the status of each finger touching the screen during the last frame by accessing the Input.touches property array. iPhone 및 iPod Touch 장치는 최대 5개의 손가락을 동시에 터치할 수 있습니다. Input.touches 속성 배열에 액세스하여 마지막 프레임이 작동할 동안 화면을 터치하는 각 손가락의 상태를 검색할 수 있습니다.

Android devices don’t have a unified limit on how many fingers they track. Instead, it varies from device to device and can be anything from two-touch on older devices to five fingers on some newer devices. 안드로이드 기기에는 추적하는 손가락의 수에 대해 통일된 제한이 없습니다. 대신 장치마다 다르며 구형 장치의 2번 터치부터 일부 최신 장치의 5번 터치까지 가능합니다.

0Rae commented 7 years ago

Each finger touch is represented by an Input.Touch data structure: 각 손가락 터치는 Input.Touch 데이터 구조로 표현됩니다:

Property: Function: 프로퍼티: 함수:

fingerId The unique index for a touch. fingerId 터치의 고유 인덱스.

position The screen position of the touch. 위치 터치 스크린의 위치.

deltaPosition The screen position change since the last frame. deltaPosition 마지막 프레임 이후의 화면 위치 변경.

deltaTime Amount of time that has passed since the last state change. deltaTime 마지막 상태 변경 이후 경과한 시간.

0Rae commented 7 years ago

tapCount The iPhone/iPad screen is able to distinguish quick finger taps by the user. This counter will let you know how many times the user has tapped the screen without moving a finger to the sides. Android devices do not count number of taps, this field is always 1. tapCount iPhone/iPad 화면은 사용자가 빠르게 손가락으로 터치해도 탭을 구분할 수 있습니다. 이 카운터는 사용자가 손가락을 옆으로 움직이지 않고 화면을 몇 번 터치했는지 알려줍니다. 안드로이드 기기는 탭수를 세지 않습니다. 이 필드는 항상 1입니다.

phase Describes so called “phase” or the state of the touch. It can help you determine if the touch just began, if user moved the finger or if they just lifted the finger. 펄스 "펄스" 또는 터치 상태를 설명합니다. 손가락이 방금 시작되었는지, 사용자가 손가락을 움직였는지 또는 손가락을 들었는지 결정하는데 도움이 됩니다.

Phase can be one of the following: 단계는 다음 중 하나일 수 있습니다:

Began A finger just touched the screen. 손가락으로 화면을 만졌을 경우를 나타냅니다.

Moved A finger moved on the screen. 손가락 터치가 화면에서 움직인 경우를 나타냅니다.

Stationary A finger is touching the screen but hasn’t moved since the last frame. 손가락이 화면을 터치하고 있지만 마지막 프레임 이후로 이동하지 않은 경우를 나타냅니다.

Ended A finger was lifted from the screen. This is the final phase of a touch. 사용자가 화면에서 손가락을 뗀 경우를 나타낸다. 터치의 마지막 단계를 나타냅니다.

Canceled The system cancelled tracking for the touch, as when (for example) the user puts the device to their face or more than five touches happened simultaneously. This is the final phase of a touch. 사용자의 얼굴이 장치에 가까이 오거나 5개 이상의 터치가 동시에 발생하는 경우, 해당 시스템이 터치의 추적을 취합니다. 터치의 마지막 단계를 나타냅니다.

0Rae commented 7 years ago

Following is an example script which will shoot a ray whenever the user taps on the screen: 다음은 사용자가 화면을 터치할 때 마다 레이캐스트를 발사하는 예제 스크립트 입니다:

var particle : GameObject; function Update () { for (var touch : Touch in Input.touches) { if (touch.phase == TouchPhase.Began) { // Construct a ray from the current touch coordinates // 현재 터치 좌표에서 레이캐스트 생성 var ray = Camera.main.ScreenPointToRay (touch.position); if (Physics.Raycast (ray)) { // Create a particle if hit // 부딪쳤을 경우 입자 생성 Instantiate (particle, transform.position, transform.rotation); } } } }

0Rae commented 7 years ago

Mouse Simulation 마우스 시뮬레이션

On top of native touch support Unity iOS/Android provides a mouse simulation. You can use mouse functionality from the standard Input class. Note that iOS/Android devices are designed to support multiple finger touch. Using the mouse functionality will support just a single finger touch. Also, finger touch on mobile devices can move from one area to another with no movement between them. Mouse simulation on mobile devices will provide movement, so is very different compared to touch input. The recommendation is to use the mouse simulation during early development but to use touch input as soon as possible. 고유 터치 지원 Unity iOS / Android는 마우스 시뮬레이션을 제공합니다. 표준 Input 클래스의 마우스 기능을 사용할 수 있습니다. iOS / Android 기기는 여러 손가락 터치를 지원하도록 설계되었습니다. 마우스 기능을 사용하면 손가락 하나만 지탱할 수 있습니다. 또한 모바일 장치의 손가락 터치는 이동하지 않고 한 영역에서 다른 영역으로 이동할 수 있습니다. 모바일 장치의 마우스 시뮬레이션은 움직임을 제공하므로 터치 입력과 비교할 때 매우 다릅니다. 권장 사항은 초기 개발 중에 마우스 시뮬레이션을 사용하는 것이지만 최대한 빨리 터치 입력을 사용하는 것입니다.

0Rae commented 7 years ago

Accelerometer 가속도계

As the mobile device moves, a built-in accelerometer reports linear acceleration changes along the three primary axes in three-dimensional space. Acceleration along each axis is reported directly by the hardware as G-force values. A value of 1.0 represents a load of about +1g along a given axis while a value of –1.0 represents –1g. If you hold the device upright (with the home button at the bottom) in front of you, the X axis is positive along the right, the Y axis is positive directly up, and the Z axis is positive pointing toward you. 모바일 장치가 움직일 때 내장 된 가속도계는 3차원 공간에서 3개의 기본 축을 따라 선형 가속도 변화를 보고합니다. 각 축을 따른 가속도는 하드웨어에 의해 직접 G-force 값으로보고됩니다. 값 1.0은 주어진 축을 따라 약 + 1g의 하중을 나타내고 -1.0의 값은 -1g를 나타냅니다. 장치를 똑바로 세우고 (맨 아래 홈 단추 포함) 앞면에 X 축이 양수이고 Y 축이 양수이고 Z 축이 양쪽을 가리키고 있습니다

You can retrieve the accelerometer value by accessing the Input.acceleration property. Input.acceleration 속성에 액세스하여 가속도계 값을 검색 할 수 있습니다.

0Rae commented 7 years ago

The following is an example script which will move an object using the accelerometer: 다음은 가속도계를 사용하여 객체를 움직이는 예제 스크립트입니다:

var speed = 10.0; function Update () { var dir : Vector3 = Vector3.zero;

// we assume that the device is held parallel to the ground
// 장치가지면과 평행을 유지한다고 가정
    // and the Home button is in the right hand
// 홈버튼이 오른쪽에 있다

    // remap the device acceleration axis to game coordinates:
// 장치 가속 축을 게임 좌표로 다시 매핑:
    // 1) XY plane of the device is mapped onto XZ plane
// 1) 장치의 XY 평면은 XY 평면에 매핑
    // 2) rotated 90 degrees around Y axis
// 2) Y축을 중심으로 90도 회전
    dir.x = -Input.acceleration.y;
    dir.z = Input.acceleration.x;

    // clamp acceleration vector to the unit sphere
// 단위 구에 가속도 벡터를 더한다
    if (dir.sqrMagnitude > 1)
    dir.Normalize();

    // Make it move 10 meters per second instead of 10 meters per frame...
// 프레임 당 10미터가 아닌 초당 10미터로 이동한다...
    dir *= Time.deltaTime;

    // Move object
// 오브젝트를 이동
    transform.Translate (dir * speed);

}

0Rae commented 7 years ago

Low-Pass Filter 로우-패스 필터

Accelerometer readings can be jerky and noisy. Applying low-pass filtering on the signal allows you to smooth it and get rid of high frequency noise. 가속도계 판독값에 예상치못하게 노이즈가 생깁니다. 신호에 로우 패스 필터링을 적용하면 노이즈를 제거하고 고주파 노이즈를 제거 할 수 있습니다.

The following script shows you how to apply low-pass filtering to accelerometer readings: 다음 스크립트는 가속도계 판독값에 로우 패스 필터링을 적용하는 방법을 보여줍니다:

var AccelerometerUpdateInterval : float = 1.0 / 60.0; var LowPassKernelWidthInSeconds : float = 1.0;

private var LowPassFilterFactor : float = AccelerometerUpdateInterval / LowPassKernelWidthInSeconds; // 비꼰다 (노이즈) private var lowPassValue : Vector3 = Vector3.zero; function Start () { lowPassValue = Input.acceleration; }

function LowPassFilterAccelerometer() : Vector3 { lowPassValue = Vector3.Lerp(lowPassValue, Input.acceleration, LowPassFilterFactor); return lowPassValue; }

The greater the value of LowPassKernelWidthInSeconds, the slower the filtered value will converge towards the current input sample (and vice versa). LowPassKernelWidthInSeconds의 값이 클수록 필터링 된 값이 현재 입력 샘플로 수렴되는 속도가 느려집니다.

0Rae commented 7 years ago

The greater the value of LowPassKernelWidthInSeconds, the slower the filtered value will converge towards the current input sample (and vice versa). LowPassKernelWidthInSeconds의 값이 클수록 필터링 된 값이 현재 입력 샘플로 수렴되는 속도가 느려집니다.

I’d like as much precision as possible when reading the accelerometer. What should I do? 나는 가속도계를 읽을 때 가능한 많은 정밀도를 원합니다. 이럴 땐 어떻게 해야 할까요?

Reading the Input.acceleration variable does not equal sampling the hardware. Put simply, Unity samples the hardware at a frequency of 60Hz and stores the result into the variable. In reality, things are a little bit more complicated – accelerometer sampling doesn’t occur at consistent time intervals, if under significant CPU loads. As a result, the system might report 2 samples during one frame, then 1 sample during the next frame. Input.acceleration 변수를 읽는 것은 하드웨어 샘플링과 동일하지 않습니다. 간단히 말해 유니티는 60Hz의 주파수로 하드웨어를 샘플링하고 그 결과를 변수에 저장합니다. 실제로 상황은 좀 더 복잡합니다. 가속도계 샘플링은 상당한 CPU 부하가 걸리는 경우 일관된 시간 간격으로 발생하지 않습니다. 결과적으로 시스템은 한 프레임 동안 두 개의 샘플을 보고한 후 다음 프레임 동안 한개의 샘플을 보고할 수 있습니다.

0Rae commented 7 years ago

You can access all measurements executed by accelerometer during the frame. The following code will illustrate a simple average of all the accelerometer events that were collected within the last frame: 프레임 중에 가속도계로 실행 된 모든 측정에 액세스 할 수 있습니다. 다음 코드는 마지막 프레임 내에서 수집 된 모든 가속도계 이벤트의 단순 평균을 보여줍니다.

var period : float = 0.0; var acc : Vector3 = Vector3.zero; for (var evnt : iPhoneAccelerationEvent in iPhoneInput.accelerationEvents) { acc += evnt.acceleration evnt.deltaTime; period += evnt.deltaTime; } if (period > 0) acc = 1.0/period; return acc;