I'm working on a vector map renderer. I want to calculate the far plane for a protective transformation, based on the yaw, pitch, roll and height of the camera above the map. Yaw (looking to the left and right), pitch (the direction you also have on Google Maps e.g.) and roll (rotation around Y axis in this case) are limited to 30°.
I recorded a video here of the movements users are able to do: https://youtu.be/NejhvULvhys
As you can see there is some clipping, which demonstrates that the calculation of the far distance field is not correct yet. Though, please note that I do have a working version if you only use pitch and roll. So this question is about: How do I calculate the far distance plane if I not only want pitch and roll?
I prepared a geogebra drawing to explain the current calculations. It is not that simple because there are not that many right-angles: https://www.geogebra.org/m/cvhtwhng
In that diagram:
- height of the blue triangle is the height of the camera.
- Roll is not really relevant as it does not influence the far distance plane.
- Yaw and pitch are equal to "pitch" in the diagram. Note that this is only a 2d cut of the real situation which is 3d. So the geogebra diagram is a simplification.
Finally, I have some code to share.
- The implementation of the geogebra paramter d: https://github.com/maplibre/maplibre-rs/blob/31c3fa7ebc5dd47a9f298e787b858e2059aa4c5d/maplibre/src/render/view_state.rs#L86-L93
- Alternative implementation for the same above (adds yaw and pitch together and uses that as “pitch” from geogebra: https://github.com/maplibre/maplibre-rs/blob/31c3fa7ebc5dd47a9f298e787b858e2059aa4c5d/maplibre/src/render/view_state.rs#L144-L149)
- Calculation of the camera height, above ground: https://github.com/maplibre/maplibre-rs/blob/31c3fa7ebc5dd47a9f298e787b858e2059aa4c5d/maplibre/src/render/view_state.rs#L194-L203
- This function experiments with adding together different additional heights calculated from the “geogebra function": https://github.com/maplibre/maplibre-rs/blob/31c3fa7ebc5dd47a9f298e787b858e2059aa4c5d/maplibre/src/render/view_state.rs#L205-L265
- The final view projection matrix is built here: https://github.com/maplibre/maplibre-rs/blob/31c3fa7ebc5dd47a9f298e787b858e2059aa4c5d/maplibre/src/render/view_state.rs#L270-L326
I have tried a few method to calculate the far distance plane based on the current pitch and yaw. Unfortunately, I have not gained confidence whether the correct is calculated. I am certain that the geogebra calculations are correct as they work well for the "only pitch" case. Though, the combination of both seems more involved.
Let me know if something is unclear!