-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathARCameraUtil.cs
More file actions
31 lines (25 loc) · 817 Bytes
/
ARCameraUtil.cs
File metadata and controls
31 lines (25 loc) · 817 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
30
31
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ARCameraUtil : MonoBehaviour {
public static Mesh CameraBackplate(Camera camera, float distance){
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[4];
Vector2[] uv = new Vector2[]{
new Vector2(0f, 0f),
new Vector2(1f, 0f),
new Vector2(0f, 1f),
new Vector2(1f, 1f)
};
int[] triangles = new int[6]{0, 3, 1, 0, 2, 3};
for (int i = 0; i < 4; i++) {
vertices [i] = camera.ViewportPointToRay (new Vector3 (uv[i].x, uv[i].y, 0f)).direction;
vertices [i] = Quaternion.Inverse (camera.transform.rotation) * vertices [i];
vertices [i] = vertices [i] * (1f / vertices [i].z) * distance;
}
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
return mesh;
}
}