VIDEO: camera rotation speed is no longer using the same variable as camera movement

master
mgerhardy 2016-04-15 22:34:41 +02:00
parent 5509992fc5
commit 6d9ea85195
6 changed files with 13 additions and 13 deletions

View File

@ -27,6 +27,7 @@ Client::Client(video::MeshPoolPtr meshPool, network::NetworkPtr network, voxel::
_worldRenderer(world) {
_world->setClientData(true);
init("engine", "client");
_rotationSpeed = core::Var::get(cfg::ClientMouseRotationSpeed, "0.01");
}
Client::~Client() {
@ -52,7 +53,7 @@ void Client::sendMovement() {
void Client::onMouseMotion(int32_t x, int32_t y, int32_t relX, int32_t relY) {
UIApp::onMouseMotion(x, y, relX, relY);
_camera.onMotion(x, y, relX, relY);
_camera.onMotion(x, y, relX, relY, _rotationSpeed->floatVal());
}
void Client::onEvent(const network::DisconnectEvent& event) {

View File

@ -37,6 +37,7 @@ protected:
frontend::ClientEntityId _userId = -1;
ENetPeer* _peer = nullptr;
uint8_t _moveMask = 0;
core::VarPtr _rotationSpeed;
util::PosLerp _posLerp;
long _lastMovement = 0l;

View File

@ -2,6 +2,7 @@
namespace cfg {
constexpr const char *ClientMouseRotationSpeed = "cl_cammouserotspeed";
constexpr const char *ClientMouseSpeed = "cl_cammousespeed";
// the max pitch should not be bigger than 89.9 - because at 90 we have a visual switch
constexpr const char *ClientCameraMaxPitch = "cl_cammaxpitch";

View File

@ -6,20 +6,18 @@
namespace video {
Camera::Camera() :
_pos(0.0f, 0.0f, 0.0f), _width(0), _height(0), _pitch(-M_PI_2), _yaw(M_PI), _direction(0.0f, 0.0f, 0.0f), _mouseSpeed(
core::Var::get(cfg::ClientMouseSpeed, "0.01")), _maxpitch(core::Var::get(cfg::ClientCameraMaxPitch, std::to_string(glm::radians(89.0)))) {
_pos(0.0f, 0.0f, 0.0f), _width(0), _height(0), _pitch(-M_PI_2), _yaw(M_PI), _direction(0.0f, 0.0f, 0.0f), _maxpitch(core::Var::get(cfg::ClientCameraMaxPitch, std::to_string(glm::radians(89.0)))) {
updateDirection();
}
Camera::~Camera() {
}
void Camera::updatePosition(long dt, bool left, bool right, bool forward, bool backward) {
void Camera::updatePosition(long dt, bool left, bool right, bool forward, bool backward, float speed) {
const float angle = _yaw - M_PI_2;
const glm::vec3 rightvec(glm::sin(angle), 0.0, glm::cos(angle));
const float deltaTime = static_cast<float>(dt);
const float speed = _mouseSpeed->floatVal();
if (forward) {
_pos += _direction * deltaTime * speed;
}
@ -50,10 +48,9 @@ void Camera::updateDirection() {
_direction = glm::vec3(cosV * sinH, sinV, cosV * cosH);
}
void Camera::onMotion(int32_t x, int32_t y, int32_t deltaX, int32_t deltaY) {
const float mouseSpeed = _mouseSpeed->floatVal();
_yaw -= static_cast<float>(deltaX) * mouseSpeed;
_pitch -= static_cast<float>(deltaY) * mouseSpeed;
void Camera::onMotion(int32_t x, int32_t y, int32_t deltaX, int32_t deltaY, float rotationSpeed) {
_yaw -= static_cast<float>(deltaX) * rotationSpeed;
_pitch -= static_cast<float>(deltaY) * rotationSpeed;
updateDirection();
}

View File

@ -18,7 +18,6 @@ private:
float _pitch;
float _yaw;
glm::vec3 _direction;
core::VarPtr _mouseSpeed;
core::VarPtr _maxpitch;
public:
@ -26,10 +25,10 @@ public:
~Camera();
void init(int width, int height);
void onMotion(int32_t x, int32_t y, int32_t relX, int32_t relY);
void onMotion(int32_t x, int32_t y, int32_t relX, int32_t relY, float rotationSpeed = 0.01f);
void onMovement(int32_t forward, int32_t sideward);
void updatePosition(long dt, bool left, bool right, bool forward, bool backward);
void updatePosition(long dt, bool left, bool right, bool forward, bool backward, float speed = 0.01f);
// Direction : Spherical coordinates to Cartesian coordinates conversion
void updateDirection();

View File

@ -63,7 +63,8 @@ void ShapeTool::beforeUI() {
const bool right = _moveMask & MOVERIGHT;
const bool forward = _moveMask & MOVEFORWARD;
const bool backward = _moveMask & MOVEBACKWARD;
_camera.updatePosition(_deltaFrame, left, right, forward, backward);
const float speed = core::Var::get(cfg::ClientMouseSpeed, "0.01")->floatVal();
_camera.updatePosition(_deltaFrame, left, right, forward, backward, speed);
_camera.updateViewMatrix();
_worldRenderer.onRunning(_now);