mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 20:50:59 -05:00
Create functions to look in WWT-window at direction in OpenSpace and some cleanup
This commit is contained in:
@@ -36,8 +36,7 @@
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
|
||||
#include <cmath> // For atan2
|
||||
|
||||
#include "skybrowsermodule_lua.inl"
|
||||
|
||||
@@ -88,16 +87,24 @@ scripting::LuaLibrary SkybrowserModule::luaLibrary() const {
|
||||
res.name = "skybrowser";
|
||||
res.functions = {
|
||||
{
|
||||
"test",
|
||||
&skybrowser::luascriptfunctions::testFunction,
|
||||
"create",
|
||||
&skybrowser::luascriptfunctions::createBrowser,
|
||||
{},
|
||||
"string or list of strings",
|
||||
"Add one or multiple exoplanet systems to the scene, as specified by the "
|
||||
"input. An input string should be the name of the system host star"
|
||||
},
|
||||
{
|
||||
"update",
|
||||
&skybrowser::luascriptfunctions::updateFunction,
|
||||
"move",
|
||||
&skybrowser::luascriptfunctions::moveBrowser,
|
||||
{},
|
||||
"string or list of strings",
|
||||
"Add one or multiple exoplanet systems to the scene, as specified by the "
|
||||
"input. An input string should be the name of the system host star"
|
||||
},
|
||||
{
|
||||
"follow",
|
||||
&skybrowser::luascriptfunctions::followCamera,
|
||||
{},
|
||||
"string or list of strings",
|
||||
"Add one or multiple exoplanet systems to the scene, as specified by the "
|
||||
@@ -123,6 +130,21 @@ void SkybrowserModule::internalInitialize(const ghoul::Dictionary& dict) {
|
||||
*/
|
||||
}
|
||||
|
||||
void SkybrowserModule::WWTfollowCamera() const {
|
||||
// Get camera view direction
|
||||
const glm::dvec3 viewDirection = global::navigationHandler->camera()->viewDirectionWorldSpace();
|
||||
|
||||
// Convert to celestial coordinates
|
||||
const SkybrowserModule* module = global::moduleEngine->module<SkybrowserModule>();
|
||||
glm::dvec2 celestCoords = module->convertGalacticToCelestial(viewDirection);
|
||||
|
||||
// Execute javascript on browser
|
||||
ScreenSpaceBrowser* browser = dynamic_cast<ScreenSpaceBrowser*>(global::renderEngine->screenSpaceRenderable("ScreenSpaceBowser"));
|
||||
std::string script = "vm.onMessage({event: 'center_on_coordinates', ra : Number(" + std::to_string(celestCoords[0]) + "), dec : Number(" + std::to_string(celestCoords[1]) + "), fov : Number(" + std::to_string(_zoomFactor) + "), instant : false})";
|
||||
browser->executeJavascript(script);
|
||||
|
||||
}
|
||||
|
||||
glm::dvec2 SkybrowserModule::convertGalacticToCelestial(glm::dvec3 rGal) const {
|
||||
|
||||
// Used the math from this website: https://gea.esac.esa.int/archive/documentation/GD -->
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
|
||||
float zoomFactor() const;
|
||||
glm::dvec2 convertGalacticToCelestial(glm::dvec3 coords) const;
|
||||
void WWTfollowCamera() const;
|
||||
|
||||
scripting::LuaLibrary luaLibrary() const override;
|
||||
//std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
@@ -27,43 +27,31 @@ namespace {
|
||||
|
||||
namespace openspace::skybrowser::luascriptfunctions {
|
||||
|
||||
int updateFunction(lua_State* L) {
|
||||
// Get FOV from argument
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::updateFunction");
|
||||
float fov = ghoul::lua::value<float>(L, 1);
|
||||
int followCamera(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::followCamera");
|
||||
|
||||
// Get camera position
|
||||
//const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3();
|
||||
const glm::dvec3 cameraPosition = global::navigationHandler->camera()->viewDirectionWorldSpace();
|
||||
|
||||
// Convert to celestial coordinates
|
||||
const SkybrowserModule* module = global::moduleEngine->module<SkybrowserModule>();
|
||||
glm::dvec2 celestCoords = module->convertGalacticToCelestial(glm::dvec3(cameraPosition[0], cameraPosition[1], cameraPosition[2]));
|
||||
|
||||
// Execute javascript on browser
|
||||
ScreenSpaceBrowser* browser = dynamic_cast<ScreenSpaceBrowser*>(global::renderEngine->screenSpaceRenderable("ScreenSpaceBowser"));
|
||||
std::string script = "vm.onMessage({event: 'center_on_coordinates', ra : Number(" + std::to_string(celestCoords[0]) + "), dec : Number(" + std::to_string(celestCoords[1]) + "), fov : Number(" + std::to_string(fov) + "), instant : false})";
|
||||
browser->executeJavascript(script);
|
||||
module->WWTfollowCamera();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int testFunction(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::testFunction");
|
||||
int moveBrowser(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::moveBrowser");
|
||||
ScreenSpaceBrowser* browser = dynamic_cast<ScreenSpaceBrowser*>(global::renderEngine->screenSpaceRenderable("ScreenSpaceBowser"));
|
||||
browser->translate(glm::vec3(-0.8, -0.4, 0.0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int createBrowser(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::createBrowser");
|
||||
ghoul::lua::value<std::string>(L, 1);
|
||||
|
||||
const SkybrowserModule* module = global::moduleEngine->module<SkybrowserModule>();
|
||||
glm::dvec3 testvec = glm::dvec3(0.0, 0.0, 0.0);
|
||||
module->convertGalacticToCelestial(testvec);
|
||||
|
||||
LINFOC(_loggerCat, "hoho");
|
||||
LINFOC(_loggerCat, std::to_string(module->zoomFactor()));
|
||||
|
||||
//std::string _url = "https://wallpaperaccess.com/full/3010132.jpg";
|
||||
// 'https://cdn.wallpapersafari.com/6/92/0nbCPw.jpg'
|
||||
/*
|
||||
// get url from user
|
||||
const std::string _url = ghoul::lua::value<std::string>(L, 1);
|
||||
*/
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary node;
|
||||
@@ -77,8 +65,6 @@ namespace openspace::skybrowser::luascriptfunctions {
|
||||
"openspace.addScreenSpaceRenderable(" + ghoul::formatLua(node) + ")",
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ public:
|
||||
bool isReady() const override;
|
||||
|
||||
void executeJavascript(std::string &script) const;
|
||||
void translate(glm::vec3 translation);
|
||||
|
||||
private:
|
||||
class ScreenSpaceRenderHandler : public WebRenderHandler {
|
||||
|
||||
@@ -62,7 +62,13 @@ void ScreenSpaceBrowser::executeJavascript(std::string &script) const {
|
||||
LINFOC(_loggerCat, "Executing javascript " + script);
|
||||
|
||||
CefRefPtr<CefFrame> frame = _browserInstance->getBrowser()->GetMainFrame();
|
||||
frame->ExecuteJavaScript(script, frame->GetURL(), 0);
|
||||
frame->ExecuteJavaScript(script, frame->GetURL(), 0);
|
||||
}
|
||||
|
||||
void ScreenSpaceBrowser::translate(glm::vec3 translation) {
|
||||
glm::vec4 homogenousCoords(glm::vec4(translation, 1.0));
|
||||
glm::vec3 position = _cartesianPosition;
|
||||
_cartesianPosition = glm::translate(glm::mat4(1.f), translation) * glm::vec4(position, 1.0f);
|
||||
}
|
||||
|
||||
void ScreenSpaceBrowser::ScreenSpaceRenderHandler::draw() {}
|
||||
|
||||
Reference in New Issue
Block a user