Merge pull request #2296 from OpenSpace/issue/2093

Make dragging in skybrowser work in fisheye projection with new mode
This commit is contained in:
Ylva Selling
2022-11-07 13:00:42 -05:00
committed by GitHub
7 changed files with 84 additions and 40 deletions

View File

@@ -3,7 +3,7 @@ asset.require("./static_server")
local guiCustomization = asset.require("customization/gui")
-- Select which commit hashes to use for the frontend and backend
local frontendHash = "082a855e6d29359f492ebbc82b625eee56e42e52"
local frontendHash = "b98a6cb556e5e28538fa0221e71123d313046661"
local dataProvider = "data.openspaceproject.com/files/webgui"
local frontend = asset.syncedResource({

View File

@@ -57,16 +57,24 @@ public:
static documentation::Documentation Documentation();
void applyRoll();
glm::dvec3 rightVector();
glm::dvec3 upVector();
private:
// Properties
properties::FloatProperty _crossHairSize;
properties::FloatProperty _showRectangleThreshold;
properties::FloatProperty _lineWidth;
properties::DoubleProperty _verticalFov;
properties::BoolProperty _applyRoll;
bool _isInitialized = false;
double _borderRadius = 0.0;
glm::ivec3 _borderColor = glm::ivec3(230);
float _ratio = 1.f;
glm::dvec3 _rightVector;
glm::dvec3 _upVector;
glm::dvec3 _worldPosition;
};
} // namespace openspace

View File

@@ -52,7 +52,7 @@ public:
// Mouse interaction
void startFinetuningTarget();
void fineTuneTarget(const glm::vec2& startMouse, const glm::vec2& translation);
void fineTuneTarget(const glm::vec2& translation);
void synchronizeAim();
// Browser
@@ -75,6 +75,7 @@ public:
void setBrowserRatio(float ratio);
void setVerticalFovWithScroll(float scroll);
void setImageCollectionIsLoaded(bool isLoaded);
void applyRoll();
double verticalFov() const;
glm::ivec3 borderColor() const;

View File

