Skip to content

Commit

Permalink
Correct camera model to follow OpenGL semantics; means that z-axis is…
Browse files Browse the repository at this point in the history
… inverted
  • Loading branch information
tribal-tec committed Jan 24, 2017
1 parent 80b1432 commit 1b604ad
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ common_find_package(Boost REQUIRED COMPONENTS program_options unit_test_framewor
common_find_package(vmmlib REQUIRED)
common_find_package(OptiX SYSTEM)
common_find_package(CUDA SYSTEM)
common_find_package(OSPRay SYSTEM)
#common_find_package(OSPRay SYSTEM) disabled until module on RHEL is fixed
common_find_package(OpenMP)
common_find_package(Lunchbox)

Expand Down
11 changes: 4 additions & 7 deletions brayns/common/camera/AbstractManipulator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2015-2016, EPFL/Blue Brain Project
/* Copyright (c) 2015-2017, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
Expand Down Expand Up @@ -28,11 +28,8 @@ namespace brayns

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.001f;
const float DEFAULT_ROTATION_SPEED = 0.005f;

}

AbstractManipulator::AbstractManipulator( Camera& camera,
Expand Down Expand Up @@ -82,18 +79,18 @@ void AbstractManipulator::rotate( const Vector3f& pivot, const float du,
const float dv, const bool updateTarget )
{
auto& matrix = _camera.getRotationMatrix();
matrix.rotate_x( dv );
matrix.rotate_x( -dv );
matrix.rotate_y( -du );

const auto dir = _camera.getTarget() - _camera.getPosition();
const auto newPivotToCam = Vector3f{ matrix * -UNIT_Z } * dir.length();
const auto newPivotToCam = Vector3f{ matrix * Vector3f::unitZ() } * dir.length();

if( updateTarget )
_camera.setTarget( _camera.getPosition() - newPivotToCam );
else
_camera.setPosition( pivot + newPivotToCam );

_camera.setUp( matrix * UNIT_Y );
_camera.setUp( matrix * Vector3f::unitY() );
}

}
2 changes: 1 addition & 1 deletion brayns/common/camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Camera::Impl
, _aspectRatio( 1.f )
, _aperture( 0.f )
, _focalLength( 0.f )
, _fieldOfView( 60.f )
, _fieldOfView( 45.f )
, _stereoMode( CameraStereoMode::none )
, _eyeSeparation( 0.0635f )
{
Expand Down
20 changes: 7 additions & 13 deletions brayns/common/camera/FlyingModeManipulator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2015-2016, EPFL/Blue Brain Project
/* Copyright (c) 2015-2017, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
Expand Down Expand Up @@ -26,12 +26,6 @@
namespace brayns
{

namespace
{
const Vector3f forwardDirection{ 0.f, 0.f , 1.f };
const Vector3f leftDirection{ 1.f, 0.f, 0.f };
}

FlyingModeManipulator::FlyingModeManipulator( Camera& camera,
KeyboardHandler& keyboardHandler )
: AbstractManipulator( camera, keyboardHandler )
Expand Down Expand Up @@ -66,7 +60,7 @@ void FlyingModeManipulator::dragRight( const Vector2i& to,
const Vector2i& from )
{
const float distance = -( to.y() - from.y( )) * getMotionSpeed();
translate( forwardDirection * distance, false );
translate( Vector3f::forward() * distance, false );
}

void FlyingModeManipulator::dragMiddle( const Vector2i& to,
Expand All @@ -80,27 +74,27 @@ void FlyingModeManipulator::dragMiddle( const Vector2i& to,
void FlyingModeManipulator::wheel( const Vector2i& /*position*/,
const float delta )
{
translate( forwardDirection * delta * getWheelSpeed(), false );
translate( Vector3f::forward() * delta * getWheelSpeed(), false );
}

void FlyingModeManipulator::_strafeLeft()
{
translate( leftDirection * getMotionSpeed(), true );
translate( Vector3f::left() * getMotionSpeed(), true );
}

void FlyingModeManipulator::_strafeRight()
{
translate( leftDirection * -getMotionSpeed(), true );
translate( Vector3f::left() * -getMotionSpeed(), true );
}

void FlyingModeManipulator::_flyForward()
{
translate( forwardDirection * getWheelSpeed(), true );
translate( Vector3f::forward() * getWheelSpeed(), true );
}

