diff options
author | DS <vorunbekannt75@web.de> | 2022-09-18 15:28:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-18 15:28:53 +0200 |
commit | c9ed059d9170f2f7f662cbb59e6009fd54c8ed3f (patch) | |
tree | 99b6adee12a0e76b3f2a25e2a6e5975bfaeaac28 /src/client/camera.h | |
parent | a428a0cf37581a35f9c4f81c2e71633e6cc3dbb9 (diff) | |
download | minetest-c9ed059d9170f2f7f662cbb59e6009fd54c8ed3f.tar.xz |
Client map: do frustum culling via planes (#12710)
Diffstat (limited to 'src/client/camera.h')
-rw-r--r-- | src/client/camera.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/client/camera.h b/src/client/camera.h index cbf248d97..1018af55a 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/tile.h" #include <ICameraSceneNode.h> #include <ISceneNode.h> +#include <plane3d.h> +#include <array> #include <list> #include "util/Optional.h" @@ -133,6 +135,23 @@ public: return MYMAX(m_fov_x, m_fov_y); } + // Returns a lambda that when called with an object's position and bounding-sphere + // radius (both in BS space) returns true if, and only if the object should be + // frustum-culled. + auto getFrustumCuller() const + { + return [planes = getFrustumCullPlanes(), + camera_offset = intToFloat(m_camera_offset, BS) + ](v3f position, f32 radius) { + v3f pos_camspace = position - camera_offset; + for (auto &plane : planes) { + if (plane.getDistanceTo(pos_camspace) > radius) + return true; + } + return false; + }; + } + // Notify about new server-sent FOV and initialize smooth FOV transition void notifyFovChange(); @@ -190,6 +209,10 @@ public: inline void addArmInertia(f32 player_yaw); private: + // Use getFrustumCuller(). + // This helper just exists to decrease the header's number of includes. + std::array<core::plane3d<f32>, 4> getFrustumCullPlanes() const; + // Nodes scene::ISceneNode *m_playernode = nullptr; scene::ISceneNode *m_headnode = nullptr; |