Change equatorial aim to be vec2 and fix hard crash bug with texture resolution and scaling

This commit is contained in:
sylvass
2021-12-14 11:21:46 -05:00
parent fa5812c83a
commit efddc8bc46
12 changed files with 113 additions and 91 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ public:
void setCallbackDimensions(const std::function<void(const glm::dvec2&)>& function);
protected:
properties::Vec2Property _dimensions;
properties::Vec2Property _browserPixeldimensions;
properties::StringProperty _url;
properties::TriggerProperty _reload;
+1 -1
View File
@@ -87,7 +87,7 @@ public:
// Getters by value
float verticalFov() const;
glm::ivec3 borderColor() const;
glm::dvec3 targetDirectionEquatorial() const;
glm::dvec2 targetDirectionEquatorial() const;
glm::dvec3 targetDirectionGalactic() const;
std::string browserGuiName() const;
std::string browserId() const;
@@ -6,6 +6,7 @@
#include <openspace/documentation/documentation.h>
#include <openspace/properties/scalar/doubleproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec2property.h>
namespace openspace {
@@ -35,11 +36,11 @@ namespace openspace {
// Setters
void setVerticalFovWithScroll(float scroll);
void setScale(glm::vec2 scalingFactor);
void setScale(float scalingFactor);
void setOpacity(float opacity);
void setScreenSpaceSize(const glm::vec2& newSize);
// Set callback functions
void setCallbackEquatorialAim(std::function<void(glm::dvec3, bool)> function);
void setCallbackEquatorialAim(std::function<void(const glm::dvec2&)> function);
void setCallbackVerticalFov(std::function<void(float)> function);
void setCallbackDimensions(std::function<void(const glm::vec2&)> function);
void setCallbackBorderColor(std::function<void(const glm::ivec3&)> function);
@@ -58,12 +59,14 @@ namespace openspace {
private:
properties::DoubleProperty _animationSpeed;
properties::FloatProperty _textureQuality;
properties::Vec2Property _size;
void bindTexture() override;
// Flags
bool _isSyncedWithWwt{ false };
bool _isFovAnimated{ false };
bool _textureDimensionsIsDirty{ false };
// Animation of fieldOfView
float _endVfov{ 0.f };
@@ -42,13 +42,11 @@ namespace openspace {
void setLock(bool isLocked);
// Set callbacks
void setCallbackEnabled(std::function<void(bool)> function);
void setCallbackPosition(std::function<void(const glm::vec3&)> function);
void setSkyBrowser(ScreenSpaceSkyBrowser* browser);
// Target directions
glm::dvec3 directionGalactic() const;
glm::dvec3 equatorialAim() const;
glm::dvec2 equatorialAim() const;
// Locking functionality
bool isLocked() const;
+2 -2
View File
@@ -60,13 +60,13 @@ public:
float verticalFov() const;
glm::dvec2 fieldsOfView();
bool hasLoadedImages() const;
glm::dvec3 equatorialAim() const;
glm::dvec2 equatorialAim() const;
// Setters
void setHasLoadedImages(bool isLoaded);
void setVerticalFov(float vfov);
void setIsSyncedWithWwt(bool isSynced);
void setEquatorialAim(glm::dvec3 cartesian);
void setEquatorialAim(const glm::dvec2& equatorial);
// Display
void highlight(glm::ivec3 addition);
+3 -2
View File
@@ -337,8 +337,9 @@ int getTargetData(lua_State* L) {
selectedImagesVector.push_back(i);
});
glm::dvec3 cartesian = pair->targetDirectionEquatorial();
glm::dvec2 spherical = skybrowser::cartesianToSpherical(cartesian);
glm::dvec2 spherical = pair->targetDirectionEquatorial();
glm::dvec3 cartesian = skybrowser::sphericalToCartesian(spherical);
std::vector<double> cartesianVec = {
cartesian.x,
+12 -9
View File
@@ -69,7 +69,7 @@ namespace openspace {
Browser::Browser(const ghoul::Dictionary& dictionary)
: _url(UrlInfo)
, _dimensions(DimensionsInfo, glm::vec2(0.f), glm::vec2(0.f), glm::vec2(3000.f))
, _browserPixeldimensions(DimensionsInfo, glm::vec2(500.f), glm::vec2(10.f), glm::vec2(3000.f))
, _reload(ReloadInfo)
{
if (dictionary.hasValue<std::string>(UrlInfo.identifier)) {
@@ -77,10 +77,10 @@ namespace openspace {
}
glm::vec2 windowDimensions = global::windowDelegate->currentSubwindowSize();
_dimensions = windowDimensions;
_browserPixeldimensions = windowDimensions;
_url.onChange([this]() { _isUrlDirty = true; });
_dimensions.onChange([this]() { _isDimensionsDirty = true; });
_browserPixeldimensions.onChange([this]() { _isDimensionsDirty = true; });
_reload.onChange([this]() { _shouldReload = true; });
// Create browser and render handler
@@ -103,7 +103,7 @@ namespace openspace {
bool Browser::initializeGL() {
_texture = std::make_unique<ghoul::opengl::Texture>(
glm::uvec3(_dimensions.value(), 1.0f)
glm::uvec3(_browserPixeldimensions.value(), 1.0f)
);
_renderHandler->setTexture(*_texture);
@@ -153,7 +153,10 @@ namespace openspace {
}
if (_isDimensionsDirty) {
_browserInstance->reshape(_dimensions.value());
ghoul_assert(_browserPixeldimensions.value().x > 0 &&
_browserPixeldimensions.value().y > 0);
_browserInstance->reshape(_browserPixeldimensions.value());
_isDimensionsDirty = false;
}
@@ -168,12 +171,12 @@ namespace openspace {
}
glm::vec2 Browser::browserPixelDimensions() const {
return _dimensions.value();
return _browserPixeldimensions.value();
}
// Updates the browser size to match the size of the texture
void Browser::updateBrowserSize() {
_dimensions = _texture->dimensions();
_browserPixeldimensions = _texture->dimensions();
}
float Browser::browserRatio() const
@@ -185,8 +188,8 @@ namespace openspace {
void Browser::setCallbackDimensions(
const std::function<void(const glm::dvec2&)>& function)
{
_dimensions.onChange([&]() {
function(_dimensions.value());
_browserPixeldimensions.onChange([&]() {
function(_browserPixeldimensions.value());
});
}
+10 -10
View File
@@ -46,13 +46,14 @@ namespace openspace {
// Set browser callback functions
// Set callback functions so that the target and the browser update each other
_browser->setCallbackEquatorialAim(
[&](const glm::dvec3& equatorialAim, bool) {
double diff = glm::length(equatorialAim - _target->equatorialAim());
if ( diff > AnimationThreshold) {
_target->setCartesianPosition(
skybrowser::equatorialToScreenSpace3d(equatorialAim)
);
}
[&](const glm::dvec2& equatorialAim) {
glm::dvec3 cartesian = skybrowser::sphericalToCartesian(
equatorialAim
);
_target->setCartesianPosition(
skybrowser::equatorialToScreenSpace3d(cartesian)
);
}
);
_browser->setCallbackBorderColor(
@@ -75,10 +76,9 @@ namespace openspace {
[&](bool enabled) {
_target->setEnabled(enabled);
}
);
);
_target->setSkyBrowser(_browser);
}
Pair& Pair::operator=(Pair other)
@@ -206,7 +206,7 @@ namespace openspace {
return _browser->borderColor();
}
glm::dvec3 Pair::targetDirectionEquatorial() const
glm::dvec2 Pair::targetDirectionEquatorial() const
{
return _target->equatorialAim();
}
@@ -69,10 +69,10 @@ namespace openspace {
// Maybe change later
glm::vec2 windowDimensions = global::windowDelegate->currentSubwindowSize();
float maxDimension = std::max(windowDimensions.x, windowDimensions.y);
_dimensions = { maxDimension, maxDimension };
_browserPixeldimensions = { maxDimension, maxDimension };
addProperty(_url);
addProperty(_dimensions);
addProperty(_browserPixeldimensions);
addProperty(_reload);
addProperty(_verticalFov);
addProperty(_borderColor);
@@ -40,6 +40,16 @@ namespace {
"slower framerate. Lower value means lower resolution of texture and faster "
"frame rate."
};
constexpr const openspace::properties::Property::PropertyInfo SizeInfo =
{
"Size",
"Screen space size of the sky browser",
"The size of the sky browser determines how large is on screen. The y parameter "
"determines the percentage of the screen the browser will cover in the "
"y-direction. The x parameter determines how large the sky browser will be in "
"the x direction."
};
struct [[codegen::Dictionary(ScreenSpaceSkyBrowser)]] Parameters {
@@ -66,6 +76,7 @@ namespace openspace {
, WwtCommunicator(dictionary)
, _animationSpeed(AnimationSpeedInfo, 5.0, 0.1, 10.0)
, _textureQuality(TextureQualityInfo, 1.f, 0.25f, 1.f)
, _size(SizeInfo, glm::vec2(0.5f), glm::vec2(0.f), glm::vec2(2.f))
{
// Set a unique identifier
std::string identifier;
@@ -88,20 +99,25 @@ namespace openspace {
_textureQuality = p.textureQuality.value_or(_textureQuality);
addProperty(_url);
addProperty(_dimensions);
addProperty(_browserPixeldimensions);
addProperty(_reload);
addProperty(_verticalFov);
addProperty(_borderColor);
addProperty(_equatorialAim);
addProperty(_textureQuality);
addProperty(_size);
_textureQuality.onChange([this]() {
updateTextureResolution();
_textureDimensionsIsDirty = true;
});
_size.onChange([this]() {
setScreenSpaceSize(_size);
});
// Ensure that the browser is placed at the z-coordinate of the screen space plane
glm::vec2 screenPosition = _cartesianPosition.value();
_cartesianPosition.setValue(glm::vec3(screenPosition, skybrowser::ScreenSpaceZ));
_cartesianPosition.setValue(glm::vec3(screenPosition, skybrowser::ScreenSpaceZ));
}
ScreenSpaceSkyBrowser::~ScreenSpaceSkyBrowser() {
@@ -137,16 +153,16 @@ namespace openspace {
void ScreenSpaceSkyBrowser::updateTextureResolution()
{
// Scale texture depending on the height of the window
// Set texture size to the actual pixel size it covers
glm::vec2 pixels = glm::vec2(global::windowDelegate->currentSubwindowSize());
glm::vec2 browserDim = screenSpaceDimensions();
float newResY = pixels.y * browserDim.y;
float newResX = newResY * (_dimensions.value().x / _dimensions.value().y);
// If the scale is 1, it covers half the window. Hence multiplication with 2
float newResY = pixels.y * 2.f * _scale;
float newResX = newResY * (_browserPixeldimensions.value().x / _browserPixeldimensions.value().y);
glm::vec2 newSize = glm::vec2(newResX , newResY) * _textureQuality.value();
_dimensions = glm::ivec2(newSize);
_browserPixeldimensions = glm::ivec2(newSize);
_texture->setDimensions(glm::ivec3(newSize, 1));
}
@@ -194,14 +210,16 @@ namespace openspace {
}
void ScreenSpaceSkyBrowser::update() {
if (global::windowDelegate->windowHasResized()) {
// Change the resolution of the texture
// Texture of window is 1x1 when minimized
bool isWindow = global::windowDelegate->currentSubwindowSize() != glm::ivec2(1);
bool isWindowResized = global::windowDelegate->windowHasResized();
if ((isWindowResized && isWindow) || _textureDimensionsIsDirty) {
updateTextureResolution();
_textureDimensionsIsDirty = false;
}
_objectSize = _texture->dimensions();
_objectSize = _texture->dimensions();
WwtCommunicator::update();
ScreenSpaceRenderable::update();
}
@@ -258,8 +276,15 @@ namespace openspace {
glm::vec2 scaling = mouseDrag * glm::vec2(_resizeDirection);
glm::vec2 newSizeRelToOld = (_originalScreenSpaceSize + (scaling)) /
_originalScreenSpaceSize;
_scale = _originalScale * abs(newSizeRelToOld.y);
// Resize the dimensions of the texture on the x axis
glm::vec2 newDimensions = abs(newSizeRelToOld) * _originalDimensions;
// Scale the browser
setScale(newSizeRelToOld);
// Scale on the y axis, this is to ensure that _scale = 1 is
// equal to the height of the window
_texture->setDimensions(glm::ivec3(newDimensions, 1));
_objectSize = _texture->dimensions();
// For dragging functionality, translate so it looks like the
// browser isn't moving. Make sure the browser doesn't move in
@@ -270,22 +295,6 @@ namespace openspace {
translate(translation, start);
}
void ScreenSpaceSkyBrowser::setScale(float scalingFactor) {
_scale = _originalScale * scalingFactor;
}
// Scales the ScreenSpaceBrowser to a new ratio
void ScreenSpaceSkyBrowser::setScale(glm::vec2 scalingFactor) {
// Scale on the y axis, this is to ensure that _scale = 1 is
// equal to the height of the window
setScale(abs(scalingFactor.y));
// Resize the dimensions of the texture on the x axis
glm::vec2 newSize = abs(scalingFactor) * _originalDimensions;
_texture->setDimensions(glm::ivec3(newSize, 1));
_objectSize = _texture->dimensions();
}
glm::mat4 ScreenSpaceSkyBrowser::scaleMatrix() {
// To ensure the plane has the right ratio
// The _scale tells us how much of the windows height the
@@ -301,15 +310,15 @@ namespace openspace {
void ScreenSpaceSkyBrowser::saveResizeStartSize() {
_originalScreenSpaceSize = screenSpaceDimensions();
_originalDimensions = _dimensions;
_originalDimensions = _browserPixeldimensions;
_originalScale = _scale;
}
void ScreenSpaceSkyBrowser::setCallbackEquatorialAim(
std::function<void(glm::dvec3, bool)> function)
std::function<void(const glm::dvec2&)> function)
{
_equatorialAim.onChange([this, f = std::move(function)]() {
f(skybrowser::sphericalToCartesian(_equatorialAim), false);
f(_equatorialAim);
});
}
@@ -324,8 +333,8 @@ namespace openspace {
void ScreenSpaceSkyBrowser::setCallbackDimensions(
std::function<void(const glm::vec2&)> function)
{
_dimensions.onChange([this, f = std::move(function)]() {
f(_dimensions);
_browserPixeldimensions.onChange([this, f = std::move(function)]() {
f(_browserPixeldimensions);
});
}
@@ -342,12 +351,27 @@ namespace openspace {
});
}
void ScreenSpaceSkyBrowser::setOpacity(float opacity)
{
_opacity = opacity;
}
void ScreenSpaceSkyBrowser::setScreenSpaceSize(const glm::vec2& newSize)
{
_scale = abs(newSize.y) * 0.5f;
glm::vec2 newSizeRelToOld = abs((screenSpaceDimensions() + newSize) /
screenSpaceDimensions());
glm::vec2 newDimensions = newSizeRelToOld * glm::vec2(_texture->dimensions());
// Scale the browser
// Scale on the y axis, this is to ensure that _scale = 1 is
// equal to the height of the window
_browserPixeldimensions = glm::ivec2(newDimensions);
_texture->setDimensions(glm::ivec3(newDimensions, 1));
_objectSize = _texture->dimensions();
updateTextureResolution();
}
float ScreenSpaceSkyBrowser::opacity() const {
return _opacity;
}
+11 -18
View File
@@ -270,7 +270,9 @@ namespace openspace {
void ScreenSpaceSkyTarget::startAnimation(glm::dvec3 equatorialCoordsEnd,
bool shouldLockAfter)
{
_animationStart = glm::normalize(equatorialAim());
_animationStart = glm::normalize(
skybrowser::sphericalToCartesian(equatorialAim())
);
_animationEnd = glm::normalize(equatorialCoordsEnd);
_shouldLockAfterAnimation = shouldLockAfter;
_isAnimated = true;
@@ -302,7 +304,8 @@ namespace openspace {
_cartesianPosition = skybrowser::equatorialToScreenSpace3d(newDir);
// Update position
_animationStart = glm::normalize(equatorialAim());
glm::dvec3 cartesian = skybrowser::sphericalToCartesian(equatorialAim());
_animationStart = glm::normalize(cartesian);
}
else {
glm::dvec3 screenSpace = skybrowser::equatorialToScreenSpace3d(_animationEnd);
@@ -314,10 +317,13 @@ namespace openspace {
}
}
glm::dvec3 ScreenSpaceSkyTarget::equatorialAim() const {
glm::dvec2 ScreenSpaceSkyTarget::equatorialAim() const {
// Calculate the galactic coordinate of the target direction
// projected onto the celestial sphere
return skybrowser::localCameraToEquatorial(_cartesianPosition.value());
glm::dvec3 cartesian = skybrowser::localCameraToEquatorial(
_cartesianPosition.value()
);
return skybrowser::cartesianToSpherical(cartesian);
}
@@ -342,22 +348,9 @@ namespace openspace {
{
_isLocked = isLocked;
if (_isLocked) {
_lockedCoordinates = equatorialAim();
_lockedCoordinates = skybrowser::sphericalToCartesian(equatorialAim());
}
}
void ScreenSpaceSkyTarget::setCallbackEnabled(std::function<void(bool)> function)
{
_enabled.onChange([this, f = std::move(function)]() {
f(_enabled);
});
}
void ScreenSpaceSkyTarget::setCallbackPosition(
std::function<void(const glm::vec3&)> function)
{
_cartesianPosition.onChange([this, f = std::move(function)]() {
f(_cartesianPosition);
});
}
void ScreenSpaceSkyTarget::setSkyBrowser(ScreenSpaceSkyBrowser* browser)
{
_browser = browser;
+4 -4
View File
@@ -127,9 +127,9 @@ namespace openspace {
_isSyncedWithWwt = isSynced;
}
void WwtCommunicator::setEquatorialAim(glm::dvec3 cartesian)
void WwtCommunicator::setEquatorialAim(const glm::dvec2& equatorial)
{
_equatorialAim = skybrowser::cartesianToSpherical(cartesian);
_equatorialAim = equatorial;
updateAim();
}
@@ -170,9 +170,9 @@ namespace openspace {
return _hasLoadedImages;
}
glm::dvec3 WwtCommunicator::equatorialAim() const
glm::dvec2 WwtCommunicator::equatorialAim() const
{
return skybrowser::sphericalToCartesian(_equatorialAim);
return _equatorialAim;
}
void WwtCommunicator::setImageOrder(int i, int order) {