Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use adaptive motion speed for zooming depending on camera distance #65

Merged
merged 1 commit into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions apps/ui/BaseWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,12 @@ void BaseWindow::_resetCamera()

void BaseWindow::_increaseMotionSpeed()
{
const auto speed = _brayns->getCameraManipulator().getMotionSpeed();
_brayns->getCameraManipulator().setMotionSpeed( speed * DEFAULT_MOTION_ACCELERATION );
_brayns->getCameraManipulator().updateMotionSpeed( DEFAULT_MOTION_ACCELERATION );
}

void BaseWindow::_decreaseMotionSpeed()
{
const auto speed = _brayns->getCameraManipulator().getMotionSpeed();
_brayns->getCameraManipulator().setMotionSpeed( speed / DEFAULT_MOTION_ACCELERATION );
_brayns->getCameraManipulator().updateMotionSpeed( 1.f / DEFAULT_MOTION_ACCELERATION );
}

void BaseWindow::_displayCameraInformation()
Expand Down
17 changes: 7 additions & 10 deletions brayns/common/camera/AbstractManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ namespace
{
const Vector3f UNIT_Y = { 0.f, 1.f, 0.f };
const Vector3f UNIT_Z = { 0.f, 0.f, 1.f };
const float DEFAULT_MOTION_SPEED = 0.01f;
const float DEFAULT_ROTATION_SPEED = 0.005f;

float _getDefaultMotionSpeed( const Camera& camera )
{
const auto& position = camera.getPosition();
const auto& target = camera.getTarget();
return Vector3f{ target - position }.length() * 0.001f;
}
}

AbstractManipulator::AbstractManipulator( Camera& camera,
KeyboardHandler& keyboardHandler )
: _camera( camera )
, _keyboardHandler( keyboardHandler )
, _motionSpeed{ _getDefaultMotionSpeed( camera ) }
, _motionSpeed{ DEFAULT_MOTION_SPEED }
, _rotationSpeed{ DEFAULT_ROTATION_SPEED }
{}

Expand All @@ -57,12 +52,14 @@ float AbstractManipulator::getRotationSpeed() const

float AbstractManipulator::getMotionSpeed() const
{
return _motionSpeed;
const auto& position = _camera.getPosition();
const auto& target = _camera.getTarget();
return Vector3f{ target - position }.length() * _motionSpeed;
}

void AbstractManipulator::setMotionSpeed( const float speed )
void AbstractManipulator::updateMotionSpeed( const float speed )
{
_motionSpeed = speed;
_motionSpeed *= speed;
}

void AbstractManipulator::translate( const Vector3f& vector,
Expand Down
2 changes: 1 addition & 1 deletion brayns/common/camera/AbstractManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AbstractManipulator
virtual void wheel( const Vector2i& position, float delta ) = 0;

float getMotionSpeed() const;
void setMotionSpeed( float speed );
void updateMotionSpeed( float speed );

float getRotationSpeed() const;

Expand Down
2 changes: 1 addition & 1 deletion brayns/common/camera/FlyingModeManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void FlyingModeManipulator::dragMiddle( const Vector2i& to,
void FlyingModeManipulator::wheel( const Vector2i& /*position*/,
const float delta )
{
translate( forwardDirection * delta, false );
translate( forwardDirection * delta * getMotionSpeed(), false );
}

void FlyingModeManipulator::_strafeLeft()
Expand Down
3 changes: 2 additions & 1 deletion brayns/common/camera/InspectCenterManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ void InspectCenterManipulator::dragMiddle( const Vector2i& to,
}

void InspectCenterManipulator::wheel( const Vector2i& /*position*/,
const float delta )
float delta )
{
delta *= getMotionSpeed();
if( delta < ( _camera.getTarget() - _camera.getPosition( )).length( ))
translate( forwardDirection * delta, false );
}
Expand Down