Interaction Updates (#353)

* Interaction speed is not dependent on framerate

* Split up interaction code in files and perform smooth interpolation when changing focus

* Abstract interaction code in to functions.

* Interpolation time is dependent on angle to focus node.

* Use correct delta time when interpolating

* Fix bug regarding decomposition of camera rotation.

* Make orbital interaction mode behave as globe browsing and no longer use interactiondepth below ellipsoid.

* Do not always rotate with object. Depending on distance

* Remove interaction depth below ellipsoid. Now able to interact without renderable

* Remove specification of interactionDepthBelowEllipsoid and cameraMinHeight

* Remove GlobeBrowsingInteractionMode

* Rename OrbitalInteractionMode to OrbitalNavigator and no longer extend interactionmode.

* Move properties from interaction handler to orbital navigator

* Use smooth step for follow rotation interpolator

* Rename KeyframeInteractionMode to KeyframeNavigator

* Rename files

* Clean up.

* Separate mousestate from orbitalnavigator

* Clean up

* Split keybindingmanager from interactionhandler interactionhandler

* Rename interactionhandler to navigationhandler

* Rename files

* Clean up

* Take back usage of gotochunk and gotogeo

* Rename lua library navigation

* Move functionality from navigationhandler to keyframenavigator

* Update scripts for navigation

* Comment code

* Clean up

* Solve but that caused NaN values for camera position when being in center of globe and setting focus to the globe.

* Update jenkins file to remove build folder before building.

* Fix error in jenkins script

* Update jenkins file

* Update jenkins file

* Revert jenkins file

* I hope this makes Jenkins happy.

* Line endings God damnit

* Line endings

* Clean up

* Fix compilation issue

* Take back default scene.

* Fix indentation

* Move functions goToGeo and goToChunk to GlobeBrowsingModule.

* Include algorithm for std::find

* Remove auto and other clean up
This commit is contained in:
Kalle Bladin
2017-07-14 17:17:17 +02:00
committed by GitHub
parent 4ecb98f06f
commit 2e4f31ded8
68 changed files with 2764 additions and 1977 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ Chunk::BoundingHeights Chunk::getBoundingHeights() const {
// a single raster image. If it is not we will just use the first raster
// (that is channel 0).
const size_t HeightChannel = 0;
const LayerGroup& heightmaps = layerManager->layerGroup(layergroupid::HeightLayers);
const LayerGroup& heightmaps = layerManager->layerGroup(layergroupid::GroupID::HeightLayers);
std::vector<ChunkTileSettingsPair> chunkTileSettingPairs =
tileselector::getTilesAndSettingsUnsorted(
heightmaps, _tileIndex);
@@ -27,11 +27,10 @@
#include <modules/globebrowsing/geometry/geodetic2.h>
#include <modules/globebrowsing/tile/quad.h>
#include <modules/globebrowsing/tile/tileindex.h>
namespace openspace {
namespace globebrowsing {
struct TileIndex;
class GeodeticPatch {
public:
+177 -1
View File
@@ -25,8 +25,11 @@
#include <modules/globebrowsing/globebrowsingmodule.h>
#include <modules/globebrowsing/cache/memoryawaretilecache.h>
#include <modules/globebrowsing/geometry/geodetic2.h>
#include <modules/globebrowsing/geometry/geodeticpatch.h>
#include <modules/globebrowsing/globes/renderableglobe.h>
#include <modules/globebrowsing/other/distanceswitch.h>
#include <modules/globebrowsing/tile/tileindex.h>
#include <modules/globebrowsing/tile/rawtiledatareader/gdalwrapper.h>
#include <modules/globebrowsing/tile/tileprovider/defaulttileprovider.h>
#include <modules/globebrowsing/tile/tileprovider/singleimageprovider.h>
@@ -37,11 +40,11 @@
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
#include <modules/globebrowsing/tile/tileprovider/tileproviderbylevel.h>
#include <modules/globebrowsing/tile/tileprovider/tileproviderbyindex.h>
#include <modules/globebrowsing/rendering/layer/layermanager.h>
#include <modules/globebrowsing/rendering/layer/layer.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/misc/templatefactory.h>
@@ -51,6 +54,10 @@
#include "globebrowsingmodule_lua.inl"
namespace {
const char* _loggerCat = "GlobeBrowsingModule";
}
namespace openspace {
GlobeBrowsingModule::GlobeBrowsingModule() : OpenSpaceModule(Name) {}
@@ -146,6 +153,18 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const {
"any of " + listLayerGroups + ". The third argument is the dictionary"
"defining the layer."
},
{
"goToChunk",
&globebrowsing::luascriptfunctions::goToChunk,
"void",
"Go to chunk with given index x, y, level"
},
{
"goToGeo",
&globebrowsing::luascriptfunctions::goToGeo,
"void",
"Go to geographic coordinates latitude and longitude"
}
},
{
"${MODULE_GLOBEBROWSING}/scripts/layer_support.lua"
@@ -156,6 +175,163 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const {
};
}
void GlobeBrowsingModule::goToChunk(int x, int y, int level) {
using namespace globebrowsing;
Camera* cam = OsEng.navigationHandler().camera();
goToChunk(*cam, TileIndex(x,y,level), glm::vec2(0.5, 0.5), true);
}
void GlobeBrowsingModule::goToGeo(double latitude, double longitude) {
using namespace globebrowsing;
Camera* cam = OsEng.navigationHandler().camera();
goToGeodetic2(*cam, Geodetic2(latitude, longitude) / 180 * glm::pi<double>(), true);
}
void GlobeBrowsingModule::goToGeo(double latitude, double longitude,
double altitude)
{
using namespace globebrowsing;
Camera* cam = OsEng.navigationHandler().camera();
goToGeodetic3(
*cam,
{
Geodetic2(latitude, longitude) / 180 * glm::pi<double>(),
altitude
},
true
);
}
void GlobeBrowsingModule::goToChunk(Camera& camera, globebrowsing::TileIndex ti,
glm::vec2 uv, bool resetCameraDirection)
{
using namespace globebrowsing;
RenderableGlobe* globe = castFocusNodeRenderableToGlobe();
if (!globe) {
LERROR("Focus node must have a RenderableGlobe renderable.");
return;
}
// Camera position in model space
glm::dvec3 camPos = camera.positionVec3();
glm::dmat4 inverseModelTransform = globe->inverseModelTransform();
glm::dvec3 cameraPositionModelSpace =
glm::dvec3(inverseModelTransform * glm::dvec4(camPos, 1));
GeodeticPatch patch(ti);
Geodetic2 corner = patch.getCorner(SOUTH_WEST);
Geodetic2 positionOnPatch = patch.getSize();
positionOnPatch.lat *= uv.y;
positionOnPatch.lon *= uv.x;
Geodetic2 pointPosition = corner + positionOnPatch;
glm::dvec3 positionOnEllipsoid =
globe->ellipsoid().geodeticSurfaceProjection(cameraPositionModelSpace);
double altitude = glm::length(cameraPositionModelSpace - positionOnEllipsoid);
goToGeodetic3(camera, {pointPosition, altitude}, resetCameraDirection);
}
void GlobeBrowsingModule::goToGeodetic2(Camera& camera,
globebrowsing::Geodetic2 geo2,
bool resetCameraDirection)
{
using namespace globebrowsing;
RenderableGlobe* globe = castFocusNodeRenderableToGlobe();
if (!globe) {
LERROR("Focus node must have a RenderableGlobe renderable.");
return;
}
// Camera position in model space
glm::dvec3 camPos = camera.positionVec3();
glm::dmat4 inverseModelTransform = globe->inverseModelTransform();
glm::dvec3 cameraPositionModelSpace =
glm::dvec3(inverseModelTransform * glm::dvec4(camPos, 1));
glm::dvec3 positionOnEllipsoid =
globe->ellipsoid().geodeticSurfaceProjection(cameraPositionModelSpace);
double altitude = glm::length(cameraPositionModelSpace - positionOnEllipsoid);
goToGeodetic3(camera, {geo2, altitude}, resetCameraDirection);
}
void GlobeBrowsingModule::goToGeodetic3(Camera& camera, globebrowsing::Geodetic3 geo3,
bool resetCameraDirection)
{
using namespace globebrowsing;
RenderableGlobe* globe = castFocusNodeRenderableToGlobe();
if (!globe) {
LERROR("Focus node must have a RenderableGlobe renderable.");
return;
}
glm::dvec3 positionModelSpace = globe->ellipsoid().cartesianPosition(geo3);
glm::dmat4 modelTransform = globe->modelTransform();
glm::dvec3 positionWorldSpace = modelTransform * glm::dvec4(positionModelSpace, 1.0);
camera.setPositionVec3(positionWorldSpace);
if (resetCameraDirection) {
this->resetCameraDirection(camera, geo3.geodetic2);
}
}
void GlobeBrowsingModule::resetCameraDirection(Camera& camera, globebrowsing::Geodetic2 geo2)
{
using namespace globebrowsing;
RenderableGlobe* globe = castFocusNodeRenderableToGlobe();
if (!globe) {
LERROR("Focus node must have a RenderableGlobe renderable.");
return;
}
// Camera is described in world space
glm::dmat4 modelTransform = globe->modelTransform();
// Lookup vector
glm::dvec3 positionModelSpace = globe->ellipsoid().cartesianSurfacePosition(geo2);
glm::dvec3 slightlyNorth = globe->ellipsoid().cartesianSurfacePosition(
Geodetic2(geo2.lat + 0.001, geo2.lon));
glm::dvec3 lookUpModelSpace = glm::normalize(slightlyNorth - positionModelSpace);
glm::dvec3 lookUpWorldSpace = glm::dmat3(modelTransform) * lookUpModelSpace;
// Lookat vector
glm::dvec3 lookAtWorldSpace = modelTransform * glm::dvec4(positionModelSpace, 1.0);
// Eye position
glm::dvec3 eye = camera.positionVec3();
// Matrix
glm::dmat4 lookAtMatrix = glm::lookAt(
eye, lookAtWorldSpace, lookUpWorldSpace);
// Set rotation
glm::dquat rotation = glm::quat_cast(inverse(lookAtMatrix));
camera.setRotation(rotation);
}
globebrowsing::RenderableGlobe* GlobeBrowsingModule::castFocusNodeRenderableToGlobe() {
using namespace globebrowsing;
Renderable* baseRenderable = OsEng.navigationHandler().focusNode()->renderable();
if (!baseRenderable) {
return nullptr;
}
if (globebrowsing::RenderableGlobe* globe =
dynamic_cast<RenderableGlobe*>(baseRenderable))
{
return globe;
}
else {
return nullptr;
}
}
std::string GlobeBrowsingModule::layerGroupNamesList() {
std::string listLayerGroups("");
for (int i = 0; i < globebrowsing::layergroupid::NUM_LAYER_GROUPS - 1; ++i) {
+21 -3
View File
@@ -26,11 +26,17 @@
#define __OPENSPACE_MODULE_GLOBEBROWSING___GLOBEBROWSING_MODULE___H__
#include <openspace/util/openspacemodule.h>
#include <ghoul/glm.h>
#include <memory>
namespace openspace {
class Camera;
namespace globebrowsing {
class RenderableGlobe;
class TileIndex;
class Geodetic2;
class Geodetic3;
namespace cache {
class MemoryAwareTileCache;
}
@@ -42,14 +48,26 @@ public:
GlobeBrowsingModule();
globebrowsing::cache::MemoryAwareTileCache* tileCache();
void goToChunk(int x, int y, int level);
void goToGeo(double latitude, double longitude);
void goToGeo(double latitude, double longitude, double altitude);
globebrowsing::cache::MemoryAwareTileCache* tileCache();
scripting::LuaLibrary luaLibrary() const override;
protected:
void internalInitialize() override;
private:
void goToChunk(Camera& camera, globebrowsing::TileIndex ti, glm::vec2 uv,
bool resetCameraDirection);
void goToGeodetic2(Camera& camera, globebrowsing::Geodetic2 geo2,
bool resetCameraDirection);
void goToGeodetic3(Camera& camera, globebrowsing::Geodetic3 geo3,
bool resetCameraDirection);
void resetCameraDirection(Camera& camera, globebrowsing::Geodetic2 geo2);
globebrowsing::RenderableGlobe* castFocusNodeRenderableToGlobe();
/**
\return a comma separated list of layer group names.
*/
@@ -29,6 +29,7 @@
#include <modules/globebrowsing/rendering/layer/layer.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/rendering/renderable.h>
#include <openspace/scene/scene.h>
@@ -135,6 +136,47 @@ int deleteLayer(lua_State* L) {
return 0;
}
int goToChunk(lua_State* L) {
using ghoul::lua::luaTypeToString;
// Check arguments
int nArguments = lua_gettop(L);
if (nArguments != 3) {
return luaL_error(L, "Expected %i arguments, got %i", 3, nArguments);
}
int x = static_cast<int>(lua_tonumber(L, 1));
int y = static_cast<int>(lua_tonumber(L, 2));
int level = static_cast<int>(lua_tonumber(L, 3));
OsEng.moduleEngine().module<GlobeBrowsingModule>()->goToChunk(x, y, level);
return 0;
}
int goToGeo(lua_State* L) {
using ghoul::lua::luaTypeToString;
int nArguments = lua_gettop(L);
if (nArguments != 2 && nArguments != 3) {
return luaL_error(L, "Expected 2 or 3 arguments.");
}
double latitude = static_cast<int>(lua_tonumber(L, 1));
double longitude = static_cast<int>(lua_tonumber(L, 2));
if (nArguments == 2) {
OsEng.moduleEngine().module<GlobeBrowsingModule>()->goToGeo(latitude, longitude);
}
else if (nArguments == 3) {
double altitude = static_cast<int>(lua_tonumber(L, 3));
OsEng.moduleEngine().module<GlobeBrowsingModule>()->goToGeo(latitude, longitude,
altitude);
}
return 0;
}
} // namespace luascriptfunctions
} // nameapace globebrowsing
@@ -174,7 +174,7 @@ float ChunkedLodGlobe::getHeight(glm::dvec3 position) const {
// Get the tile providers for the height maps
const std::vector<std::shared_ptr<Layer>>& heightMapLayers =
_layerManager->layerGroup(layergroupid::HeightLayers).activeLayers();
_layerManager->layerGroup(layergroupid::GroupID::HeightLayers).activeLayers();
for (const std::shared_ptr<Layer>& layer : heightMapLayers) {
tileprovider::TileProvider* tileProvider = layer->tileProvider();
@@ -32,8 +32,6 @@
namespace {
const char* keyFrame = "Frame";
const char* keyRadii = "Radii";
const char* keyInteractionDepthBelowEllipsoid = "InteractionDepthBelowEllipsoid";
const char* keyCameraMinHeight = "CameraMinHeight";
const char* keySegmentsPerPatch = "SegmentsPerPatch";
const char* keyLayers = "Layers";
}
@@ -86,15 +84,6 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
double patchSegmentsd;
dictionary.getValue(keySegmentsPerPatch, patchSegmentsd);
int patchSegments = patchSegmentsd;
if (!dictionary.getValue(keyInteractionDepthBelowEllipsoid,
_interactionDepthBelowEllipsoid)) {
_interactionDepthBelowEllipsoid = 0;
}
float cameraMinHeight;
dictionary.getValue(keyCameraMinHeight, cameraMinHeight);
_generalProperties.cameraMinHeight.set(cameraMinHeight);
// Init layer manager
ghoul::Dictionary layersDictionary;
@@ -262,8 +251,33 @@ const std::shared_ptr<const Camera> RenderableGlobe::savedCamera() const {
return _savedCamera;
}
double RenderableGlobe::interactionDepthBelowEllipsoid() {
return _interactionDepthBelowEllipsoid;
SurfacePositionHandle RenderableGlobe::calculateSurfacePositionHandle(
const glm::dvec3& targetModelSpace)
{
glm::dvec3 centerToEllipsoidSurface =
_ellipsoid.geodeticSurfaceProjection(targetModelSpace);
glm::dvec3 ellipsoidSurfaceToTarget = targetModelSpace - centerToEllipsoidSurface;
// ellipsoidSurfaceOutDirection will point towards the target, we want the outward
// direction. Therefore it must be flipped in case the target is under the reference
// ellipsoid so that it always points outwards
glm::dvec3 ellipsoidSurfaceOutDirection = glm::normalize(ellipsoidSurfaceToTarget);
if (glm::dot(ellipsoidSurfaceOutDirection, centerToEllipsoidSurface) < 0) {
ellipsoidSurfaceOutDirection *= -1.0;
}
double heightToSurface = getHeight(targetModelSpace);
heightToSurface = glm::isnan(heightToSurface) ? 0.0 : heightToSurface;
centerToEllipsoidSurface = glm::isnan(glm::length(centerToEllipsoidSurface)) ?
(glm::dvec3(0.0, 1.0, 0.0) * static_cast<double>(boundingSphere())) :
centerToEllipsoidSurface;
ellipsoidSurfaceOutDirection = glm::isnan(glm::length(ellipsoidSurfaceOutDirection)) ?
glm::dvec3(0.0, 1.0, 0.0) : ellipsoidSurfaceOutDirection;
return {
centerToEllipsoidSurface,
ellipsoidSurfaceOutDirection,
heightToSurface
};
}
void RenderableGlobe::setSaveCamera(std::shared_ptr<Camera> camera) {
@@ -107,7 +107,11 @@ public:
double interactionDepthBelowEllipsoid();
// Setters
void setSaveCamera(std::shared_ptr<Camera> camera);
void setSaveCamera(std::shared_ptr<Camera> camera);
virtual SurfacePositionHandle calculateSurfacePositionHandle(
const glm::dvec3& targetModelSpace) override;
private:
// Globes. These are renderables inserted in a distance switch so that the heavier
// <code>ChunkedLodGlobe</code> does not have to be rendered at far distances.
@@ -119,7 +123,6 @@ private:
DistanceSwitch _distanceSwitch;
std::shared_ptr<Camera> _savedCamera;
double _interactionDepthBelowEllipsoid;
std::string _frame;
double _time;
@@ -228,9 +228,9 @@ void ChunkRenderer::renderChunkGlobally(const Chunk& chunk, const RenderData& da
programObject->setUniform("radiiSquared", glm::vec3(ellipsoid.radiiSquared()));
if (_layerManager->layerGroup(
layergroupid::NightLayers).activeLayers().size() > 0 ||
layergroupid::GroupID::NightLayers).activeLayers().size() > 0 ||
_layerManager->layerGroup(
layergroupid::WaterMasks).activeLayers().size() > 0 ||
layergroupid::GroupID::WaterMasks).activeLayers().size() > 0 ||
chunk.owner().generalProperties().atmosphereEnabled ||
chunk.owner().generalProperties().performShading)
{
@@ -58,7 +58,7 @@ void GPULayerGroup::bind(ghoul::opengl::ProgramObject* programObject,
int pileSize = layerGroup.pileSize();
for (size_t i = 0; i < _gpuActiveLayers.size(); ++i) {
// should maybe a proper GPULayer factory
_gpuActiveLayers[i] = (category == layergroupid::HeightLayers) ?
_gpuActiveLayers[i] = (category == layergroupid::GroupID::HeightLayers) ?
std::make_unique<GPUHeightLayer>() :
std::make_unique<GPULayer>();
std::string nameExtension = "[" + std::to_string(i) + "].";