0

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..

enter image description here

Jackie
  • 19
  • 4
  • Id say its pivot point is exactly on the clipping plane... its just still unit wide so you see half of it – BugFinder Mar 03 '20 at 15:46
  • @BugFinder it seems to be offset on the y and z axis by a bit and not directly at the location of the near clipping plane, but I want it to be exact... – Jackie Mar 03 '20 at 15:49

0 Answers0