mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
Add ScreenSpaceSkyTarget class to handle target
This commit is contained in:
@@ -28,6 +28,7 @@ set(HEADER_FILES
|
||||
|
||||
skybrowsermodule.h
|
||||
include/screenspaceskybrowser.h
|
||||
include/screenspaceskytarget.h
|
||||
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
@@ -37,6 +38,8 @@ set(SOURCE_FILES
|
||||
skybrowsermodule.cpp
|
||||
skybrowsermodule_lua.inl
|
||||
src/screenspaceskybrowser.cpp
|
||||
src/screenspaceskytarget.cpp
|
||||
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace openspace {
|
||||
void translate(glm::vec3 translation);
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
29
modules/skybrowser/include/screenspaceskytarget.h
Normal file
29
modules/skybrowser/include/screenspaceskytarget.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef __OPENSPACE_MODULE_SKYBROWSER___SCREENSPACESKYTARGET___H__
|
||||
#define __OPENSPACE_MODULE_SKYBROWSER___SCREENSPACESKYTARGET___H__
|
||||
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace::documentation { struct Documentation; }
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ScreenSpaceSkyTarget : public ScreenSpaceRenderable {
|
||||
|
||||
public:
|
||||
ScreenSpaceSkyTarget(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ScreenSpaceSkyTarget() = default;
|
||||
|
||||
void bindTexture() override;
|
||||
private:
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SKYBROWSER___SCREENSPACESKYTARGET___H__
|
||||
|
||||
17
modules/skybrowser/shaders/target_fs.glsl
Normal file
17
modules/skybrowser/shaders/target_fs.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
uniform sampler2D texture1;
|
||||
uniform float OcclusionDepth;
|
||||
uniform float Alpha;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_position;
|
||||
|
||||
#include "fragment.glsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
vec3 color = vec3(1.0);
|
||||
frag.color = vec4(color, 1.0);
|
||||
|
||||
return frag;
|
||||
}
|
||||
16
modules/skybrowser/shaders/target_vs.glsl
Normal file
16
modules/skybrowser/shaders/target_vs.glsl
Normal file
@@ -0,0 +1,16 @@
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ModelTransform;
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_position;
|
||||
|
||||
void main(){
|
||||
vs_st = in_st;
|
||||
vs_position = ViewProjectionMatrix * ModelTransform * in_position * vec4(1.0, -1.0, 1.0, 1.0);
|
||||
gl_Position = vec4(vs_position);
|
||||
}
|
||||
@@ -26,15 +26,12 @@
|
||||
|
||||
//#include <modules/webbrowser/webbrowsermodule.h>
|
||||
//#include <modules/webbrowser/include/screenspacebrowser.h>
|
||||
#include <modules/base/rendering/screenspaceimagelocal.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <openspace/engine/moduleengine.h>
|
||||
|
||||
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/globalscallbacks.h>
|
||||
#include <openspace/interaction/navigationhandler.h>
|
||||
@@ -45,6 +42,10 @@
|
||||
#include <chrono>
|
||||
#include "skybrowsermodule_lua.inl"
|
||||
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <cmath> // For atan2
|
||||
#include <ghoul/misc/dictionaryjsonformatter.h> // formatJson
|
||||
|
||||
@@ -145,6 +146,11 @@ void SkyBrowserModule::internalInitialize(const ghoul::Dictionary& dict) {
|
||||
auto fScreenSpaceRenderable = FactoryManager::ref().factory<ScreenSpaceRenderable>();
|
||||
ghoul_assert(fScreenSpaceRenderable, "ScreenSpaceRenderable factory was not created");
|
||||
fScreenSpaceRenderable->registerClass<ScreenSpaceSkyBrowser>("ScreenSpaceSkyBrowser");
|
||||
|
||||
// register ScreenSpaceTarget
|
||||
ghoul_assert(fScreenSpaceRenderable, "ScreenSpaceRenderable factory was not created");
|
||||
fScreenSpaceRenderable->registerClass<ScreenSpaceSkyTarget>("ScreenSpaceSkyTarget");
|
||||
|
||||
}
|
||||
|
||||
bool SkyBrowserModule::sendMessageToWWT(const ghoul::Dictionary& msg) {
|
||||
@@ -160,7 +166,6 @@ bool SkyBrowserModule::sendMessageToWWT(const ghoul::Dictionary& msg) {
|
||||
}
|
||||
|
||||
void SkyBrowserModule::WWTfollowCamera() {
|
||||
showTarget();
|
||||
while (true) {
|
||||
// Get camera view direction
|
||||
const glm::dvec3 viewDirection = global::navigationHandler->camera()->viewDirectionWorldSpace();
|
||||
@@ -232,20 +237,37 @@ glm::dvec2 SkyBrowserModule::convertGalacticToCelestial(glm::dvec3 rGal) const {
|
||||
return glm::dvec2(glm::degrees(ra), glm::degrees(dec));
|
||||
}
|
||||
|
||||
void SkyBrowserModule::showTarget() const {
|
||||
void SkyBrowserModule::checkIfTargetExist() {
|
||||
ScreenSpaceSkyTarget* target = static_cast<ScreenSpaceSkyTarget*>(global::renderEngine->screenSpaceRenderable("ScreenSpaceTarget"));
|
||||
|
||||
if (target) {
|
||||
LINFO("Target is not null!");
|
||||
|
||||
}
|
||||
LINFO("Target has been checked!");
|
||||
}
|
||||
|
||||
void SkyBrowserModule::createTarget() {
|
||||
|
||||
using namespace std::string_literals;
|
||||
ghoul::Dictionary node;
|
||||
node.setValue("Type", "ScreenSpaceImageLocal"s);
|
||||
node.setValue("Identifier", "Target"s);
|
||||
node.setValue("TexturePath", "D:/Ylvas/OpenSpace/modules/skybrowser/target.png"s);
|
||||
node.setValue("Scale", 0.07);
|
||||
|
||||
// Create target test
|
||||
std::string node = "{"
|
||||
"Type = 'ScreenSpaceSkyTarget',"
|
||||
"Identifier = 'ScreenSpaceTarget',"
|
||||
"Name = 'Screen Space Target',"
|
||||
"FaceCamera = false"
|
||||
"}";
|
||||
|
||||
openspace::global::scriptEngine->queueScript(
|
||||
"openspace.addScreenSpaceRenderable(" + ghoul::formatLua(node) + ")",
|
||||
"openspace.addScreenSpaceRenderable(" + node + ")",
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
std::vector<documentation::Documentation> SkyBrowserModule::documentations() const {
|
||||
return {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
namespace openspace {
|
||||
|
||||
class ScreenSpaceSkyBrowser;
|
||||
class ScreenSpaceSkyTarget;
|
||||
|
||||
class SkyBrowserModule : public OpenSpaceModule {
|
||||
public:
|
||||
@@ -48,7 +49,10 @@ public:
|
||||
glm::dvec2 convertGalacticToCelestial(glm::dvec3 coords) const;
|
||||
|
||||
void WWTfollowCamera();
|
||||
void showTarget() const;
|
||||
|
||||
// target
|
||||
void createTarget();
|
||||
void checkIfTargetExist();
|
||||
|
||||
ghoul::Dictionary createMessageForMovingWWTCamera(const glm::dvec2 celestCoords, const float fov, const bool moveInstantly = true) const;
|
||||
ghoul::Dictionary createMessageForPausingWWTTime() const;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <modules/skybrowser/include/screenspaceskybrowser.h>
|
||||
#include <modules/skybrowser/include/screenspaceskytarget.h>
|
||||
#include <openspace/interaction/navigationhandler.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <thread>
|
||||
@@ -61,14 +62,14 @@ namespace openspace::skybrowser::luascriptfunctions {
|
||||
|
||||
module->initializeBrowser(browser);
|
||||
module->skyBrowser()->translate(glm::vec3(-0.8, -0.4, 0.0));
|
||||
module->checkIfTargetExist();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int createBrowser(lua_State* L) {
|
||||
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::createBrowser");
|
||||
ghoul::lua::value<std::string>(L, 1);
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::createBrowser");
|
||||
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
|
||||
@@ -96,6 +97,9 @@ namespace openspace::skybrowser::luascriptfunctions {
|
||||
scripting::ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
|
||||
//test create target
|
||||
module->createTarget();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
56
modules/skybrowser/src/screenspaceskytarget.cpp
Normal file
56
modules/skybrowser/src/screenspaceskytarget.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <modules/skybrowser/include/screenspaceskytarget.h>
|
||||
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <ghoul/misc/dictionaryluaformatter.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/rendering/helper.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureconversion.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <optional>
|
||||
#include <ghoul/opengl/openglstatecache.h>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "ScreenSpaceSkyTarget";
|
||||
|
||||
constexpr const std::array<const char*, 4> UniformNames = {
|
||||
"Alpha", "ModelTransform", "ViewProjectionMatrix", "texture1"
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
namespace openspace {
|
||||
ScreenSpaceSkyTarget::ScreenSpaceSkyTarget(const ghoul::Dictionary& dictionary)
|
||||
: ScreenSpaceRenderable(dictionary)
|
||||
{
|
||||
std::string identifier;
|
||||
if (dictionary.hasValue<std::string>(KeyIdentifier)) {
|
||||
identifier = dictionary.value<std::string>(KeyIdentifier);
|
||||
}
|
||||
else {
|
||||
identifier = "ScreenSpaceSkyTarget";
|
||||
}
|
||||
identifier = makeUniqueIdentifier(identifier);
|
||||
setIdentifier(identifier);
|
||||
}
|
||||
|
||||
void ScreenSpaceSkyTarget::bindTexture() {
|
||||
if (_texture) {
|
||||
_texture->bind();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user