aboutsummaryrefslogtreecommitdiff
path: root/src/client/camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/camera.cpp')
-rw-r--r--src/client/camera.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp
index 994497224..e2f50e4a6 100644
--- a/src/client/camera.cpp
+++ b/src/client/camera.cpp
@@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "fontengine.h"
#include "script/scripting_client.h"
#include "gettext.h"
+#include <SViewFrustum.h>
#define CAMERA_OFFSET_STEP 200
#define WIELDMESH_OFFSET_X 55.0f
@@ -318,6 +319,9 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
v3f old_player_position = m_playernode->getPosition();
v3f player_position = player->getPosition();
+ f32 yaw = player->getYaw();
+ f32 pitch = player->getPitch();
+
// This is worse than `LocalPlayer::getPosition()` but
// mods expect the player head to be at the parent's position
// plus eye height.
@@ -342,7 +346,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
// Set player node transformation
m_playernode->setPosition(player_position);
- m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0));
+ m_playernode->setRotation(v3f(0, -1 * yaw, 0));
m_playernode->updateAbsolutePosition();
// Get camera tilt timer (hurt animation)
@@ -379,7 +383,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
// Set head node transformation
eye_offset.Y += cameratilt * -player->hurt_tilt_strength + fall_bobbing;
m_headnode->setPosition(eye_offset);
- m_headnode->setRotation(v3f(player->getPitch(), 0,
+ m_headnode->setRotation(v3f(pitch, 0,
cameratilt * player->hurt_tilt_strength));
m_headnode->updateAbsolutePosition();
}
@@ -463,6 +467,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
// Set camera node transformation
m_cameranode->setPosition(my_cp-intToFloat(m_camera_offset, BS));
+ m_cameranode->updateAbsolutePosition();
m_cameranode->setUpVector(abs_cam_up);
// *100.0 helps in large map coordinates
m_cameranode->setTarget(my_cp-intToFloat(m_camera_offset, BS) + 100 * m_camera_direction);
@@ -511,8 +516,11 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
m_cameranode->setAspectRatio(m_aspect);
m_cameranode->setFOV(m_fov_y);
+ // Make new matrices and frustum
+ m_cameranode->updateMatrices();
+
if (m_arm_inertia)
- addArmInertia(player->getYaw());
+ addArmInertia(yaw);
// Position the wielded item
//v3f wield_position = v3f(45, -35, 65);
@@ -643,6 +651,7 @@ void Camera::drawWieldedTool(irr::core::matrix4* translation)
irr::core::vector3df camera_pos =
(startMatrix * *translation).getTranslation();
cam->setPosition(camera_pos);
+ cam->updateAbsolutePosition();
cam->setTarget(focusPoint);
}
m_wieldmgr->drawAll();
@@ -704,3 +713,15 @@ void Camera::removeNametag(Nametag *nametag)
m_nametags.remove(nametag);
delete nametag;
}
+
+std::array<core::plane3d<f32>, 4> Camera::getFrustumCullPlanes() const
+{
+ using irr::scene::SViewFrustum;
+ const auto &frustum_planes = m_cameranode->getViewFrustum()->planes;
+ return {
+ frustum_planes[SViewFrustum::VF_LEFT_PLANE],
+ frustum_planes[SViewFrustum::VF_RIGHT_PLANE],
+ frustum_planes[SViewFrustum::VF_BOTTOM_PLANE],
+ frustum_planes[SViewFrustum::VF_TOP_PLANE],
+ };
+}