how to get the actual width and height of the near clipping plane

Hi,
I want to draw a rectangular mesh in front of my camera. For this i want to control its size and position in pixels.
This is what i have so far…
The position of this mesh is at the near clipping plane position + 0.0001f (so its not clipped by the camera).
The orientation is towards the camera.

Now i need the actual width and height of the near clipping plane so i can calculate the dimensions of my mesh.

Does anyone have a idea?

Use “ScreenToWorldPoint (Vector3 (0, 0, camera.nearClipPlane+.0001) )” and “ScreenToWorldPoint (Vector3 (Screen.width-1, Screen.height-1, camera.nearClipPlane+.0001) )”.

–Eric

I dont get it… Can you tell me what it does?

thanx in advance

It gives you the positions of two of the four vertices. You can create the other two using info from those, or use ScreenToWorldPoint again.

–Eric

Heej Eric… Thanx for you’re answer. But i’ve found another solution since i didn’t get your’s properly working…
I sat behind my screen scribbling on some paper and suddenly i saw it… Here is it…

Rect NearPlaneDimensions(Camera cam)
    {
        Rect r = new Rect();
        float a = cam.nearClipPlane;//get length
        float A = cam.fieldOfView * 0.5f;//get angle
        A = A * Mathf.Deg2Rad;//convert tor radians
        float h = (Mathf.Tan(A) * a);//calc height
        float w = (h / cam.pixelHeight) * cam.pixelWidth;//deduct width

        r.xMin = -w;
        r.xMax = w;
        r.yMin = -h;
        r.yMax = h;
        return r;
    }

but if you have a better solution or faster/simpler then i realy lik to know…

thanx again

1 Like