void FlyingModeManipulator::_flyBackwards()
{
translate( forwardDirection * -getWheelSpeed(), true );
translate( Vector3f::forward() * -getWheelSpeed(), true );
}

}
11 changes: 3 additions & 8 deletions brayns/common/camera/InspectCenterManipulator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2015-2016, EPFL/Blue Brain Project
/* Copyright (c) 2015-2017, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
Expand Down Expand Up @@ -26,11 +26,6 @@
namespace brayns
{

namespace
{
const Vector3f forwardDirection{ 0.f, 0.f , 1.f };
}

InspectCenterManipulator::InspectCenterManipulator( Camera& camera,
KeyboardHandler& handler )
: AbstractManipulator{ camera, handler }
Expand Down Expand Up @@ -80,7 +75,7 @@ void InspectCenterManipulator::dragRight( const Vector2i& to,
{
const float distance = -( to.y() - from.y() ) * getMotionSpeed();
if( distance < ( _camera.getTarget() - _camera.getPosition( )).length( ))
translate( forwardDirection * distance, false );
translate( Vector3f::forward() * distance, false );
}

void InspectCenterManipulator::dragMiddle( const Vector2i& to,
Expand All @@ -96,7 +91,7 @@ void InspectCenterManipulator::wheel( const Vector2i& /*position*/,
{
delta *= getWheelSpeed();
if( delta < ( _camera.getTarget() - _camera.getPosition( )).length( ))
translate( forwardDirection * delta, false );
translate( Vector3f::forward() * delta, false );
}

void InspectCenterManipulator::_rotateLeft()
Expand Down
2 changes: 1 addition & 1 deletion brayns/common/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void Engine::setDefaultCamera()
const Vector3f& target = worldBounds.getCenter();
const Vector3f& diag = worldBounds.getSize();
Vector3f position = target;
position.z() -= diag.find_max();
position.z() += diag.find_max();

const Vector3f up = Vector3f( 0.f, 1.f, 0.f );
_camera->setInitialState( position, target, up );
Expand Down
4 changes: 2 additions & 2 deletions brayns/common/light/DirectionalLight.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2015-2016, EPFL/Blue Brain Project
/* Copyright (c) 2015-2017, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
Expand Down Expand Up @@ -26,7 +26,7 @@
namespace brayns
{

const Vector3f DEFAULT_SUN_DIRECTION = { 0.1f, -0.2f, 0.5f };
const Vector3f DEFAULT_SUN_DIRECTION = { 0.1f, -0.2f, -0.5f };
const Vector3f DEFAULT_SUN_COLOR = { 1.f, 1.f, 1.f };
const float DEFAULT_SUN_INTENSITY = 0.5f;
const float DEFAULT_SUN_CUTOFF = 1000.f;
Expand Down
4 changes: 2 additions & 2 deletions brayns/common/scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ void Scene::buildDefault( )

const uint16_t indices[6][6] =
{
{ 0, 1, 3, 3, 2, 0 }, // Front
{ 5, 4, 6, 6, 7, 5 }, // Front
{ 1, 5, 7, 7, 3, 1 }, // Right
{ 5, 4, 6, 6, 7, 5 }, // Back
{ 0, 1, 3, 3, 2, 0 }, // Back
{ 4, 0, 2, 2, 6, 4 }, // Left
{ 0, 1, 5, 5, 4, 0 }, // Bottom
{ 2, 3, 7, 7, 6, 2 } // Top
Expand Down
2 changes: 1 addition & 1 deletion brayns/common/vocabulary/camera.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ table Camera
origin: [float:3];
look_at: [float:3];
up: [float:3];
field_of_view: float = 60;
field_of_view: float = 45;
aperture: float = 0;
focal_length: float = 0;
stereo_mode: CameraStereoMode;
Expand Down
3 changes: 1 addition & 2 deletions plugins/engines/ospray/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ set(BRAYNSOSPRAYENGINEPLUGIN_PUBLIC_HEADERS
)

set(BRAYNSOSPRAYENGINEPLUGIN_LINK_LIBRARIES
PUBLIC vmmlib braynsCommon braynsIO
PRIVATE ${OSPRAY_LIBRARIES}
PUBLIC vmmlib braynsCommon braynsIO ${OSPRAY_LIBRARIES}
)

if(BRAYNS_REST_ENABLED)
Expand Down
2 changes: 1 addition & 1 deletion tests/brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE( defaults )

auto& camera = brayns.getEngine().getCamera();
BOOST_CHECK( camera.getType() == brayns::CameraType::perspective );
BOOST_CHECK_EQUAL( camera.getPosition(), brayns::Vector3f( 0.5f, 0.5f, -0.5f ));
BOOST_CHECK_EQUAL( camera.getPosition(), brayns::Vector3f( 0.5f, 0.5f, 1.5f ));
BOOST_CHECK_EQUAL( camera.getTarget(), brayns::Vector3f( 0.5f, 0.5f, 0.5f ));
BOOST_CHECK_EQUAL( camera.getUp(), brayns::Vector3f( 0, 1, 0 ));
BOOST_CHECK_EQUAL( camera.getAspectRatio(), 4.f/3.f );
Expand Down
1 change: 1 addition & 0 deletions tests/braynsTestData.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/* Copyright (c) 2016, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Daniel.Nachbaur@epfl.ch
Expand Down
Binary file modified tests/testdataLayer1.bin
Binary file not shown.
Binary file modified tests/testdataProtein.bin
Binary file not shown.
Binary file modified tests/testdataProteinStereo.bin
Binary file not shown.

0 comments on commit 1b604ad

Please sign in to comment.