lecture6
The spherical polar coordinate system
Spherical Coordinates — from Wolfram MathWorld
theta to be the azimuthal angle in the xy-plane from the x-axis with 0<=theta<2pi (denoted lambda when referred to as the longitude)
phi to be the polar angle (also known as the zenith angle and colatitude, with phi=90 degrees-delta where delta is the latitude) from the positive z-axis with 0<=phi<=pi
r to be distance (radius) from a point to the origin.
KeyboardMouse
KeyboardMouse
– Draw Circle by GLPrimitiveTypes (Space-Key to change types)
– Draw Quad With Mouse Clicking
– Free-Draw Line With Mouse Dragging
– Rotate Cube With Mouse Horizontal/Vertical Movement
– Select Object With Mouse Clicking (mouse clicking on the empty space to unselect)
How to convert the mouse position to world space in Unity (2D + 3D)
Unity Camera.ScreenPointToRay
Unity – Scripting API: Camera.ScreenPointToRay (unity3d.com)
Camera 클래스의 ScreenPointToRay 함수는 스크린 좌표를 카메라에서 시작하여 스크린 좌표에 해당하는 3차원의 좌표로 Ray를 생성해줌.
void Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitData;
if(Physics.Raycast(ray, out hitData, 1000))
{
worldPosition = hitData.point;
}
}
Unity Camera.ScreenToWorldPoint
Unity – Scripting API: Camera.ScreenToWorldPoint (unity3d.com)
Camera 클래스의 ScreenToWorldPoint 함수는 스크린 좌표를 카메라가 찍고있는 3차원의 좌표로 바꿔줌.
void OnGUI() { Vector3 point = new Vector3(); Event currentEvent = Event.current; Vector3 mousePos = new Vector3(); // Get the mouse position from Event. // Note that the y position from Event is inverted. (GUI space -> Screen space) mousePos.x = currentEvent.mousePosition.x; mousePos.y = Camera.main.pixelHeight - currentEvent.mousePosition.y; mousePos.z = Camera.main.nearClipPlane; point = Camera.main.ScreenToWorldPoint(mousePos); GUILayout.BeginArea(new Rect(20, 20, 250, 120)); GUILayout.Label("Screen pixels: " + cam.pixelWidth + ":" + cam.pixelHeight); GUILayout.Label("Mouse position: " + mousePos); GUILayout.Label("World position: " + point.ToString("F3")); GUILayout.EndArea(); }
lecture5
lecture5
lecture5-ch3