SPICE-time dependency, retrieval of spice ephemerides and rotational matrix + coordinate references.

Added functionality:
- New class renderablesphericalgrid is repurposed code from powerscaledsphere class.
  Due to z-buffer issues used as reference grid to confirm planetary orbits are correct.
  This has been a major problem as prior we had no visual reference.
  Now we have a Galactic-, Celestial- and Ecliptic-coordinate grid.
  To this also added separate shader: grid_vs.glsl / grid_fs.glsl
  These grids have a static-rotational matrix derived from partiview (thanks to Brian)
  since spice req. to-from frame to compute rotational matrix.

Time dependency:
- Added struct RuntimeData - which for now only contains openspace time and is passed to all renderables
- All renderables accept runtimeData, keep private reference and use for computation of rotational matrix
- This obviously carries corresponding changes to Scenegraph and ScenegraphNode.

Spicemanager:
- Added function that more easily provides access to rotational matrix used in spice
 (used in renderableplanet for computing planetary objects spin around axis)

Ephemeris-classes:
- Now compute ephemeris from spice based on timeepoch in runtimedata
  TODO: once z-buffer fixed - set ephemeris correctly as meters (not kilometers)

Renderengine:
- Advances time with the advanceTime method in RuntimeData struct

ISSUES:
- Our Y axis NOT same as SPICE or star-catalogue, all renderables rotated now 90deg, needs redefinition,
  lots of debugging and major headaches before this conclusion.
- Depth buffer needs to be fixed in order to properly place planets.
- Spice kernels have finite time-range, when time stops - simulation ends - ugly fix: reset time to zero.
  Possible fix: kernels de431 (part 1-2) cover huge timespan and most likely have functions to extrapolate time,
  drawback is that they are 1,7 gb each.

TODO:
- Compute and draw dynamic ephemeries for each renderable. Either do full year sweep then update for each point or
  create a tail of linesegments for each planet. Dont know yet how to do this, would like spicephemeris to be
  sub-class of Renderable (have own render() method) - good/bad?
