Pryme8 Posted October 4, 2017 Share Posted October 4, 2017 So, I can definitely figure this math out but I was looking to see if there is a quick trick anyone can think of to make a plane fit exactly into the camera's frustum. IE if I have a camera at (0,0,-10) and a view port that is 1:1 or even 1:1.5 ratio what size would a plane need to be to cover the whole viewport... (I know I know simple math), I was hoping for a quick method if anyone has one though, no rush its not anything I actively need but would be useful for a side projects I am doing. Basically what ShaderToy is doing. *EDIT* Ill prolly just use this https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html ShiftedClock 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted October 4, 2017 Share Posted October 4, 2017 well, assuming that d is the distance from the camera to your plane, fov the camera fov angle and y the plane half height (and assuming that the frustum cam.minZ is still 1), then y = d * tan(fov / 2) and if x the half the plane width x = y * camera.aspectRatio if I remember well ShiftedClock and Pryme8 1 1 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 4, 2017 Share Posted October 4, 2017 Unless, you do not want to care. Switch to orthogonal camera an distance as long as z is neg. Would not plane be, wait I'll check. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 4, 2017 Share Posted October 4, 2017 window.innerWidth & window.innerHeight Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted October 4, 2017 Author Share Posted October 4, 2017 @JCPalmer is that to get the aspectRatio? That's what I am assuming but was wondering about your input. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted October 4, 2017 Author Share Posted October 4, 2017 @jerome, @JCPalmer : Thanks guys! https://playground.babylonjs.com/#UJWGY4 Your math off the top of you head was close homie! not halfsizing the fov was the only change. jerome 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted October 5, 2017 Share Posted October 5, 2017 some little fixes imho : https://playground.babylonjs.com/#UJWGY4#1 Pryme8, RaananW and ShiftedClock 3 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 5, 2017 Share Posted October 5, 2017 18 hours ago, Pryme8 said: @JCPalmer is that to get the aspectRatio? That's what I am assuming but was wondering about your input. No simpler than that. From a lack of math standpoint, I win!!! I did switch to asking engine for the width, but no fov, tangent() calls, & my camera distance must only be less than the max z Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 6, 2017 Share Posted October 6, 2017 whoops, forgot to show the supporting playground https://playground.babylonjs.com/#UJWGY4#2 Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted October 6, 2017 Author Share Posted October 6, 2017 That's awesome! Way Clean! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.