mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Make apperance of target match the dimensions of the sky browser. Fixes issue #1926
This commit is contained in:
@@ -53,7 +53,6 @@ public:
|
||||
float opacity() const;
|
||||
double animationSpeed() const;
|
||||
double stopAnimationThreshold() const;
|
||||
double smallestFov() const;
|
||||
|
||||
void setDimensions(glm::vec2 dimensions);
|
||||
void setColor(glm::ivec3 color);
|
||||
@@ -69,7 +68,6 @@ private:
|
||||
properties::FloatProperty _crossHairSize;
|
||||
properties::FloatProperty _showRectangleThreshold;
|
||||
properties::FloatProperty _lineWidth;
|
||||
properties::DoubleProperty _smallestFov;
|
||||
properties::DoubleProperty _stopAnimationThreshold;
|
||||
properties::DoubleProperty _animationSpeed;
|
||||
|
||||
|
||||
@@ -67,8 +67,6 @@ public:
|
||||
|
||||
// Target
|
||||
void centerTargetOnScreen();
|
||||
void lock();
|
||||
void unlock();
|
||||
void incrementallyAnimateTarget(float deltaTime);
|
||||
|
||||
bool hasFinishedFading(float goalState) const;
|
||||
@@ -116,9 +114,7 @@ private:
|
||||
bool isTargetFadeFinished(float goalState) const;
|
||||
bool isBrowserFadeFinished(float goalState) const;
|
||||
|
||||
void aimTargetGalactic(glm::dvec3 position);
|
||||
|
||||
void setFovTarget(double fov);
|
||||
void aimTargetGalactic(glm::dvec3 direction);
|
||||
|
||||
// Selection
|
||||
ScreenSpaceSkyBrowser* _selected = nullptr;
|
||||
|
||||
@@ -42,7 +42,7 @@ uniform vec3 multiplyColor;
|
||||
|
||||
// A factor which states how much thicker vertical lines are rendered than horizontal
|
||||
// This compensates for the optical illusion that vertical lines appear thinner
|
||||
const float VerticalThickness = 1.15;
|
||||
const float VerticalThickness = 1.1;
|
||||
|
||||
float createLine(float lineCenter, float lineWidth, float coord) {
|
||||
// Calculate edges of line
|
||||
@@ -52,28 +52,13 @@ float createLine(float lineCenter, float lineWidth, float coord) {
|
||||
return step(startEdge, coord) - step(endEdge, coord);
|
||||
}
|
||||
|
||||
float createFilledRectangle(float width, vec2 coord) {
|
||||
return createLine(0.5, width, coord.x) * createLine(0.5, width, coord.y);
|
||||
}
|
||||
|
||||
float createRectangle(float linewidthY, float ratio, vec2 coord) {
|
||||
// Calculate the widths and centers for the lines
|
||||
float linewidthX = linewidthY * ratio * VerticalThickness;
|
||||
float linecenterX = linewidthX * 0.5;
|
||||
float linecenterY = linewidthY * 0.5;
|
||||
|
||||
// Create the four lines for the rectangle
|
||||
float l = createLine(linecenterX, linewidthX, coord.x);
|
||||
float r = createLine(1.0 - linecenterX, linewidthX, coord.x);
|
||||
float b = createLine(linecenterY, linewidthY, coord.y);
|
||||
float t = createLine(1.0 - linecenterY, linewidthY, coord.y);
|
||||
|
||||
return l + r + b + t;
|
||||
float createFilledRectangle(float width, float height, vec2 coord) {
|
||||
return createLine(0.5, width, coord.x) * createLine(0.5, height, coord.y);
|
||||
}
|
||||
|
||||
float createCrosshair(in float linewidth, in float ratio, in vec2 coord) {
|
||||
const float Center = 0.5;
|
||||
float crosshairVertical = createLine(Center, linewidth * ratio * VerticalThickness, coord.x);
|
||||
float crosshairVertical = createLine(Center, linewidth * VerticalThickness, coord.x);
|
||||
float crosshairHorizontal = createLine(Center, linewidth, coord.y);
|
||||
|
||||
return crosshairHorizontal + crosshairVertical;
|
||||
@@ -84,14 +69,22 @@ float createCrosshair(in float linewidth, in float ratio, in vec2 coord) {
|
||||
Fragment getFragment() {
|
||||
float ratio = dimensions.y / dimensions.x;
|
||||
float rectangle = 0.0;
|
||||
float lineWidthUsed = (lineWidth * 0.01)/max(fov,2);
|
||||
float maxWwtFov = 70;
|
||||
|
||||
float crosshair = createCrosshair(lineWidthUsed, ratio, vs_st);
|
||||
float crossHairBox = createFilledRectangle(crossHairSize/max(fov,2), vs_st);
|
||||
float crosshair = createCrosshair(lineWidth, ratio, vs_st);
|
||||
float crossHairHeight = crossHairSize/maxWwtFov;
|
||||
float crossHairWidth = crossHairHeight * ratio;
|
||||
float crossHairBox = createFilledRectangle(crossHairHeight, crossHairWidth, vs_st);
|
||||
crosshair *= crossHairBox;
|
||||
|
||||
if (showRectangle) {
|
||||
rectangle = createRectangle(lineWidthUsed, ratio, vs_st);
|
||||
float height = fov/maxWwtFov;
|
||||
float width = height * ratio;
|
||||
float outerEdge = createFilledRectangle(height, width, vs_st);
|
||||
float lineWidthX = lineWidth * 2 * VerticalThickness;
|
||||
float lineWidthY = lineWidth * 2;
|
||||
float innerEdge = createFilledRectangle(height-lineWidthX, width-lineWidthY, vs_st);
|
||||
rectangle = outerEdge - innerEdge;
|
||||
}
|
||||
|
||||
float result = clamp(crosshair + rectangle, 0.0, 1.0);
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include <modules/skybrowser/skybrowsermodule.h>
|
||||
|
||||
#include <modules/skybrowser/include/utility.h>
|
||||
#include <modules/skybrowser/include/targetbrowserpair.h>
|
||||
#include <modules/skybrowser/include/wwtdatahandler.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
@@ -394,7 +396,7 @@ namespace {
|
||||
glm::dvec3 galacticTarget = skybrowser::localCameraToGalactic(positionTarget);
|
||||
std::string guiPath = "/SkyBrowser";
|
||||
std::string url = "https://data.openspaceproject.com/dist/skybrowser/page/";
|
||||
double fov = 5.0;
|
||||
double fov = 70.0;
|
||||
double size = skybrowser::sizeFromFov(fov, galacticTarget);
|
||||
|
||||
const std::string browser = "{"
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace {
|
||||
{
|
||||
"CrosshairSize",
|
||||
"Crosshair Size",
|
||||
"Determines the size of the crosshair."
|
||||
"Determines the size of the crosshair. The size is determined in fov (degrees). "
|
||||
};
|
||||
|
||||
constexpr const openspace::properties::Property::PropertyInfo RectangleThresholdInfo =
|
||||
@@ -85,12 +85,6 @@ namespace {
|
||||
"The thickness of the line of the target. The larger number, the thicker line."
|
||||
};
|
||||
|
||||
constexpr const openspace::properties::Property::PropertyInfo SmallestFovInfo = {
|
||||
"SmallestFov",
|
||||
"Smallest Vertical Field Of View",
|
||||
"The smallest field of view that the target will display on screen."
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(RenderableSkyTarget)]] Parameters {
|
||||
// [[codegen::verbatim(crossHairSizeInfo.description)]]
|
||||
std::optional<float> crossHairSize;
|
||||
@@ -106,9 +100,6 @@ namespace {
|
||||
|
||||
// [[codegen::verbatim(LineWidthInfo.description)]]
|
||||
std::optional<float> lineWidth;
|
||||
|
||||
// [[codegen::verbatim(SmallestFovInfo.description)]]
|
||||
std::optional<float> smallestFov;
|
||||
};
|
||||
|
||||
#include "renderableskytarget_codegen.cpp"
|
||||
@@ -122,7 +113,6 @@ namespace openspace {
|
||||
, _stopAnimationThreshold(AnimationThresholdInfo, 5.0f, 1.f, 10.f)
|
||||
, _animationSpeed(AnimationSpeedInfo, 5.0, 0.1, 10.0)
|
||||
, _lineWidth(LineWidthInfo, 13.f, 1.f, 100.f)
|
||||
, _smallestFov(SmallestFovInfo, 3.0, 0.5, 20.0)
|
||||
, _borderColor(220, 220, 220)
|
||||
{
|
||||
// Handle target dimension property
|
||||
@@ -131,14 +121,12 @@ namespace openspace {
|
||||
_showRectangleThreshold = p.rectangleThreshold.value_or(_showRectangleThreshold);
|
||||
_stopAnimationThreshold = p.crossHairSize.value_or(_stopAnimationThreshold);
|
||||
_animationSpeed = p.animationSpeed.value_or(_animationSpeed);
|
||||
_smallestFov = p.smallestFov.value_or(_smallestFov);
|
||||
|
||||
addProperty(_crossHairSize);
|
||||
addProperty(_showRectangleThreshold);
|
||||
addProperty(_stopAnimationThreshold);
|
||||
addProperty(_animationSpeed);
|
||||
addProperty(_lineWidth);
|
||||
addProperty(_smallestFov);
|
||||
}
|
||||
|
||||
void RenderableSkyTarget::bindTexture() {}
|
||||
@@ -186,7 +174,7 @@ void RenderableSkyTarget::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
_shader->setUniform("crossHairSize", _crossHairSize);
|
||||
_shader->setUniform("showRectangle", showRectangle);
|
||||
_shader->setUniform("lineWidth", _lineWidth);
|
||||
_shader->setUniform("lineWidth", _lineWidth * 0.0001f);
|
||||
_shader->setUniform("dimensions", _dimensions);
|
||||
_shader->setUniform("lineColor", color);
|
||||
_shader->setUniform("fov", static_cast<float>(_verticalFov));
|
||||
@@ -279,10 +267,6 @@ double RenderableSkyTarget::stopAnimationThreshold() const {
|
||||
return _stopAnimationThreshold * 0.0001;
|
||||
}
|
||||
|
||||
double RenderableSkyTarget::smallestFov() const {
|
||||
return _smallestFov;
|
||||
}
|
||||
|
||||
void RenderableSkyTarget::setOpacity(float opacity) {
|
||||
_opacity = opacity;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ glm::dvec2 ScreenSpaceSkyBrowser::fineTuneVector(glm::dvec2 drag) {
|
||||
glm::dvec2 resultRelativeOs = angleResult / openSpaceFOV;
|
||||
|
||||
// Convert to screen space coordinate system
|
||||
glm::dvec2 convertToScreenSpace{ (2 * skybrowser::windowRatio()), 2.f };
|
||||
glm::dvec2 convertToScreenSpace{ (2.f * skybrowser::windowRatio()), 2.f };
|
||||
glm::dvec2 result = - convertToScreenSpace * resultRelativeOs;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -92,24 +92,6 @@ void TargetBrowserPair::aimTargetGalactic(glm::dvec3 direction) {
|
||||
);
|
||||
}
|
||||
|
||||
void TargetBrowserPair::setFovTarget(double fov) {
|
||||
std::string id = _targetNode->identifier();
|
||||
std::string renderableId = _targetRenderable->identifier();
|
||||
// Uris for properties
|
||||
std::string sizeUri = "Scene." + id + "." + renderableId + ".Size";
|
||||
|
||||
double renderedFov = std::max(fov, _targetRenderable->smallestFov());
|
||||
double size = skybrowser::sizeFromFov(renderedFov, _targetNode->worldPosition());
|
||||
|
||||
std::string setValue = "openspace.setPropertyValueSingle('";
|
||||
|
||||
openspace::global::scriptEngine->queueScript(
|
||||
setValue + sizeUri + "', " + std::to_string(size) + ");",
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
_targetRenderable->setVerticalFov(renderedFov);
|
||||
}
|
||||
|
||||
bool TargetBrowserPair::checkMouseIntersection(const glm::vec2& mousePosition) {
|
||||
_selected = _browser->isIntersecting(mousePosition) ? _browser : nullptr;
|
||||
|
||||
@@ -162,7 +144,7 @@ void TargetBrowserPair::synchronizeAim() {
|
||||
// target, send the locked coordinates to wwt
|
||||
glm::dvec2 aim = targetDirectionEquatorial();
|
||||
_browser->setEquatorialAim(aim);
|
||||
setFovTarget(_browser->verticalFov());
|
||||
_targetRenderable->setVerticalFov(_browser->verticalFov());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +158,7 @@ bool TargetBrowserPair::isEnabled() const {
|
||||
|
||||
void TargetBrowserPair::initialize() {
|
||||
_targetRenderable->setColor(_browser->borderColor());
|
||||
_targetRenderable->setDimensions(_browser->browserPixelDimensions());
|
||||
_targetRenderable->setDimensions(_browser->screenSpaceDimensions());
|
||||
_browser->updateBorderColor();
|
||||
}
|
||||
|
||||
@@ -271,7 +253,7 @@ void TargetBrowserPair::setIsSyncedWithWwt(bool isSynced) {
|
||||
|
||||
void TargetBrowserPair::setVerticalFov(float vfov) {
|
||||
_browser->setVerticalFov(vfov);
|
||||
setFovTarget(vfov);
|
||||
_targetRenderable->setVerticalFov(vfov);
|
||||
}
|
||||
|
||||
void TargetBrowserPair::setEquatorialAim(const glm::dvec2& aim) {
|
||||
@@ -290,6 +272,7 @@ void TargetBrowserPair::setBorderColor(const glm::ivec3& color) {
|
||||
|
||||
void TargetBrowserPair::setScreenSpaceSize(const glm::vec2& dimensions) {
|
||||
_browser->setScreenSpaceSize(dimensions);
|
||||
_targetRenderable->setDimensions(dimensions);
|
||||
}
|
||||
|
||||
void TargetBrowserPair::setVerticalFovWithScroll(float scroll) {
|
||||
@@ -303,7 +286,7 @@ void TargetBrowserPair::incrementallyAnimateToCoordinate(double deltaTime) {
|
||||
}
|
||||
else if (_browser->isAnimated()) {
|
||||
_browser->incrementallyAnimateToFov(static_cast<float>(deltaTime));
|
||||
setFovTarget(_browser->verticalFov());
|
||||
_targetRenderable->setVerticalFov(_browser->verticalFov());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user