Merge branch 'develop' of openspace.itn.liu.se:/openspace into develop

Conflicts:
	src/rendering/planets/renderableplanet.cpp
	src/rendering/renderablefieldlines.cpp
	src/rendering/renderablevolumegl.cpp
	src/rendering/stars/renderablestars.cpp
This commit is contained in:
Jonas Strandstedt
2014-09-26 17:17:18 +02:00
36 changed files with 1033 additions and 1007 deletions
+43 -87
View File
@@ -24,10 +24,6 @@
#include <openspace/engine/openspaceengine.h>
// sgct header has to be included before all others due to Windows header
#define SGCT_WINDOWS_INCLUDE
#include "sgct.h"
#include <openspace/interaction/deviceidentifier.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/rendering/renderengine.h>
@@ -37,7 +33,6 @@
#include <openspace/util/spicemanager.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/constants.h>
#include <openspace/util/runtimedata.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/filesystem/filesystem.h>
@@ -324,26 +319,11 @@ bool OpenSpaceEngine::initialize()
OsEng.configurationManager().getValueSafe(constants::openspaceengine::keyConfigTimekernel, timeKernel);
// initialize OpenSpace helpers
//Time::init();
//Time::ref().setTime("2007 feb 26 17:41:00");
//Time::ref().setTime("2010 jun 13 13:50:00");
//std::cout <<"Initial time : " << initialData->getTime() << std::endl;
SpiceManager::initialize();
Time::initialize(timeKernel);
Spice::init();
Spice::ref().loadDefaultKernels(); // changeto: instantiate spicemanager, load kernels.
RuntimeData* initialData = new RuntimeData;
initialData->setTime(Time::ref().currentTime());
//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");
@@ -363,36 +343,18 @@ bool OpenSpaceEngine::initialize()
SceneGraph* sceneGraph = new SceneGraph;
_renderEngine->setSceneGraph(sceneGraph);
std::string sceneDescriptionPath;
bool success = OsEng.configurationManager().getValueSafe(
constants::openspaceengine::keyConfigScene, sceneDescriptionPath);
if (!success) {
LFATAL("The configuration does not contain a scene file under key '" <<
constants::openspaceengine::keyConfigScene << "'");
return false;
}
if (!FileSys.fileExists(sceneDescriptionPath)) {
LFATAL("Could not find scene description '" << sceneDescriptionPath << "'");
return false;
}
std::string scenePath;
success = _configurationManager->getValueSafe(
constants::openspaceengine::keyPathScene, scenePath);
if (!success) {
LFATAL("Could not find key '" << constants::openspaceengine::keyPathScene <<
"' in configuration file '" << sceneDescriptionPath << "'");
return false;
}
// initialize the RenderEngine, needs ${SCENEPATH} to be set
_renderEngine->initialize();
_renderEngine->setRuntimeData(initialData);
sceneGraph->setRuntimeData(initialData);
sceneGraph->loadScene(sceneDescriptionPath, scenePath);
sceneGraph->initialize();
std::string sceneDescriptionPath;
bool success = OsEng.configurationManager().getValueSafe(
constants::openspaceengine::keyConfigScene, sceneDescriptionPath);
if (success)
sceneGraph->scheduleLoadSceneFile(sceneDescriptionPath);
_renderEngine->setSceneGraph(sceneGraph);
#ifdef FLARE_ONLY
@@ -406,28 +368,24 @@ bool OpenSpaceEngine::initialize()
_engine->_interactionHandler->connectDevices();
// Run start up scripts
//using ghoul::Dictionary;
//using constants::openspaceengine::keyStartupScript;
ghoul::Dictionary scripts;
success = _engine->configurationManager().getValueSafe(
constants::openspaceengine::keyStartupScript, scripts);
if (success) {
for (size_t i = 0; i < scripts.size(); ++i) {
std::stringstream stream;
// Dictionary-size is 0-based; script numbers are 1-based
stream << (i + 1);
const std::string& key = stream.str();
const bool hasKey = scripts.hasKeyAndValue<std::string>(key);
if (!hasKey) {
LERROR("The startup scripts have to be declared in a simple array format");
break;
}
std::string scriptPath;
scripts.getValue(key, scriptPath);
std::string&& absoluteScriptPath = absPath(scriptPath);
_engine->scriptEngine().runScriptFile(absoluteScriptPath);
for (size_t i = 1; i <= scripts.size(); ++i) {
std::stringstream stream;
stream << i;
const std::string& key = stream.str();
const bool hasKey = scripts.hasKeyAndValue<std::string>(key);
if (!hasKey) {
LERROR("The startup scripts have to be declared in a simple array format."
" Startup scripts did not contain the key '" << key << "'");
break;
}
std::string scriptPath;
scripts.getValue(key, scriptPath);
std::string&& absoluteScriptPath = absPath(scriptPath);
_engine->scriptEngine().runScriptFile(absoluteScriptPath);
}
#ifdef OPENSPACE_VIDEO_EXPORT
@@ -545,8 +503,6 @@ void OpenSpaceEngine::keyboardCallback(int key, int action)
_interactionHandler->keyboardCallback(key, action);
}
#ifdef OPENSPACE_VIDEO_EXPORT
// LDEBUG("key: " << key);
// LDEBUG("SGCT_KEY_PRINT_SCREEN: " << SGCT_KEY_PRINT_SCREEN);
if(action == SGCT_PRESS && key == SGCT_KEY_PRINT_SCREEN)
_doVideoExport = !_doVideoExport;
#endif
@@ -577,32 +533,32 @@ void OpenSpaceEngine::mouseScrollWheelCallback(int pos)
void OpenSpaceEngine::encode()
{
#ifdef FLARE_ONLY
_flare->encode();
#else
std::vector<char> dataStream(1024);
size_t offset = 0;
// serialization
_renderEngine->serialize(dataStream, offset);
_synchronizationBuffer.setVal(dataStream);
sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
#endif
//#ifdef FLARE_ONLY
// _flare->encode();
//#else
// std::vector<char> dataStream(1024);
//
// size_t offset = 0;
// // serialization
// _renderEngine->serialize(dataStream, offset);
//
// _synchronizationBuffer.setVal(dataStream);
// sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
//#endif
}
void OpenSpaceEngine::decode()
{
#ifdef FLARE_ONLY
_flare->decode();
#else
sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
std::vector<char> dataStream = std::move(_synchronizationBuffer.getVal());
size_t offset = 0;
// deserialize in the same order as done in serialization
_renderEngine->deserialize(dataStream, offset);
#endif
//#ifdef FLARE_ONLY
// _flare->decode();
//#else
// sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
// std::vector<char> dataStream = std::move(_synchronizationBuffer.getVal());
// size_t offset = 0;
//
// // deserialize in the same order as done in serialization
// _renderEngine->deserialize(dataStream, offset);
//#endif
}
void OpenSpaceEngine::externalControlCallback(const char* receivedChars,
+450 -447
View File
@@ -1,449 +1,452 @@
#include <openspace/flare/flare.h>
#include <ghoul/opengl/texture.h>
#include <openspace/flare/Renderer.h>
#include <openspace/flare/TransferFunction.h>
#include <openspace/flare/BrickManager.h>
#include <openspace/flare/TSP.h>
#include <openspace/flare/CLManager.h>
#include <openspace/flare/Utils.h>
#include <ghoul/filesystem/filesystem.h>
#include <sgct.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <iostream>
namespace {
std::string _loggerCat = "Flare";
}
namespace openspace {
using namespace osp;
Flare::Flare()
: Renderable(ghoul::Dictionary())
, _oldTime(0.f)
, _currentTime(0.f)
, _leftMouseButton(false)
, _currentMouseX(0)
, _currentMouseY(0)
, _lastMouseX(0)
, _lastMouseY(0)
{
setBoundingSphere(PowerScaledScalar::CreatePSS(sqrt(3.0f)));
}
Flare::~Flare() {
// Clean up like a good citizen
delete _config;
delete _raycaster;
delete _animator;
}
void exit_msg(std::string m) {
LDEBUG(m);
exit(1);
}
bool Flare::initialize() {
init();
return true;
}
bool Flare::deinitialize() {
return true;
}
void Flare::render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData) {
render();
}
void Flare::update() {
}
void Flare::render() {
// Sync timestep
//unsigned int ts = static_cast<unsigned int>(_timeStep.getVal());
//LDEBUG("ts: " << ts);
// Reload config if flag is set
if (_reloadFlag.getVal()) _raycaster->Reload();
// Set model and view params
_raycaster->SetModelParams(_pitch.getVal(),
_yaw.getVal(),
_roll.getVal());
_raycaster->SetViewParams(_translateX.getVal(),
_translateY.getVal(),
_translateZ.getVal());
// Render
if (!_raycaster->Render(_elapsedTime.getVal())) {
LDEBUG("!_raycaster->Render(_elapsedTime.getVal())");
exit(1);
}
// Save screenshot
if (_config->TakeScreenshot()) sgct::Engine::instance()->takeScreenshot();
// Update animator with synchronized time
_animator->SetPaused(_animationPaused.getVal());
_animator->SetFPSMode(_fpsMode.getVal());
_animator->Update(_elapsedTime.getVal());
_animator->ManualTimestep(_manualTimestep.getVal());
}
void Flare::initNavigation() {
_animationPaused.setVal(false);
_reloadFlag.setVal(false);
// FPS mode should be OFF for cluster syncing
_fpsMode.setVal(true);
_manualTimestep.setVal(0);
// Read initial values from config
_pitch.setVal(_config->StartPitch());
_yaw.setVal(_config->StartYaw());
_roll.setVal(_config->StartRoll());
_translateX.setVal(_config->TranslateX());
_translateY.setVal(_config->TranslateY());
_translateZ.setVal(_config->TranslateZ());
}
void Flare::init() {
// Start with reading a config file
_config = Config::New(absPath("${CONFIG}/flareConfig.txt"));
if (!_config) {
LDEBUG("!_Config");
exit(1);
}
initNavigation();
_reloadFlag.setVal(false);
// Get the viewport coordinates from OpenGL
GLint currentViewPort[4];
glGetIntegerv( GL_VIEWPORT, currentViewPort);
// Make sure texture width/height and global kernel worksizes are
// multiples of the local worksize
// Window dimensions
unsigned int width = currentViewPort[2] - currentViewPort[0];
unsigned int height = currentViewPort[3] - currentViewPort[1];
unsigned int xFactor = width/_config->LocalWorkSizeX();
unsigned int yFactor = height/_config->LocalWorkSizeY();
width = xFactor * _config->LocalWorkSizeX();
height = yFactor * _config->LocalWorkSizeY();
width /= _config->TextureDivisionFactor();
height /= _config->TextureDivisionFactor();
// Create TSP structure from file
TSP *tsp = TSP::New(_config);
if (!tsp->ReadHeader()) {
LDEBUG("!tsp->ReadHeader()");
exit(1);
}
// Read cache if it exists, calculate otherwise
if (tsp->ReadCache()) {
INFO("\nUsing cached TSP file");
} else {
INFO("\nNo cached TSP file found");
if (!tsp->Construct()) {
LDEBUG("!tsp->Construct()");
exit(1);
}
if (_config->CalculateError() == 0) {
INFO("Not calculating errors");
} else {
if (!tsp->CalculateSpatialError()) {
LDEBUG("!tsp->CalculateSpatialError()");
exit(1);
}
if (!tsp->CalculateTemporalError()) {
LDEBUG("!tsp->CalculateTemporalError()");
exit(1);
}
if (!tsp->WriteCache()) {
LDEBUG("!tsp->WriteCache()");
exit(1);
}
}
}
// Create brick manager and init (has to be done after init OpenGL!)
BrickManager *brickManager= BrickManager::New(_config);
if (!brickManager->ReadHeader()) {
LDEBUG("!brickManager->ReadHeader()");
exit(1);
}
if (!brickManager->InitAtlas()) {
LDEBUG("!brickManager->InitAtlas()");
exit(1);
}
using ghoul::opengl::ShaderObject;
using ghoul::opengl::ProgramObject;
ProgramObject* cubeShaderProgram = nullptr;
ShaderObject* cubeShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex,
_config->CubeShaderVertFilename(),
"cubeShaderProgram_vs"
);
ShaderObject* cubeShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment,
_config->CubeShaderFragFilename(),
"cubeShaderProgram_fs"
);
cubeShaderProgram = new ProgramObject;
cubeShaderProgram->attachObject(cubeShaderProgram_vs);
cubeShaderProgram->attachObject(cubeShaderProgram_fs);
if( ! cubeShaderProgram->compileShaderObjects())
LDEBUG("Could not compile cubeShaderProgram");
if( ! cubeShaderProgram->linkProgramObject())
LDEBUG("Could not link cubeShaderProgram");
ProgramObject* quadShaderProgram = nullptr;
ShaderObject* quadShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex,
_config->QuadShaderVertFilename(),
"quadShaderProgram_vs"
);
ShaderObject* quadShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment,
_config->QuadShaderFragFilename(),
"quadShaderProgram_fs"
);
quadShaderProgram = new ProgramObject;
quadShaderProgram->attachObject(quadShaderProgram_vs);
quadShaderProgram->attachObject(quadShaderProgram_fs);
if( ! quadShaderProgram->compileShaderObjects())
LDEBUG("Could not compile quadShaderProgram");
if( ! quadShaderProgram->linkProgramObject())
LDEBUG("Could not link quadShaderProgram");
// Create shaders for color cube and output textured quad
/*
ShaderProgram *cubeShaderProgram = ShaderProgram::New();
cubeShaderProgram->CreateShader(ShaderProgram::VERTEX,
_config->CubeShaderVertFilename());
cubeShaderProgram->CreateShader(ShaderProgram::FRAGMENT,
_config->CubeShaderFragFilename());
cubeShaderProgram->CreateProgram();
ShaderProgram *quadShaderProgram = ShaderProgram::New();
quadShaderProgram->CreateShader(ShaderProgram::VERTEX,
_config->QuadShaderVertFilename());
quadShaderProgram->CreateShader(ShaderProgram::FRAGMENT,
_config->QuadShaderFragFilename());
quadShaderProgram->CreateProgram();
*/
// Create two textures to hold the color cube
std::vector<unsigned int> dimensions(2);
dimensions[0] = width;
dimensions[1] = height;
ghoul::opengl::Texture* cubeFrontTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1),
ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT);
cubeFrontTex->uploadTexture();
ghoul::opengl::Texture* cubeBackTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1),
ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT);
cubeBackTex->uploadTexture();
/*
Texture2D *cubeFrontTex = Texture2D::New(dimensions);
Texture2D *cubeBackTex = Texture2D::New(dimensions);
cubeFrontTex->Init();
cubeBackTex->Init();
*/
// Create an output texture to write to
ghoul::opengl::Texture* quadTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1),
ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT);
quadTex->uploadTexture();
//Texture2D *quadTex = Texture2D::New(dimensions);
//quadTex->Init();
// Create transfer functions
TransferFunction *transferFunction = TransferFunction::New();
transferFunction->SetInFilename(_config->TFFilename());
if (!transferFunction->ReadFile()) exit_msg("!transferFunction->ReadFile()");
if (!transferFunction->ConstructTexture()) exit_msg("!transferFunction->ConstructTexture()");
// Create animator
_animator = Animator::New(_config);
// Use original (not adjusted) number of timesteps for animator
_animator->SetNumTimesteps(brickManager->NumOrigTimesteps());
// Create CL manager
CLManager *clManager = CLManager::New();
// Set up the raycaster
_raycaster = Raycaster::New(_config);
_raycaster->SetWinWidth(width);
_raycaster->SetWinHeight(height);
if (!_raycaster->InitCube()) exit_msg("!_raycaster->InitCube()");
if (!_raycaster->InitQuad()) exit_msg("!_raycaster->InitQuad()");
_raycaster->SetBrickManager(brickManager);
_raycaster->SetCubeFrontTexture(cubeFrontTex);
_raycaster->SetCubeBackTexture(cubeBackTex);
_raycaster->SetQuadTexture(quadTex);
_raycaster->SetCubeShaderProgram(cubeShaderProgram);
_raycaster->SetQuadShaderProgram(quadShaderProgram);
if (!_raycaster->InitFramebuffers()) exit_msg("!_raycaster->InitFramebuffers()");
_raycaster->SetAnimator(_animator);
_raycaster->AddTransferFunction(transferFunction);
// Tie CL manager to renderer
_raycaster->SetCLManager(clManager);
_raycaster->SetTSP(tsp);
if (!_raycaster->InitCL()) exit_msg("!_raycaster->InitCL()");
if (!_raycaster->InitPipeline()) exit_msg("!_raycaster->InitCL()");
}
void Flare::keyboard(int key, int action) {
if (action == GLFW_PRESS) {
switch(key) {
case 32: // space bar
// Toggle animation paused
INFO("Pausing");
_animationPaused.setVal(!_animationPaused.getVal());
break;
case 'Z':
case 'z':
// Decrease timestep
// NOTE: Can't decrease timestep with double buffered approach atm
//manualTimestep_.setVal(-1);
break;
case 'X':
case 'x':
// Increase timestep
_manualTimestep.setVal(1);
break;
case 'D':
case 'd':
_translateX.setVal(_translateX.getVal() + _config->ZoomFactor());
break;
case 'A':
case 'a':
_translateX.setVal(_translateX.getVal() - _config->ZoomFactor());
break;
case 'W':
case 'w':
_translateY.setVal(_translateY.getVal() + _config->ZoomFactor());
break;
case 'S':
case 's':
_translateY.setVal(_translateY.getVal() - _config->ZoomFactor());
break;
case 'Q':
case 'q':
_translateZ.setVal(_translateZ.getVal() + _config->ZoomFactor());
break;
case 'E':
case 'e':
_translateZ.setVal(_translateZ.getVal() - _config->ZoomFactor());
break;
case 'R':
case 'r':
_reloadFlag.setVal(true);
break;
case 'F':
case 'f':
_fpsMode.setVal(!_fpsMode.getVal());
if (_fpsMode.getVal()) {
INFO("Updating animation ASAP");
} else {
INFO("Using refresh interval variable");
}
break;
}
}
}
void Flare::mouse(int button, int action) {
switch (button) {
case GLFW_MOUSE_BUTTON_LEFT:
_leftMouseButton = (action == GLFW_PRESS) ? true : false;
std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId();
sgct::Engine::getMousePos(winId, &_lastMouseX, &_lastMouseY);
}
}
void Flare::preSync() {
// Update time
_oldTime = _currentTime;
_currentTime = static_cast<float>(sgct::Engine::getTime());
_elapsedTime.setVal(_currentTime - _oldTime);
_timeStep.setVal(_animator->CurrentTimestep());
// Update automatic model transform
if (!_animationPaused.getVal()) {
_pitch.setVal(_pitch.getVal() + _config->PitchSpeed());
_roll.setVal(_roll.getVal() + _config->RollSpeed());
_yaw.setVal(_yaw.getVal() + _config->YawSpeed());
}
// Update mouse
if (_leftMouseButton) {
std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId();
sgct::Engine::getMousePos(winId ,&_currentMouseX, &_currentMouseY);
_pitch.setVal(_pitch.getVal() + _config->MousePitchFactor() *
static_cast<float>(_currentMouseX-_lastMouseX));
_roll.setVal(_roll.getVal() + _config->MouseRollFactor() *
static_cast<float>(_currentMouseY-_lastMouseY));
}
}
void Flare::postSyncPreDraw() {
_animator->SetCurrentTimestep(static_cast<unsigned int>(_timeStep.getVal()));
}
void Flare::postDraw() {
// Reset manual timestep
_manualTimestep.setVal(0);
// Reset reload flag
_reloadFlag.setVal(false);
}
void Flare::encode() {
sgct::SharedData::instance()->writeInt(&_timeStep);
sgct::SharedData::instance()->writeBool(&_animationPaused);
sgct::SharedData::instance()->writeBool(&_fpsMode);
sgct::SharedData::instance()->writeFloat(&_elapsedTime);
sgct::SharedData::instance()->writeInt(&_manualTimestep);
sgct::SharedData::instance()->writeFloat(&_pitch);
sgct::SharedData::instance()->writeFloat(&_yaw);
sgct::SharedData::instance()->writeFloat(&_roll);
sgct::SharedData::instance()->writeFloat(&_translateX);
sgct::SharedData::instance()->writeFloat(&_translateY);
sgct::SharedData::instance()->writeFloat(&_translateZ);
sgct::SharedData::instance()->writeBool(&_reloadFlag);
}
void Flare::decode() {
sgct::SharedData::instance()->readInt(&_timeStep);
sgct::SharedData::instance()->readBool(&_animationPaused);
sgct::SharedData::instance()->readBool(&_fpsMode);
sgct::SharedData::instance()->readFloat(&_elapsedTime);
sgct::SharedData::instance()->readInt(&_manualTimestep);
sgct::SharedData::instance()->readFloat(&_pitch);
sgct::SharedData::instance()->readFloat(&_yaw);
sgct::SharedData::instance()->readFloat(&_roll);
sgct::SharedData::instance()->readFloat(&_translateX);
sgct::SharedData::instance()->readFloat(&_translateY);
sgct::SharedData::instance()->readFloat(&_translateZ);
sgct::SharedData::instance()->readBool(&_reloadFlag);
}
} // namespace openspace
// The source is still in here to be cannibalized later (ab)
//#include <openspace/flare/flare.h>
//
//#include <ghoul/opengl/texture.h>
//
//#include <openspace/flare/Renderer.h>
//#include <openspace/flare/TransferFunction.h>
//#include <openspace/flare/BrickManager.h>
//#include <openspace/flare/TSP.h>
//#include <openspace/flare/CLManager.h>
//#include <openspace/flare/Utils.h>
//
//#include <ghoul/filesystem/filesystem.h>
//
//#include <sgct.h>
//
//#include <string>
//#include <cstdlib>
//#include <vector>
//#include <iostream>
//
//namespace {
// std::string _loggerCat = "Flare";
//}
//
//namespace openspace {
//using namespace osp;
//
//Flare::Flare()
// : Renderable(ghoul::Dictionary())
// , _oldTime(0.f)
// , _currentTime(0.f)
// , _leftMouseButton(false)
// , _currentMouseX(0)
// , _currentMouseY(0)
// , _lastMouseX(0)
// , _lastMouseY(0)
//{
// setBoundingSphere(PowerScaledScalar::CreatePSS(sqrt(3.0f)));
//}
//
//Flare::~Flare() {
// // Clean up like a good citizen
// delete _config;
// delete _raycaster;
// delete _animator;
//}
//
//void exit_msg(std::string m) {
// LDEBUG(m);
// exit(1);
//}
//
//
//bool Flare::initialize() {
// init();
// return true;
//}
//bool Flare::deinitialize() {
// return true;
//}
//
//void Flare::render(const Camera *camera, const psc& thisPosition, RuntimeData* runtimeData) {
// render();
//}
//void Flare::update() {
//
//}
//
//void Flare::render() {
// // Sync timestep
// //unsigned int ts = static_cast<unsigned int>(_timeStep.getVal());
// //LDEBUG("ts: " << ts);
// // Reload config if flag is set
// if (_reloadFlag.getVal()) _raycaster->Reload();
//
// // Set model and view params
// _raycaster->SetModelParams(_pitch.getVal(),
// _yaw.getVal(),
// _roll.getVal());
// _raycaster->SetViewParams(_translateX.getVal(),
// _translateY.getVal(),
// _translateZ.getVal());
// // Render
// if (!_raycaster->Render(_elapsedTime.getVal())) {
// LDEBUG("!_raycaster->Render(_elapsedTime.getVal())");
// exit(1);
// }
//
// // Save screenshot
// if (_config->TakeScreenshot()) sgct::Engine::instance()->takeScreenshot();
//
// // Update animator with synchronized time
// _animator->SetPaused(_animationPaused.getVal());
// _animator->SetFPSMode(_fpsMode.getVal());
// _animator->Update(_elapsedTime.getVal());
// _animator->ManualTimestep(_manualTimestep.getVal());
//}
//
//void Flare::initNavigation() {
// _animationPaused.setVal(false);
// _reloadFlag.setVal(false);
//
// // FPS mode should be OFF for cluster syncing
// _fpsMode.setVal(true);
// _manualTimestep.setVal(0);
//
// // Read initial values from config
// _pitch.setVal(_config->StartPitch());
// _yaw.setVal(_config->StartYaw());
// _roll.setVal(_config->StartRoll());
//
// _translateX.setVal(_config->TranslateX());
// _translateY.setVal(_config->TranslateY());
// _translateZ.setVal(_config->TranslateZ());
//}
//
//void Flare::init() {
// // Start with reading a config file
// _config = Config::New(absPath("${CONFIG}/flareConfig.txt"));
// if (!_config) {
// LDEBUG("!_Config");
// exit(1);
// }
//
// initNavigation();
// _reloadFlag.setVal(false);
//
// // Get the viewport coordinates from OpenGL
// GLint currentViewPort[4];
// glGetIntegerv( GL_VIEWPORT, currentViewPort);
//
// // Make sure texture width/height and global kernel worksizes are
// // multiples of the local worksize
//
// // Window dimensions
// unsigned int width = currentViewPort[2] - currentViewPort[0];
// unsigned int height = currentViewPort[3] - currentViewPort[1];
// unsigned int xFactor = width/_config->LocalWorkSizeX();
// unsigned int yFactor = height/_config->LocalWorkSizeY();
// width = xFactor * _config->LocalWorkSizeX();
// height = yFactor * _config->LocalWorkSizeY();
// width /= _config->TextureDivisionFactor();
// height /= _config->TextureDivisionFactor();
//
//
// // Create TSP structure from file
// TSP *tsp = TSP::New(_config);
// if (!tsp->ReadHeader()) {
// LDEBUG("!tsp->ReadHeader()");
// exit(1);
// }
// // Read cache if it exists, calculate otherwise
// if (tsp->ReadCache()) {
// INFO("\nUsing cached TSP file");
// } else {
// INFO("\nNo cached TSP file found");
// if (!tsp->Construct()) {
// LDEBUG("!tsp->Construct()");
// exit(1);
// }
// if (_config->CalculateError() == 0) {
// INFO("Not calculating errors");
// } else {
// if (!tsp->CalculateSpatialError()) {
// LDEBUG("!tsp->CalculateSpatialError()");
// exit(1);
// }
// if (!tsp->CalculateTemporalError()) {
// LDEBUG("!tsp->CalculateTemporalError()");
// exit(1);
// }
// if (!tsp->WriteCache()) {
// LDEBUG("!tsp->WriteCache()");
// exit(1);
// }
// }
// }
//
// // Create brick manager and init (has to be done after init OpenGL!)
// BrickManager *brickManager= BrickManager::New(_config);
// if (!brickManager->ReadHeader()) {
// LDEBUG("!brickManager->ReadHeader()");
// exit(1);
// }
// if (!brickManager->InitAtlas()) {
// LDEBUG("!brickManager->InitAtlas()");
// exit(1);
// }
//
// using ghoul::opengl::ShaderObject;
// using ghoul::opengl::ProgramObject;
//
// ProgramObject* cubeShaderProgram = nullptr;
// ShaderObject* cubeShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex,
// _config->CubeShaderVertFilename(),
// "cubeShaderProgram_vs"
// );
// ShaderObject* cubeShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment,
// _config->CubeShaderFragFilename(),
// "cubeShaderProgram_fs"
// );
//
// cubeShaderProgram = new ProgramObject;
// cubeShaderProgram->attachObject(cubeShaderProgram_vs);
// cubeShaderProgram->attachObject(cubeShaderProgram_fs);
//
// if( ! cubeShaderProgram->compileShaderObjects())
// LDEBUG("Could not compile cubeShaderProgram");
// if( ! cubeShaderProgram->linkProgramObject())
// LDEBUG("Could not link cubeShaderProgram");
//
// ProgramObject* quadShaderProgram = nullptr;
// ShaderObject* quadShaderProgram_vs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeVertex,
// _config->QuadShaderVertFilename(),
// "quadShaderProgram_vs"
// );
// ShaderObject* quadShaderProgram_fs = new ShaderObject(ShaderObject::ShaderType::ShaderTypeFragment,
// _config->QuadShaderFragFilename(),
// "quadShaderProgram_fs"
// );
//
// quadShaderProgram = new ProgramObject;
// quadShaderProgram->attachObject(quadShaderProgram_vs);
// quadShaderProgram->attachObject(quadShaderProgram_fs);
//
// if( ! quadShaderProgram->compileShaderObjects())
// LDEBUG("Could not compile quadShaderProgram");
// if( ! quadShaderProgram->linkProgramObject())
// LDEBUG("Could not link quadShaderProgram");
//
// // Create shaders for color cube and output textured quad
// /*
// ShaderProgram *cubeShaderProgram = ShaderProgram::New();
// cubeShaderProgram->CreateShader(ShaderProgram::VERTEX,
// _config->CubeShaderVertFilename());
// cubeShaderProgram->CreateShader(ShaderProgram::FRAGMENT,
// _config->CubeShaderFragFilename());
// cubeShaderProgram->CreateProgram();
//
// ShaderProgram *quadShaderProgram = ShaderProgram::New();
// quadShaderProgram->CreateShader(ShaderProgram::VERTEX,
// _config->QuadShaderVertFilename());
// quadShaderProgram->CreateShader(ShaderProgram::FRAGMENT,
// _config->QuadShaderFragFilename());
// quadShaderProgram->CreateProgram();
// */
//
// // Create two textures to hold the color cube
// std::vector<unsigned int> dimensions(2);
// dimensions[0] = width;
// dimensions[1] = height;
// ghoul::opengl::Texture* cubeFrontTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1),
// ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT);
// cubeFrontTex->uploadTexture();
// ghoul::opengl::Texture* cubeBackTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1),
// ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT);
// cubeBackTex->uploadTexture();
// /*
// Texture2D *cubeFrontTex = Texture2D::New(dimensions);
// Texture2D *cubeBackTex = Texture2D::New(dimensions);
// cubeFrontTex->Init();
// cubeBackTex->Init();
//*/
// // Create an output texture to write to
// ghoul::opengl::Texture* quadTex = new ghoul::opengl::Texture(glm::size3_t(width, height, 1),
// ghoul::opengl::Texture::Format::RGBA, GL_RGBA, GL_FLOAT);
// quadTex->uploadTexture();
//
// //Texture2D *quadTex = Texture2D::New(dimensions);
// //quadTex->Init();
//
// // Create transfer functions
// TransferFunction *transferFunction = TransferFunction::New();
// transferFunction->SetInFilename(_config->TFFilename());
// if (!transferFunction->ReadFile()) exit_msg("!transferFunction->ReadFile()");
// if (!transferFunction->ConstructTexture()) exit_msg("!transferFunction->ConstructTexture()");
//
//
// // Create animator
// _animator = Animator::New(_config);
// // Use original (not adjusted) number of timesteps for animator
// _animator->SetNumTimesteps(brickManager->NumOrigTimesteps());
//
// // Create CL manager
// CLManager *clManager = CLManager::New();
//
// // Set up the raycaster
// _raycaster = Raycaster::New(_config);
// _raycaster->SetWinWidth(width);
// _raycaster->SetWinHeight(height);
// if (!_raycaster->InitCube()) exit_msg("!_raycaster->InitCube()");
// if (!_raycaster->InitQuad()) exit_msg("!_raycaster->InitQuad()");
// _raycaster->SetBrickManager(brickManager);
// _raycaster->SetCubeFrontTexture(cubeFrontTex);
// _raycaster->SetCubeBackTexture(cubeBackTex);
// _raycaster->SetQuadTexture(quadTex);
// _raycaster->SetCubeShaderProgram(cubeShaderProgram);
// _raycaster->SetQuadShaderProgram(quadShaderProgram);
// if (!_raycaster->InitFramebuffers()) exit_msg("!_raycaster->InitFramebuffers()");
// _raycaster->SetAnimator(_animator);
// _raycaster->AddTransferFunction(transferFunction);
//
// // Tie CL manager to renderer
// _raycaster->SetCLManager(clManager);
// _raycaster->SetTSP(tsp);
//
// if (!_raycaster->InitCL()) exit_msg("!_raycaster->InitCL()");
// if (!_raycaster->InitPipeline()) exit_msg("!_raycaster->InitCL()");
//}
//
//void Flare::keyboard(int key, int action) {
// if (action == GLFW_PRESS) {
// switch(key) {
// case 32: // space bar
// // Toggle animation paused
// INFO("Pausing");
// _animationPaused.setVal(!_animationPaused.getVal());
// break;
// case 'Z':
// case 'z':
// // Decrease timestep
// // NOTE: Can't decrease timestep with double buffered approach atm
// //manualTimestep_.setVal(-1);
// break;
// case 'X':
// case 'x':
// // Increase timestep
// _manualTimestep.setVal(1);
// break;
// case 'D':
// case 'd':
// _translateX.setVal(_translateX.getVal() + _config->ZoomFactor());
// break;
// case 'A':
// case 'a':
// _translateX.setVal(_translateX.getVal() - _config->ZoomFactor());
// break;
// case 'W':
// case 'w':
// _translateY.setVal(_translateY.getVal() + _config->ZoomFactor());
// break;
// case 'S':
// case 's':
// _translateY.setVal(_translateY.getVal() - _config->ZoomFactor());
// break;
// case 'Q':
// case 'q':
// _translateZ.setVal(_translateZ.getVal() + _config->ZoomFactor());
// break;
// case 'E':
// case 'e':
// _translateZ.setVal(_translateZ.getVal() - _config->ZoomFactor());
// break;
// case 'R':
// case 'r':
// _reloadFlag.setVal(true);
// break;
// case 'F':
// case 'f':
// _fpsMode.setVal(!_fpsMode.getVal());
// if (_fpsMode.getVal()) {
// INFO("Updating animation ASAP");
// } else {
// INFO("Using refresh interval variable");
// }
// break;
// }
// }
//}
//
//void Flare::mouse(int button, int action) {
// switch (button) {
// case GLFW_MOUSE_BUTTON_LEFT:
// _leftMouseButton = (action == GLFW_PRESS) ? true : false;
// std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId();
// sgct::Engine::getMousePos(winId, &_lastMouseX, &_lastMouseY);
// }
//}
//
//void Flare::preSync() {
// // Update time
// _oldTime = _currentTime;
// _currentTime = static_cast<float>(sgct::Engine::getTime());
// _elapsedTime.setVal(_currentTime - _oldTime);
// _timeStep.setVal(_animator->CurrentTimestep());
//
// // Update automatic model transform
// if (!_animationPaused.getVal()) {
// _pitch.setVal(_pitch.getVal() + _config->PitchSpeed());
// _roll.setVal(_roll.getVal() + _config->RollSpeed());
// _yaw.setVal(_yaw.getVal() + _config->YawSpeed());
// }
//
// // Update mouse
// if (_leftMouseButton) {
// std::size_t winId = sgct::Engine::instance()->getActiveWindowPtr()->getId();
// sgct::Engine::getMousePos(winId ,&_currentMouseX, &_currentMouseY);
// _pitch.setVal(_pitch.getVal() + _config->MousePitchFactor() *
// static_cast<float>(_currentMouseX-_lastMouseX));
// _roll.setVal(_roll.getVal() + _config->MouseRollFactor() *
// static_cast<float>(_currentMouseY-_lastMouseY));
// }
//}
//
//void Flare::postSyncPreDraw() {
// _animator->SetCurrentTimestep(static_cast<unsigned int>(_timeStep.getVal()));
//}
//
//void Flare::postDraw() {
// // Reset manual timestep
// _manualTimestep.setVal(0);
//
// // Reset reload flag
// _reloadFlag.setVal(false);
//}
//
//void Flare::encode() {
// sgct::SharedData::instance()->writeInt(&_timeStep);
// sgct::SharedData::instance()->writeBool(&_animationPaused);
// sgct::SharedData::instance()->writeBool(&_fpsMode);
// sgct::SharedData::instance()->writeFloat(&_elapsedTime);
// sgct::SharedData::instance()->writeInt(&_manualTimestep);
// sgct::SharedData::instance()->writeFloat(&_pitch);
// sgct::SharedData::instance()->writeFloat(&_yaw);
// sgct::SharedData::instance()->writeFloat(&_roll);
// sgct::SharedData::instance()->writeFloat(&_translateX);
// sgct::SharedData::instance()->writeFloat(&_translateY);
// sgct::SharedData::instance()->writeFloat(&_translateZ);
// sgct::SharedData::instance()->writeBool(&_reloadFlag);
//}
//
//void Flare::decode() {
// sgct::SharedData::instance()->readInt(&_timeStep);
// sgct::SharedData::instance()->readBool(&_animationPaused);
// sgct::SharedData::instance()->readBool(&_fpsMode);
// sgct::SharedData::instance()->readFloat(&_elapsedTime);
// sgct::SharedData::instance()->readInt(&_manualTimestep);
// sgct::SharedData::instance()->readFloat(&_pitch);
// sgct::SharedData::instance()->readFloat(&_yaw);
// sgct::SharedData::instance()->readFloat(&_roll);
// sgct::SharedData::instance()->readFloat(&_translateX);
// sgct::SharedData::instance()->readFloat(&_translateY);
// sgct::SharedData::instance()->readFloat(&_translateZ);
// sgct::SharedData::instance()->readBool(&_reloadFlag);
//}
//
//} // namespace openspace
//
//
-4
View File
@@ -51,11 +51,7 @@ PropertyOwner::PropertyOwner()
PropertyOwner::~PropertyOwner()
{
for (Property* p : _properties)
delete p;
_properties.clear();
for (PropertyOwner* s : _subOwners)
delete s;
_subOwners.clear();
}
+12 -13
View File
@@ -68,7 +68,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
= planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
}
dictionary.getValue("Frame", _target);
dictionary.getValue(constants::renderableplanet::keyFrame, _target);
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
@@ -113,7 +113,7 @@ bool RenderablePlanet::deinitialize()
return true;
}
void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData)
void RenderablePlanet::render(const RenderData& data)
{
if (!_programObject)
return;
@@ -124,9 +124,9 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run
_programObject->activate();
// fetch data
psc currentPosition = thisPosition;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
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);
@@ -134,25 +134,21 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run
// scale the planet to appropriate size since the planet is a unit sphere
glm::mat4 transform = glm::mat4(1);
// 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[i][j] = _stateMatrix[i][j];
}
}
transform = transform* rot;
// setup the data to the shader
_programObject->setUniform("ViewProjection", camera->viewProjectionMatrix());
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(_programObject, camera, currentPosition);
setPscUniforms(_programObject, &data.camera, data.position);
// Bind texture
ghoul::opengl::TextureUnit unit;
@@ -168,8 +164,11 @@ void RenderablePlanet::render(const Camera* camera, const psc& thisPosition, Run
}
void RenderablePlanet::update()
void RenderablePlanet::update(const UpdateData& data)
{
// set spice-orientation in accordance to timestamp
openspace::SpiceManager::ref().getPositionTransformMatrixGLM("GALACTIC", "IAU_EARTH", data.time, _stateMatrix);
}
void RenderablePlanet::loadTexture()
+1 -1
View File
@@ -88,7 +88,7 @@ const PowerScaledScalar& Renderable::getBoundingSphere()
return boundingSphere_;
}
void Renderable::update()
void Renderable::update(const UpdateData&)
{
}
+7 -7
View File
@@ -211,15 +211,15 @@ bool RenderableFieldlines::deinitialize() {
return true;
}
void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData) {
void RenderableFieldlines::render(const RenderData& data) {
if(_update) {
_update = false;
safeShaderCompilation();
}
glm::mat4 transform = camera->viewProjectionMatrix();
glm::mat4 camTransform = camera->viewRotationMatrix();
psc relative = thisPosition-camera->position();
glm::mat4 transform = data.camera.viewProjectionMatrix();
glm::mat4 camTransform = data.camera.viewRotationMatrix();
psc relative = data.position - data.camera.position();
transform = transform*camTransform;
transform = glm::mat4(1.0);
@@ -228,9 +228,9 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition,
// Activate shader
_fieldlinesProgram->activate();
_fieldlinesProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix());
_fieldlinesProgram->setUniform("modelViewProjection", data.camera.viewProjectionMatrix());
_fieldlinesProgram->setUniform("modelTransform", transform);
setPscUniforms(_fieldlinesProgram, camera, thisPosition);
setPscUniforms(_fieldlinesProgram, &data.camera, data.position);
// ------ FIELDLINES -----------------
glBindVertexArray(_VAO);
@@ -245,7 +245,7 @@ void RenderableFieldlines::render(const Camera* camera, const psc& thisPosition,
_fieldlinesProgram->deactivate();
}
void RenderableFieldlines::update() {
void RenderableFieldlines::update(const UpdateData& data) {
}
void RenderableFieldlines::safeShaderCompilation() {
+7 -7
View File
@@ -181,21 +181,21 @@ bool RenderableSphericalGrid::initialize(){
return completeSuccess;
}
void RenderableSphericalGrid::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){
void RenderableSphericalGrid::render(const RenderData& data){
assert(_gridProgram);
_gridProgram->activate();
// fetch data
psc currentPosition = thisPosition;
psc campos = camera->position();
glm::mat4 camrot = camera->viewRotationMatrix();
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
_gridProgram->setUniform("ViewProjection", camera->viewProjectionMatrix());
_gridProgram->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_gridProgram->setUniform("ModelTransform", transform);
_gridProgram->setUniform("campos", campos.vec4());
_gridProgram->setUniform("objpos", currentPosition.vec4());
@@ -216,7 +216,7 @@ void RenderableSphericalGrid::render(const Camera* camera, const psc& thisPositi
_gridProgram->deactivate();
}
void RenderableSphericalGrid::update(){
void RenderableSphericalGrid::update(const UpdateData& data){
}
}
+5 -5
View File
@@ -228,7 +228,7 @@ bool RenderableVolumeGL::deinitialize() {
return true;
}
void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, RuntimeData* runtimeData) {
void RenderableVolumeGL::render(const RenderData& data) {
if(_updateTransferfunction) {
_updateTransferfunction = false;
ghoul::opengl::Texture* transferFunction = loadTransferFunction(_transferFunctionPath);
@@ -248,7 +248,7 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R
transform = glm::scale(transform, _boxScaling);
// fetch data
psc currentPosition = thisPosition;
psc currentPosition = data.position;
// psc addon(-1.1,0.0,0.0,0.0);
// currentPosition += addon;
@@ -257,9 +257,9 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R
_boxProgram->activate();
_boxProgram->setUniform(_typeLocation, _id);
_boxProgram->setUniform("modelViewProjection", camera->viewProjectionMatrix());
_boxProgram->setUniform("modelViewProjection", data.camera.viewProjectionMatrix());
_boxProgram->setUniform("modelTransform", transform);
setPscUniforms(_boxProgram, camera, currentPosition);
setPscUniforms(_boxProgram, &data.camera, currentPosition);
// make sure GL_CULL_FACE is enabled (it should be)
glEnable(GL_CULL_FACE);
@@ -276,7 +276,7 @@ void RenderableVolumeGL::render(const Camera *camera, const psc &thisPosition, R
_boxProgram->deactivate();
}
void RenderableVolumeGL::update() {
void RenderableVolumeGL::update(const UpdateData& data) {
}
} // namespace openspace
+133 -144
View File
@@ -51,7 +51,6 @@ namespace openspace {
RenderEngine::RenderEngine()
: _mainCamera(nullptr)
, _sceneGraph(nullptr)
, _runtimeData(nullptr)
, _abuffer(nullptr)
{
}
@@ -82,10 +81,6 @@ bool RenderEngine::initialize()
return true;
}
void RenderEngine::setRuntimeData(RuntimeData* runtimeData){
_runtimeData = runtimeData;
}
bool RenderEngine::initializeGL()
{
// LDEBUG("RenderEngine::initializeGL()");
@@ -177,7 +172,7 @@ void RenderEngine::postSynchronizationPreDraw()
_mainCamera->compileViewRotationMatrix();
// update and evaluate the scene starting from the root node
_sceneGraph->update();
_sceneGraph->update({Time::ref().currentTime()});
_mainCamera->setCameraDirection(glm::vec3(0, 0, -1));
_sceneGraph->evaluate(_mainCamera);
}
@@ -212,7 +207,7 @@ void RenderEngine::render()
// render the scene starting from the root node
_abuffer->clear();
_abuffer->preRender();
_sceneGraph->render(_mainCamera);
_sceneGraph->render({*_mainCamera, psc()});
_abuffer->postRender();
_abuffer->resolve();
@@ -227,21 +222,15 @@ void RenderEngine::render()
#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 * 20, "OpenSpace Time: (%s)", timeGUI.c_str());
const std::string time = Time::ref().currentTimeUTC().c_str();
std::string&& time = Time::ref().currentTimeUTC().c_str();
Freetype::print(
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
FONT_SIZE, FONT_SIZE * 18, "Date: %s", time.c_str()
@@ -306,164 +295,164 @@ void RenderEngine::serialize(std::vector<char>& dataStream, size_t& offset) {
// camera->scaling
const glm::vec2 scaling = _mainCamera->scaling();
const psc position = _mainCamera->position();
//const psc origin = OsEng.interactionHandler().getOrigin();
//const pss pssl = (position - origin).length();
//_mainCamera->cameraDirection()
//const glm::vec2 scaling = _mainCamera->scaling();
//const psc position = _mainCamera->position();
////const psc origin = OsEng.interactionHandler().getOrigin();
////const pss pssl = (position - origin).length();
////_mainCamera->cameraDirection()
union storage {
float value;
std::array<char, 4> representation;
} s;
//union storage {
// float value;
// std::array<char, 4> representation;
//} s;
s.value = _mainCamera->cameraDirection().x;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->cameraDirection().x;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->cameraDirection().y;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->cameraDirection().y;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->cameraDirection().z;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->cameraDirection().z;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->rotation().x;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->rotation().x;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->rotation().y;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->rotation().y;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->rotation().z;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->rotation().z;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->rotation().w;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->rotation().w;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->position().vec4().x;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->position().vec4().x;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->position().vec4().y;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->position().vec4().y;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->position().vec4().z;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->position().vec4().z;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
s.value = _mainCamera->position().vec4().w;
dataStream[offset++] = s.representation[0];
dataStream[offset++] = s.representation[1];
dataStream[offset++] = s.representation[2];
dataStream[offset++] = s.representation[3];
//s.value = _mainCamera->position().vec4().w;
//dataStream[offset++] = s.representation[0];
//dataStream[offset++] = s.representation[1];
//dataStream[offset++] = s.representation[2];
//dataStream[offset++] = s.representation[3];
}
void RenderEngine::deserialize(const std::vector<char>& dataStream, size_t& offset) {
// TODO: This has to be redone properly (ab)
union storage {
float value;
std::array<char, 4> representation;
} s;
// union storage {
// float value;
// std::array<char, 4> representation;
// } s;
glm::vec3 cameraDirection;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
cameraDirection.x = s.value;
// glm::vec3 cameraDirection;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// cameraDirection.x = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
cameraDirection.y = s.value;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// cameraDirection.y = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
cameraDirection.z = s.value;
_mainCamera->setCameraDirection(cameraDirection);
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// cameraDirection.z = s.value;
// _mainCamera->setCameraDirection(cameraDirection);
glm::quat rotation;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
rotation.x = s.value;
// glm::quat rotation;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// rotation.x = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
rotation.y = s.value;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// rotation.y = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
rotation.z = s.value;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// rotation.z = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
rotation.w = s.value;
_mainCamera->setRotation(rotation);
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// rotation.w = s.value;
// _mainCamera->setRotation(rotation);
glm::vec4 position;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
position.x = s.value;
// glm::vec4 position;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// position.x = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
position.y = s.value;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// position.y = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
position.z = s.value;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// position.z = s.value;
s.representation[0] = dataStream[offset++];
s.representation[1] = dataStream[offset++];
s.representation[2] = dataStream[offset++];
s.representation[3] = dataStream[offset++];
position.w = s.value;
// s.representation[0] = dataStream[offset++];
// s.representation[1] = dataStream[offset++];
// s.representation[2] = dataStream[offset++];
// s.representation[3] = dataStream[offset++];
// position.w = s.value;
_mainCamera->setPosition(position);
//_mainCamera->setPosition(position);
}
Camera* RenderEngine::camera() const {
+7 -7
View File
@@ -28,7 +28,7 @@
#include <limits>
#include <vector>
#include <iomanip>
#include <iterator>
// openspace includes
#include <openspace/rendering/stars/renderablestars.h>
@@ -306,7 +306,7 @@ bool RenderableStars::deinitialize(){
}
//#define TMAT
void RenderableStars::render(const Camera* camera, const psc& thisPosition, RuntimeData* runtimeData){
void RenderableStars::render(const RenderData& data){
assert(_haloProgram);
printOpenGLError();
// activate shader
@@ -327,9 +327,9 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt
//glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
#ifdef GLSPRITES
glm::mat4 modelMatrix = camera->modelMatrix();
glm::mat4 viewMatrix = camera->viewMatrix();
glm::mat4 projectionMatrix = camera->projectionMatrix();
glm::mat4 modelMatrix = data.camera.modelMatrix();
glm::mat4 viewMatrix = data.camera.viewMatrix();
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
// ---------------------- RENDER HALOS -----------------------------
_haloProgram->setUniform("model", modelMatrix);
@@ -338,7 +338,7 @@ void RenderableStars::render(const Camera* camera, const psc& thisPosition, Runt
//_haloProgram->setUniform("ViewProjection", camera->viewProjectionMatrix());
_haloProgram->setUniform("ModelTransform", glm::mat4(1));
setPscUniforms(_haloProgram, camera, thisPosition);
setPscUniforms(_haloProgram, &data.camera, data.position);
_haloProgram->setUniform("scaling", scaling);
// Bind texure
@@ -397,7 +397,7 @@ void RenderableStars::loadTexture(){
}
}
void RenderableStars::update()
void RenderableStars::update(const UpdateData& data)
{
}
+1 -1
View File
@@ -68,6 +68,6 @@ bool Ephemeris::initialize() {
return true;
}
void Ephemeris::update() {}
void Ephemeris::update(const UpdateData& data) {}
} // namespace openspace
+170 -108
View File
@@ -32,6 +32,7 @@
#include <openspace/util/constants.h>
#include <openspace/util/shadercreator.h>
#include <openspace/query/query.h>
#include <openspace/util/time.h>
// ghoul includes
#include "ghoul/opengl/programobject.h"
@@ -173,13 +174,29 @@ int property_getValue(lua_State* L) {
return 1;
}
/**
* \ingroup LuaScripts
* getPropertyValue(string):
* Returns the value of the property identified by the passed URI as a Lua object that can
* be passed to the setPropertyValue method.
*/
int loadScene(lua_State* L) {
const std::string _loggerCat = "loadScene";
// TODO Check for argument number (ab)
std::string sceneFile = luaL_checkstring(L, -1);
OsEng.renderEngine().sceneGraph()->scheduleLoadSceneFile(sceneFile);
return 0;
}
} // namespace luascriptfunctions
SceneGraph::SceneGraph()
: _focus(SceneGraphNode::RootNodeName)
, _position(SceneGraphNode::RootNodeName)
, _root(nullptr)
, _runtimeData(nullptr)
{
}
@@ -188,10 +205,6 @@ SceneGraph::~SceneGraph()
deinitialize();
}
void SceneGraph::setRuntimeData(RuntimeData* runtimeData){
_runtimeData = runtimeData;
}
bool SceneGraph::initialize()
{
LDEBUG("Initializing SceneGraph");
@@ -206,8 +219,7 @@ bool SceneGraph::initialize()
typedef std::chrono::high_resolution_clock clock_;
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> beg_(clock_::now());
std::chrono::time_point<clock_> beginning(clock_::now());
// pscstandard
tmpProgram = sc.buildShader("pscstandard",
@@ -267,8 +279,8 @@ bool SceneGraph::initialize()
double elapsed = std::chrono::duration_cast<second_>(clock_::now() - beg_).count();
LERROR("Time to load shaders: " << elapsed);
double elapsed = std::chrono::duration_cast<second_>(clock_::now()-beginning).count();
LINFO("Time to load shaders: " << elapsed);
/*
@@ -432,9 +444,147 @@ bool SceneGraph::initialize()
*/
//>>>>>>> develop
return true;
}
bool SceneGraph::deinitialize()
{
clearSceneGraph();
return true;
}
void SceneGraph::update(const UpdateData& data)
{
if (!_sceneGraphToLoad.empty()) {
OsEng.renderEngine().sceneGraph()->clearSceneGraph();
bool success = loadSceneInternal(_sceneGraphToLoad);
_sceneGraphToLoad = "";
if (!success)
return;
}
for (auto node : _nodes)
node->update(data);
}
void SceneGraph::evaluate(Camera* camera)
{
if (_root)
_root->evaluate(camera);
}
void SceneGraph::render(const RenderData& data)
{
if (_root)
_root->render(data);
}
void SceneGraph::scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath) {
_sceneGraphToLoad = sceneDescriptionFilePath;
}
void SceneGraph::clearSceneGraph() {
// deallocate the scene graph. Recursive deallocation will occur
delete _root;
_root = nullptr;
_nodes.erase(_nodes.begin(), _nodes.end());
_allNodes.erase(_allNodes.begin(), _allNodes.end());
_focus.clear();
_position.clear();
}
bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath)
{
using ghoul::Dictionary;
using ghoul::lua::loadDictionaryFromFile;
if (!FileSys.fileExists(sceneDescriptionFilePath)) {
LFATAL("Scene description file '" << sceneDescriptionFilePath << "' not found");
return false;
}
LDEBUG("Loading scenegraph nodes");
if (_root != nullptr) {
LFATAL("Scenegraph already loaded");
return false;
}
// initialize the root node
_root = new SceneGraphNode();
_root->setName(SceneGraphNode::RootNodeName);
_nodes.push_back(_root);
_allNodes.emplace(SceneGraphNode::RootNodeName, _root);
Dictionary dictionary;
//load default.scene
loadDictionaryFromFile(sceneDescriptionFilePath, dictionary);
std::string&& sceneDescriptionDirectory =
ghoul::filesystem::File(sceneDescriptionFilePath).directoryName();
std::string moduleDirectory(".");
dictionary.getValueSafe(constants::scenegraph::keyPathScene, moduleDirectory);
// The scene path could either be an absolute or relative path to the description
// paths directory
std::string&& relativeCandidate = sceneDescriptionDirectory +
ghoul::filesystem::FileSystem::PathSeparator + moduleDirectory;
std::string&& absoluteCandidate = absPath(moduleDirectory);
if (FileSys.directoryExists(relativeCandidate))
moduleDirectory = relativeCandidate;
else if (FileSys.directoryExists(absoluteCandidate))
moduleDirectory = absoluteCandidate;
else {
LFATAL("The '" << constants::scenegraph::keyPathScene << "' pointed to a "
"path '" << moduleDirectory << "' that did not exist");
return false;
}
Dictionary moduleDictionary;
if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) {
std::vector<std::string> keys = moduleDictionary.keys();
std::sort(keys.begin(), keys.end());
for (const std::string& key : keys) {
std::string moduleFolder;
if (moduleDictionary.getValue(key, moduleFolder))
loadModule(moduleDirectory + "/" + moduleFolder);
}
}
// TODO: Make it less hard-coded and more flexible when nodes are not found
Dictionary cameraDictionary;
if (dictionary.getValue(constants::scenegraph::keyCamera, cameraDictionary)) {
LDEBUG("Camera dictionary found");
std::string focus;
std::string position;
if (cameraDictionary.hasKey(constants::scenegraph::keyFocusObject)
&& cameraDictionary.getValue(constants::scenegraph::keyFocusObject, focus)) {
auto focusIterator = _allNodes.find(focus);
if (focusIterator != _allNodes.end()) {
_focus = focus;
LDEBUG("Setting camera focus to '" << _focus << "'");
}
else
LERROR("Could not find focus object '" << focus << "'");
}
if (cameraDictionary.hasKey(constants::scenegraph::keyPositionObject)
&& cameraDictionary.getValue(constants::scenegraph::keyPositionObject, position)) {
auto positionIterator = _allNodes.find(position);
if (positionIterator != _allNodes.end()) {
_position = position;
LDEBUG("Setting camera position to '" << _position << "'");
}
else
LERROR("Could not find object '" << position << "' to position camera");
}
}
// Initialize all nodes
for (auto node : _nodes) {
bool success = node->initialize(_runtimeData);
bool success = node->initialize();
if (success)
LDEBUG(node->name() << " initialized successfully!");
else
@@ -442,7 +592,9 @@ bool SceneGraph::initialize()
}
// update the position of all nodes
update();
// TODO need to check this; unnecessary? (ab)
for (auto node : _nodes)
node->update({Time::ref().currentTime()});
// Calculate the bounding sphere for the scenegraph
_root->calculateBoundingSphere();
@@ -484,102 +636,6 @@ bool SceneGraph::initialize()
return true;
}
bool SceneGraph::deinitialize()
{
// deallocate the scene graph. Recursive deallocation will occur
delete _root;
_root = nullptr;
_nodes.erase(_nodes.begin(), _nodes.end());
_allNodes.erase(_allNodes.begin(), _allNodes.end());
_focus.clear();
_position.clear();
return true;
}
void SceneGraph::update()
{
for (auto node : _nodes)
node->update();
}
void SceneGraph::evaluate(Camera* camera)
{
_root->evaluate(camera);
}
void SceneGraph::render(Camera* camera)
{
_root->render(camera);
}
bool SceneGraph::loadScene(const std::string& sceneDescriptionFilePath,
const std::string& defaultModulePath)
{
using ghoul::Dictionary;
using ghoul::lua::loadDictionaryFromFile;
LDEBUG("Loading scenegraph nodes");
if (_root != nullptr) {
LFATAL("Scenegraph already loaded");
return false;
}
// initialize the root node
_root = new SceneGraphNode();
_root->setName(SceneGraphNode::RootNodeName);
_nodes.push_back(_root);
_allNodes.emplace(SceneGraphNode::RootNodeName, _root);
Dictionary dictionary;
//load default.scene
loadDictionaryFromFile(sceneDescriptionFilePath, dictionary);
Dictionary moduleDictionary;
if (dictionary.getValue(constants::scenegraph::keyModules, moduleDictionary)) {
std::vector<std::string> keys = moduleDictionary.keys();
std::sort(keys.begin(), keys.end());
for (const std::string& key : keys) {
std::string moduleFolder;
if (moduleDictionary.getValue(key, moduleFolder))
loadModule(defaultModulePath + "/" + moduleFolder);
}
}
// TODO: Make it less hard-coded and more flexible when nodes are not found
Dictionary cameraDictionary;
if (dictionary.getValue(constants::scenegraph::keyCamera, cameraDictionary)) {
LDEBUG("Camera dictionary found");
std::string focus;
std::string position;
if (cameraDictionary.hasKey(constants::scenegraph::keyFocusObject)
&& cameraDictionary.getValue(constants::scenegraph::keyFocusObject, focus)) {
auto focusIterator = _allNodes.find(focus);
if (focusIterator != _allNodes.end()) {
_focus = focus;
LDEBUG("Setting camera focus to '" << _focus << "'");
}
else
LERROR("Could not find focus object '" << focus << "'");
}
if (cameraDictionary.hasKey(constants::scenegraph::keyPositionObject)
&& cameraDictionary.getValue(constants::scenegraph::keyPositionObject, position)) {
auto positionIterator = _allNodes.find(position);
if (positionIterator != _allNodes.end()) {
_position = position;
LDEBUG("Setting camera position to '" << _position << "'");
}
else
LERROR("Could not find object '" << position << "' to position camera");
}
}
return true;
}
void SceneGraph::loadModule(const std::string& modulePath)
{
auto pos = modulePath.find_last_of("/");
@@ -650,7 +706,13 @@ scripting::ScriptEngine::LuaLibrary SceneGraph::luaLibrary() {
"getPropertyValue",
&luascriptfunctions::property_getValue,
"getPropertyValue(string): Returns the value the property, identified by "
"the provided URI, has"
"the provided URI."
},
{
"loadScene",
&luascriptfunctions::loadScene,
"loadScene(string): Loads the scene found at the file passed as an "
"argument. If a scene is already loaded, it is unloaded first"
}
}
};
+12 -10
View File
@@ -128,7 +128,6 @@ SceneGraphNode::SceneGraphNode()
, _renderable(nullptr)
, _renderableVisible(false)
, _boundingSphereVisible(false)
, _runtimeData(nullptr)
{
}
@@ -137,7 +136,7 @@ SceneGraphNode::~SceneGraphNode()
deinitialize();
}
bool SceneGraphNode::initialize(RuntimeData* runtimeData)
bool SceneGraphNode::initialize()
{
if (_renderable != nullptr)
_renderable->initialize();
@@ -145,7 +144,6 @@ bool SceneGraphNode::initialize(RuntimeData* runtimeData)
if (_ephemeris != nullptr)
_ephemeris->initialize();
_runtimeData = runtimeData;
return true;
}
@@ -173,9 +171,12 @@ bool SceneGraphNode::deinitialize()
}
// essential
void SceneGraphNode::update()
void SceneGraphNode::update(const UpdateData& data)
{
_ephemeris->update(_runtimeData);
if (_ephemeris)
_ephemeris->update(data);
if (_renderable)
_renderable->update(data);
}
void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition)
@@ -220,9 +221,11 @@ void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition)
}
}
void SceneGraphNode::render(const Camera* camera, const psc& parentPosition)
void SceneGraphNode::render(const RenderData& data)
{
const psc thisPosition = parentPosition + _ephemeris->position();
const psc thisPosition = data.position + _ephemeris->position();
RenderData newData = {data.camera, thisPosition};
// check if camera is outside the node boundingsphere
/*if (!_boundingSphereVisible) {
@@ -231,13 +234,13 @@ void SceneGraphNode::render(const Camera* camera, const psc& parentPosition)
if (_renderableVisible && _renderable->isVisible()) {
// LDEBUG("Render");
_renderable->render(camera, thisPosition, _runtimeData);
_renderable->render(newData);
}
// evaluate all the children, tail-recursive function(?)
for (auto& child : _children) {
child->render(camera, thisPosition);
child->render(newData);
}
}
@@ -317,7 +320,6 @@ PowerScaledScalar SceneGraphNode::boundingSphere() const{
// renderable
void SceneGraphNode::setRenderable(Renderable* renderable) {
_renderable = renderable;
update();
}
const Renderable* SceneGraphNode::renderable() const
+2 -4
View File
@@ -78,15 +78,13 @@ const psc& SpiceEphemeris::position() const {
return _position;
}
void SpiceEphemeris::update(RuntimeData* runtimeData) {
void SpiceEphemeris::update(const UpdateData& data) {
double state[3];
_currentEphemerisTime = runtimeData->getTime();
glm::dvec3 position(0,0,0);
double lightTime = 0.0;
SpiceManager::ref().getTargetPosition(_targetName, _currentEphemerisTime, "GALACTIC", "LT+S", _originName, position, lightTime);
SpiceManager::ref().getTargetPosition(_targetName, data.time, "GALACTIC", "LT+S", _originName, position, lightTime);
/*
std::cout << _targetName << " (";
+1 -1
View File
@@ -47,7 +47,7 @@ const psc& StaticEphemeris::position() const {
return _position;
}
void StaticEphemeris::update(RuntimeData* runtimeData) {
void StaticEphemeris::update(const UpdateData&) {
}
+20
View File
@@ -122,6 +122,20 @@ namespace luascriptfunctions {
return 0;
}
/**
* \ingroup LuaScripts
* absPath(string):
* Passes the argument to FileSystem::absolutePath, which resolves occuring path
* tokens and returns the absolute path.
*/
int absolutePath(lua_State* L) {
// TODO check number of arguments (ab)
std::string path = luaL_checkstring(L, -1);
path = absPath(path);
lua_pushstring(L, path.c_str());
return 1;
}
} // namespace luascriptfunctions
namespace scripting {
@@ -371,6 +385,12 @@ void ScriptEngine::addBaseLibrary() {
&luascriptfunctions::printFatal,
"printFatal(*): Logs the passed value to the installed LogManager with a "
"LogLevel of 'Fatal'"
},
{
"absPath",
&luascriptfunctions::absolutePath,
"absPath(string): Returns the absolute path to the passed path, resolving"
" path tokens as well as resolving relative paths"
}
}
};
+1 -1
View File
@@ -599,7 +599,7 @@ void KameleonWrapper::progressBar(int current, int end) {
int spWidth = barWidth - pos + 2;
std::cout << "[" << std::setfill('=') << std::setw(eqWidth)
<< ">" << std::setfill(' ') << std::setw(spWidth)
<< "] " << iprogress << " % \r" << std::flush;
<< "] " << std::setfill(' ') << std::setw(3) << iprogress << " % \r" << std::flush;
}
_lastiProgress = iprogress;
}