mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 07:19:28 -05:00
Solve merge conflict
This commit is contained in:
@@ -30,7 +30,7 @@ return {
|
||||
Body = "EARTH",
|
||||
Radii = {6378137.0, 6378137.0, 6356752.314245}, -- Earth's radii
|
||||
--Radii = {3396190.0, 3396190.0, 3396190.0}, -- Mars as a spheroid
|
||||
SegmentsPerPatch = 90,
|
||||
SegmentsPerPatch = 64,
|
||||
TextureInitData = {
|
||||
ColorTextureMinimumSize = 1024,
|
||||
OverlayMinimumSize = 2048,
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/globebrowsing/other/threadpool.h>
|
||||
#include <modules/globebrowsing/tile/temporaltileprovider.h>
|
||||
#include <modules/globebrowsing/tile/tileselector.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -179,10 +180,70 @@ namespace openspace {
|
||||
_tileProviderManager->prerender();
|
||||
}
|
||||
|
||||
glm::dvec3 RenderableGlobe::geodeticSurfaceProjection(glm::dvec3 position) {
|
||||
glm::dvec3 RenderableGlobe::projectOnEllipsoid(glm::dvec3 position) {
|
||||
return _ellipsoid.geodeticSurfaceProjection(position);
|
||||
}
|
||||
|
||||
const Ellipsoid& RenderableGlobe::ellipsoid() {
|
||||
return _ellipsoid;
|
||||
}
|
||||
|
||||
float RenderableGlobe::getHeight(glm::dvec3 position) {
|
||||
// Get the tile provider for the height map
|
||||
const auto& heightMapProviders = _tileProviderManager->getActivatedLayerCategory(LayeredTextures::HeightMaps);
|
||||
if (heightMapProviders.size() == 0)
|
||||
return 0;
|
||||
const auto& tileProvider = heightMapProviders[0];
|
||||
|
||||
// Get the uv coordinates to sample from
|
||||
Geodetic2 geodeticPosition = _ellipsoid.cartesianToGeodetic2(position);
|
||||
int chunkLevel =
|
||||
tileProvider->getAsyncTileReader()->getTextureDataProvider()->getMaximumLevel();
|
||||
ChunkIndex chunkIdx = ChunkIndex(geodeticPosition, chunkLevel);
|
||||
GeodeticPatch patch = GeodeticPatch(chunkIdx);
|
||||
Geodetic2 geoDiffPatch = patch.getCorner(Quad::NORTH_EAST) - patch.getCorner(Quad::SOUTH_WEST);
|
||||
Geodetic2 geoDiffPoint = geodeticPosition - patch.getCorner(Quad::SOUTH_WEST);
|
||||
glm::vec2 patchUV = glm::vec2(geoDiffPoint.lon / geoDiffPatch.lon, geoDiffPoint.lat / geoDiffPatch.lat);
|
||||
|
||||
// Transform the uv coordinates to the current tile texture
|
||||
TileAndTransform tileAndTransform = TileSelector::getHighestResolutionTile(tileProvider.get(), chunkIdx);
|
||||
const auto& tile = tileAndTransform.tile;
|
||||
const auto& uvTransform = tileAndTransform.uvTransform;
|
||||
const auto& depthTransform = tileProvider->depthTransform();
|
||||
if (tile.status != Tile::Status::OK) {
|
||||
return 0;
|
||||
}
|
||||
glm::vec2 transformedUv = uvTransform.uvOffset + uvTransform.uvScale * patchUV;
|
||||
|
||||
// Sample and do linear interpolation (could possibly be moved as a function in ghoul texture)
|
||||
glm::uvec3 dimensions = tile.texture->dimensions();
|
||||
|
||||
glm::vec2 samplePos = transformedUv * glm::vec2(dimensions.xy());
|
||||
glm::uvec2 samplePos00 = samplePos;
|
||||
samplePos00 = glm::clamp(samplePos00, glm::uvec2(0, 0), dimensions.xy() - glm::uvec2(1));
|
||||
glm::vec2 samplePosFract = samplePos - glm::vec2(samplePos00);
|
||||
|
||||
glm::uvec2 samplePos10 = glm::min(samplePos00 + glm::uvec2(1, 0), dimensions.xy() - glm::uvec2(1));
|
||||
glm::uvec2 samplePos01 = glm::min(samplePos00 + glm::uvec2(0, 1), dimensions.xy() - glm::uvec2(1));
|
||||
glm::uvec2 samplePos11 = glm::min(samplePos00 + glm::uvec2(1, 1), dimensions.xy() - glm::uvec2(1));
|
||||
|
||||
float sample00 = tile.texture->texelAsFloat(samplePos00).x;
|
||||
float sample10 = tile.texture->texelAsFloat(samplePos10).x;
|
||||
float sample01 = tile.texture->texelAsFloat(samplePos01).x;
|
||||
float sample11 = tile.texture->texelAsFloat(samplePos11).x;
|
||||
|
||||
float sample0 = sample00 * (1.0 - samplePosFract.x) + sample10 * samplePosFract.x;
|
||||
float sample1 = sample01 * (1.0 - samplePosFract.x) + sample11 * samplePosFract.x;
|
||||
|
||||
float sample = sample0 * (1.0 - samplePosFract.y) + sample1 * samplePosFract.y;
|
||||
|
||||
// Perform depth transform to get the value in meters
|
||||
float height = depthTransform.depthOffset + depthTransform.depthScale * sample;
|
||||
|
||||
// Return the result
|
||||
return height;
|
||||
}
|
||||
|
||||
std::shared_ptr<ChunkedLodGlobe> RenderableGlobe::chunkedLodGlobe() {
|
||||
return _chunkedLodGlobe;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,9 @@ public:
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
glm::dvec3 geodeticSurfaceProjection(glm::dvec3 position);
|
||||
glm::dvec3 projectOnEllipsoid(glm::dvec3 position);
|
||||
const Ellipsoid& ellipsoid();
|
||||
float getHeight(glm::dvec3 position);
|
||||
std::shared_ptr<ChunkedLodGlobe> chunkedLodGlobe();
|
||||
|
||||
|
||||
|
||||
@@ -460,12 +460,12 @@ namespace openspace {
|
||||
format.ghoulFormat = Texture::Format::Red;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte: format.glFormat = GL_R8; break;
|
||||
case GDT_UInt16: format.glFormat = GL_R16; break;
|
||||
case GDT_Int16: format.glFormat = GL_R16; break;
|
||||
case GDT_UInt16: format.glFormat = GL_R16UI; break;
|
||||
case GDT_Int16: format.glFormat = GL_R16_SNORM; break;
|
||||
case GDT_UInt32: format.glFormat = GL_R32UI; break;
|
||||
case GDT_Int32: format.glFormat = GL_R32I; break;
|
||||
case GDT_Float32: format.glFormat = GL_R32F; break;
|
||||
//case GDT_Float64: format.glFormat = GL_RED; break; // No representation of 64 bit float?
|
||||
//case GDT_Float64: format.glFormat = GL_RED; break; // No representation of 64 bit float?
|
||||
default: LERROR("GDAL data type unknown to OpenGL: " << gdalType);
|
||||
}
|
||||
break;
|
||||
@@ -473,8 +473,8 @@ namespace openspace {
|
||||
format.ghoulFormat = Texture::Format::RG;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte: format.glFormat = GL_RG8; break;
|
||||
case GDT_UInt16: format.glFormat = GL_RG16; break;
|
||||
case GDT_Int16: format.glFormat = GL_RG16; break;
|
||||
case GDT_UInt16: format.glFormat = GL_RG16UI; break;
|
||||
case GDT_Int16: format.glFormat = GL_RG16_SNORM; break;
|
||||
case GDT_UInt32: format.glFormat = GL_RG32UI; break;
|
||||
case GDT_Int32: format.glFormat = GL_RG32I; break;
|
||||
case GDT_Float32: format.glFormat = GL_RG32F; break;
|
||||
@@ -486,8 +486,8 @@ namespace openspace {
|
||||
format.ghoulFormat = Texture::Format::RGB;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte: format.glFormat = GL_RGB8; break;
|
||||
case GDT_UInt16: format.glFormat = GL_RGB16; break;
|
||||
case GDT_Int16: format.glFormat = GL_RGB16; break;
|
||||
case GDT_UInt16: format.glFormat = GL_RGB16UI; break;
|
||||
case GDT_Int16: format.glFormat = GL_RGB16_SNORM; break;
|
||||
case GDT_UInt32: format.glFormat = GL_RGB32UI; break;
|
||||
case GDT_Int32: format.glFormat = GL_RGB32I; break;
|
||||
case GDT_Float32: format.glFormat = GL_RGB32F; break;
|
||||
@@ -499,8 +499,8 @@ namespace openspace {
|
||||
format.ghoulFormat = Texture::Format::RGBA;
|
||||
switch (gdalType) {
|
||||
case GDT_Byte: format.glFormat = GL_RGBA8; break;
|
||||
case GDT_UInt16: format.glFormat = GL_RGBA16; break;
|
||||
case GDT_Int16: format.glFormat = GL_RGBA16; break;
|
||||
case GDT_UInt16: format.glFormat = GL_RGBA16UI; break;
|
||||
case GDT_Int16: format.glFormat = GL_RGB16_SNORM; break;
|
||||
case GDT_UInt32: format.glFormat = GL_RGBA32UI; break;
|
||||
case GDT_Int32: format.glFormat = GL_RGBA32I; break;
|
||||
case GDT_Float32: format.glFormat = GL_RGBA32F; break;
|
||||
@@ -590,8 +590,6 @@ namespace openspace {
|
||||
pixelStart = glm::uvec2(pixelStart0.x >> toShift, pixelStart0.y >> toShift);
|
||||
pixelEnd = glm::uvec2(pixelEnd0.x >> toShift, pixelEnd0.y >> toShift);
|
||||
numPixels = pixelEnd - pixelStart;
|
||||
if (numPixels.x < 1000 && (pixelStart.x % 2 || pixelStart.y % 2))
|
||||
int hej = 0;
|
||||
}
|
||||
|
||||
TileDataset::DataLayout::DataLayout() {
|
||||
|
||||
@@ -51,8 +51,6 @@ namespace openspace {
|
||||
|
||||
const Tile Tile::TileUnavailable = {nullptr, nullptr, Tile::Status::Unavailable };
|
||||
|
||||
|
||||
|
||||
CachingTileProvider::CachingTileProvider(std::shared_ptr<AsyncTileDataProvider> tileReader,
|
||||
std::shared_ptr<TileCache> tileCache,
|
||||
int framesUntilFlushRequestQueue)
|
||||
@@ -102,7 +100,6 @@ namespace openspace {
|
||||
return tile;
|
||||
}
|
||||
|
||||
|
||||
void CachingTileProvider::initTexturesFromLoadedData() {
|
||||
while (_asyncTextureDataProvider->hasLoadedTextureData()) {
|
||||
std::shared_ptr<TileIOResult> tileIOResult = _asyncTextureDataProvider->nextTileIOResult();
|
||||
|
||||
@@ -616,7 +616,6 @@ void InteractionHandler::clearKeyframes(){
|
||||
#else // USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
|
||||
|
||||
// InteractionHandler
|
||||
InteractionHandler::InteractionHandler()
|
||||
: _origin("origin", "Origin", "")
|
||||
@@ -764,6 +763,7 @@ void InteractionHandler::restoreCameraPosition(const std::string& filepath) {
|
||||
|
||||
_camera->setPositionVec3(p);
|
||||
_camera->setRotation(r);
|
||||
_currentInteractionMode->initialize(*_camera);
|
||||
_cameraUpdatedFromScript = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,63 +338,91 @@ void GlobeBrowsingInteractionMode::setFocusNode(SceneGraphNode* focusNode) {
|
||||
|
||||
|
||||
void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates(Camera& camera) {
|
||||
using namespace glm;
|
||||
|
||||
if (_focusNode && _globe) {
|
||||
// Declare variables to use in interaction calculations
|
||||
dvec3 centerPos = _focusNode->worldPosition().dvec3();
|
||||
dvec3 camPos = camera.positionVec3();
|
||||
dvec3 posDiff = camPos - centerPos;
|
||||
dvec3 newPosition = camPos;
|
||||
// Shrink interaction ellipsoid to enable interaction below height = 0
|
||||
double ellipsoidShrinkTerm = 10000.0;
|
||||
double minHeightAboveGround = 100.0;
|
||||
|
||||
dvec3 centerToSurface = _globe->geodeticSurfaceProjection(camPos);
|
||||
dvec3 surfaceToCamera = camPos - (centerPos + centerToSurface);
|
||||
dvec3 directionFromSurfaceToCamera = normalize(surfaceToCamera);
|
||||
double distFromCenterToSurface = length(centerToSurface);
|
||||
double distFromSurfaceToCamera = length(surfaceToCamera);
|
||||
double distFromCenterToCamera = length(posDiff);
|
||||
glm::dvec3 centerPos = _focusNode->worldPosition().dvec3();
|
||||
glm::dvec3 camPos = camera.positionVec3();
|
||||
glm::dvec3 posDiff = camPos - centerPos;
|
||||
|
||||
glm::dvec3 directionFromSurfaceToCamera =
|
||||
_globe->ellipsoid().geodeticSurfaceNormal(
|
||||
_globe->ellipsoid().cartesianToGeodetic2(camPos));
|
||||
glm::dvec3 centerToEllipsoidSurface = _globe->projectOnEllipsoid(camPos) -
|
||||
directionFromSurfaceToCamera * ellipsoidShrinkTerm;
|
||||
glm::dvec3 ellipsoidSurfaceToCamera = camPos - (centerPos + centerToEllipsoidSurface);
|
||||
|
||||
double distFromCenterToSurface =
|
||||
glm::length(centerToEllipsoidSurface);
|
||||
double distFromEllipsoidSurfaceToCamera = glm::length(ellipsoidSurfaceToCamera);
|
||||
double distFromCenterToCamera = glm::length(posDiff);
|
||||
|
||||
{ // Do local rotation
|
||||
dvec3 eulerAngles(_localRotationMouseState.velocity.get().y, 0, 0);
|
||||
dquat rotationDiff = dquat(eulerAngles);
|
||||
glm::dvec3 eulerAngles(_localRotationMouseState.velocity.get().y, 0, 0);
|
||||
glm::dquat rotationDiff = glm::dquat(eulerAngles);
|
||||
|
||||
_localCameraRotation = _localCameraRotation * rotationDiff;
|
||||
}
|
||||
{ // Do global rotation
|
||||
dvec2 smoothMouseVel = _globalRotationMouseState.velocity.get();
|
||||
dvec3 eulerAngles(smoothMouseVel.y, -smoothMouseVel.x, 0);
|
||||
dquat rotationDiffCamSpace = dquat(eulerAngles);
|
||||
glm::dvec3 eulerAngles = glm::dvec3(
|
||||
-_globalRotationMouseState.velocity.get().y,
|
||||
-_globalRotationMouseState.velocity.get().x,
|
||||
0) * glm::clamp(distFromEllipsoidSurfaceToCamera / distFromCenterToSurface, 0.0, 1.0);
|
||||
glm::dquat rotationDiffCamSpace = glm::dquat(eulerAngles);
|
||||
|
||||
glm::dquat rotationDiffWorldSpace =
|
||||
_globalCameraRotation *
|
||||
rotationDiffCamSpace *
|
||||
glm::inverse(_globalCameraRotation);
|
||||
|
||||
dquat rotationDiffWorldSpace = _globalCameraRotation * rotationDiffCamSpace
|
||||
* inverse(_globalCameraRotation);
|
||||
glm::dvec3 rotationDiffVec3 =
|
||||
(distFromCenterToCamera * directionFromSurfaceToCamera)
|
||||
* rotationDiffWorldSpace
|
||||
- (distFromCenterToCamera * directionFromSurfaceToCamera);
|
||||
|
||||
dvec3 rotationDiffVec3 = (distFromCenterToCamera * directionFromSurfaceToCamera)
|
||||
* rotationDiffWorldSpace - (distFromCenterToCamera * directionFromSurfaceToCamera);
|
||||
rotationDiffVec3 *= clamp(distFromSurfaceToCamera / distFromCenterToSurface, 0.0, 1.0);
|
||||
camPos = camPos + rotationDiffVec3;
|
||||
|
||||
newPosition = camPos + rotationDiffVec3;
|
||||
directionFromSurfaceToCamera =
|
||||
_globe->ellipsoid().geodeticSurfaceNormal(
|
||||
_globe->ellipsoid().cartesianToGeodetic2(camPos));
|
||||
centerToEllipsoidSurface = _globe->projectOnEllipsoid(camPos) -
|
||||
directionFromSurfaceToCamera * ellipsoidShrinkTerm;
|
||||
ellipsoidSurfaceToCamera = camPos - (centerPos + centerToEllipsoidSurface);
|
||||
|
||||
dvec3 newCenterToSurface = _globe->geodeticSurfaceProjection(newPosition);
|
||||
dvec3 newSurfaceToCamera = newPosition - (centerPos + newCenterToSurface);
|
||||
dvec3 newDirectionFromSurfaceToCamera = normalize(newSurfaceToCamera);
|
||||
|
||||
dvec3 lookUpWhenFacingSurface = _globalCameraRotation * dvec3(camera.lookUpVectorCameraSpace());
|
||||
dmat4 lookAtMat = lookAt(dvec3(0, 0, 0), -newDirectionFromSurfaceToCamera, lookUpWhenFacingSurface);
|
||||
_globalCameraRotation = normalize(quat_cast(inverse(lookAtMat)));
|
||||
glm::dvec3 lookUpWhenFacingSurface =
|
||||
_globalCameraRotation * glm::dvec3(camera.lookUpVectorCameraSpace());
|
||||
glm::dmat4 lookAtMat = glm::lookAt(
|
||||
glm::dvec3(0, 0, 0),
|
||||
-directionFromSurfaceToCamera,
|
||||
lookUpWhenFacingSurface);
|
||||
_globalCameraRotation =
|
||||
glm::normalize(glm::quat_cast(glm::inverse(lookAtMat)));
|
||||
}
|
||||
{ // Move position towards or away from focus node
|
||||
newPosition += -(posDiff - centerToSurface) * _truckMovementMouseState.velocity.get().y;
|
||||
distFromEllipsoidSurfaceToCamera = glm::length(ellipsoidSurfaceToCamera);
|
||||
camPos += -directionFromSurfaceToCamera * distFromEllipsoidSurfaceToCamera *
|
||||
_truckMovementMouseState.velocity.get().y;
|
||||
}
|
||||
{ // Do roll
|
||||
dquat cameraRollRotation =
|
||||
angleAxis(_rollMouseState.velocity.get().x, directionFromSurfaceToCamera);
|
||||
glm::dquat cameraRollRotation =
|
||||
glm::angleAxis(_rollMouseState.velocity.get().x, directionFromSurfaceToCamera);
|
||||
_globalCameraRotation = cameraRollRotation * _globalCameraRotation;
|
||||
}
|
||||
{ // Push up to surface
|
||||
ellipsoidSurfaceToCamera = camPos - (centerPos + centerToEllipsoidSurface);
|
||||
|
||||
distFromEllipsoidSurfaceToCamera = glm::length(ellipsoidSurfaceToCamera);
|
||||
double heightToSurface = _globe->getHeight(camPos) + ellipsoidShrinkTerm;
|
||||
double heightToSurfaceAndPadding = heightToSurface + minHeightAboveGround;
|
||||
camPos += directionFromSurfaceToCamera *
|
||||
glm::max(heightToSurfaceAndPadding - distFromEllipsoidSurfaceToCamera, 0.0);
|
||||
}
|
||||
// Update the camera state
|
||||
camera.setRotation(_globalCameraRotation * _localCameraRotation);
|
||||
camera.setPositionVec3(newPosition);
|
||||
camera.setPositionVec3(camPos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user