|
|
|
|
|
|
using System; |
|
|
|
using UnityEditorInternal; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Experimental.Rendering; |
|
|
|
using UnityEngine.Experimental.Rendering.HDPipeline; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
var viewerCamera = Camera.current; |
|
|
|
var c = Gizmos.color; |
|
|
|
var m = Gizmos.matrix; |
|
|
|
|
|
|
|
float nearClipPlane, farClipPlane, aspect, fov; |
|
|
|
Color backgroundColor; |
|
|
|
|
|
|
Matrix4x4 worldToCamera, projection; |
|
|
|
Matrix4x4 worldToCameraRHS, projection; |
|
|
|
out worldToCamera, out projection, |
|
|
|
out worldToCameraRHS, out projection, |
|
|
|
// TODO: draw frustrum gizmo
|
|
|
|
#if false
|
|
|
|
// TODO: fix frustrum drawing
|
|
|
|
|
|
|
|
var viewProj = projection * worldToCameraRHS; |
|
|
|
var invViewProj = viewProj.inverse; |
|
|
|
|
|
|
|
var near = new[] |
|
|
|
{ |
|
|
|
new Vector3(-1, -1, -1), |
|
|
|
new Vector3(-1, 1, -1), |
|
|
|
new Vector3(1, 1, -1), |
|
|
|
new Vector3(1, -1, -1), |
|
|
|
}; |
|
|
|
|
|
|
|
var far = new[] |
|
|
|
{ |
|
|
|
new Vector3(-1, -1, 1), |
|
|
|
new Vector3(-1, 1, 1), |
|
|
|
new Vector3(1, 1, 1), |
|
|
|
new Vector3(1, -1, 1), |
|
|
|
}; |
|
|
|
|
|
|
|
for (var i = 0; i < near.Length; ++i) |
|
|
|
{ |
|
|
|
var p = invViewProj * new Vector4(near[i].x, near[i].y, near[i].z, 1); |
|
|
|
var w = Mathf.Abs(p.w); |
|
|
|
near[i].Set(p.x / w, p.y / w, p.z / w); |
|
|
|
} |
|
|
|
|
|
|
|
for (var i = 0; i < far.Length; ++i) |
|
|
|
{ |
|
|
|
var p = invViewProj * new Vector4(far[i].x, far[i].y, far[i].z, 1); |
|
|
|
var w = Mathf.Abs(p.w); |
|
|
|
far[i].Set(p.x / w, p.y / w, p.z / w); |
|
|
|
} |
|
|
|
|
|
|
|
Gizmos.color = k_GizmoCamera; |
|
|
|
for (var i = 0; i < 4; ++i) |
|
|
|
{ |
|
|
|
Gizmos.DrawLine(near[i], near[(i + 1) % 4]); |
|
|
|
Gizmos.DrawLine(far[i], far[(i + 1) % 4]); |
|
|
|
Gizmos.DrawLine(near[i], far[i]); |
|
|
|
} |
|
|
|
Gizmos.matrix = m; |
|
|
|
#endif
|
|
|
|
|
|
|
|
Gizmos.DrawSphere(capturePosition, HandleUtility.GetHandleSize(capturePosition) * 0.2f); |
|
|
|
Gizmos.color = c; |
|
|
|