mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-02 16:59:37 -05:00
Real world update time interval
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user