Fix bugs with 3D browser scale and place synchronization of the target and browser in the targets update function

This commit is contained in:
sylvass
2021-12-02 14:55:15 -05:00
parent 148b68123c
commit f5721cee14
11 changed files with 88 additions and 62 deletions
@@ -43,15 +43,18 @@ namespace openspace {
void initializeGL() override;
void deinitializeGL() override;
void update(const UpdateData& data) override;
void render(const RenderData& data, RendererTasks& rendererTask) override;
// Set up initialization with wwt
void setIdInBrowser();
// Place
void placeAt3dPosition(const glm::dvec3& positionSpeck, float verticalFov);
void placeAt3dPosition(const glm::dvec3& positionSpeck, float verticalFov,
const std::string& sceneGraphNodeId);
private:
void bindTexture() override;
void unbindTexture() override;
};
}
@@ -80,7 +80,7 @@ namespace openspace {
// Time variables
// For capping the calls onchange properties from scrolling
constexpr static const std::chrono::milliseconds _timeUpdateInterval{ 10 };
std::chrono::system_clock::time_point _lastUpdateTime;
std::chrono::system_clock::time_point _lastUpdateTime;
};
}
@@ -42,6 +42,7 @@ namespace openspace {
// 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;
@@ -84,6 +85,7 @@ namespace openspace {
// Sky browser
glm::ivec3 _color;
ScreenSpaceSkyBrowser* _browser{ nullptr };
float _verticalFov{ 0.f };
// Lock target to a coordinate on the sky
@@ -93,6 +95,12 @@ namespace openspace {
glm::dvec3 _animationEnd; // Cartesian equatorial coordinates
glm::dvec3 _animationStart; // Cartesian equatorial coordinates
// Time variables
// For capping the set equatorial coordinates to sky browser
const std::chrono::microseconds interval = std::chrono::microseconds(10000);
std::chrono::time_point<std::chrono::high_resolution_clock> latestCall;
constexpr static const std::chrono::milliseconds _timeUpdateInterval{ 10 };
std::chrono::system_clock::time_point _lastUpdateTime;
};
}
+8 -5
View File
@@ -41,13 +41,17 @@ public:
WwtCommunicator(WwtCommunicator const&) = default;
virtual ~WwtCommunicator();
void update();
void render();
void initializeGL();
void deinitializeGL();
// WorldWide Telescope communication
void displayImage(const std::string& url, int i);
void removeSelectedImage(const int i);
void setImageOrder(int i, int order);
void loadImageCollection(const std::string& collection);
void setImageOpacity(int i, float opacity);
void update();
// Getters
const std::deque<int>& getSelectedImages();
@@ -67,6 +71,7 @@ public:
void highlight(glm::ivec3 addition);
void removeHighlight(glm::ivec3 removal);
void updateBorderColor();
void updateAim();
protected:
@@ -82,16 +87,14 @@ protected:
private:
bool _isSyncedWithWwt{ false };
const std::chrono::microseconds interval = std::chrono::microseconds(10000);
std::chrono::time_point<std::chrono::high_resolution_clock> latestCall;
void setWebpageBorderColor(glm::ivec3 color);
void sendMessageToWwt(const ghoul::Dictionary& msg);
int messageCounter{ 0 };
ghoul::Dictionary moveCamera(const glm::dvec2& celestCoords, const double fov,
const double roll, const bool shouldMoveInstantly = true);
ghoul::Dictionary moveCamera(const glm::dvec2& celestCoords, double fov,
double roll, bool shouldMoveInstantly = true);
ghoul::Dictionary loadCollection(const std::string& url);
ghoul::Dictionary setForeground(const std::string& name);
ghoul::Dictionary addImage(const std::string& id, const std::string& url);
+2 -1
View File
@@ -701,7 +701,8 @@ void SkyBrowserModule::place3dBrowser(const ImageData& image, const int i)
// If the image has a 3D position, add it to the scene graph
if (image.has3dCoords && _browser3d) {
_browser3d->displayImage(image.imageUrl, i);
_browser3d->placeAt3dPosition(image.position3d, image.fov);
_browser3d->placeAt3dPosition(image.position3d, image.fov,
_browser3dNode->identifier());
}
else {
LINFO("Image has no 3D coordinate!");
+4 -6
View File
@@ -40,12 +40,10 @@ int selectImage(lua_State* L) {
}
}
else if (module->get3dBrowser()) {
RenderableSkyBrowser* renderable = dynamic_cast<RenderableSkyBrowser*>(
module->get3dBrowser());
if (renderable) {
const ImageData& image = module->getWwtDataHandler()->getImage(i);
renderable->displayImage(image.imageUrl, i);
}
const ImageData& image = module->getWwtDataHandler()->getImage(i);
module->get3dBrowser()->displayImage(image.imageUrl, i);
module->get3dBrowser()->setEquatorialAim(image.equatorialCartesian);
module->get3dBrowser()->setVerticalFov(image.fov);
}
return 0;
+2 -18
View File
@@ -77,24 +77,8 @@ namespace openspace {
}
);
// Set target callback functions
_target->setCallbackEnabled(
[&](bool enabled) {
_browser->setEnabled(enabled);
}
);
_target->setCallbackPosition(
[&](glm::vec3 localCameraPosition) {
double diff = glm::length(
_browser->equatorialAim() - _target->equatorialAim()
);
if (diff > AnimationThreshold) {
_browser->setEquatorialAim(
skybrowser::localCameraToEquatorial(localCameraPosition)
);
}
}
);
_target->setSkyBrowser(_browser);
}
Pair& Pair::operator=(Pair other)
@@ -127,8 +127,7 @@ namespace openspace {
// /_| Adjacent is the horizontal line, opposite the vertical
// \ | Calculate for half the triangle first, then multiply with 2
// \|
glm::dvec3 j2000 = skybrowser::galacticToEquatorial(position);
double adjacent = glm::length(j2000);
double adjacent = glm::length(position);
double opposite = 2 * adjacent * glm::tan(glm::radians(verticalFov * 0.5));
// Calculate rotation to make the plane face the solar system barycenter
@@ -137,7 +136,7 @@ namespace openspace {
glm::cross(glm::dvec3(0.0, 0.0, 1.0), normal)
);
glm::dvec3 newUp = glm::cross(normal, newRight);
// Face the Solar System Barycenter
// Face the Solar System Barycenter as an approximation of Earth
glm::dmat3 rotation = glm::dmat3(1.0);
rotation[0] = newRight;
rotation[1] = newUp;
@@ -126,7 +126,7 @@ namespace openspace {
bool ScreenSpaceSkyBrowser::initializeGL() {
Browser::initializeGL();
WwtCommunicator::initializeGL();
ScreenSpaceRenderable::initializeGL();
updateTextureResolution();
return true;
@@ -168,7 +168,7 @@ namespace openspace {
bool ScreenSpaceSkyBrowser::deinitializeGL() {
ScreenSpaceRenderable::deinitializeGL();
Browser::deinitializeGL();
WwtCommunicator::deinitializeGL();
return true;
}
@@ -199,7 +199,7 @@ namespace openspace {
}
void ScreenSpaceSkyBrowser::render() {
Browser::render();
WwtCommunicator::render();
draw(
globalRotationMatrix() *
@@ -1,5 +1,6 @@
#include <modules/skybrowser/include/screenspaceskytarget.h>
#include <modules/skybrowser/include/screenspaceskybrowser.h>
#include <modules/skybrowser/include/utility.h>
#include <openspace/engine/globals.h>
#include <openspace/navigation/navigationhandler.h>
@@ -211,6 +212,22 @@ namespace openspace {
_lockedCoordinates
);
}
if (_browser) {
const std::chrono::time_point<std::chrono::high_resolution_clock>
timeBefore = std::chrono::high_resolution_clock::now();
std::chrono::microseconds duration =
std::chrono::duration_cast<std::chrono::microseconds>(
timeBefore - latestCall
);
if (duration > interval) {
// Message WorldWide Telescope current view
_browser->setEquatorialAim(equatorialAim()); // Use camera roll
latestCall = std::chrono::high_resolution_clock::now();
}
}
}
void ScreenSpaceSkyTarget::setDimensions(glm::vec2 dimensions) {
@@ -230,7 +247,6 @@ namespace openspace {
// Update the scale of the target (the height of the target in relation to the
// OpenSpace window)
void ScreenSpaceSkyTarget::setScaleFromVfov(float verticalFov) {
_verticalFov = verticalFov;
glm::dvec2 fovs = skybrowser::fovWindow();
@@ -339,4 +355,11 @@ namespace openspace {
f(_cartesianPosition);
});
}
void ScreenSpaceSkyTarget::setSkyBrowser(ScreenSpaceSkyBrowser* browser)
{
_browser = browser;
_enabled.onChange([this]() {
_browser->setEnabled(_enabled);
});
}
}
+29 -22
View File
@@ -111,6 +111,7 @@ namespace openspace {
void WwtCommunicator::setVerticalFov(float vfov) {
_verticalFov = vfov;
updateAim();
}
void WwtCommunicator::setWebpageBorderColor(glm::ivec3 color) {
@@ -129,6 +130,7 @@ namespace openspace {
void WwtCommunicator::setEquatorialAim(glm::dvec3 cartesian)
{
_equatorialAim = skybrowser::cartesianToSpherical(cartesian);
updateAim();
}
void WwtCommunicator::highlight(glm::ivec3 addition)
@@ -146,6 +148,18 @@ namespace openspace {
setWebpageBorderColor(_borderColor);
}
void WwtCommunicator::updateAim()
{
double roll = _isSyncedWithWwt ? skybrowser::cameraRoll() : 0.0;
// Message WorldWide Telescope current view
ghoul::Dictionary message = moveCamera(
_equatorialAim,
_verticalFov,
roll
);
sendMessageToWwt(message);
}
glm::dvec2 WwtCommunicator::fieldsOfView() {
glm::dvec2 browserFov = glm::dvec2(verticalFov() * browserRatio(), verticalFov());
@@ -194,31 +208,24 @@ namespace openspace {
void WwtCommunicator::update()
{
if (_isSyncedWithWwt) {
const std::chrono::time_point<std::chrono::high_resolution_clock>
timeBefore = std::chrono::high_resolution_clock::now();
std::chrono::microseconds duration =
std::chrono::duration_cast<std::chrono::microseconds>(
timeBefore - latestCall
);
if (duration > interval) {
// Message WorldWide Telescope current view
ghoul::Dictionary message = moveCamera(
_equatorialAim,
_verticalFov,
skybrowser::cameraRoll()
);
sendMessageToWwt(message);
latestCall = std::chrono::high_resolution_clock::now();
}
}
Browser::update();
}
void WwtCommunicator::render()
{
Browser::render();
}
void WwtCommunicator::initializeGL()
{
Browser::initializeGL();
}
void WwtCommunicator::deinitializeGL()
{
Browser::deinitializeGL();
}
void WwtCommunicator::setHasLoadedImages(bool isLoaded) {
_hasLoadedImages = isLoaded;
}