mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 18:11:01 -05:00
Real world update time interval
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
namespace openspace{
|
||||
|
||||
@@ -27,7 +28,7 @@ CygnetPlane::CygnetPlane(const ghoul::Dictionary& dictionary)
|
||||
:ISWACygnet(dictionary)
|
||||
,_quad(0)
|
||||
,_vertexPositionBuffer(0)
|
||||
,_planeIsDirty(true)
|
||||
,_futureObject(nullptr)
|
||||
{}
|
||||
|
||||
CygnetPlane::~CygnetPlane(){}
|
||||
@@ -41,6 +42,114 @@ bool CygnetPlane::isReady() const{
|
||||
return ready;
|
||||
}
|
||||
|
||||
void CygnetPlane::render(const RenderData& data){
|
||||
|
||||
if(!_texture) return;
|
||||
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
|
||||
glm::mat4 rot = glm::mat4(1.0);
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
|
||||
// Correct for the small error of x-axis not pointing directly at the sun
|
||||
if(_data->frame == "GSM"){
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("SUN", "Earth", "GALACTIC", {}, _openSpaceTime, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
|
||||
position += transform*glm::vec4(_data->spatialScale.x*_data->offset, _data->spatialScale.y);
|
||||
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
|
||||
// _shader->setUniform("top", _topColor.value());
|
||||
// _shader->setUniform("mid", _midColor.value());
|
||||
// _shader->setUniform("bot", _botColor.value());
|
||||
// _shader->setUniform("tfValues", _tfValues.value());
|
||||
|
||||
setPscUniforms(*_shader.get(), data.camera, position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
_shader->deactivate();
|
||||
|
||||
// position += transform*(glm::vec4(0.5f*_data->scale.x+100.0f ,-0.5f*_data->scale.y, 0.0f, _data->scale.w));
|
||||
// // RenderData data = { *_camera, psc(), doPerformanceMeasurements };
|
||||
// ColorBarData cbdata = { data.camera,
|
||||
// position,
|
||||
// transform,
|
||||
// _topColor.value(),
|
||||
// _midColor.value(),
|
||||
// _botColor.value(),
|
||||
// _tfValues.value()
|
||||
// // transform
|
||||
// };
|
||||
// _colorbar->render(cbdata);
|
||||
}
|
||||
|
||||
void CygnetPlane::update(const UpdateData& data){
|
||||
_openSpaceTime = Time::ref().currentTime();
|
||||
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());;
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _openSpaceTime);
|
||||
|
||||
if(Time::ref().timeJumped()){
|
||||
updateTexture();
|
||||
|
||||
_lastUpdateRealTime = _realTime;
|
||||
_lastUpdateOpenSpaceTime = _openSpaceTime;
|
||||
}
|
||||
|
||||
|
||||
if(fabs(_openSpaceTime-_lastUpdateOpenSpaceTime) >= _data->updateTime &&
|
||||
(_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval)
|
||||
{
|
||||
updateTexture();
|
||||
|
||||
_lastUpdateRealTime = _realTime;
|
||||
_lastUpdateOpenSpaceTime = _openSpaceTime;
|
||||
}
|
||||
|
||||
if(_futureObject && _futureObject->isFinished){
|
||||
if(loadTexture())
|
||||
_futureObject = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CygnetPlane::createPlane(){
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
@@ -72,8 +181,6 @@ void CygnetPlane::createPlane(){
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
|
||||
_planeIsDirty = false;
|
||||
}
|
||||
|
||||
void CygnetPlane::destroyPlane(){
|
||||
|
||||
@@ -36,6 +36,9 @@ public:
|
||||
~CygnetPlane();
|
||||
|
||||
virtual bool isReady() const override;
|
||||
virtual void render(const RenderData& data) override;
|
||||
virtual void update(const UpdateData& data) override;
|
||||
|
||||
|
||||
protected:
|
||||
virtual bool loadTexture() = 0;
|
||||
@@ -48,7 +51,9 @@ protected:
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
bool _planeIsDirty;
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> _futureObject;
|
||||
|
||||
};
|
||||
} //namespace openspace
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataPlane";
|
||||
@@ -44,7 +43,6 @@ namespace openspace {
|
||||
DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
|
||||
:CygnetPlane(dictionary)
|
||||
,_dataOptions("dataOptions", "Data Options")
|
||||
,_futureData(nullptr)
|
||||
,_normValues("normValues", "Normalize Values", glm::vec2(0.1,0.2), glm::vec2(0), glm::vec2(0.5))
|
||||
,_useLog("useLog","Use Logarithm Norm", false)
|
||||
// ,_topColor("topColor", "Top Color", glm::vec4(1,0,0,1), glm::vec4(0), glm::vec4(1))
|
||||
@@ -89,8 +87,9 @@ DataPlane::~DataPlane(){}
|
||||
|
||||
|
||||
bool DataPlane::initialize(){
|
||||
initializeTime();
|
||||
|
||||
createPlane();
|
||||
|
||||
if (_shader == nullptr) {
|
||||
// DatePlane Program
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
@@ -128,108 +127,51 @@ bool DataPlane::deinitialize(){
|
||||
return true;
|
||||
}
|
||||
|
||||
// void DataPlane::render(const RenderData& data){} //moved to CygnetPlane
|
||||
// void DataPLane::update(const UpdateData& data){} //moved to CygnetPlane
|
||||
|
||||
bool DataPlane::loadTexture() {
|
||||
float* values = readData();
|
||||
if(!values){
|
||||
return false;
|
||||
}
|
||||
|
||||
void DataPlane::render(const RenderData& data){
|
||||
|
||||
if(!_texture) return;
|
||||
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
if (!_texture) {
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = std::make_unique<ghoul::opengl::Texture>(
|
||||
values,
|
||||
_dimensions,
|
||||
ghoul::opengl::Texture::Format::Red,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
ghoul::opengl::Texture::FilterMode::Linear,
|
||||
ghoul::opengl::Texture::WrappingMode::ClampToEdge
|
||||
);
|
||||
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
|
||||
glm::mat4 rot = glm::mat4(1.0);
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
|
||||
if(texture){
|
||||
texture->uploadTexture();
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
}else{
|
||||
_texture->setPixelData(values);
|
||||
_texture->uploadTexture();
|
||||
}
|
||||
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
|
||||
if(_data->frame == "GSM"){
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("SUN", "Earth", "GALACTIC", {}, _time, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
|
||||
position += transform*glm::vec4(_data->spatialScale.x*_data->offset, _data->spatialScale.y);
|
||||
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
|
||||
// _shader->setUniform("top", _topColor.value());
|
||||
// _shader->setUniform("mid", _midColor.value());
|
||||
// _shader->setUniform("bot", _botColor.value());
|
||||
// _shader->setUniform("tfValues", _tfValues.value());
|
||||
|
||||
setPscUniforms(*_shader.get(), data.camera, position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
_shader->deactivate();
|
||||
|
||||
// position += transform*(glm::vec4(0.5f*_data->scale.x+100.0f ,-0.5f*_data->scale.y, 0.0f, _data->scale.w));
|
||||
// // RenderData data = { *_camera, psc(), doPerformanceMeasurements };
|
||||
// ColorBarData cbdata = { data.camera,
|
||||
// position,
|
||||
// transform,
|
||||
// _topColor.value(),
|
||||
// _midColor.value(),
|
||||
// _botColor.value(),
|
||||
// _tfValues.value()
|
||||
// // transform
|
||||
// };
|
||||
// _colorbar->render(cbdata);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DataPlane::update(const UpdateData& data){
|
||||
if(_planeIsDirty)
|
||||
createPlane();
|
||||
bool DataPlane::updateTexture(){
|
||||
if(_futureObject)
|
||||
return false;
|
||||
|
||||
_time = Time::ref().currentTime();
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _time);
|
||||
_memorybuffer = "";
|
||||
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadDataToMemory(_data->id, _memorybuffer);
|
||||
|
||||
//add real world limit!!!
|
||||
if(fabs(_time-_lastUpdateTime) >= _data->updateTime){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
if(future){
|
||||
_futureObject = future;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(_futureData && _futureData->isFinished && _memorybuffer != ""){
|
||||
if(!_dataOptions.options().size()){
|
||||
readHeader();
|
||||
}
|
||||
|
||||
if(loadTexture())
|
||||
_futureData = nullptr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DataPlane::readHeader(){
|
||||
@@ -279,6 +221,9 @@ void DataPlane::readHeader(){
|
||||
}
|
||||
|
||||
float* DataPlane::readData(){
|
||||
if(!_dataOptions.options().size()) // load options for value selection
|
||||
readHeader();
|
||||
|
||||
if(!_memorybuffer.empty()){
|
||||
std::stringstream memorystream(_memorybuffer);
|
||||
std::string line;
|
||||
@@ -394,50 +339,6 @@ float DataPlane::normalizeWithLogarithm(float value, int logMean){
|
||||
return glm::clamp(logNormalized,0.0f, 1.0f);
|
||||
}
|
||||
|
||||
bool DataPlane::loadTexture() {
|
||||
float* values = readData();
|
||||
if(!values){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_texture) {
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = std::make_unique<ghoul::opengl::Texture>(
|
||||
values,
|
||||
_dimensions,
|
||||
ghoul::opengl::Texture::Format::Red,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
ghoul::opengl::Texture::FilterMode::Linear,
|
||||
ghoul::opengl::Texture::WrappingMode::ClampToEdge
|
||||
);
|
||||
|
||||
if(texture){
|
||||
texture->uploadTexture();
|
||||
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
_texture = std::move(texture);
|
||||
}
|
||||
}else{
|
||||
_texture->setPixelData(values);
|
||||
_texture->uploadTexture();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataPlane::updateTexture(){
|
||||
if(_futureData)
|
||||
return false;
|
||||
|
||||
_memorybuffer = "";
|
||||
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadDataToMemory(_data->id, _memorybuffer);
|
||||
|
||||
if(future){
|
||||
_futureData = future;
|
||||
return (_memorybuffer != "");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int DataPlane::id(){
|
||||
static int id = 0;
|
||||
return id++;
|
||||
|
||||
@@ -40,8 +40,8 @@ class DataPlane : public CygnetPlane {
|
||||
|
||||
virtual bool initialize() override;
|
||||
virtual bool deinitialize() override;
|
||||
virtual void render(const RenderData& data) override;
|
||||
virtual void update(const UpdateData& data) override;
|
||||
// virtual void render(const RenderData& data) override; //moved to cygnetPlane
|
||||
// virtual void update(const UpdateData& data) override; //moved to cygnetPlane
|
||||
|
||||
private:
|
||||
virtual bool loadTexture() override;
|
||||
@@ -61,20 +61,12 @@ class DataPlane : public CygnetPlane {
|
||||
// properties::Vec4Property _midColor;
|
||||
// properties::Vec4Property _botColor;
|
||||
// properties::Vec2Property _tfValues;
|
||||
|
||||
|
||||
// std::shared_ptr<KameleonWrapper> _kw;
|
||||
// std::string _kwPath;
|
||||
|
||||
glm::size3_t _dimensions;
|
||||
int numDataValues;
|
||||
int numDataOptions = 0;
|
||||
|
||||
// float* _dataSlice;
|
||||
// std::string _var;
|
||||
|
||||
std::shared_ptr<ColorBar> _colorbar;
|
||||
std::shared_ptr<DownloadManager::FileFuture> _futureData;
|
||||
// std::shared_ptr<ColorBar> _colorbar;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -104,4 +104,14 @@ void ISWACygnet::unregisterProperties(){
|
||||
OsEng.gui()._iSWAproperty.unregisterProperties(name());
|
||||
}
|
||||
|
||||
void ISWACygnet::initializeTime(){
|
||||
_openSpaceTime = Time::ref().currentTime();
|
||||
_lastUpdateOpenSpaceTime = _openSpaceTime;
|
||||
|
||||
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||
_lastUpdateRealTime = _realTime;
|
||||
|
||||
_minRealTimeUpdateInterval = 100;
|
||||
}
|
||||
|
||||
}//namespace openspac
|
||||
@@ -28,8 +28,9 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
@@ -83,6 +84,8 @@ protected:
|
||||
// void setPscUniforms(ghoul::opengl::ProgramObject* program, const Camera* camera, const PowerScaledCoordinate& position);
|
||||
void registerProperties();
|
||||
void unregisterProperties();
|
||||
void initializeTime();
|
||||
void updateCygnet();
|
||||
// void setParent();
|
||||
|
||||
// properties::BoolProperty _enabled;
|
||||
@@ -97,8 +100,12 @@ protected:
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
|
||||
double _time;
|
||||
double _lastUpdateTime = 0;
|
||||
double _openSpaceTime;
|
||||
double _lastUpdateOpenSpaceTime;
|
||||
|
||||
std::chrono::milliseconds _realTime;
|
||||
std::chrono::milliseconds _lastUpdateRealTime;
|
||||
int _minRealTimeUpdateInterval;
|
||||
|
||||
int _id;
|
||||
};
|
||||
|
||||
@@ -32,9 +32,7 @@
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TexutePlane";
|
||||
@@ -44,7 +42,6 @@ namespace openspace {
|
||||
|
||||
TexturePlane::TexturePlane(const ghoul::Dictionary& dictionary)
|
||||
:CygnetPlane(dictionary)
|
||||
,_futureTexture(nullptr)
|
||||
{
|
||||
_id = id();
|
||||
std::string name;
|
||||
@@ -57,6 +54,7 @@ TexturePlane::TexturePlane(const ghoul::Dictionary& dictionary)
|
||||
TexturePlane::~TexturePlane(){}
|
||||
|
||||
bool TexturePlane::initialize(){
|
||||
initializeTime();
|
||||
createPlane();
|
||||
createShader();
|
||||
updateTexture();
|
||||
@@ -73,85 +71,8 @@ bool TexturePlane::deinitialize(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void TexturePlane::render(const RenderData& data){
|
||||
|
||||
if(!_texture) return;
|
||||
|
||||
psc position = data.position;
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
glm::mat4 rotx = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotz = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(0, 0, 1));
|
||||
|
||||
glm::mat4 rot = glm::mat4(1.0);
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
transform = transform * rotz * roty; //BATSRUS
|
||||
|
||||
// Correct for the small error of x-axis not pointing directly at the sun
|
||||
if(_data->frame == "GSM"){
|
||||
glm::vec4 v(1,0,0,1);
|
||||
glm::vec3 xVec = glm::vec3(transform*v);
|
||||
xVec = glm::normalize(xVec);
|
||||
|
||||
double lt;
|
||||
glm::vec3 sunVec =
|
||||
SpiceManager::ref().targetPosition("SUN", "Earth", "GALACTIC", {}, _time, lt);
|
||||
sunVec = glm::normalize(sunVec);
|
||||
|
||||
float angle = acos(glm::dot(xVec, sunVec));
|
||||
glm::vec3 ref = glm::cross(xVec, sunVec);
|
||||
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), angle, ref);
|
||||
transform = rotation * transform;
|
||||
}
|
||||
|
||||
position += transform*glm::vec4(_data->spatialScale.x*_data->offset, _data->spatialScale.y);
|
||||
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
_shader->setUniform("ViewProjection", OsEng.renderEngine().camera()->viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", transform);
|
||||
setPscUniforms(*_shader.get(), *OsEng.renderEngine().camera(), position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
_shader->deactivate();
|
||||
}
|
||||
|
||||
void TexturePlane::update(const UpdateData& data){
|
||||
if(_planeIsDirty)
|
||||
createPlane();
|
||||
|
||||
_time = Time::ref().currentTime();
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", _data->frame, _time);
|
||||
|
||||
//add real world limit!!!
|
||||
if(fabs(_time-_lastUpdateTime) >= _data->updateTime){
|
||||
updateTexture();
|
||||
_lastUpdateTime = _time;
|
||||
}
|
||||
|
||||
if(_futureTexture && _futureTexture->isFinished){
|
||||
loadTexture();
|
||||
_futureTexture = nullptr;
|
||||
}
|
||||
}
|
||||
// void TexturePlane::render(const RenderData& data){} //moved to CygnetPlane
|
||||
// void TexturePlane::update(const UpdateData& data){} //moved to CygnetPlane
|
||||
|
||||
bool TexturePlane::loadTexture() {
|
||||
if(_memorybuffer != ""){
|
||||
@@ -172,14 +93,14 @@ bool TexturePlane::loadTexture() {
|
||||
}
|
||||
|
||||
bool TexturePlane::updateTexture(){
|
||||
if(_futureTexture)
|
||||
if(_futureObject)
|
||||
return false;
|
||||
|
||||
_memorybuffer = "";
|
||||
std::shared_ptr<DownloadManager::FileFuture> future = ISWAManager::ref().downloadImageToMemory(_data->id, _memorybuffer);
|
||||
|
||||
if(future){
|
||||
_futureTexture = future;
|
||||
_futureObject = future;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,19 +36,17 @@
|
||||
TexturePlane(const ghoul::Dictionary& dictionary);
|
||||
~TexturePlane();
|
||||
|
||||
virtual bool initialize() override;
|
||||
virtual bool initialize() override;
|
||||
virtual bool deinitialize() override;
|
||||
|
||||
virtual void render(const RenderData& data) override;
|
||||
virtual void update(const UpdateData& data) override;
|
||||
// virtual void render(const RenderData& data) override; //moved to cygnetPlane
|
||||
// virtual void update(const UpdateData& data) override; //moved to cygnetPlane
|
||||
|
||||
private:
|
||||
virtual bool loadTexture() override;
|
||||
virtual bool loadTexture() override;
|
||||
virtual bool updateTexture() override;
|
||||
|
||||
static int id();
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> _futureTexture;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user