aboutsummaryrefslogtreecommitdiff
path: root/src/camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera.cpp')
-rw-r--r--src/camera.cpp96
1 files changed, 30 insertions, 66 deletions
diff --git a/src/camera.cpp b/src/camera.cpp
index 5200f71ba..0c6d03e4e 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -20,14 +20,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "camera.h"
#include "debug.h"
#include "client.h"
-#include "main.h" // for g_settings
#include "map.h"
-#include "clientmap.h" // MapDrawControl
+#include "clientmap.h" // MapDrawControl
#include "player.h"
#include <cmath>
#include "settings.h"
#include "wieldmesh.h"
-#include "noise.h" // easeCurve
+#include "noise.h" // easeCurve
#include "gamedef.h"
#include "sound.h"
#include "event.h"
@@ -93,10 +92,9 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
// all other 3D scene nodes and before the GUI.
m_wieldmgr = smgr->createNewSceneManager();
m_wieldmgr->addCameraSceneNode();
- m_wieldnode = new WieldMeshSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr, -1, true);
+ m_wieldnode = new WieldMeshSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr, -1, false);
m_wieldnode->setItem(ItemStack(), m_gamedef);
m_wieldnode->drop(); // m_wieldmgr grabbed it
- m_wieldlightnode = m_wieldmgr->addLightSceneNode(NULL, v3f(0.0, 50.0, 0.0));
/* TODO: Add a callback function so these can be updated when a setting
* changes. At this point in time it doesn't matter (e.g. /set
@@ -119,34 +117,22 @@ Camera::~Camera()
m_wieldmgr->drop();
}
-bool Camera::successfullyCreated(std::wstring& error_message)
+bool Camera::successfullyCreated(std::string &error_message)
{
- if (m_playernode == NULL)
- {
- error_message = L"Failed to create the player scene node";
- return false;
- }
- if (m_headnode == NULL)
- {
- error_message = L"Failed to create the head scene node";
- return false;
- }
- if (m_cameranode == NULL)
- {
- error_message = L"Failed to create the camera scene node";
- return false;
- }
- if (m_wieldmgr == NULL)
- {
- error_message = L"Failed to create the wielded item scene manager";
- return false;
- }
- if (m_wieldnode == NULL)
- {
- error_message = L"Failed to create the wielded item scene node";
- return false;
+ if (!m_playernode) {
+ error_message = "Failed to create the player scene node";
+ } else if (!m_headnode) {
+ error_message = "Failed to create the head scene node";
+ } else if (!m_cameranode) {
+ error_message = "Failed to create the camera scene node";
+ } else if (!m_wieldmgr) {
+ error_message = "Failed to create the wielded item scene manager";
+ } else if (!m_wieldnode) {
+ error_message = "Failed to create the wielded item scene node";
+ } else {
+ error_message.clear();
}
- return true;
+ return error_message.empty();
}
// Returns the fractional part of x
@@ -175,55 +161,37 @@ void Camera::step(f32 dtime)
{
//f32 offset = dtime * m_view_bobbing_speed * 0.035;
f32 offset = dtime * m_view_bobbing_speed * 0.030;
- if (m_view_bobbing_state == 2)
- {
-#if 0
+ if (m_view_bobbing_state == 2) {
// Animation is getting turned off
- if (m_view_bobbing_anim < 0.5)
+ if (m_view_bobbing_anim < 0.25) {
m_view_bobbing_anim -= offset;
- else
- m_view_bobbing_anim += offset;
- if (m_view_bobbing_anim <= 0 || m_view_bobbing_anim >= 1)
- {
- m_view_bobbing_anim = 0;
- m_view_bobbing_state = 0;
- }
-#endif
-#if 1
- // Animation is getting turned off
- if(m_view_bobbing_anim < 0.25)
- {
- m_view_bobbing_anim -= offset;
- } else if(m_view_bobbing_anim > 0.75) {
+ } else if (m_view_bobbing_anim > 0.75) {
m_view_bobbing_anim += offset;
}
- if(m_view_bobbing_anim < 0.5)
- {
+
+ if (m_view_bobbing_anim < 0.5) {
m_view_bobbing_anim += offset;
- if(m_view_bobbing_anim > 0.5)
+ if (m_view_bobbing_anim > 0.5)
m_view_bobbing_anim = 0.5;
} else {
m_view_bobbing_anim -= offset;
- if(m_view_bobbing_anim < 0.5)
+ if (m_view_bobbing_anim < 0.5)
m_view_bobbing_anim = 0.5;
}
- if(m_view_bobbing_anim <= 0 || m_view_bobbing_anim >= 1 ||
- fabs(m_view_bobbing_anim - 0.5) < 0.01)
- {
+
+ if (m_view_bobbing_anim <= 0 || m_view_bobbing_anim >= 1 ||
+ fabs(m_view_bobbing_anim - 0.5) < 0.01) {
m_view_bobbing_anim = 0;
m_view_bobbing_state = 0;
}
-#endif
}
- else
- {
+ else {
float was = m_view_bobbing_anim;
m_view_bobbing_anim = my_modf(m_view_bobbing_anim + offset);
bool step = (was == 0 ||
(was < 0.5f && m_view_bobbing_anim >= 0.5f) ||
(was > 0.5f && m_view_bobbing_anim <= 0.5f));
- if(step)
- {
+ if(step) {
MtEvent *e = new SimpleTriggerEvent("ViewBobbingStep");
m_gamedef->event()->put(e);
}
@@ -482,11 +450,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
m_wieldnode->setPosition(wield_position);
m_wieldnode->setRotation(wield_rotation);
- // Shine light upon the wield mesh
- video::SColor black(255,0,0,0);
- m_wieldmgr->setAmbientLight(player->light_color.getInterpolated(black, 0.7));
- m_wieldlightnode->getLightData().DiffuseColor = player->light_color.getInterpolated(black, 0.3);
- m_wieldlightnode->setPosition(v3f(30+5*sin(2*player->getYaw()*M_PI/180), -50, 0));
+ m_wieldnode->setColor(player->light_color);
// Render distance feedback loop
updateViewingRange(frametime, busytime);