@@ -111,6 +111,7 @@ namespace {
"The url of the image collection which is loaded into AAS WorldWide Telescope"
};
struct [[codegen::Dictionary(SkyBrowserModule)]] Parameters {
// [[codegen::verbatim(EnabledInfo.description)]]
std::optional<bool> enabled;

View File

@@ -743,18 +743,15 @@ namespace {
* and third is the end position of the drag.
*/
[[codegen::luawrap]] void finetuneTargetPosition(std::string identifier,
glm::vec2 startPosition,
glm::vec2 endPosition)
glm::dvec2 translation)
{
using namespace openspace;
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
TargetBrowserPair* pair = module->pair(identifier);
if (pair) {
glm::vec2 startScreenSpace = skybrowser::pixelToScreenSpace2d(startPosition);
glm::vec2 endScreenSpace = skybrowser::pixelToScreenSpace2d(endPosition);
glm::vec2 translation = endScreenSpace - startScreenSpace;
pair->fineTuneTarget(startScreenSpace, translation);
pair->fineTuneTarget(translation);
}
}

View File

@@ -74,6 +74,13 @@ namespace {
"The vertical field of view of the target."
};
constexpr openspace::properties::Property::PropertyInfo ApplyRollInfo = {
"ApplyRoll",
"Apply Roll",
"Always rotate the target to have it's up direction aligned with the up direction "
"of the camera"
};
struct [[codegen::Dictionary(RenderableSkyTarget)]] Parameters {
// [[codegen::verbatim(crossHairSizeInfo.description)]]
std::optional<float> crossHairSize;
@@ -86,6 +93,9 @@ namespace {
// [[codegen::verbatim(VerticalFovInfo.description)]]
std::optional<double> verticalFov;
// [[codegen::verbatim(ApplyRollInfo.description)]]
std::optional<bool> applyRoll;
};
#include "renderableskytarget_codegen.cpp"
@@ -104,6 +114,7 @@ RenderableSkyTarget::RenderableSkyTarget(const ghoul::Dictionary& dictionary)
, _lineWidth(LineWidthInfo, 13.f, 1.f, 100.f)
, _verticalFov(VerticalFovInfo, 10.0, 0.00000000001, 70.0)
, _borderColor(220, 220, 220)
, _applyRoll(ApplyRollInfo, true)
{
// Handle target dimension property
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -120,6 +131,8 @@ RenderableSkyTarget::RenderableSkyTarget(const ghoul::Dictionary& dictionary)
_verticalFov= p.verticalFov.value_or(_verticalFov);
_verticalFov.setReadOnly(true);
addProperty(_verticalFov);
addProperty(_applyRoll);
}
void RenderableSkyTarget::bindTexture() {}
@@ -151,6 +164,26 @@ glm::ivec3 RenderableSkyTarget::borderColor() const {
return _borderColor;
}
glm::dvec3 RenderableSkyTarget::rightVector() const {
double scaling = (_verticalFov / 70)* static_cast<double>(_size.value());
return scaling * _rightVector;
}
glm::dvec3 RenderableSkyTarget::upVector() const {
double scaling = (_verticalFov / 70) * static_cast<double>(_size.value());
return scaling * _upVector;
}
void RenderableSkyTarget::applyRoll() {
Camera* camera = global::navigationHandler->camera();
glm::dvec3 normal = glm::normalize(camera->positionVec3() - _worldPosition);
_rightVector = glm::normalize(
glm::cross(camera->lookUpVectorWorldSpace(), normal)
);
_upVector = glm::cross(normal, _rightVector);
}
void RenderableSkyTarget::render(const RenderData& data, RendererTasks&) {
ZoneScoped
const bool showRectangle = _verticalFov > _showRectangleThreshold;
@@ -159,7 +192,6 @@ void RenderableSkyTarget::render(const RenderData& data, RendererTasks&) {
_shader->activate();
_shader->setUniform("opacity", opacity());
_shader->setUniform("crossHairSize", _crossHairSize);
_shader->setUniform("showRectangle", showRectangle);
_shader->setUniform("lineWidth", _lineWidth * 0.0001f);
@@ -168,21 +200,31 @@ void RenderableSkyTarget::render(const RenderData& data, RendererTasks&) {
_shader->setUniform("fov", static_cast<float>(_verticalFov));
_shader->setUniform("borderRadius", static_cast<float>(_borderRadius));
glm::dvec3 objectPositionWorld = glm::dvec3(
_worldPosition = glm::dvec3(
glm::translate(
glm::dmat4(1.0),
data.modelTransform.translation) * glm::dvec4(0.0, 0.0, 0.0, 1.0)
);
glm::dvec3 normal = glm::normalize(data.camera.positionVec3() - objectPositionWorld);
glm::dvec3 newRight = glm::normalize(
glm::cross(data.camera.lookUpVectorWorldSpace(), normal)
);
glm::dvec3 newUp = glm::cross(normal, newRight);
glm::dvec3 normal = glm::normalize(data.camera.positionVec3() - _worldPosition);
// There are two modes - 1) target rolls to have its up vector parallel to the
// cameras up vector or 2) it is decoupled from the camera, in which case it needs to
// be initialized once
if (!_isInitialized || _applyRoll) {
applyRoll();
_isInitialized = true;
}
else {
// Use last frames vector for right and don't apply any roll
_upVector = glm::cross(normal, _rightVector);
_rightVector = glm::normalize(
glm::cross(_upVector, normal)
);
}
glm::dmat4 cameraOrientedRotation = glm::dmat4(1.0);
cameraOrientedRotation[0] = glm::dvec4(newRight, 0.0);
cameraOrientedRotation[1] = glm::dvec4(newUp, 0.0);
cameraOrientedRotation[0] = glm::dvec4(_rightVector, 0.0);
cameraOrientedRotation[1] = glm::dvec4(_upVector, 0.0);
cameraOrientedRotation[2] = glm::dvec4(normal, 0.0);
const glm::dmat4 rotationTransform = _billboard ?

View File

@@ -74,28 +74,23 @@ void TargetBrowserPair::setImageOrder(int i, int order) {
}
void TargetBrowserPair::startFinetuningTarget() {
_startTargetPosition = _targetNode->worldPosition();
}
// The fine tune of the target is a way to "drag and drop" the target with right click
// The fine tune of the target is a way to "drag and drop" the target with click
// drag on the sky browser window. This is to be able to drag the target around when it
// has a very small field of view
void TargetBrowserPair::fineTuneTarget(const glm::vec2& startMouse,
const glm::vec2& translation)
{
glm::vec2 fineTune = _browser->fineTuneVector(translation);
glm::vec2 endMouse = startMouse + fineTune;
void TargetBrowserPair::fineTuneTarget(const glm::vec2& translation) {
glm::dvec2 percentage = glm::dvec2(translation);
glm::dvec3 right = _targetRenderable->rightVector() * percentage.x;
glm::dvec3 up = _targetRenderable->upVector() * percentage.y;
// Translation world
glm::dvec3 startWorld = skybrowser::localCameraToGalactic(
glm::vec3(startMouse, skybrowser::ScreenSpaceZ)
glm::dvec3 newPosition = _startTargetPosition - (right - up);
aimTargetGalactic(
_targetNode->identifier(),
newPosition
);
glm::dvec3 endWorld = skybrowser::localCameraToGalactic(
glm::vec3(endMouse, skybrowser::ScreenSpaceZ)
);
glm::dvec3 translationWorld = endWorld - startWorld;
aimTargetGalactic(_targetNode->identifier(), _startTargetPosition + translationWorld);
}
void TargetBrowserPair::synchronizeAim() {
@@ -169,6 +164,7 @@ ghoul::Dictionary TargetBrowserPair::dataAsDictionary() const {
ghoul::Dictionary res;
res.setValue("id", browserId());
res.setValue("targetId", targetNodeId());
res.setValue("name", browserGuiName());
res.setValue("fov", static_cast<double>(verticalFov()));
res.setValue("ra", spherical.x);
@@ -276,6 +272,10 @@ void TargetBrowserPair::setImageCollectionIsLoaded(bool isLoaded) {
_browser->setImageCollectionIsLoaded(isLoaded);
}
void TargetBrowserPair::applyRoll() {
_targetRenderable->applyRoll();
}
void TargetBrowserPair::incrementallyAnimateToCoordinate() {
// Animate the target before the field of view starts to animate
if (_targetAnimation.isAnimating()) {
@@ -344,13 +344,8 @@ double TargetBrowserPair::targetRoll() const {
_targetNode->worldPosition() -
global::navigationHandler->camera()->positionVec3()
);
glm::dvec3 right = glm::normalize(
glm::cross(
global::navigationHandler->camera()->lookUpVectorWorldSpace(),
normal
)
);
glm::dvec3 up = glm::normalize(glm::cross(normal, right));
glm::dvec3 right = _targetRenderable->rightVector();
glm::dvec3 up = glm::normalize(glm::cross(right, normal));
return skybrowser::targetRoll(up, normal);
}