This commit is contained in:
michal
2014-09-19 20:32:33 -04:00
parent c1c637efa7
commit 700f590a2a
40 changed files with 846 additions and 137 deletions
+28 -2
View File
@@ -33,8 +33,10 @@
#include <openspace/rendering/renderengine.h>
#include <openspace/util/time.h>
#include <openspace/util/spice.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/constants.h>
#include <openspace/util/runtimedata.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
@@ -248,8 +250,29 @@ bool OpenSpaceEngine::initialize()
// initialize OpenSpace helpers
Time::init();
//Time::ref().setTime("2007 feb 26 17:41:00");
Time::ref().setTime("2010 jun 13 13:50:00");
RuntimeData* initialData = new RuntimeData;
initialData->setTime(Time::ref().getTime());
std::cout <<"Initial time : " << initialData->getTime() << std::endl;
Spice::init();
Spice::ref().loadDefaultKernels();
Spice::ref().loadDefaultKernels(); // changeto: instantiate spicemanager, load kernels.
SpiceManager::initialize();
//SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/de431_part-1.bsp"), "SPK_LARGE1");
//SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/de431_part-2.bsp"), "SPK_LARGE2");
//SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/981005_PLTEPH-DE405S.bsp"), "JUPITER");
SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/de430_1850-2150.bsp"), "SPK_EARTH");
SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/MAR063.bsp") , "SPK_MARS");
SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/pck00010.tpc") , "PCK");
SpiceManager::ref().loadKernel(absPath("${OPENSPACE_DATA}/spice/naif0010.tls") , "LSK");
FactoryManager::initialize();
// Load scenegraph
@@ -277,10 +300,13 @@ bool OpenSpaceEngine::initialize()
return false;
}
// initialize the RenderEngine, needs ${SCENEPATH} to be set
_renderEngine->initialize();
_renderEngine->setRuntimeData(initialData);
sceneGraph->setRuntimeData(initialData);
sceneGraph->loadScene(sceneDescriptionPath, scenePath);
sceneGraph->initialize();
sceneGraph->initialize();
_renderEngine->setSceneGraph(sceneGraph);
#ifdef FLARE_ONLY
+1 -1
View File
@@ -59,7 +59,7 @@ bool Flare::deinitialize() {
return true;
}
void Flare::render(const Camera *camera, const psc& thisPosition) {
void Flare::render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData) {
render();
}
void Flare::update() {
+2 -2
View File
@@ -352,11 +352,11 @@ void InteractionHandler::keyboardCallback(int key, int action) {
distance(dist);
}
if (key == 'T') {
PowerScaledScalar dist(-speed * pow(10,8) * dt, 0.0);
PowerScaledScalar dist(-speed * pow(10,18) * dt, 0.0);
distance(dist);
}
if (key == 'G') {
PowerScaledScalar dist(speed * pow(10, 8) * dt, 0.0);
PowerScaledScalar dist(speed * pow(10, 18) * dt, 0.0);
distance(dist);
}
/*
+29 -13
View File
@@ -31,6 +31,9 @@
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
@@ -56,10 +59,11 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
geometryDictionary.setValue(constants::scenegraph::keyPathModule, path);
geometryDictionary.setValue(constants::scenegraphnode::keyName, name());
_geometry
= planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
}
dictionary.getValue("Frame", _target);
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
std::string texturePath = "";
@@ -105,7 +109,7 @@ bool RenderablePlanet::deinitialize()
return true;
}
void RenderablePlanet::render(const Camera* camera, const psc& thisPosition)
void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData)
{
// TODO replace with more robust assert
// check so that the shader is set
@@ -117,19 +121,30 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition)
// fetch data
psc currentPosition = thisPosition;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
//PowerScaledScalar scaling = camera->scaling();
//std::cout << scaling << std::endl;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
// PowerScaledScalar scaling = camera->scaling();
PowerScaledScalar scaling = glm::vec2(1, -6);
PowerScaledScalar scaling = glm::vec2(1, -6);
// scale the planet to appropriate size since the planet is a unit sphere
glm::mat4 transform = glm::mat4(1);
transform = glm::rotate(
transform, 4.1f * static_cast<float>(sgct::Engine::instance()->getTime()),
glm::vec3(0.0f, 1.0f, 0.0f));
// set spice-orientation in accordance to timestamp
glm::dmat3 stateMatrix;
openspace::SpiceManager::ref().getPositionTransformMatrixGLM("GALACTIC", "IAU_EARTH", runtimeData->getTime(), stateMatrix);
//earth needs to be rotated for that to work.
glm::mat4 rot = glm::rotate(transform, 90.f, glm::vec3(1, 0, 0));
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
transform[i][j] = stateMatrix[i][j];
}
}
transform = transform* rot;
// setup the data to the shader
_programObject->setUniform("ViewProjection", camera->viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
@@ -137,7 +152,7 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition)
_programObject->setUniform("objpos", currentPosition.vec4());
_programObject->setUniform("camrot", camrot);
_programObject->setUniform("scaling", scaling.vec2());
// Bind texture
ghoul::opengl::TextureUnit unit;
unit.activate();
@@ -149,6 +164,7 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition)
// disable shader
_programObject->deactivate();
}
void RenderablePlanet::update()
+222
View File
@@ -0,0 +1,222 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
//standard includes.
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderablesphericalgrid.h>
#include <openspace/util/constants.h>
#include <openspace/util/spicemanager.h>
namespace {
const std::string _loggerCat = "RenderableSphericalGrid";
}
namespace openspace {
// needs to be set from dictionary - REMEMBER
const PowerScaledScalar radius = PowerScaledScalar(1000.f, 6.f);
RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _gridProgram(nullptr)
, _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_LINES)
{
_gridMatrix = glm::mat4(1);
glm::vec2 s;
dictionary.getValue(constants::renderablesphericalgrid::gridType , _gridType);
dictionary.getValue(constants::renderablesphericalgrid::gridColor , _gridColor);
dictionary.getValue(constants::renderablesphericalgrid::gridMatrix , _gridMatrix);
dictionary.getValue(constants::renderablesphericalgrid::gridSegments, s);
_segments = s[0];
_isize = int(6 * _segments * _segments);
_vsize = int((_segments + 1) * (_segments + 1));
_varray = new Vertex[_vsize];
_iarray = new int[_isize];
static_assert(sizeof(Vertex) == 64, "The size of the Vertex needs to be 64 for performance");
int nr = 0;
const float fsegments = static_cast<float>(_segments);
const float r = static_cast<float>(radius[0]);
int nr2 = 0;
for (int i = 0; i <= _segments; i++) {
// define an extra vertex around the y-axis due to texture mapping
for (int j = 0; j <= _segments; j++) {
const float fi = static_cast<float>(i);
const float fj = static_cast<float>(j);
// inclination angle (north to south)
const float theta = fi * float(M_PI) / fsegments*2.f; // 0 -> PI
// azimuth angle (east to west)
const float phi = fj * float(M_PI) * 2.0f / fsegments; // 0 -> 2*PI
const float x = r * sin(phi) * sin(theta); //
const float y = r * cos(theta); // up
const float z = r * cos(phi) * sin(theta); //
glm::vec3 normal = glm::vec3(x, y, z);
if (!(x == 0.f && y == 0.f && z == 0.f))
normal = glm::normalize(normal);
const float t1 = fj / fsegments;
const float t2 = fi / fsegments;
// tex coord. not used, use to manip color
if (round(y) == 0.0f) _varray[nr].tex[0] = -2;
_varray[nr].tex[1] = t2;
/* // we wont do this anymore, old code, now static grids. ignore or remove.
glm::mat4 rot = glm::rotate(glm::mat4(1), 90.f, glm::vec3(1, 0, 0));
glm::mat4 transform(1);
glm::dmat3 stateMatrix;
double initTime = 0;
openspace::SpiceManager::ref().getPositionTransformMatrixGLM("IAU_EARTH", "GALACTIC", 0, stateMatrix);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
transform[i][j] = stateMatrix[i][j];
}
}
*/
glm::vec4 tmp(x, y, z, 1);
glm::mat4 rot = glm::rotate(glm::mat4(1), 90.f, glm::vec3(1, 0, 0));
tmp = _gridMatrix*rot*tmp;
for (int i = 0; i < 3; i++){
_varray[nr].location[i] = tmp[i];
_varray[nr].normal[i] = normal[i];
}
_varray[nr].location[3] = static_cast<GLfloat>(radius[1]);
++nr;
}
}
nr = 0;
// define indices for all triangles
for (int i = 1; i <= _segments; ++i) {
for (int j = 0; j < _segments; ++j) {
const int t = _segments + 1;
_iarray[nr] = t * (i - 1) + j + 0; ++nr;
_iarray[nr] = t * (i + 0) + j + 0; ++nr;
_iarray[nr] = t * (i + 0) + j + 1; ++nr;
_iarray[nr] = t * (i - 1) + j + 1; ++nr;
_iarray[nr] = t * (i - 1) + j + 0; ++nr;
}
}
}
RenderableSphericalGrid::~RenderableSphericalGrid(){
deinitialize();
}
bool RenderableSphericalGrid::deinitialize(){
return true;
}
bool RenderableSphericalGrid::initialize(){
bool completeSuccess = true;
if (_gridProgram == nullptr)
completeSuccess &= OsEng.ref().configurationManager().getValue("GridProgram", _gridProgram);
// Initialize and upload to graphics card
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
glGenBuffers(1, &_iBufferID);
// First VAO setup
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferData(GL_ARRAY_BUFFER, _vsize * sizeof(Vertex), _varray, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, location)));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, tex)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
reinterpret_cast<const GLvoid*>(offsetof(Vertex, normal)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _isize * sizeof(int), _iarray, GL_STATIC_DRAW);
glBindVertexArray(0);
return completeSuccess;
}
void RenderableSphericalGrid::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){
assert(_gridProgram);
_gridProgram->activate();
// fetch data
psc currentPosition = thisPosition;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
// PowerScaledScalar scaling = camera->scaling();
PowerScaledScalar scaling = glm::vec2(1, -6);
glm::mat4 transform = glm::mat4(1);
// setup the data to the shader
_gridProgram->setUniform("ViewProjection", camera->viewProjectionMatrix());
_gridProgram->setUniform("ModelTransform", transform);
_gridProgram->setUniform("campos", campos.vec4());
_gridProgram->setUniform("objpos", currentPosition.vec4());
_gridProgram->setUniform("camrot", camrot);
_gridProgram->setUniform("scaling", scaling.vec2());
_gridProgram->setUniform("gridColor", _gridColor);
glLineWidth(1.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glBindVertexArray(_vaoID); // select first VAO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glDrawElements(_mode, _isize, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
_gridProgram->deactivate();
}
void RenderableSphericalGrid::update(){
}
}
+1 -1
View File
@@ -245,7 +245,7 @@ bool RenderableVolumeCL::deinitialize() {
return true;
}
void RenderableVolumeCL::render(const Camera *camera, const psc &thisPosition) {
void RenderableVolumeCL::render(const Camera *camera, const psc &thisPosition, RuntimeData* runtimeData) {
if( ! _kernel.isValidKernel())
return;
+1 -1
View File
@@ -337,7 +337,7 @@ bool RenderableVolumeExpert::deinitialize() {
return true;
}
void RenderableVolumeExpert::render(const Camera *camera, const psc &thisPosition) {
void RenderableVolumeExpert::render(const Camera *camera, const psc &thisPosition, RuntimeData* runtimeData) {
if( ! _kernel.isValidKernel())
return;
+1 -1
View File
@@ -195,7 +195,7 @@ bool RenderableVolumeGL::deinitialize() {
return true;
}
void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition) {
void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, RuntimeData* runtimeData) {
float speed = 50.0f;
float time = sgct::Engine::getTime();
+27 -4
View File
@@ -28,6 +28,9 @@
#include <openspace/scenegraph/scenegraph.h>
#include <openspace/util/camera.h>
// We need to decide where this is set
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include "sgct.h"
#include <ghoul/filesystem/filesystem.h>
@@ -39,9 +42,11 @@ const std::string _loggerCat = "RenderEngine";
}
namespace openspace {
RenderEngine::RenderEngine()
: _mainCamera(nullptr)
, _sceneGraph(nullptr)
, _runtimeData(nullptr)
{
}
@@ -60,10 +65,13 @@ bool RenderEngine::initialize()
// if master, setup interaction
//if (sgct::Engine::instance()->isMaster())
OsEng.interactionHandler().setCamera(_mainCamera);
return true;
}
void RenderEngine::setRuntimeData(RuntimeData* runtimeData){
_runtimeData = runtimeData;
}
bool RenderEngine::initializeGL()
{
sgct::SGCTWindow* wPtr = sgct::Engine::instance()->getActiveWindowPtr();
@@ -75,7 +83,7 @@ bool RenderEngine::initializeGL()
// set the close clip plane and the far clip plane to extreme values while in
// development
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f,100.0f);
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.00001f, 100.0f);
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 1000.00f);
// calculating the maximum field of view for the camera, used to
// determine visibility of objects in the scene graph
@@ -139,12 +147,18 @@ bool RenderEngine::initializeGL()
void RenderEngine::postSynchronizationPreDraw()
{
// Move time forward.
//_runtimeData->advanceTimeBy(1, DAY);
_runtimeData->advanceTimeBy(1, HOUR);
//_runtimeData->advanceTimeBy(30, MINUTE);
//_runtimeData->advanceTimeBy(1, MILLISECOND);
// converts the quaternion used to rotation matrices
_mainCamera->compileViewRotationMatrix();
// update and evaluate the scene starting from the root node
_sceneGraph->update(); // old time + time
// in time setTime using double!
_sceneGraph->update();
_mainCamera->setCameraDirection(glm::vec3(0, 0, -1));
_sceneGraph->evaluate(_mainCamera);
}
@@ -186,12 +200,21 @@ void RenderEngine::render()
#define FONT_SIZE 10
#endif
std::string timeGUI = SpiceManager::ref().ephemerisTimeToString(_runtimeData->getTime());
if (timeGUI == "") _runtimeData->setTime(0); // if time ends -> reset time to julian date 0.
const glm::vec2 scaling = _mainCamera->scaling();
const glm::vec3 viewdirection = _mainCamera->viewDirection();
const psc position = _mainCamera->position();
const psc origin = OsEng.interactionHandler().getOrigin();
const PowerScaledScalar pssl = (position - origin).length();
/* GUI PRINT */
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 12, "OpenSpace Time: (%s)", timeGUI.c_str());
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 10, "Origin: (%.5f, %.5f, %.5f, %.5f)", origin[0],
+27 -59
View File
@@ -27,17 +27,19 @@
#include <fstream>
#include <limits>
#include <vector>
#include <iomanip> // std::setw
#include <iomanip>
// open space includes
// openspace includes
#include <openspace/rendering/stars/renderablestars.h>
#include <openspace/util/constants.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/opengl/texturereader.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/engine/openspaceengine.h>
#include <sgct.h>
#define _USE_MATH_DEFINES
#include <math.h>
@@ -48,8 +50,7 @@ int printOglError(char *file, int line){
int retCode = 0;
glErr = glGetError();
if (glErr != GL_NO_ERROR){
printf("glError in file %s @ line %d: %s\n",
file, line, gluErrorString(glErr));
printf("glError %s\n", gluErrorString(glErr));
retCode = 1;
}
return retCode;
@@ -71,7 +72,6 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
, _pointProgram(nullptr)
, _texture(nullptr)
{
//setBoundingSphere(PowerScaledScalar::CreatePSS(100)); // <---- do we need this?
std::string path;
dictionary.getValue(constants::renderablestars::keyPathModule, path);
@@ -89,6 +89,8 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
}
RenderableStars::~RenderableStars(){
glDeleteBuffers(1, &_vboID);
glDeleteVertexArrays(1, &_vaoID);
deinitialize();
}
@@ -115,6 +117,7 @@ psc psc_addition(psc v1, psc v2) {
}
}
//#define ROTATESTARS
bool RenderableStars::readSpeckFile(const std::string& path){
@@ -127,7 +130,6 @@ bool RenderableStars::readSpeckFile(const std::string& path){
std::vector<float> floatingPointData;
int count = 0;
std::cout << path << std::endl;
const std::string absPath = FileSys.absolutePath(path);
std::string::size_type last
= absPath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator);
@@ -136,22 +138,6 @@ bool RenderableStars::readSpeckFile(const std::string& path){
std::string basePath = absPath.substr(0, last);
cacheName = basePath + "\\" + cacheName + ".bin";
/**
The READ LOGIC:
1. skip metadata
2. read everything in line until # symbol (nongeneric reader)
3. split line on whitespaces
4. convert x,y,z to floats
5. convert m -> pc
6. convert to psc
7. pass to vector
8. pass vectors internal arr for vbo creation
TODO:
Right now we are not reading cache files as luminocity, appmag etc are not cached
in the first place. This is the reason for longer loading times, will get fixed.
*/
//if (!FileSys.fileExists(cacheName)){
if (!readCache){ // dumb boolean for now.
std::ofstream cache;
@@ -201,48 +187,32 @@ bool RenderableStars::readSpeckFile(const std::string& path){
// Could convert floatingPointData instead ??
// (possible as 3.4 × 10^38 is max rep nr of float)
PowerScaledScalar parsecsToMetersFactor = glm::vec2(0.308567758, 17);
//powerscaled *= parsecsToMetersFactor; // <--- buggy dont use.
powerscaled[0] *= parsecsToMetersFactor[0];
powerscaled[1] *= parsecsToMetersFactor[0];
powerscaled[2] *= parsecsToMetersFactor[0];
powerscaled[3] += parsecsToMetersFactor[1];
// TESTING DISTANCE MODULUS FORMULA LOGIC (see: star_ge.glsl) ------------------------------------
//psc campos(3.17657, 0.0, 0.0, 4.0); // same input as in shader.
psc campos(0.8, 0.0, 0.0, 4.0);
psc psc_position = powerscaled;
float k = 10.f;
#ifdef ROTATESTARS
glm::mat4 transform = glm::mat4(1);
psc cam_negative = psc(-campos[0], -campos[1], -campos[2], campos[3]);
psc result = psc_addition(psc_position, cam_negative);
// checked with wolfram, correct.
//std::cout << result << std::endl;
float x, y, z, w;
x = result[0];
y = result[1];
z = result[2];
w = result[3];
glm::vec2 dpc_psc( sqrt(x*x + y*y + z*z), w );
// checked with wolfram, correct.
glm::dmat3 stateMatrix;
double initTime = 0;
openspace::SpiceManager::ref().getPositionTransformMatrixGLM("GALACTIC", "IAU_EARTH", 0, stateMatrix);
dpc_psc[0] *= 0.324077929;
dpc_psc[1] += -18;
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
transform[i][j] = stateMatrix[i][j];
}
}
float parsecDist = dpc_psc[0] * pow(10, dpc_psc[1]);
// checked with wolfram, 100% correct to the 8th decimal.
glm::vec4 tmp(powerscaled[0], powerscaled[1], powerscaled[2], powerscaled[3] );
tmp = transform*tmp;
float M = floatingPointData[3];
float apparent = (M - 5.0f * (1.f - log10(parsecDist)));
// checked with wolfram, 100% correct to the 7th decimal.
// WORKS, REPRODUCE ON SHADER!!!!!!
//std::cout << std::setw(3) << round(apparent) << " ";
//if (count % 15 == 0) std::cout << std::endl;
// --------------------------------------------------------------------------------
powerscaled[0] = tmp[0];
powerscaled[1] = tmp[1];
powerscaled[2] = tmp[2];
powerscaled[3] = tmp[3];
#endif
// We use std::vector to store data
// needs no preallocation and has tightly packed arr.
for (int i = 0; i < 4; i++){
@@ -336,15 +306,12 @@ bool RenderableStars::deinitialize(){
}
//#define TMAT
void RenderableStars::render(const Camera* camera, const psc& thisPosition){
void RenderableStars::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){
assert(_haloProgram);
printOpenGLError();
// activate shader
_haloProgram->activate();
// psc vantagePointTestTarget = PowerScaledCoordinate::CreatePowerScaledCoordinate(8000, 0.0, 0.0);
// psc campos = vantagePointTestTarget;
// fetch data
psc currentPosition = thisPosition;
psc campos = camera->position();
@@ -415,6 +382,7 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition){
glDisable(GL_BLEND);
_pointProgram->deactivate();
glEnable(GL_DEPTH_TEST);
#endif
}
+19 -3
View File
@@ -67,6 +67,7 @@ SceneGraph::SceneGraph()
: _focus("Root")
, _position("Root")
, _root(nullptr)
, _runtimeData(nullptr)
{
}
@@ -75,6 +76,10 @@ SceneGraph::~SceneGraph()
deinitialize();
}
void SceneGraph::setRuntimeData(RuntimeData* runtimeData){
_runtimeData = runtimeData;
}
bool SceneGraph::initialize()
{
LDEBUG("Initializing SceneGraph");
@@ -108,6 +113,17 @@ bool SceneGraph::initialize()
OsEng.ref().configurationManager().setValue("pscShader", po);
ProgramObject* _gridProgram = new ProgramObject("GridProgram");
ShaderObject* gridvs = new ShaderObject(ShaderObject::ShaderTypeVertex,
absPath("${SHADERS}/grid_vs.glsl"));
ShaderObject* gridfs = new ShaderObject(ShaderObject::ShaderTypeFragment,
absPath("${SHADERS}/grid_fs.glsl"));
_gridProgram->attachObject(gridvs);
_gridProgram->attachObject(gridfs);
_gridProgram->compileShaderObjects();
_gridProgram->linkProgramObject();
// STAR HALO RENDERING
ProgramObject* _starProgram = new ProgramObject("StarProgram");
ShaderObject* starvs = new ShaderObject(ShaderObject::ShaderTypeVertex,
@@ -176,12 +192,12 @@ bool SceneGraph::initialize()
OsEng.ref().configurationManager().setValue("Quad", quad);
OsEng.ref().configurationManager().setValue("PointProgram", _pointProgram);
OsEng.ref().configurationManager().setValue("StarProgram", _starProgram);
OsEng.ref().configurationManager().setValue("GridProgram", _gridProgram);
// Initialize all nodes
for (auto node : _nodes) {
bool success = node->initialize();
bool success = node->initialize(_runtimeData);
if (success)
LDEBUG(node->nodeName() << " initialized successfully!");
else
@@ -189,7 +205,7 @@ bool SceneGraph::initialize()
}
// update the position of all nodes
update();
update();
// Calculate the bounding sphere for the scenegraph
_root->calculateBoundingSphere();
+6 -3
View File
@@ -117,6 +117,7 @@ SceneGraphNode::SceneGraphNode()
, _renderable(nullptr)
, _renderableVisible(false)
, _boundingSphereVisible(false)
, _runtimeData(nullptr)
{
}
@@ -125,13 +126,15 @@ SceneGraphNode::~SceneGraphNode()
deinitialize();
}
bool SceneGraphNode::initialize()
bool SceneGraphNode::initialize(RuntimeData* runtimeData)
{
if (_renderable != nullptr)
_renderable->initialize();
if (_ephemeris != nullptr)
_ephemeris->initialize();
_runtimeData = runtimeData;
return true;
}
@@ -162,7 +165,7 @@ bool SceneGraphNode::deinitialize()
// essential
void SceneGraphNode::update()
{
_ephemeris->update();
_ephemeris->update(_runtimeData);
}
void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition)
@@ -212,7 +215,7 @@ void SceneGraphNode::render(const Camera* camera, const psc& parentPosition)
if (_renderableVisible) {
// LDEBUG("Render");
_renderable->render(camera, thisPosition);
_renderable->render(camera, thisPosition, _runtimeData);
}
// evaluate all the children, tail-recursive function(?)
+29 -8
View File
@@ -25,14 +25,16 @@
#include <openspace/scenegraph/spiceephemeris.h>
#include <openspace/util/spice.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/time.h>
namespace openspace {
SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary): _targetName(""),
_originName(""),
_target(0),
_origin(0),
_position()
_originName(""),
_target(0),
_origin(0),
_position()
{
dictionary.getValue("Body", _targetName);
dictionary.getValue("Observer", _originName);
@@ -59,11 +61,30 @@ const psc& SpiceEphemeris::position() const {
return _position;
}
void SpiceEphemeris::update() {
void SpiceEphemeris::update(RuntimeData* runtimeData) {
double state[3];
Spice::ref().spk_getPosition(_target, _origin, state);
_position = psc::CreatePowerScaledCoordinate(state[0], state[1], state[2]);
_currentEphemerisTime = runtimeData->getTime();
glm::dvec3 position(0,0,0);
double lightTime = 0.0;
SpiceManager::ref().getTargetPosition(_targetName, _currentEphemerisTime, "GALACTIC", "LT+S", _originName, position, lightTime);
/*
std::cout << _targetName << " (";
std::cout << position[0] << ", ";
std::cout << position[1] << ", ";
std::cout << position[2] << ")";
std::cout << std::endl;
assert(_targetName != "JUPITER");
*/
_position = psc::CreatePowerScaledCoordinate(position.x, position.y, position.z);
_position[3] -= 0.01;
//_position[3] += 1;
//_position[3] += 3;
}
} // namespace openspace
+1 -1
View File
@@ -47,7 +47,7 @@ const psc& StaticEphemeris::position() const {
return _position;
}
void StaticEphemeris::update() {
void StaticEphemeris::update(RuntimeData* runtimeData) {
}
-3
View File
@@ -79,9 +79,6 @@ int main(int argc, char** argv) {
}
}
/*openspace::Time::init();
openspace::Spice::init();
openspace::Spice::ref().loadDefaultKernels();*/
openspace::FactoryManager::initialize();
testing::InitGoogleTest(&argc, argv);
+3
View File
@@ -28,6 +28,7 @@
// renderables
#include <openspace/rendering/stars/renderablestars.h>
#include <openspace/rendering/renderablesphericalgrid.h>
#include <openspace/rendering/planets/renderableplanet.h>
#include <openspace/rendering/renderablevolumeexpert.h>
#include <openspace/rendering/renderablevolumecl.h>
@@ -58,6 +59,8 @@ void FactoryManager::initialize()
"RenderablePlanet");
_manager->factory<Renderable>()->registerClass<RenderableStars>(
"RenderableStars");
_manager->factory<Renderable>()->registerClass<RenderableSphericalGrid>(
"RenderableSphericalGrid");
_manager->factory<Renderable>()->registerClass<RenderableVolumeCL>(
"RenderableVolumeCL");
_manager->factory<Renderable>()->registerClass<RenderableVolumeGL>(
+22 -9
View File
@@ -40,7 +40,7 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen
: _vaoID(0)
, _vBufferID(0)
, _iBufferID(0)
, _mode(GL_TRIANGLES)
, _mode(GL_TRIANGLES)
, _isize(6 * segments * segments)
, _vsize((segments + 1) * (segments + 1))
, _varray(new Vertex[_vsize])
@@ -53,12 +53,13 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen
const float fsegments = static_cast<float>(segments);
const float r = static_cast<float>(radius[0]);
for (int i = 0; i <= segments; i++) {
// define an extra vertex around the y-axis due to texture mapping
for (int j = 0; j <= segments; j++) {
const float fi = static_cast<float>(i);
const float fj = static_cast<float>(j);
// inclination angle (north to south)
const float theta = fi * float(M_PI) / fsegments; // 0 -> PI
@@ -95,19 +96,32 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen
for (int i = 1; i <= segments; ++i) {
for (int j = 0; j < segments; ++j) {
const int t = segments + 1;
_iarray[nr] = t * (i - 1) + j + 0;
_iarray[nr] = t * (i - 1) + j + 0; //1
++nr;
_iarray[nr] = t * (i + 0) + j + 0;
_iarray[nr] = t * (i + 0) + j + 0; //2
++nr;
_iarray[nr] = t * (i + 0) + j + 1;
_iarray[nr] = t * (i + 0) + j + 1; //3
++nr;
_iarray[nr] = t * (i - 1) + j + 0;
_iarray[nr] = t * (i - 1) + j + 0; //4
++nr;
_iarray[nr] = t * (i + 0) + j + 1;
_iarray[nr] = t * (i + 0) + j + 1; //5
++nr;
_iarray[nr] = t * (i - 1) + j + 1;
_iarray[nr] = t * (i - 1) + j + 1; //6
++nr;
/*
_iarray[nr] = t * (i - 1) + j + 0; //1
++nr;
_iarray[nr] = t * (i + 0) + j + 0; //2
++nr;
_iarray[nr] = t * (i + 0) + j + 1; //3
++nr;
_iarray[nr] = t * (i - 1) + j + 1; //6
++nr;
_iarray[nr] = t * (i - 1) + j + 0; //4
++nr;
*/
}
}
}
@@ -121,7 +135,6 @@ PowerScaledSphere::~PowerScaledSphere()
glDeleteBuffers(1, &_iBufferID);
glDeleteVertexArrays(1, &_vaoID);
}
#define cppOffsetOf(s, m) ((size_t)&(((s *)NULL)->m))
bool PowerScaledSphere::initialize()
{
+17 -3
View File
@@ -212,15 +212,21 @@ double SpiceManager::stringToEphemerisTime(const std::string& epochString) const
return et;
}
std::string SpiceManager::ephemerisTimeToString(const double et) const{
char utcstr[40];
timout_c(et, "YYYY MON DD HR:MN:SC.### ::RND", 32, utcstr);
return std::string(utcstr);
}
bool SpiceManager::getTargetPosition(const std::string& target,
double ephemerisTime,
const std::string& referenceFrame,
const std::string& aberrationCorrection,
const std::string& observer,
glm::dvec3& targetPosition,
double lightTime) const{
double& lightTime) const{
double pos[3] = { NULL, NULL, NULL };
//method to put error out...
spkpos_c(target.c_str(), ephemerisTime, referenceFrame.c_str(),
aberrationCorrection.c_str(), observer.c_str(), pos, &lightTime);
@@ -238,7 +244,7 @@ bool SpiceManager::getTargetState(const std::string& target,
const std::string& observer,
glm::dvec3& targetPosition,
glm::dvec3& targetVelocity,
double lightTime) const{
double& lightTime) const{
double state[6];
std::fill_n(state, 6, NULL);
@@ -275,6 +281,14 @@ bool SpiceManager::getPositionTransformMatrix(const std::string& fromFrame,
return true;
}
void SpiceManager::getPositionTransformMatrixGLM(const std::string& fromFrame,
const std::string& toFrame,
double ephemerisTime,
glm::dmat3& positionMatrix) const{
pxform_c(fromFrame.c_str(), toFrame.c_str(),
ephemerisTime, (double(*)[3])glm::value_ptr(positionMatrix));
}
bool SpiceManager::getFieldOfView(const std::string& naifInstrumentId,
std::string& fovShape,
std::string& frameName,
+5
View File
@@ -54,6 +54,11 @@ void Time::setTime(const char* stringTime) {
str2et_c ( stringTime, &time_ );
}
void Time::setTime(double intTime) {
assert(this_);
time_ = intTime;
}
double Time::getTime() {
assert(this_);
return time_;