I'm trying to put a cube at the exact location and rotation as the near clipping plane of a camera, and also scale it to be the exact height and width of the near clipping plane.
Through code, I'm getting very close to doing this but it is still a little off from the actual near clipping plane. From researching other people trying to d similar things, I've become even more confused at concepts like normalization and world coordinates that I haven't dealt with much before. Can anyone help?
Here is what I have so far:
float h = 2.0f * 0.3f * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad);
float w = h * cam.aspect;
cube.transform.localScale = new Vector3(w, h, 0.02f);
cube.transform.localRotation = cam.transform.localRotation;
cube.transform.localPosition = new Vector3(cam.transform.localPosition.x - cam.nearClipPlane, cam.transform.localPosition.y, cam.transform.localPosition.z);
Here is a picture: as you can see it is kinda close but not exact..