mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-21 11:59:00 -05:00
Replaced renderableLightTravel with a more general and better renderableTravelSpeed
This commit is contained in:
-1
@@ -1 +0,0 @@
|
||||
{"test":["339","340","351","352","353","354","365","366","367"]}
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"test":["136","138","145","146","147","149","154","155","157","158","159","160","167","168","169","170","172","174","180","181","183","356","364"]}
|
||||
@@ -0,0 +1,32 @@
|
||||
asset.info = {
|
||||
Name = "Lighttravel sun to earth",
|
||||
Version = "1.0",
|
||||
Description = "Speed of light from sun to earth",
|
||||
Author = "Christian Adamsson, Emilie Ho",
|
||||
URL = "",
|
||||
License = ""
|
||||
}
|
||||
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local transforms = asset.require('./transforms')
|
||||
local sunTransforms = asset.require('scene/solarsystem/sun/transforms')
|
||||
local earthTransforms = asset.require('scene/solarsystem/planets/earth/transforms')
|
||||
|
||||
--openspace.setPropertyValueSingle("Modules.Space.ShowExceptions", false)
|
||||
|
||||
local travelSpeedIndicator = {
|
||||
Identifier = "travelSpeedIndicator",
|
||||
Parent = earthTransforms.EarthCenter.Identifier,-- sunTransforms.SolarSystemBarycenter.Identifier,
|
||||
Renderable = {
|
||||
Type = "RenderableTravelSpeed",
|
||||
Target = "Moon", --name of scene graph node. Earth by default
|
||||
|
||||
},
|
||||
GUI = {
|
||||
Path = "/Solar System/Heliosphere",
|
||||
Name = "Travel Speed"
|
||||
}
|
||||
}
|
||||
|
||||
assetHelper.registerSceneGraphNodesAndExport(asset, { travelSpeedIndicator })
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
asset.info = {
|
||||
Name = "Lighttravel sun to earth",
|
||||
Version = "1.0",
|
||||
Description = "Speed of light from sun to earth",
|
||||
Author = "Christian Adamsson, Emilie Ho",
|
||||
URL = "https://dx.doi.org/10.3847/1538-4357/aab36d",
|
||||
License = ""
|
||||
}
|
||||
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local transforms = asset.require('./transforms')
|
||||
local sunTransforms = asset.require('scene/solarsystem/sun/transforms')
|
||||
local earthTransforms = asset.require('scene/solarsystem/planets/earth/transforms')
|
||||
|
||||
openspace.setPropertyValueSingle("Modules.Space.ShowExceptions", false)
|
||||
--openspace.setPropertyValueSingle("Scene.NeptuneTrail.Renderable.Enabled", false)
|
||||
--openspace.setPropertyValueSingle("Scene.UranusTrail.Renderable.Enabled", false)
|
||||
--openspace.setPropertyValueSingle("Scene.SaturnTrail.Renderable.Enabled", false)
|
||||
|
||||
local speedofLight = {
|
||||
Identifier = "SpeedofLight",
|
||||
Parent = sunTransforms.SolarSystemBarycenter.Identifier,
|
||||
Renderable = {
|
||||
Type = "RenderableLightTravel"
|
||||
},
|
||||
GUI = {
|
||||
Path = "/Solar System/Heliosphere",
|
||||
Name = "Light Travel"
|
||||
}
|
||||
}
|
||||
|
||||
assetHelper.registerSceneGraphNodesAndExport(asset, { speedofLight })
|
||||
|
||||
@@ -61,7 +61,8 @@ local Streamnodes = {
|
||||
ScaleToMeters = 1.0,
|
||||
SecondsBefore = 24*60*60,
|
||||
SecondsAfter = 24*60*60,
|
||||
--SimulationModel = "mas"
|
||||
--SimulationModel = "mas",
|
||||
Enabled = false
|
||||
},
|
||||
GUI = {
|
||||
Path = "/Solar System/Heliosphere",
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace openspace::distanceconstants {
|
||||
constexpr double LightMonth = LightYear / 12;
|
||||
constexpr double LightDay = LightYear / 365;
|
||||
constexpr double LightHour = LightDay / 24;
|
||||
constexpr double LightSecond = 299792458.0;
|
||||
constexpr double AstronomicalUnit = 1.495978707E11;
|
||||
constexpr double Parsec = 3.0856776E16;
|
||||
} // openspace::distanceconstants
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
//#include <fstream>
|
||||
//#include <thread>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderableFieldlinesSequence";
|
||||
|
||||
@@ -26,25 +26,25 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestreamnodes.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelighttravel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetimevaryingimage.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletravelspeed.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletimevaryingsphere.h
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestreamnodes.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelighttravel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetimevaryingimage.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletravelspeed.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletimevaryingsphere.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/streamnodes_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/streamnodes_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/lighttravel_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/lighttravel_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/streamnodes_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/travelspeed_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/travelspeed_vs.glsl
|
||||
)
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
|
||||
@@ -1,379 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
#include <modules/streamnodes/rendering/renderablelighttravel.h>
|
||||
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
// Test debugging tools more then logmanager
|
||||
//#include <ghoul/logging/logmanager.h>
|
||||
//#include <ghoul/logging/consolelog.h>
|
||||
//#include <ghoul/logging/visualstudiooutputlog.h>
|
||||
|
||||
//#include <thread>
|
||||
#include <openspace/query/query.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "renderableLightTravel";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LightSpeedInfo = {
|
||||
"lightSpeed",
|
||||
"Speed of light",
|
||||
"The speed of light."
|
||||
};
|
||||
constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = {
|
||||
"lineWidth",
|
||||
"Line width",
|
||||
"This value specifies the line width of the field lines if the "
|
||||
"selected rendering method includes lines."
|
||||
};
|
||||
constexpr openspace::properties::Property::PropertyInfo RenderModeInfo = {
|
||||
"renderMode",
|
||||
"The draw method",
|
||||
"Can be used to decide what rendering method to use."
|
||||
};
|
||||
constexpr openspace::properties::Property::PropertyInfo LightColorInfo = {
|
||||
"lightColor",
|
||||
"The color of the light particle",
|
||||
"Choose what color to light the particle as it is traversing the line."
|
||||
};
|
||||
constexpr openspace::properties::Property::PropertyInfo DefaultcolorInfo = {
|
||||
"defaultColor",
|
||||
"The color of the lines",
|
||||
"Choose what color each line should have as default value."
|
||||
};
|
||||
constexpr openspace::properties::Property::PropertyInfo PointSizeInfo = {
|
||||
"pointSize",
|
||||
"Size of points",
|
||||
"Change the size of the points."
|
||||
};
|
||||
constexpr openspace::properties::Property::PropertyInfo TimeStepInfo = {
|
||||
"timeStep",
|
||||
"Timestep for light travel",
|
||||
"Change the timestep for the points along the line between sun and earth."
|
||||
};
|
||||
constexpr openspace::properties::Property::PropertyInfo DistanceFactorInfo = {
|
||||
"distanceFactor",
|
||||
"The distance factor for what to show as default vs light",
|
||||
"This value is multiplicated by a maximum distance of 1000000000.f meters."
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
using namespace properties;
|
||||
RenderableLightTravel::RenderableLightTravel(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _pLightSpeed(LightSpeedInfo, 299792458.f, 0, 299792458.f)
|
||||
, _pLineWidth(LineWidthInfo, 5, 0.1, 20)
|
||||
, _pRenderMode(RenderModeInfo, OptionProperty::DisplayType::Dropdown)
|
||||
, _pDefaultColor(DefaultcolorInfo, glm::vec4(0.3, 0.3, 0.3, 0),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f))
|
||||
, _pLightColor(LightColorInfo, glm::vec4(1, 1, 1, 1),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f))
|
||||
, _pPointSize(PointSizeInfo, 2.f, 0, 20)
|
||||
, _pTimeStep(TimeStepInfo, 1, 1, 30)
|
||||
, _pDistanceFactor(DistanceFactorInfo, 20, 1, 30)
|
||||
{
|
||||
_dictionary = std::make_unique<ghoul::Dictionary>(dictionary);
|
||||
}
|
||||
|
||||
void RenderableLightTravel::initializeGL() {
|
||||
_dictionary.reset();
|
||||
_shaderProgram = global::renderEngine->buildRenderProgram(
|
||||
"Lighttravel",
|
||||
absPath("${MODULE_STREAMNODES}/shaders/lighttravel_vs.glsl"),
|
||||
absPath("${MODULE_STREAMNODES}/shaders/lighttravel_fs.glsl")
|
||||
);
|
||||
|
||||
glGenVertexArrays(1, &_vertexArrayObject);
|
||||
glGenBuffers(1, &_vertexPositionBuffer);
|
||||
|
||||
setRenderBin(Renderable::RenderBin::PreDeferredTransparent);
|
||||
glm::vec3 currentpos = glm::vec3(0.0, 0.0, 0.0);
|
||||
addProperty(_pLightSpeed);
|
||||
addProperty(_pLineWidth);
|
||||
addProperty(_pDistanceFactor);
|
||||
|
||||
_pLightSpeed = 299792458.f;
|
||||
|
||||
_triggerTime = -1;
|
||||
//Earthnode worldposition, is not aligned with the actual position shown as it seems right now.
|
||||
|
||||
_spriteTexture = nullptr;
|
||||
std::string texturepath = absPath("${SYNC}/http/stars_textures/1/halo.png");
|
||||
|
||||
_spriteTexture = ghoul::io::TextureReader::ref().loadTexture(
|
||||
texturepath
|
||||
);
|
||||
if (_spriteTexture) {
|
||||
_spriteTexture->uploadTexture();
|
||||
}
|
||||
|
||||
_pRenderMode.addOption(static_cast<int>(RenderMethod::LineStrip), "LineStrip");
|
||||
_pRenderMode.addOption(static_cast<int>(RenderMethod::Lines), "Lines");
|
||||
_pRenderMode.addOption(static_cast<int>(RenderMethod::Points), "Points");
|
||||
_pRenderMode.addOption(static_cast<int>(RenderMethod::Sprites), "Sprites");
|
||||
addProperty(_pRenderMode);
|
||||
addProperty(_pLightColor);
|
||||
addProperty(_pDefaultColor);
|
||||
addProperty(_pPointSize);
|
||||
addProperty(_pTimeStep);
|
||||
|
||||
}
|
||||
void RenderableLightTravel::deinitializeGL()
|
||||
{
|
||||
glDeleteVertexArrays(1, &_vertexArrayObject);
|
||||
_vertexArrayObject = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
if (_shaderProgram) {
|
||||
global::renderEngine->removeRenderProgram(_shaderProgram.get());
|
||||
_shaderProgram = nullptr;
|
||||
}
|
||||
}
|
||||
double RenderableLightTravel::calculateEndTime(const double starttime,
|
||||
const glm::vec3 startpos, const glm::vec3 endpos) {
|
||||
|
||||
glm::vec3 newpos = glm::vec3(0, 0, 0);
|
||||
glm::vec3 normalizedVector = glm::normalize(endpos);
|
||||
_normalizedVector = normalizedVector;
|
||||
double endtime = starttime;
|
||||
int counter = 0;
|
||||
positions.clear();
|
||||
positions.push_back(startpos);
|
||||
glm::vec3 newpos2 = glm::vec3(0, 0, 0);
|
||||
newpos2.x = normalizedVector.x * _Timesincestart * _pLightSpeed;
|
||||
newpos2.y = normalizedVector.y * _Timesincestart * _pLightSpeed;
|
||||
newpos2.z = normalizedVector.z * _Timesincestart * _pLightSpeed;
|
||||
int interval = _pTimeStep;
|
||||
|
||||
while(endtime - starttime < 500){
|
||||
newpos.x += interval * _pLightSpeed * normalizedVector.x;
|
||||
newpos.y += interval * _pLightSpeed * normalizedVector.y;
|
||||
newpos.z += interval * _pLightSpeed * normalizedVector.z;
|
||||
|
||||
endtime += interval;
|
||||
++counter;
|
||||
|
||||
if (newpos.x > endpos.x) {
|
||||
newpos = endpos;
|
||||
positions.push_back(newpos);
|
||||
break;
|
||||
}
|
||||
positions.push_back(newpos);
|
||||
}
|
||||
positions.push_back(endpos);
|
||||
|
||||
_needPositionUpdate = true;
|
||||
return endtime;
|
||||
}
|
||||
bool RenderableLightTravel::isReady() const
|
||||
{
|
||||
return _shaderProgram != nullptr;
|
||||
}
|
||||
void RenderableLightTravel::render(const RenderData& data, RendererTasks& rendererTask)
|
||||
{
|
||||
if (!this->_enabled) return;
|
||||
if (_triggerTime == -1) {
|
||||
_triggerTime = data.time.j2000Seconds();
|
||||
_endTime = _triggerTime + 599;
|
||||
}
|
||||
|
||||
_shaderProgram->activate();
|
||||
// Calculate Model View MatrixProjection
|
||||
|
||||
const glm::dmat4 rotMat = glm::dmat4(data.modelTransform.rotation);
|
||||
const glm::dmat4 modelMat =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
|
||||
rotMat *
|
||||
glm::dmat4(glm::scale(glm::dmat4(1), glm::dvec3(data.modelTransform.scale)));
|
||||
const glm::dmat4 modelViewMat = data.camera.combinedViewMatrix() * modelMat;
|
||||
|
||||
_shaderProgram->setUniform("modelViewProjection",
|
||||
data.camera.sgctInternal.projectionMatrix()* glm::mat4(modelViewMat));
|
||||
|
||||
glm::dmat4 modelMatrix =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
|
||||
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
|
||||
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
|
||||
|
||||
glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix;
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
|
||||
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix;
|
||||
|
||||
glm::dvec3 cameraViewDirectionWorld = -data.camera.viewDirectionWorldSpace();
|
||||
glm::dvec3 cameraUpDirectionWorld = data.camera.lookUpVectorWorldSpace();
|
||||
glm::dvec3 orthoRight = glm::normalize(
|
||||
glm::cross(cameraUpDirectionWorld, cameraViewDirectionWorld)
|
||||
);
|
||||
if (orthoRight == glm::dvec3(0.0)) {
|
||||
glm::dvec3 otherVector(
|
||||
cameraUpDirectionWorld.y,
|
||||
cameraUpDirectionWorld.x,
|
||||
cameraUpDirectionWorld.z
|
||||
);
|
||||
orthoRight = glm::normalize(glm::cross(otherVector, cameraViewDirectionWorld));
|
||||
}
|
||||
glm::dvec3 orthoUp = glm::normalize(glm::cross(cameraViewDirectionWorld, orthoRight));
|
||||
|
||||
glBindVertexArray(_vertexArrayObject);
|
||||
|
||||
if (positions.size() > 2) {
|
||||
const double currentTime = data.time.j2000Seconds();
|
||||
_Timesincestart = currentTime - _triggerTime;
|
||||
float dist_from_start = glm::distance(positions[0], positions[positions.size()]);
|
||||
float transmissiontime = _endTime - _triggerTime;
|
||||
_shaderProgram->setUniform("in_time_since_start", _Timesincestart);
|
||||
_shaderProgram->setUniform("normalizedVectorFromSunToEarth", _normalizedVector);
|
||||
_shaderProgram->setUniform("renderMode", _pRenderMode);
|
||||
_shaderProgram->setUniform("pointSize", _pPointSize);
|
||||
_shaderProgram->setUniform("defaultColor", _pDefaultColor);
|
||||
_shaderProgram->setUniform("lightColor", _pLightColor);
|
||||
_shaderProgram->setUniform("distanceFactor", _pDistanceFactor);
|
||||
|
||||
}
|
||||
|
||||
if(_pRenderMode == 0){
|
||||
glLineWidth(_pLineWidth);
|
||||
GLint temp = 0;
|
||||
glDrawArrays(
|
||||
GL_LINE_STRIP,
|
||||
temp,
|
||||
static_cast<GLsizei>(positions.size())
|
||||
);
|
||||
}
|
||||
else if(_pRenderMode == 1){
|
||||
glLineWidth(_pLineWidth);
|
||||
GLint temp = 0;
|
||||
glDrawArrays(
|
||||
GL_LINES,
|
||||
temp,
|
||||
static_cast<GLsizei>(positions.size())
|
||||
);
|
||||
}
|
||||
else if(_pRenderMode == 2){
|
||||
GLint temp = 0;
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
glDrawArrays(
|
||||
GL_POINTS,
|
||||
temp,
|
||||
static_cast<GLsizei>(positions.size())
|
||||
);
|
||||
}
|
||||
else if(_pRenderMode == 3){
|
||||
ghoul::opengl::TextureUnit spriteTextureUnit;
|
||||
spriteTextureUnit.activate();
|
||||
_spriteTexture->bind();
|
||||
_shaderProgram->setUniform("spriteTexture", spriteTextureUnit);
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
|
||||
glDrawArrays(
|
||||
GL_POINTS,
|
||||
0,
|
||||
static_cast<GLsizei>(positions.size())
|
||||
);
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
_shaderProgram->deactivate();
|
||||
}
|
||||
|
||||
inline void unbindGL() {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void RenderableLightTravel::update(const UpdateData& data)
|
||||
{
|
||||
if (!this->_enabled) return;
|
||||
if (_shaderProgram->isDirty()) {
|
||||
_shaderProgram->rebuildFromFile();
|
||||
}
|
||||
|
||||
const double currentTime = data.time.j2000Seconds();
|
||||
|
||||
if (_needPositionUpdate) {
|
||||
SceneGraphNode* earthNode = sceneGraphNode("Earth");
|
||||
glm::vec3 earthPos = earthNode->worldPosition();
|
||||
glm::vec3 currentpos = glm::vec3(0.0, 0.0, 0.0);
|
||||
|
||||
_needPositionUpdate = false;
|
||||
_endTime = calculateEndTime(_triggerTime, currentpos, earthPos);
|
||||
|
||||
}
|
||||
if (_triggerTime < currentTime && _endTime > currentTime) {
|
||||
|
||||
glBindVertexArray(_vertexArrayObject);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
|
||||
|
||||
const std::vector<glm::vec3>& vertPos = positions;
|
||||
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
vertPos.size() * sizeof(glm::vec3),
|
||||
vertPos.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
constexpr const GLuint VaPosition = 0;
|
||||
glEnableVertexAttribArray(VaPosition);
|
||||
glVertexAttribPointer(VaPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
|
||||
constexpr const GLuint VaDistance = 1;
|
||||
constexpr const GLuint VaTimeSinceStart = 2;
|
||||
constexpr const GLuint VaTransmissionTime = 3;
|
||||
constexpr const GLuint VaLightTravelTime = 4;
|
||||
|
||||
//glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
|
||||
glVertexAttribPointer(VaDistance, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(VaDistance);
|
||||
|
||||
glVertexAttribPointer(VaTimeSinceStart, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(VaTimeSinceStart);
|
||||
|
||||
glVertexAttribPointer(VaTransmissionTime, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(VaTransmissionTime);
|
||||
|
||||
glVertexAttribPointer(VaLightTravelTime, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(VaLightTravelTime);
|
||||
|
||||
unbindGL();
|
||||
}
|
||||
else {
|
||||
_needPositionUpdate = true;
|
||||
_triggerTime = data.time.j2000Seconds();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <modules/fieldlinessequence/util/fieldlinesstate.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
#include <openspace/properties/scalar/intproperty.h>
|
||||
#include <openspace/properties/vector/vec2property.h>
|
||||
#include <openspace/properties/vector/vec4property.h>
|
||||
#include <openspace/rendering/transferfunction.h>
|
||||
#include <atomic>
|
||||
|
||||
#include <modules/base/rendering/renderabletrail.h>
|
||||
|
||||
namespace ghoul::fontrendering { class Font; }
|
||||
namespace openspace {
|
||||
class RenderableLightTravel : public Renderable {
|
||||
public:
|
||||
RenderableLightTravel(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data, RendererTasks& rendererTask) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
|
||||
std::string _identifier;
|
||||
std::vector<float> _vertexArray;
|
||||
glm::vec3 _normalizedVector;
|
||||
// OpenGL Vertex Array Object
|
||||
GLuint _vertexArrayObject = 0;
|
||||
// OpenGL Vertex Buffer Object containing the vertex positions
|
||||
GLuint _vertexPositionBuffer = 0;
|
||||
// OpenGL Vertex Buffer Object containing the Flux values used for coloring
|
||||
// the nodes
|
||||
GLuint _vertexColorBuffer = 0;
|
||||
// OpenGL Vertex Buffer Object containing the positions to filter the nodes
|
||||
GLuint _vertexFilteringBuffer = 0;
|
||||
// OpenGL Vertex Buffer Object containing the index of nodes
|
||||
GLuint _vertexindexBuffer = 0;
|
||||
|
||||
enum class RenderMethod : int {
|
||||
LineStrip = 0,
|
||||
Lines = 1,
|
||||
Points = 2,
|
||||
Sprites = 3
|
||||
};
|
||||
|
||||
std::vector<glm::vec3> positions;
|
||||
float _Timesincestart = -1.f;
|
||||
double _triggerTime;
|
||||
double _endTime;
|
||||
bool _needPositionUpdate = true;
|
||||
|
||||
properties::FloatProperty _pLightSpeed;
|
||||
properties::FloatProperty _pLineWidth;
|
||||
properties::OptionProperty _pRenderMode;
|
||||
properties::FloatProperty _pPointSize;
|
||||
properties::IntProperty _pTimeStep;
|
||||
properties::FloatProperty _pDistanceFactor;
|
||||
|
||||
//properties::BoolProperty _pShowLabel;
|
||||
//properties::BoolProperty _pShouldFollowLight;
|
||||
//properties::FloatProperty _pFadeDistance;
|
||||
|
||||
properties::Vec4Property _pDefaultColor;
|
||||
properties::Vec4Property _pLightColor;
|
||||
|
||||
//properties::IntProperty _pTextMinSize;
|
||||
//properties::IntProperty _pTextMaxSize;
|
||||
std::unique_ptr<ghoul::Dictionary> _dictionary;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shaderProgram;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::Texture> _spriteTexture;
|
||||
std::unique_ptr<ghoul::filesystem::File> _spriteTextureFile;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
|
||||
glm::vec3 _labelPos;
|
||||
GLuint _quad = 0;
|
||||
/* void renderLabels(const RenderData& data,
|
||||
const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp,
|
||||
float fadeInVariable);*/
|
||||
double calculateEndTime(const double starttime, const glm::vec3 startpos, const glm::vec3 endpos);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
#include <modules/streamnodes/rendering/renderabletravelspeed.h>
|
||||
|
||||
#include <modules/base/basemodule.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/distanceconstants.h>
|
||||
#include <openspace/util/timemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "renderableTravelSpeed";
|
||||
|
||||
constexpr const std::array<const char*, 2> UniformNames = {
|
||||
"lineColor", "opacity"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo SpeedInfo = {
|
||||
"travelSpeed",
|
||||
"Speed of travel",
|
||||
"The speed of light is the default value."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo TargetInfo = {
|
||||
"targetNode",
|
||||
"Target object",
|
||||
"This value sets which scene graph node to target with the light speed indicator"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LineColorInfo = {
|
||||
"Color",
|
||||
"Color",
|
||||
"This value determines the RGB color for the line."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LineOpacityInfo = {
|
||||
"Opacity",
|
||||
"Opacity",
|
||||
"This value determines the opacity for the line."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = {
|
||||
"LineWidth",
|
||||
"Line Width",
|
||||
"This value specifies the line width."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo IndicatorLengthInfo = {
|
||||
"IndicatorLength",
|
||||
"Indicator Length",
|
||||
"This value specifies the length of the light indicator set in light seconds."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo FadeLengthInfo = {
|
||||
"FadeLength",
|
||||
"Fade Length",
|
||||
"This value specifies the length of the faded tail of the light indicator "
|
||||
"set in light seconds."
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(RenderableLightTravel)]] Parameters {
|
||||
// [[codegen::verbatim(TargetInfo.description)]]
|
||||
std::string target;
|
||||
|
||||
// [[codegen::verbatim(SpeedInfo.description)]]
|
||||
std::optional<double> travelSpeed;
|
||||
|
||||
// [[codegen::verbatim(LineColorInfo.description)]]
|
||||
std::optional<glm::vec3> color;
|
||||
|
||||
// [[codegen::verbatim(LineOpacityInfo.description)]]
|
||||
std::optional<float> opacity;
|
||||
|
||||
// [[codegen::verbatim(LineWidthInfo.description)]]
|
||||
std::optional<float> lineWidth;
|
||||
|
||||
// [[codegen::verbatim(IndicatorLengthInfo.description)]]
|
||||
std::optional<int> indicatorLength;
|
||||
|
||||
// [[codegen::verbatim(FadeLengthInfo.description)]]
|
||||
std::optional<int> fadeLength;
|
||||
|
||||
|
||||
};
|
||||
#include "renderabletravelspeed_codegen.cpp"
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
using namespace properties;
|
||||
|
||||
documentation::Documentation RenderableTravelSpeed::Documentation() {
|
||||
documentation::Documentation doc = codegen::doc<Parameters>();
|
||||
doc.id = "base_renderable_renderabletravelspeed";
|
||||
return doc;
|
||||
}
|
||||
|
||||
RenderableTravelSpeed::RenderableTravelSpeed(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _targetName(TargetInfo)
|
||||
, _travelSpeed(SpeedInfo, distanceconstants::LightSecond, 1.0,
|
||||
distanceconstants::LightSecond)
|
||||
, _indicatorLength(IndicatorLengthInfo, 1, 1, 360)
|
||||
, _fadeLength(FadeLengthInfo, 1, 0, 360)
|
||||
, _lineColor(LineColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f))
|
||||
// , _opacity(LineOpacityInfo, 1.0, 0.0, 1.0)
|
||||
, _lineWidth(LineWidthInfo, 2.f, 1.f, 20.f)
|
||||
|
||||
{
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
setRenderBin(RenderBin::Overlay);
|
||||
|
||||
_lineColor = p.color.value_or(_lineColor);
|
||||
addProperty(_lineColor);
|
||||
|
||||
_opacity = p.opacity.value_or(_opacity);
|
||||
addProperty(_opacity);
|
||||
|
||||
_lineWidth = p.lineWidth.value_or(_lineWidth);
|
||||
addProperty(_lineWidth);
|
||||
|
||||
_indicatorLength = p.indicatorLength.value_or(_indicatorLength);
|
||||
addProperty(_indicatorLength);
|
||||
|
||||
_fadeLength = p.fadeLength.value_or(_fadeLength);
|
||||
addProperty(_fadeLength);
|
||||
|
||||
_targetName = p.target;
|
||||
addProperty(_targetName);
|
||||
_targetName.onChange([this]() {
|
||||
if (SceneGraphNode* n = sceneGraphNode(_targetName); n) {
|
||||
_targetNode = n;
|
||||
_targetPosition = _targetNode->worldPosition();
|
||||
_lightTravelTime = calculateLightTravelTime(
|
||||
_sourcePosition, _targetPosition
|
||||
);
|
||||
calculateDirectionVector();
|
||||
reinitiateTravel();
|
||||
}
|
||||
});
|
||||
|
||||
_travelSpeed = p.travelSpeed.value_or(_travelSpeed);
|
||||
addProperty(_travelSpeed);
|
||||
_travelSpeed.onChange([this]() {
|
||||
reinitiateTravel();
|
||||
});
|
||||
|
||||
} // constructor
|
||||
|
||||
void RenderableTravelSpeed::initialize() {
|
||||
|
||||
_initiationTime = -1;
|
||||
_targetNode = sceneGraphNode(_targetName);
|
||||
|
||||
} // initialize
|
||||
|
||||
void RenderableTravelSpeed::initializeGL() {
|
||||
|
||||
_shaderProgram = BaseModule::ProgramObjectManager.request(
|
||||
"Travelspeed",
|
||||
[]() -> std::unique_ptr<ghoul::opengl::ProgramObject> {
|
||||
return global::renderEngine->buildRenderProgram(
|
||||
"Travelspeed",
|
||||
absPath("${MODULE_STREAMNODES}/shaders/travelspeed_vs.glsl"),
|
||||
absPath("${MODULE_STREAMNODES}/shaders/travelspeed_fs.glsl")
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
glGenVertexArrays(1, &_vaoId);
|
||||
glGenBuffers(1, &_vBufferId);
|
||||
|
||||
ghoul::opengl::updateUniformLocations(*_shaderProgram, _uniformCache, UniformNames);
|
||||
|
||||
} // initializeGL
|
||||
|
||||
void RenderableTravelSpeed::deinitializeGL() {
|
||||
BaseModule::ProgramObjectManager.release(
|
||||
"Travelspeed",
|
||||
[](ghoul::opengl::ProgramObject* p) {
|
||||
global::renderEngine->removeRenderProgram(p);
|
||||
}
|
||||
);
|
||||
glDeleteVertexArrays(1, &_vaoId);
|
||||
glDeleteBuffers(1, &_vBufferId);
|
||||
} // deinitializeGL
|
||||
|
||||
double RenderableTravelSpeed::calculateLightTravelTime(glm::dvec3 startPosition,
|
||||
glm::dvec3 targetPosition) {
|
||||
return glm::distance(targetPosition, startPosition) /
|
||||
_travelSpeed;
|
||||
}
|
||||
|
||||
void RenderableTravelSpeed::calculateDirectionVector() {
|
||||
_directionVector = glm::normalize(_targetPosition - _sourcePosition);
|
||||
}
|
||||
|
||||
void RenderableTravelSpeed::calculateVerticesPositions() {
|
||||
|
||||
// 3: start of light, 2: start of fade, 1: end of fade
|
||||
_verticesPositions[2].x = _travelSpeed * _timeSinceStart * _directionVector.x;
|
||||
_verticesPositions[2].y = _travelSpeed * _timeSinceStart * _directionVector.y;
|
||||
_verticesPositions[2].z = _travelSpeed * _timeSinceStart * _directionVector.z;
|
||||
//_verticesPositions[2] += _sourcePosition;
|
||||
|
||||
if (_timeSinceStart < _indicatorLength) {
|
||||
_verticesPositions[1] = glm::vec3(0.0, 0.0, 0.0); //_sourcePosition;
|
||||
}
|
||||
else {
|
||||
_verticesPositions[1].x =
|
||||
_travelSpeed * _directionVector.x * (_timeSinceStart - _indicatorLength);
|
||||
_verticesPositions[1].y =
|
||||
_travelSpeed * _directionVector.y * (_timeSinceStart - _indicatorLength);
|
||||
_verticesPositions[1].z =
|
||||
_travelSpeed * _directionVector.z * (_timeSinceStart - _indicatorLength);
|
||||
//_verticesPositions[1] += _sourcePosition;
|
||||
|
||||
}
|
||||
|
||||
if (_timeSinceStart < (_indicatorLength + _fadeLength)) {
|
||||
_verticesPositions[0] = glm::vec3(0.0, 0.0, 0.0); // _sourcePosition;
|
||||
}
|
||||
else {
|
||||
_verticesPositions[0].x =
|
||||
_travelSpeed * _directionVector.x *
|
||||
(_timeSinceStart - _indicatorLength - _fadeLength);
|
||||
_verticesPositions[0].y =
|
||||
_travelSpeed * _directionVector.y *
|
||||
(_timeSinceStart - _indicatorLength - _fadeLength);
|
||||
_verticesPositions[0].z =
|
||||
_travelSpeed * _directionVector.z *
|
||||
(_timeSinceStart - _indicatorLength - _fadeLength);
|
||||
//_verticesPositions[0] += _sourcePosition;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableTravelSpeed::updateVertexData() {
|
||||
//glm::vec3 z = glm::vec3(0.0);
|
||||
//std::fill(std::begin(_verticesPositions), std::end(_verticesPositions), z);
|
||||
|
||||
calculateVerticesPositions();
|
||||
|
||||
glBindVertexArray(_vaoId);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferId);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
sizeof(_verticesPositions),
|
||||
_verticesPositions,
|
||||
GL_DYNAMIC_DRAW
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), nullptr);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void RenderableTravelSpeed::reinitiateTravel() {
|
||||
_initiationTime = global::timeManager->time().j2000Seconds();
|
||||
_arrivalTime = _initiationTime + _lightTravelTime;
|
||||
}
|
||||
|
||||
bool RenderableTravelSpeed::isReady() const{
|
||||
return _shaderProgram != nullptr;
|
||||
}
|
||||
|
||||
void RenderableTravelSpeed::update(const UpdateData& data) {
|
||||
|
||||
if (_initiationTime == -1) {
|
||||
_initiationTime = data.time.j2000Seconds();
|
||||
std::string_view temp = data.time.ISO8601();
|
||||
_arrivalTime = _initiationTime + _lightTravelTime;
|
||||
}
|
||||
|
||||
_targetPosition = _targetNode->worldPosition();
|
||||
SceneGraphNode* mySGNPointer = dynamic_cast<SceneGraphNode*>(owner());
|
||||
ghoul_assert(mySGNPointer, "Renderable have to be owned by scene graph node");
|
||||
_sourcePosition = mySGNPointer->worldPosition();
|
||||
|
||||
_lightTravelTime = calculateLightTravelTime(
|
||||
_sourcePosition, _targetPosition
|
||||
);
|
||||
|
||||
const double currentTime = data.time.j2000Seconds();
|
||||
if (_initiationTime < currentTime && _arrivalTime > currentTime) {
|
||||
|
||||
_timeSinceStart = currentTime - _initiationTime;
|
||||
calculateDirectionVector();
|
||||
updateVertexData();
|
||||
|
||||
}
|
||||
else {
|
||||
reinitiateTravel();
|
||||
}
|
||||
|
||||
//_shaderProgram->setUniform(_uniformCache.travelTime, _lightTravelTime);
|
||||
_shaderProgram->setUniform("lineColor", _lineColor);
|
||||
_shaderProgram->setUniform("opacity", _opacity);
|
||||
//_shaderProgram->setUniform(_uniformCache.travelTime, _lightTravelTime);
|
||||
|
||||
} // update
|
||||
|
||||
void RenderableTravelSpeed::render(const RenderData& data, RendererTasks& ) {
|
||||
if (!this->_enabled) return;
|
||||
|
||||
_shaderProgram->activate();
|
||||
|
||||
const glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
|
||||
glm::dmat4(data.modelTransform.rotation) *
|
||||
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
|
||||
|
||||
const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() *
|
||||
modelTransform;
|
||||
|
||||
_shaderProgram->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
|
||||
_shaderProgram->setUniform("projectionTransform", data.camera.projectionMatrix());
|
||||
|
||||
#ifdef __APPLE__
|
||||
glLineWidth(1);
|
||||
#endif
|
||||
glLineWidth(_lineWidth);
|
||||
glBindVertexArray(_vaoId);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferId);
|
||||
glDrawArrays(
|
||||
GL_LINE_STRIP,
|
||||
0,
|
||||
3
|
||||
);
|
||||
glBindVertexArray(0);
|
||||
|
||||
_shaderProgram->deactivate();
|
||||
|
||||
} // render
|
||||
} // namespace
|
||||
@@ -0,0 +1,92 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_STREAMNODES___RENDERABLETRAVELSPEED___H__
|
||||
#define __OPENSPACE_MODULE_STREAMNODES___RENDERABLETRAVELSPEED___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
#include <openspace/properties/scalar/intproperty.h>
|
||||
|
||||
|
||||
#include <ghoul/opengl/uniformcache.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SceneGraphNode;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
class RenderableTravelSpeed : public Renderable{
|
||||
public:
|
||||
RenderableTravelSpeed(const ghoul::Dictionary& dictionary);
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
void initializeGL() override;
|
||||
void initialize() override;
|
||||
void deinitializeGL() override;
|
||||
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data, RendererTasks& rendererTask) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
properties::StringProperty _targetName;
|
||||
SceneGraphNode* _targetNode = nullptr;
|
||||
properties::DoubleProperty _travelSpeed;
|
||||
properties::IntProperty _indicatorLength;
|
||||
properties::IntProperty _fadeLength;
|
||||
properties::FloatProperty _lineWidth;
|
||||
properties::Vec3Property _lineColor;
|
||||
|
||||
|
||||
//0 at parent, 1 at end of fade, 2 between light and fade,
|
||||
//3 at head of light, 4 at target
|
||||
glm::vec3 _verticesPositions[3];
|
||||
|
||||
glm::dvec3 _sourcePosition;
|
||||
glm::dvec3 _targetPosition;
|
||||
double _lightTravelTime;
|
||||
glm::dvec3 _directionVector;
|
||||
double _initiationTime;
|
||||
double _arrivalTime;
|
||||
double _timeSinceStart = -1.f;
|
||||
|
||||
|
||||
ghoul::opengl::ProgramObject* _shaderProgram = nullptr;
|
||||
// The vertex attribute location for position
|
||||
// must correlate to layout location in vertex shader
|
||||
GLuint _vaoId = 0;
|
||||
GLuint _vBufferId = 0;
|
||||
|
||||
double calculateLightTravelTime(glm::dvec3 startPosition, glm::dvec3 targetPosition);
|
||||
void calculateVerticesPositions();
|
||||
void calculateDirectionVector();
|
||||
void updateVertexData();
|
||||
void reinitiateTravel();
|
||||
UniformCache(lineColor, opacity) _uniformCache;
|
||||
};
|
||||
} // namespace
|
||||
#endif //__OPENSPACE_MODULE_STREAMNODES___RENDERABLETRAVELSPEED___H__
|
||||
@@ -1,125 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2020 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
uniform mat4 modelViewProjection;
|
||||
//uniform mat4 modelViewProjectionTransform;
|
||||
//uniform mat4 modelViewTransform;
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_color;
|
||||
out float vs_depth;
|
||||
|
||||
uniform float in_time_since_start;
|
||||
|
||||
uniform vec3 normalizedVectorFromSunToEarth;
|
||||
uniform int renderMode;
|
||||
uniform float pointSize;
|
||||
uniform vec4 defaultColor;
|
||||
uniform vec4 lightColor;
|
||||
uniform float distanceFactor;
|
||||
|
||||
out float distanceFromStart;
|
||||
out float timeSinceStart;
|
||||
out float transmissionTime;
|
||||
out float lightTravelTime;
|
||||
out vec4 vs_positionScreenSpace;
|
||||
out vec4 vs_gPosition;
|
||||
out int render_mode;
|
||||
|
||||
float maxDistance = distanceFactor * 1000000000.f;
|
||||
const float lightSpeed = 299792458.0;
|
||||
|
||||
bool calculateDistance(vec3 inposition) {
|
||||
vec3 newpos = vec3(0, 0, 0);
|
||||
|
||||
newpos.x = normalizedVectorFromSunToEarth.x * in_time_since_start * lightSpeed;
|
||||
newpos.y = normalizedVectorFromSunToEarth.y * in_time_since_start * lightSpeed;
|
||||
newpos.z = normalizedVectorFromSunToEarth.z * in_time_since_start * lightSpeed;
|
||||
|
||||
if(newpos.y < inposition.y && newpos.x < inposition.x && newpos.z > inposition.z){
|
||||
return false;
|
||||
}
|
||||
if(distance(newpos, inposition) < maxDistance){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
float smoothmotion(){
|
||||
vec3 newpos = vec3(0,0,0);
|
||||
newpos.x = normalizedVectorFromSunToEarth.x * in_time_since_start * lightSpeed;
|
||||
newpos.y = normalizedVectorFromSunToEarth.y * in_time_since_start * lightSpeed;
|
||||
newpos.z = normalizedVectorFromSunToEarth.z * in_time_since_start * lightSpeed;
|
||||
|
||||
float smoothFront = 1 - smoothstep(0, maxDistance, distance(newpos, in_position));
|
||||
|
||||
if(smoothFront < 0.95f){
|
||||
float alphaV = 0.1 * smoothFront * smoothFront;
|
||||
if(alphaV < 0.01){
|
||||
return 0;
|
||||
}
|
||||
return alphaV;
|
||||
}
|
||||
return smoothFront;
|
||||
}
|
||||
|
||||
vec4 z_normalization(vec4 v_in) {
|
||||
vec4 v_out = v_in;
|
||||
v_out.z = 0;
|
||||
return v_out;
|
||||
}
|
||||
|
||||
void main() {
|
||||
if(calculateDistance(in_position)){
|
||||
vs_color = lightColor;
|
||||
vs_color.a = vs_color.a * smoothmotion();
|
||||
}
|
||||
else{
|
||||
if(renderMode == 3){
|
||||
vs_color = vec4(0);
|
||||
}
|
||||
else{
|
||||
vs_color = defaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
if(renderMode == 2 || renderMode == 3){
|
||||
gl_PointSize = pointSize;
|
||||
}
|
||||
|
||||
vec4 position_in_meters = vec4(in_position.xyz, 1);
|
||||
vec4 positionClipSpace = modelViewProjection * position_in_meters;
|
||||
|
||||
gl_Position = positionClipSpace;
|
||||
|
||||
vs_depth = gl_Position.w;
|
||||
timeSinceStart = in_time_since_start;
|
||||
render_mode = renderMode;
|
||||
vs_st = in_st;
|
||||
}
|
||||
+20
-39
@@ -1,8 +1,9 @@
|
||||
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2020 *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
@@ -23,47 +24,27 @@
|
||||
****************************************************************************************/
|
||||
#include "fragment.glsl"
|
||||
#include "floatoperations.glsl"
|
||||
in vec4 vs_color;
|
||||
in float vs_depth;
|
||||
in flat int render_mode;
|
||||
in vec2 vs_st;
|
||||
|
||||
uniform sampler2D spriteTexture;
|
||||
float lightSpeed = 299792458.0;
|
||||
|
||||
in vec4 vs_positionScreenSpace;
|
||||
in vec4 vs_gPosition;
|
||||
in float distanceFromStart;
|
||||
in float timeSinceStart;
|
||||
in float transmissionTime;
|
||||
in float lightTravelTime;
|
||||
|
||||
|
||||
float flowSpeedFactor = 1000000000;
|
||||
float segmentSizeFactor = 200;
|
||||
float spacingSizeFactor = 2000;
|
||||
float fadeFactor = 0.2;
|
||||
float baseOpacity = 0.5;
|
||||
|
||||
Fragment getFragment() {
|
||||
if (vs_color.a == 0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 fragColor = vs_color;
|
||||
in float vs_depth;
|
||||
in float t;
|
||||
in vec4 smoothColor;
|
||||
in vec4 vs_positionViewSpace;
|
||||
|
||||
Fragment getFragment() {
|
||||
|
||||
Fragment frag;
|
||||
// vec4 fragColor = smoothColor;
|
||||
// frag.color.x = 1.0; //t*vs_color.x;
|
||||
// frag.color.y = 0.0;//t*vs_color.y;
|
||||
// frag.color.z = 1.0;//t*vs_color.z;
|
||||
// frag.color.a = vs_opacity;
|
||||
|
||||
frag.color = smoothColor;
|
||||
frag.depth = vs_depth;
|
||||
|
||||
if(render_mode == 3){
|
||||
frag.color = texture(spriteTexture, gl_PointCoord) * vec4(1, 1, 1, 0.1);
|
||||
}
|
||||
else{
|
||||
frag.color = fragColor;
|
||||
}
|
||||
|
||||
frag.gPosition = vs_gPosition;
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gPosition = vs_positionViewSpace;
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
return frag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
out float t;
|
||||
out float vs_depth;
|
||||
out vec4 vs_positionViewSpace;
|
||||
out vec4 smoothColor;
|
||||
|
||||
uniform vec3 lineColor;
|
||||
uniform float opacity;
|
||||
uniform mat4 modelViewTransform;
|
||||
uniform mat4 projectionTransform;
|
||||
|
||||
void main(){
|
||||
|
||||
vs_positionViewSpace = vec4(modelViewTransform * dvec4(in_position, 1));
|
||||
vec4 positionScreenSpace = projectionTransform * vs_positionViewSpace;
|
||||
vs_depth = positionScreenSpace.w;
|
||||
gl_Position = positionScreenSpace;
|
||||
|
||||
t = 1.f;
|
||||
|
||||
if (gl_VertexID == 0) {
|
||||
smoothColor = vec4(0.0, 0.0, 0.0, opacity);
|
||||
}
|
||||
|
||||
else if (gl_VertexID == 1) {
|
||||
smoothColor = vec4(lineColor, opacity);
|
||||
}
|
||||
|
||||
else if (gl_VertexID == 2 ) {
|
||||
smoothColor = vec4(lineColor, opacity);
|
||||
}
|
||||
|
||||
else {
|
||||
smoothColor = vec4(1.0, 1.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
gl_Position.z = 0.f;
|
||||
|
||||
}
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
#include <modules/streamnodes/streamnodesmodule.h>
|
||||
#include <modules/streamnodes/rendering/renderablestreamnodes.h>
|
||||
#include <modules/streamnodes/rendering/renderablelighttravel.h>
|
||||
#include <modules/streamnodes/rendering/renderableplanetimevaryingimage.h>
|
||||
#include <modules/streamnodes/rendering/renderabletravelspeed.h>
|
||||
#include <modules/streamnodes/rendering/renderabletimevaryingsphere.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -63,9 +63,9 @@ void StreamNodesModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
ghoul_assert(factory, "No renderable factory existed");
|
||||
|
||||
factory->registerClass<RenderableStreamNodes>("RenderableStreamNodes");
|
||||
factory->registerClass<RenderableLightTravel>("RenderableLightTravel");
|
||||
factory->registerClass<RenderablePlaneTimeVaryingImage>
|
||||
("RenderablePlaneTimeVaryingImage");
|
||||
factory->registerClass<RenderableTravelSpeed>("RenderableTravelSpeed");
|
||||
factory->registerClass<RenderableTimeVaryingSphere>("RenderableTimeVaryingSphere");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user