forked from TouchScript/TouchScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectionUtils.cs
More file actions
29 lines (27 loc) · 892 Bytes
/
Copy pathProjectionUtils.cs
File metadata and controls
29 lines (27 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* @author Valentin Simonov / http://va.lent.in/
*/
using UnityEngine;
namespace TouchScript.Utils
{
/// <summary>
/// Projection utils.
/// </summary>
public class ProjectionUtils
{
/// <summary>
/// Projects a screen point to a plane.
/// </summary>
/// <param name="position">Screen point.</param>
/// <param name="camera">The camera.</param>
/// <param name="projectionPlane">The projection plane.</param>
/// <returns></returns>
public static Vector3 CameraToPlaneProjection(Vector2 position, Camera camera, Plane projectionPlane)
{
var ray = camera.ScreenPointToRay(position);
var relativeIntersection = 0f;
projectionPlane.Raycast(ray, out relativeIntersection);
return ray.origin + ray.direction*relativeIntersection;
}
}
}