1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-16 18:01:40 +00:00

Client map: do frustum culling via planes (#12710)

This commit is contained in:
DS 2022-09-18 15:28:53 +02:00 committed by GitHub
parent a428a0cf37
commit c9ed059d91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 113 additions and 42 deletions

View file

@ -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;