Skip to content

Instantly share code, notes, and snippets.

@PilzAdam
Created December 7, 2014 12:01
Show Gist options
  • Save PilzAdam/5386e4e1b38dbd6bff87 to your computer and use it in GitHub Desktop.
Save PilzAdam/5386e4e1b38dbd6bff87 to your computer and use it in GitHub Desktop.
diff --git a/src/camera.cpp b/src/camera.cpp
index e5954a5..d680845 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -379,31 +379,36 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
my_cp.Y += 2;
// Calculate new position
- bool abort = false;
- for (int i = BS; i <= BS*2.75; i++)
- {
- my_cp.X = m_camera_position.X + m_camera_direction.X*-i;
- my_cp.Z = m_camera_position.Z + m_camera_direction.Z*-i;
- if (i > 12)
- my_cp.Y = m_camera_position.Y + (m_camera_direction.Y*-i);
-
- // Prevent camera positioned inside nodes
- INodeDefManager *nodemgr = m_gamedef->ndef();
- MapNode n = c_env.getClientMap().getNodeNoEx(floatToInt(my_cp, BS));
- const ContentFeatures& features = nodemgr->get(n);
- if(features.walkable)
+ if (m_gamedef->checkLocalPrivilege("noclip") && g_settings->getBool("noclip")) {
+ my_cp = m_camera_position + m_camera_direction * (-BS * 2.75);
+ } else {
+ bool abort = false;
+ for (int i = BS; i <= BS*2.75; i++)
{
- my_cp.X += m_camera_direction.X*-1*-BS/2;
- my_cp.Z += m_camera_direction.Z*-1*-BS/2;
- my_cp.Y += m_camera_direction.Y*-1*-BS/2;
- abort = true;
- break;
+ my_cp.X = m_camera_position.X + m_camera_direction.X*-i;
+ my_cp.Z = m_camera_position.Z + m_camera_direction.Z*-i;
+ if (i > 12)
+ my_cp.Y = m_camera_position.Y + (m_camera_direction.Y*-i);
+
+ // Prevent camera positioned inside nodes
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+ MapNode n = c_env.getClientMap().getNodeNoEx(floatToInt(my_cp, BS));
+ const ContentFeatures& features = nodemgr->get(n);
+ if(features.walkable)
+ {
+ my_cp.X += m_camera_direction.X*-1*-BS/2;
+ my_cp.Z += m_camera_direction.Z*-1*-BS/2;
+ my_cp.Y += m_camera_direction.Y*-1*-BS/2;
+ abort = true;
+ break;
+ }
}
+
+ // If node blocks camera position don't move y to heigh
+ if (abort && my_cp.Y > player_position.Y+BS*2)
+ my_cp.Y = player_position.Y+BS*2;
}
- // If node blocks camera position don't move y to heigh
- if (abort && my_cp.Y > player_position.Y+BS*2)
- my_cp.Y = player_position.Y+BS*2;
}
// Update offset if too far away from the center of the map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment