got renderable ephemeris working for larger deltas, problems with leap years though

This commit is contained in:
michal
2014-10-02 11:00:43 -04:00
parent b331bdba9b
commit 938c442dd6
13 changed files with 688 additions and 5 deletions

View File

@@ -13,7 +13,7 @@
<!-- <Size x="960" y="540" /> -->
<!-- <Size x="640" y="360" /> -->
<!--<Size x="640" y="310" />-->
<Pos x="1700" y="50.0" />
<Pos x="500" y="500.0" />
<Viewport>
<Pos x="0.0" y="0.0" />
<Size x="1.0" y="1.0" />

View File

@@ -0,0 +1,91 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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 __RENDERABLEEPHEMERIS_H__
#define __RENDERABLEEPHEMERIS_H__
// open space includes
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
//#include <openspace/util/runtimedata.h>
namespace openspace {
class RenderableEphemeris : public Renderable{
public:
RenderableEphemeris(const ghoul::Dictionary& dictionary);
~RenderableEphemeris();
bool initialize() override;
bool deinitialize() override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
properties::StringProperty _colorTexturePath; // not used now, will be later though.
ghoul::opengl::ProgramObject* _programObject;
ghoul::opengl::Texture* _texture;
void loadTexture();
typedef struct {
GLfloat location[4];
GLfloat velocity[4];
GLubyte padding[32]; // Pads the struct out to 64 bytes for performance increase
} Vertex;
GLuint _vaoID = 6;
GLuint _vBufferID = 7;
GLuint _iBufferID = 8;
void nextIndex();
GLenum _mode;
unsigned int _isize;
unsigned int _vsize;
Vertex* _varray;
int* _iarray;
Vertex* batchArray;
bool* _updated;
psc _pscpos, _pscvel;
std::vector<std::pair<int, double>> _intervals;
double _increment;
// etc...
int _index[2];
int _prev[2];
int _delta;
double _time = 0;
double _previousTime = 0;
};
}
#endif

View File

@@ -25,6 +25,7 @@
#define __SPICEWRAPPER_H__
#include "SpiceUsr.h"
#include <openspace\util\powerscaledcoordinate.h>
#include <string>
#include <ghoul/glm.h>
@@ -161,6 +162,14 @@ public:
const std::string& observer,
glm::dvec3& targetPosition,
double& lightTime) const;
bool getTargetPscPosition(const std::string& target,
double ephemerisTime,
const std::string& referenceFrame,
const std::string& aberrationCorrection,
const std::string& observer,
PowerScaledCoordinate& targetPosition,
double& lightTime) const;
/**
* Return the state (position and velocity) of a target body
* relative to an observing body, optionally corrected for light
@@ -186,6 +195,15 @@ public:
glm::dvec3& targetVelocity,
double& lightTime) const;
bool getTargetPscState(const std::string& target,
double ephemerisTime,
const std::string& referenceFrame,
const std::string& aberrationCorrection,
const std::string& observer,
PowerScaledCoordinate& targetPosition,
PowerScaledCoordinate& targetVelocity,
double& lightTime) const;
// Computing Transformations Between Frames (FK) -------------------------------------- //
/**
@@ -365,6 +383,9 @@ private:
unsigned int _kernelCount = 0;
};
#define SM (openspace::SpiceManager::ref())
/**
* SpiceManager helper class, a storage container used to
* transform state vectors from one reference frame to another.

View File

@@ -32,6 +32,7 @@ namespace openspace {
struct UpdateData {
double time;
double delta;
};
struct RenderData {

View File

@@ -1,5 +1,5 @@
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
openspace.time.setTime("2007-11-01T00:00:00")
openspace.time.setDeltaTime(100000.0)
openspace.time.setTime("2005-11-01T00:00:00")
openspace.time.setDeltaTime(86400.0)
print(openspace.time.currentTimeUTC())

101
shaders/ephemeris_fs.glsl Normal file
View File

@@ -0,0 +1,101 @@
/**
Copyright (C) 2012-2014 Jonas Strandstedt
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 400 core
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 campos;
uniform vec4 objpos;
//uniform vec4 etColor;
in vec4 vs_point_position;
in vec4 vs_point_velocity;
out vec4 diffuse;
const float k = 10.0;
vec4 psc_normlization(vec4 invec) {
float xymax = max(invec.x,invec.y);
if(invec.z > 0.0f || invec.z < 0.0f) {
return invec / abs(invec.z);
} else if (xymax != 0.0f) {
return invec / xymax;
} else {
return invec / -.0;
}
}
void main()
{
// Observable universe is 10^27m, setting the far value to extremely high, aka 30!! ERMAHGERD!
float s_far = 40.0; //= gl_DepthRange.far; // 40
float s_farcutoff = 12.0;
float s_nearcutoff = 7.0;
float s_near = 0.0f;// gl_DepthRange.near; // 0.1
float depth;
// the value can be normalized to 1
vec4 p = vs_point_position;
if(vs_point_position.w <= 0.5) {
//depth = abs(vs_point_position.z * pow(10, vs_point_position.w)) / pow(k,s_far);
depth = (vs_point_position.w+log(abs(vs_point_position.z)))/pow(k, vs_point_position.w);
} else if(vs_point_position.w < 3.0) {
depth = vs_point_position.w+log(abs(vs_point_position.z))/pow(k, vs_point_position.w);
} else {
depth = vs_point_position.w+log(abs(vs_point_position.z));
}
// DEBUG
float depth_orig = depth;
float x = 0.0f;
float cutoffs = 0.0;
float orig_z = vs_point_position.z;
// calculate a normalized depth [0.0 1.0]
if((depth > s_near && depth <= s_nearcutoff) || (depth > s_farcutoff && depth < s_far)) {
// completely linear interpolation [s_near .. depth .. s_far]
depth = (depth - s_near) / (s_far - s_near);
} else if(depth > s_nearcutoff && depth < s_farcutoff) {
// DEBUG
cutoffs = 1.0;
// interpolate [10^s_nearcutoff .. 10^depth .. 10^s_farcutoff]
// calculate between 0..1 where the depth is
x = (pow(10,depth) - pow(10, s_nearcutoff)) / (pow(10,s_farcutoff) - pow(10, s_nearcutoff));
// remap the depth to the 0..1 depth buffer
depth = s_nearcutoff + x * (s_farcutoff - s_nearcutoff);
depth = (depth - s_near) / (s_far - s_near);
} else {
// where am I?
// do I need to be discarded?
// discard;
}
// set the depth
gl_FragDepth = depth;
//float l = length(vs_point_velocity);
diffuse = vs_point_velocity;
}

112
shaders/ephemeris_vs.glsl Normal file
View File

@@ -0,0 +1,112 @@
/**
Copyright (C) 2012-2014 Jonas Strandstedt
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 400 core
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
//uniform vec4 etColor;
uniform vec4 objectVelocity;
layout(location = 0) in vec4 in_point_position;
layout(location = 1) in vec4 in_point_velocity;
layout(location = 2) in vec2 in_point_timeindex;
out vec4 vs_point_position;
out vec4 vs_point_velocity;
const float k = 10.0;
const float dgr_to_rad = 0.0174532925;
vec4 psc_addition(vec4 v1, vec4 v2) {
float ds = v2.w - v1.w;
if(ds >= 0) {
float p = pow(k,-ds);
return vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w);
} else {
float p = pow(k,ds);
return vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w);
}
}
vec4 psc_to_meter(vec4 v1, vec2 v2) {
float factor = v2.x * pow(k,v2.y + v1.w);
return vec4(v1.xyz * factor, 1.0);
}
vec4 psc_scaling(vec4 v1, vec2 v2) {
float ds = v2.y - v1.w;
if(ds >= 0) {
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
} else {
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
}
}
void main()
{
//vs_stp = in_point_position.xyz;
//vs_normal = normalize(ModelTransform*vec4(1)); // <-- not really using right now. change later.
// add life back to the thing.
/*
vec3 vel_1 = psc_to_meter(in_point_velocity, vec2(3)).xyz;
vec3 vel_2 = psc_to_meter(objectVelocity, vec2(3)).xyz;
float a = 0;
vec3 dist = (objpos-in_point_position).xyz;
if( dot(dist, vel_2) > 0.f){
a = 2.f*dot(vel_1,vel_2)/(length(vel_1)*length(vel_2));
}*/
vs_point_velocity = in_point_velocity;
//vs_point_position = objpos;
// rotate and scale vertex with model transform and add the translation
vec3 local_vertex_pos = mat3(ModelTransform) * in_point_position.xyz;
//vec4 lvp = ModelTransform * in_point_position;
// PSC addition; local vertex position and the object power scaled world position
vs_point_position = psc_addition(vec4(local_vertex_pos,in_point_position.w),objpos);
//vs_point_position = psc_addition(lvp,objpos);
// PSC addition; rotated and viewscaled vertex and the cmaeras negative position
vs_point_position = psc_addition(vs_point_position,vec4(-campos.xyz,campos.w));
// rotate the camera
local_vertex_pos = mat3(camrot) * vs_point_position.xyz;
vs_point_position = vec4(local_vertex_pos, vs_point_position.w);
//vs_point_position = camrot* vs_point_position;
// project using the rescaled coordinates,
//vec4 vs_point_position_rescaled = psc_scaling(vs_point_position, scaling);
vec4 vs_point_position_rescaled = psc_to_meter(vs_point_position, scaling);
//vs_point_position = vs_point_position_rescaled;
// project the position to view space
gl_Position = ViewProjection * vs_point_position_rescaled;
}

View File

@@ -10,6 +10,8 @@
#include <openspace/util/powerscaledcoordinate.h>
#include <glm/gtx/vector_angle.hpp>
#include <openspace/util/time.h>
// std includes
#include <cassert>
@@ -326,6 +328,9 @@ void InteractionHandler::keyboardCallback(int key, int action) {
glm::quat rot = glm::quat(euler);
orbit(rot);
}
if (key == SGCT_KEY_Q) {
Time::ref().advanceTime(dt);
}
if (key == 262) {
glm::vec3 euler(0.0, speed * dt, 0.0);
glm::quat rot = glm::quat(euler);

View File

@@ -0,0 +1,301 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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/renderableephemeris.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/constants.h>
#include <ghoul/opengl/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/util/spicemanager.h>
#include <iomanip>
namespace {
const std::string _loggerCat = "RenderableEphemeris";
}
namespace openspace{
RenderableEphemeris::RenderableEphemeris(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _programObject(nullptr)
, _texture(nullptr)
, _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_LINES){
double lightTime = 0.0;
double planetYear = 31536000;
_time = SM.convertStringToTdbSeconds("2005 nov 01 00:00:00");
// -------------------------------------- ^ this has to be simulation start-time, not passed in here though --
double et = _time - planetYear;
int segments = 365; // note to self: code not look nice. cleanup for clarity later.
int indx = 0;
psc pscpos, pscvel;
_isize = (segments)*2;
_vsize = (segments)*2;
_varray = new Vertex[_vsize];
_iarray = new int[_isize];
_updated = new bool[_vsize];
std::fill(_updated, _updated + _vsize, false);
static_assert(sizeof(Vertex) == 64, "The size of the Vertex needs to be 64 for performance");
// get first position, ephemeris start-point
SM.getTargetPscState("EARTH", et, "GALACTIC", "LT+S", "SUN", pscpos, pscvel, lightTime);
memcpy(_varray[indx].location, glm::value_ptr(pscpos.vec4()), 4 * sizeof(double));
memcpy(_varray[indx].velocity, glm::value_ptr(glm::vec4(1, 0, 1, 1)), 4 * sizeof(double));
_intervals.push_back(std::pair<int, double>(indx, et));
_iarray[indx] = indx;
indx++;
_increment = planetYear / segments;
for (int i = 0; i < segments; i++){
et += _increment;
SM.getTargetPscState("EARTH", et, "GALACTIC", "LT+S", "SUN", pscpos, pscvel, lightTime);
for (int k = 0; k < 2; k++){
if (i == segments - 1 && k == 1) { // do copy first to last
break;
}
memcpy(_varray[indx].location, glm::value_ptr(pscpos.vec4()), 4 * sizeof(double));
memcpy(_varray[indx].velocity, glm::value_ptr(glm::vec4(0, 0, 0, 1)), 4 * sizeof(double));
_intervals.push_back(std::pair<int, double>(indx, et));
_iarray[indx] = indx;
_index[k] = indx;
indx++;
}
}
_delta = _vsize;
}
RenderableEphemeris::~RenderableEphemeris(){
deinitialize();
}
bool RenderableEphemeris::initialize(){
bool completeSuccess = true;
if (_programObject == nullptr)
completeSuccess
&= OsEng.ref().configurationManager().getValue("EphemerisProgram", _programObject);
loadTexture();
completeSuccess &= (_texture != nullptr);
// Initialize and upload to graphics card
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
glGenBuffers(1, &_iBufferID);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferData(GL_ARRAY_BUFFER, _vsize * sizeof(Vertex), NULL, GL_STREAM_DRAW); // orphaning the buffer, sending NULL data.
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(Vertex), _varray);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const GLvoid*>(offsetof(Vertex, location)));
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const GLvoid*>(offsetof(Vertex, velocity)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW);
glBindVertexArray(0);
return completeSuccess;
}
bool RenderableEphemeris::deinitialize(){
delete _texture;
_texture = nullptr;
return true;
}
void RenderableEphemeris::nextIndex(){
if (_previousTime != _time){
int skip = _index[1] - _prev[1];
_prev[0] = _index[0];
_prev[1] = _index[1];
double t = _time - 31536000;
// Better optimization:
int x = (_index[0] > _index[1]) ? _index[0] : _index[1];
if (x >= _vsize - 1 || skip + x > _vsize ) x = 1;
for (x; x < _vsize; x++){
double t1 = _intervals[x - 1].second;
double t2 = _intervals[x].second;
if (t1 != t2 && t >= t1 && t <= t2){
_index[0] = (x - 2 < 0) ? _vsize - 1 : x - 2;
_index[1] = x - 1;
break;
}
}
}
_previousTime = _time;
}
void RenderableEphemeris::render(const RenderData& data){
assert(_programObject);
_programObject->activate();
// fetch data
psc currentPosition = data.position;
psc campos = data.camera.position();
glm::mat4 camrot = data.camera.viewRotationMatrix();
// PowerScaledScalar scaling = camera->scaling();
PowerScaledScalar scaling = glm::vec2(1, -6);
glm::mat4 transform = glm::mat4(1);
// setup the data to the shader
//_programObject->setUniform("objectVelocity", pscvel.vec4());
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
_programObject->setUniform("campos", campos.vec4());
_programObject->setUniform("objpos", currentPosition.vec4());
_programObject->setUniform("camrot", camrot);
_programObject->setUniform("scaling", scaling.vec2());
nextIndex();
for (int i = 0; i < _vsize; i++){
_varray[i].velocity[0] -= 0.00008;
_varray[i].velocity[1] -= 0.00006;
_varray[i].velocity[2] -= 0.00004;
}
/*
if (_delta > 0){
int i = _index[0];
int j = _index[1];
while (i != _prev[0]){
if (_updated[i] == false && _updated[j] == false){
_updated[i] = true;
_updated[j] = true;
_intervals[i].second += 31536000; // not the cleanest solution but works. need dt
_intervals[j].second += 31536000;
// DEBUGGING COLOR CODING
memcpy(_varray[i].velocity, glm::value_ptr(glm::vec4(0, 0, 1, 1)), 4 * sizeof(double)); // blue if updated
memcpy(_varray[j].velocity, glm::value_ptr(glm::vec4(0, 0, 1, 1)), 4 * sizeof(double));
}
i = (i - 2 < 0) ? _vsize - 1 : i - 2;
j = (j - 1 < 0) ? _vsize - 1 : j - 2;
}
}
*/
if (_updated[_index[1]] == false && _updated[_index[0]] == false){
_updated[_index[0]] = true;
_updated[_index[1]] = true;
_intervals[_index[0]].second = _time;
_intervals[_index[1]].second = _time;
memcpy(_varray[_index[0]].location, glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
memcpy(_varray[_index[1]].location, glm::value_ptr(_pscpos.vec4()), 4 * sizeof(double));
memcpy(_varray[_index[0]].velocity, glm::value_ptr(glm::vec4(1, 1, 1, 1)), 4 * sizeof(double));
memcpy(_varray[_index[1]].velocity, glm::value_ptr(glm::vec4(1, 1, 1, 1)), 4 * sizeof(double));
// DEBUGGING COLOR CODING
/*
memcpy(_varray[_index[0]].velocity, glm::value_ptr(glm::vec4(0, 0, 1, 1)), 4 * sizeof(double)); // blue if updated
memcpy(_varray[_index[1]].velocity, glm::value_ptr(glm::vec4(0, 0, 1, 1)), 4 * sizeof(double));
memcpy(_varray[_index[2]].velocity, glm::value_ptr(glm::vec4(1, 0, 0, 1)), 4 * sizeof(double)); // red
memcpy(_varray[_index[3]].velocity, glm::value_ptr(glm::vec4(1, 0, 0, 1)), 4 * sizeof(double));
*/
_updated[_index[2]] = false;
_updated[_index[3]] = false;
}
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vsize * sizeof(Vertex), _varray);
//psc pointPos(_varray[_index].location[0], _varray[_index].location[1], _varray[_index].location[2], _varray[_index].location[3]);
//std::cout << "dist, indx : " << distance(_pscpos, pointPos) << ", " << _index << std::endl;
glBindVertexArray(_vaoID);
glDrawArrays(_mode, 0, GL_UNSIGNED_INT);
glBindVertexArray(0);
glPointSize(2.f);
glBindVertexArray(_vaoID);
glDrawArrays(GL_POINTS, 0, GL_UNSIGNED_INT);
glBindVertexArray(0);
_programObject->deactivate();
}
void RenderableEphemeris::update(const UpdateData& data){
double lightTime;
_time = data.time;
SM.getTargetPscState("EARTH", data.time, "GALACTIC", "LT+S", "SUN", _pscpos, _pscvel, lightTime);
}
void RenderableEphemeris::loadTexture()
{
delete _texture;
_texture = nullptr;
if (_colorTexturePath.value() != "") {
_texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath));
if (_texture) {
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
_texture->uploadTexture();
}
}
}
}

View File

@@ -163,9 +163,11 @@ void RenderEngine::postSynchronizationPreDraw()
{
// converts the quaternion used to rotation matrices
_mainCamera->compileViewRotationMatrix();
UpdateData a = { Time::ref().currentTime(), Time::ref().deltaTime() };
//std::cout << a.delta << std::endl;
// update and evaluate the scene starting from the root node
_sceneGraph->update({Time::ref().currentTime()});
_sceneGraph->update(a);
_mainCamera->setCameraDirection(glm::vec3(0, 0, -1));
_sceneGraph->evaluate(_mainCamera);
}

View File

@@ -277,6 +277,12 @@ bool SceneGraph::initialize()
if (!tmpProgram) return false;
OsEng.ref().configurationManager().setValue("GridProgram", tmpProgram);
tmpProgram = sc.buildShader("Ephemeris",
"${SHADERS}/ephemeris_vs.glsl",
"${SHADERS}/ephemeris_fs.glsl");
if (!tmpProgram) return false;
OsEng.ref().configurationManager().setValue("EphemerisProgram", tmpProgram);
double elapsed = std::chrono::duration_cast<second_>(clock_::now()-beginning).count();
LINFO("Time to load shaders: " << elapsed);
@@ -298,7 +304,6 @@ void SceneGraph::update(const UpdateData& data)
if (!success)
return;
}
for (auto node : _nodes)
node->update(data);
}

View File

@@ -28,6 +28,7 @@
// renderables
#include <openspace/rendering/stars/renderablestars.h>
#include <openspace/rendering/renderableephemeris.h>
#include <openspace/rendering/renderablesphericalgrid.h>
#include <openspace/rendering/renderablefieldlines.h>
#include <openspace/rendering/planets/renderableplanet.h>
@@ -60,6 +61,8 @@ void FactoryManager::initialize()
"RenderablePlanet");
_manager->factory<Renderable>()->registerClass<RenderableStars>(
"RenderableStars");
_manager->factory<Renderable>()->registerClass<RenderableEphemeris>(
"RenderableEphemeris");
_manager->factory<Renderable>()->registerClass<RenderableSphericalGrid>(
"RenderableSphericalGrid");
//_manager->factory<Renderable>()->registerClass<RenderableVolumeCL>(

View File

@@ -268,6 +268,27 @@ bool SpiceManager::getTargetPosition(const std::string& target,
return true;
}
bool SpiceManager::getTargetPscPosition(const std::string& target,
double ephemerisTime,
const std::string& referenceFrame,
const std::string& aberrationCorrection,
const std::string& observer,
PowerScaledCoordinate& targetPosition,
double& lightTime) const{
double pos[3] = { NULL, NULL, NULL };
spkpos_c(target.c_str(), ephemerisTime, referenceFrame.c_str(),
aberrationCorrection.c_str(), observer.c_str(), pos, &lightTime);
if (pos[0] == NULL || pos[1] == NULL || pos[2] == NULL)
return false;
targetPosition = PowerScaledCoordinate::CreatePowerScaledCoordinate(pos[0], pos[1], pos[2]);
return true;
}
bool SpiceManager::getTargetState(const std::string& target,
double ephemerisTime,
const std::string& referenceFrame,
@@ -299,6 +320,26 @@ bool SpiceManager::getTargetState(const std::string& target,
return true;
}
bool SpiceManager::getTargetPscState(const std::string& target,
double ephemerisTime,
const std::string& referenceFrame,
const std::string& aberrationCorrection,
const std::string& observer,
PowerScaledCoordinate& targetPosition,
PowerScaledCoordinate& targetVelocity,
double& lightTime) const{
double state[6];
std::fill_n(state, 6, NULL);
spkezr_c(target.c_str(), ephemerisTime, referenceFrame.c_str(),
aberrationCorrection.c_str(), observer.c_str(), state, &lightTime);
targetPosition = PowerScaledCoordinate::CreatePowerScaledCoordinate(state[0], state[1], state[2]);
targetVelocity = PowerScaledCoordinate::CreatePowerScaledCoordinate(state[3], state[4], state[5]);
return true;
}
bool SpiceManager::getStateTransformMatrix(const std::string& fromFrame,
const std::string& toFrame,
double ephemerisTime,