mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-03 01:59:35 -06:00
Cleaning up OpenSpaceEngine and RenderEngine
This commit is contained in:
Submodule ext/ghoul updated: dee11fd362...45704e45f7
@@ -77,7 +77,11 @@ private:
|
||||
OpenSpaceEngine(std::string programName);
|
||||
~OpenSpaceEngine();
|
||||
|
||||
void clearAllWindows();
|
||||
bool gatherCommandlineArguments();
|
||||
bool loadSpiceKernels();
|
||||
void runStartupScripts();
|
||||
void loadFonts();
|
||||
|
||||
static OpenSpaceEngine* _engine;
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ public:
|
||||
unsigned int commandInputButton();
|
||||
unsigned int ignoreCodepoint();
|
||||
|
||||
|
||||
private:
|
||||
void addToCommand(std::string c);
|
||||
std::string UnicodeToUTF8(unsigned int codepoint);
|
||||
|
||||
@@ -53,10 +53,10 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace openspace::scripting;
|
||||
using namespace ghoul::filesystem;
|
||||
using namespace ghoul::logging;
|
||||
|
||||
using namespace openspace::scripting;
|
||||
using namespace ghoul::cmdparser;
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "OpenSpaceEngine";
|
||||
@@ -70,7 +70,6 @@ namespace {
|
||||
} commandlineArgumentPlaceholders;
|
||||
}
|
||||
|
||||
using namespace ghoul::cmdparser;
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -82,24 +81,41 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName)
|
||||
, _console(nullptr)
|
||||
, _syncBuffer(nullptr)
|
||||
{
|
||||
// initialize OpenSpace helpers
|
||||
SpiceManager::initialize();
|
||||
Time::initialize();
|
||||
DeviceIdentifier::init();
|
||||
FactoryManager::initialize();
|
||||
ghoul::systemcapabilities::SystemCapabilities::initialize();
|
||||
}
|
||||
|
||||
OpenSpaceEngine::~OpenSpaceEngine() {
|
||||
if (_console)
|
||||
delete _console;
|
||||
|
||||
ghoul::systemcapabilities::SystemCapabilities::deinitialize();
|
||||
FactoryManager::deinitialize();
|
||||
DeviceIdentifier::deinit();
|
||||
Time::deinitialize();
|
||||
SpiceManager::deinitialize();
|
||||
Time::deinitialize();
|
||||
DeviceIdentifier::deinit();
|
||||
FileSystem::deinitialize();
|
||||
LogManager::deinitialize();
|
||||
}
|
||||
|
||||
OpenSpaceEngine& OpenSpaceEngine::ref() {
|
||||
assert(_engine);
|
||||
return *_engine;
|
||||
}
|
||||
|
||||
|
||||
void OpenSpaceEngine::clearAllWindows() {
|
||||
size_t n = sgct::Engine::instance()->getNumberOfWindows();
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GLFWwindow* win = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle();
|
||||
glfwSwapBuffers(win);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::gatherCommandlineArguments() {
|
||||
// TODO: Get commandline arguments from all modules
|
||||
|
||||
@@ -135,21 +151,77 @@ bool OpenSpaceEngine::findConfiguration(std::string& filename) {
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::loadSpiceKernels() {
|
||||
// Load time kernel
|
||||
using constants::configurationmanager::keySpiceTimeKernel;
|
||||
std::string timeKernel;
|
||||
bool success = configurationManager().getValue(keySpiceTimeKernel, timeKernel);
|
||||
if (!success) {
|
||||
LERROR("Configuration file does not contain a '" << keySpiceTimeKernel << "'");
|
||||
return false;
|
||||
}
|
||||
SpiceManager::KernelIdentifier id =
|
||||
SpiceManager::ref().loadKernel(timeKernel);
|
||||
if (id == SpiceManager::KernelFailed) {
|
||||
LERROR("Error loading time kernel '" << timeKernel << "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load SPICE leap second kernel
|
||||
using constants::configurationmanager::keySpiceLeapsecondKernel;
|
||||
std::string leapSecondKernel;
|
||||
success = configurationManager().getValue(keySpiceLeapsecondKernel, leapSecondKernel);
|
||||
if (!success) {
|
||||
LERROR("Configuration file does not have a '" << keySpiceLeapsecondKernel << "'");
|
||||
return false;
|
||||
}
|
||||
id = SpiceManager::ref().loadKernel(std::move(leapSecondKernel));
|
||||
if (id == SpiceManager::KernelFailed) {
|
||||
LERROR("Error loading leap second kernel '" << leapSecondKernel << "'");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::runStartupScripts() {
|
||||
ghoul::Dictionary scripts;
|
||||
configurationManager().getValue(
|
||||
constants::configurationmanager::keyStartupScript, scripts);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::loadFonts() {
|
||||
sgct_text::FontManager::FontPath local = sgct_text::FontManager::FontPath::FontPath_Local;
|
||||
sgct_text::FontManager::instance()->addFont(constants::fonts::keyMono, absPath("${FONTS}/Droid_Sans_Mono/DroidSansMono.ttf"), local);
|
||||
sgct_text::FontManager::instance()->addFont(constants::fonts::keyLight, absPath("${FONTS}/Roboto/Roboto-Regular.ttf"), local);
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::create(int argc, char** argv,
|
||||
std::vector<std::string>& sgctArguments)
|
||||
{
|
||||
// TODO custom assert (ticket #5)
|
||||
assert(_engine == nullptr);
|
||||
|
||||
// initialize Ghoul logging
|
||||
// initialize Ghoul classes
|
||||
LogManager::initialize(LogManager::LogLevel::Debug, true);
|
||||
LogMgr.addLog(new ConsoleLog);
|
||||
|
||||
|
||||
// Initialize FileSystem
|
||||
ghoul::filesystem::FileSystem::initialize();
|
||||
|
||||
|
||||
// Sanity check of values
|
||||
if (argc < 1) {
|
||||
LFATAL("No arguments were passed to the function");
|
||||
@@ -160,13 +232,11 @@ bool OpenSpaceEngine::create(int argc, char** argv,
|
||||
LDEBUG("Creating OpenSpaceEngine");
|
||||
_engine = new OpenSpaceEngine(std::string(argv[0]));
|
||||
|
||||
|
||||
// Query modules for commandline arguments
|
||||
const bool gatherSuccess = _engine->gatherCommandlineArguments();
|
||||
if (!gatherSuccess)
|
||||
return false;
|
||||
|
||||
|
||||
// Parse commandline arguments
|
||||
std::vector<std::string> remainingArguments;
|
||||
_engine->_commandlineParser.setCommandLine(argc, argv, &sgctArguments);
|
||||
@@ -198,10 +268,14 @@ bool OpenSpaceEngine::create(int argc, char** argv,
|
||||
}
|
||||
|
||||
// make sure cache is registered, false since we don't want to override
|
||||
FileSys.registerPathToken("${CACHE}", "${BASE_PATH}/cache", false);
|
||||
auto tokens = FileSys.tokens();
|
||||
const std::string cacheToken = "${CACHE}";
|
||||
auto cacheIterator = std::find(tokens.begin(), tokens.end(), cacheToken);
|
||||
if (cacheIterator != tokens.end()){
|
||||
FileSys.registerPathToken(cacheToken, "${BASE_PATH}/cache");
|
||||
}
|
||||
|
||||
// Create directories that doesn't exsist
|
||||
auto tokens = FileSys.tokens();
|
||||
for (auto token : tokens) {
|
||||
if (!FileSys.directoryExists(token)) {
|
||||
std::string p = absPath(token);
|
||||
@@ -212,7 +286,7 @@ bool OpenSpaceEngine::create(int argc, char** argv,
|
||||
}
|
||||
|
||||
// Create the cachemanager
|
||||
FileSys.createCacheManager("${CACHE}");
|
||||
FileSys.createCacheManager(cacheToken);
|
||||
|
||||
_engine->_console = new LuaConsole();
|
||||
_engine->_syncBuffer = new SyncBuffer(1024);
|
||||
@@ -233,7 +307,9 @@ bool OpenSpaceEngine::create(int argc, char** argv,
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::destroy() {
|
||||
delete _engine;
|
||||
delete _engine;
|
||||
FileSystem::deinitialize();
|
||||
LogManager::deinitialize();
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::isInitialized() {
|
||||
@@ -243,88 +319,35 @@ bool OpenSpaceEngine::isInitialized() {
|
||||
bool OpenSpaceEngine::initialize() {
|
||||
// clear the screen so the user don't have to see old buffer contents from the
|
||||
// graphics card
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GLFWwindow* win = sgct::Engine::instance()->getActiveWindowPtr()->getWindowHandle();
|
||||
glfwSwapBuffers(win);
|
||||
clearAllWindows();
|
||||
|
||||
// Detect and log OpenCL and OpenGL versions and available devices
|
||||
ghoul::systemcapabilities::SystemCapabilities::initialize();
|
||||
SysCap.addComponent(new ghoul::systemcapabilities::CPUCapabilitiesComponent);
|
||||
//SysCap.addComponent(new ghoul::systemcapabilities::OpenCLCapabilitiesComponent);
|
||||
SysCap.addComponent(new ghoul::systemcapabilities::OpenGLCapabilitiesComponent);
|
||||
SysCap.detectCapabilities();
|
||||
SysCap.logCapabilities();
|
||||
|
||||
// initialize OpenSpace helpers
|
||||
SpiceManager::initialize();
|
||||
Time::initialize();
|
||||
|
||||
// Load SPICE time kernel
|
||||
using constants::configurationmanager::keySpiceTimeKernel;
|
||||
std::string timeKernel;
|
||||
bool success = configurationManager().getValue(keySpiceTimeKernel, timeKernel);
|
||||
if (!success) {
|
||||
LERROR("Configuration file does not contain a '" << keySpiceTimeKernel << "'");
|
||||
bool success = loadSpiceKernels();
|
||||
if (!success)
|
||||
return false;
|
||||
}
|
||||
SpiceManager::KernelIdentifier id =
|
||||
SpiceManager::ref().loadKernel(timeKernel);
|
||||
if (id == SpiceManager::KernelFailed) {
|
||||
LERROR("Error loading time kernel '" << timeKernel << "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load SPICE leap second kernel
|
||||
using constants::configurationmanager::keySpiceLeapsecondKernel;
|
||||
std::string leapSecondKernel;
|
||||
success = configurationManager().getValue(keySpiceLeapsecondKernel, leapSecondKernel);
|
||||
if (!success) {
|
||||
LERROR("Configuration file does not have a '" << keySpiceLeapsecondKernel << "'");
|
||||
return false;
|
||||
}
|
||||
id = SpiceManager::ref().loadKernel(std::move(leapSecondKernel));
|
||||
if (id == SpiceManager::KernelFailed) {
|
||||
LERROR("Error loading leap second kernel '" << leapSecondKernel << "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
//// metakernel loading doesnt seem to work... it should. to tired to even
|
||||
//// CK
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/ck/merged_nhpc_2006_v011.bc");
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/ck/merged_nhpc_2007_v006.bc");
|
||||
//// FK
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/fk/nh_v200.tf");
|
||||
//// IK
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/ik/nh_lorri_v100.ti");
|
||||
//// LSK already loaded
|
||||
////PCK
|
||||
////SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/pck/pck00008.tpc");
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/pck/new_horizons_413.tsc");
|
||||
////SPK
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/de413.bsp");
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/jup260.bsp");
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/nh_nep_ura_000.bsp");
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/nh_recon_e2j_v1.bsp");
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/nh_recon_j2sep07_prelimv1.bsp");
|
||||
//SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/sb_2002jf56_2.bsp");
|
||||
|
||||
FactoryManager::initialize();
|
||||
|
||||
scriptEngine().initialize();
|
||||
// Initialize the script engine
|
||||
_scriptEngine.initialize();
|
||||
|
||||
// Register Lua script functions
|
||||
LDEBUG("Registering Lua libraries");
|
||||
scriptEngine().addLibrary(RenderEngine::luaLibrary());
|
||||
scriptEngine().addLibrary(SceneGraph::luaLibrary());
|
||||
scriptEngine().addLibrary(Time::luaLibrary());
|
||||
scriptEngine().addLibrary(InteractionHandler::luaLibrary());
|
||||
_scriptEngine.addLibrary(RenderEngine::luaLibrary());
|
||||
_scriptEngine.addLibrary(SceneGraph::luaLibrary());
|
||||
_scriptEngine.addLibrary(Time::luaLibrary());
|
||||
_scriptEngine.addLibrary(InteractionHandler::luaLibrary());
|
||||
|
||||
// TODO: Maybe move all scenegraph and renderengine stuff to initializeGL
|
||||
// Load scenegraph
|
||||
SceneGraph* sceneGraph = new SceneGraph;
|
||||
_renderEngine.setSceneGraph(sceneGraph);
|
||||
|
||||
// initialize the RenderEngine, needs ${SCENEPATH} to be set
|
||||
// initialize the RenderEngine
|
||||
_renderEngine.initialize();
|
||||
sceneGraph->initialize();
|
||||
|
||||
@@ -335,37 +358,14 @@ bool OpenSpaceEngine::initialize() {
|
||||
sceneGraph->scheduleLoadSceneFile(sceneDescriptionPath);
|
||||
|
||||
// Initialize OpenSpace input devices
|
||||
DeviceIdentifier::init();
|
||||
DeviceIdentifier::ref().scanDevices();
|
||||
_interactionHandler.connectDevices();
|
||||
|
||||
// Run start up scripts
|
||||
ghoul::Dictionary scripts;
|
||||
success = configurationManager().getValue(
|
||||
constants::configurationmanager::keyStartupScript, scripts);
|
||||
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);
|
||||
}
|
||||
runStartupScripts();
|
||||
|
||||
// Load a light and a monospaced font
|
||||
//sgct_text::FontManager::instance()->addFont(constants::fonts::keyMono, "ubuntu-font-family/UbuntuMono-R.ttf", absPath("${FONTS}/"));
|
||||
//sgct_text::FontManager::instance()->addFont(constants::fonts::keyLight, "ubuntu-font-family/Ubuntu-L.ttf", absPath("${FONTS}/"));
|
||||
sgct_text::FontManager::FontPath local = sgct_text::FontManager::FontPath::FontPath_Local;
|
||||
sgct_text::FontManager::instance()->addFont(constants::fonts::keyMono, absPath("${FONTS}/Droid_Sans_Mono/DroidSansMono.ttf"), local);
|
||||
sgct_text::FontManager::instance()->addFont(constants::fonts::keyLight, absPath("${FONTS}/Roboto/Roboto-Regular.ttf"), local);
|
||||
loadFonts();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -392,10 +392,7 @@ bool OpenSpaceEngine::initializeGL()
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::preSynchronization() {
|
||||
#ifdef WIN32
|
||||
// Sleeping for 0 milliseconds will trigger any pending asynchronous procedure calls
|
||||
SleepEx(0, TRUE);
|
||||
#endif
|
||||
FileSys.triggerFilesystemEvents();
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
const double dt = sgct::Engine::instance()->getDt();
|
||||
|
||||
|
||||
@@ -89,7 +89,12 @@ int main(int argc, char** argv)
|
||||
|
||||
// try to open a window
|
||||
LDEBUG("Initialize SGCT Engine");
|
||||
const bool initSuccess = _sgctEngine->init(sgct::Engine::OpenGL_4_3_Core_Profile);
|
||||
#ifdef __APPLE__
|
||||
sgct::Engine::RunMode rm = sgct::Engine::RunMode::OpenGL_4_1_Core_Profile;
|
||||
#else
|
||||
sgct::Engine::RunMode rm = sgct::Engine::RunMode::OpenGL_4_3_Core_Profile;
|
||||
#endif
|
||||
const bool initSuccess = _sgctEngine->init(rm);
|
||||
if (!initSuccess) {
|
||||
LFATAL("Initializing failed");
|
||||
// could not open a window, deallocates and exits
|
||||
|
||||
@@ -93,15 +93,11 @@ bool RenderEngine::initialize()
|
||||
{
|
||||
generateGlslConfig();
|
||||
|
||||
// LDEBUG("RenderEngine::initialize()");
|
||||
// init camera and set temporary position and scaling
|
||||
_mainCamera = new Camera();
|
||||
_mainCamera->setScaling(glm::vec2(1.0, -8.0));
|
||||
_mainCamera->setPosition(psc(0.f, 0.f, 1.499823f, 11.f));
|
||||
|
||||
// if master, setup interaction
|
||||
//if (sgct::Engine::instance()->isMaster())
|
||||
OsEng.interactionHandler().setCamera(_mainCamera);
|
||||
OsEng.interactionHandler().setCamera(_mainCamera);
|
||||
#if ABUFFER_IMPLEMENTATION == ABUFFER_SINGLE_LINKED
|
||||
_abuffer = new ABufferSingleLinked();
|
||||
#elif ABUFFER_IMPLEMENTATION == ABUFFER_FIXED
|
||||
@@ -117,16 +113,13 @@ bool RenderEngine::initializeGL()
|
||||
// LDEBUG("RenderEngine::initializeGL()");
|
||||
sgct::SGCTWindow* wPtr = sgct::Engine::instance()->getActiveWindowPtr();
|
||||
|
||||
// TODO: Fix the power scaled coordinates in such a way that these values can be
|
||||
// set
|
||||
// to more realistic values
|
||||
// TODO: Fix the power scaled coordinates in such a way that these
|
||||
// values can be set to more realistic values
|
||||
|
||||
// set the close clip plane and the far clip plane to extreme values while in
|
||||
// development
|
||||
sgct::Engine::instance()->setNearAndFarClippingPlanes(0.01f,10000.0f);
|
||||
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 1000.00f);
|
||||
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.0001f, 100.0f);
|
||||
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 200.0f);
|
||||
// sgct::Engine::instance()->setNearAndFarClippingPlanes(0.1f, 30.0f);
|
||||
|
||||
// calculating the maximum field of view for the camera, used to
|
||||
// determine visibility of objects in the scene graph
|
||||
@@ -181,7 +174,6 @@ bool RenderEngine::initializeGL()
|
||||
maxFov = radsbetween;
|
||||
}
|
||||
}
|
||||
// std::cout << maxFov << std::endl;
|
||||
_mainCamera->setMaxFov(maxFov);
|
||||
}
|
||||
|
||||
@@ -213,10 +205,8 @@ void RenderEngine::postSynchronizationPreDraw()
|
||||
_mainCamera->compileViewRotationMatrix();
|
||||
UpdateData a = { Time::ref().currentTime(), Time::ref().deltaTime() };
|
||||
|
||||
//std::cout << a.delta << std::endl;
|
||||
// update and evaluate the scene starting from the root node
|
||||
_sceneGraph->update(a);
|
||||
_mainCamera->setCameraDirection(glm::vec3(0, 0, -1));
|
||||
_sceneGraph->evaluate(_mainCamera);
|
||||
|
||||
// clear the abuffer before rendering the scene
|
||||
@@ -259,9 +249,6 @@ void RenderEngine::render()
|
||||
_abuffer->resolve();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
||||
#ifndef OPENSPACE_VIDEO_EXPORT
|
||||
|
||||
// Print some useful information on the master viewport
|
||||
sgct::SGCTWindow* w = sgct::Engine::instance()->getActiveWindowPtr();
|
||||
if (sgct::Engine::instance()->isMaster() && ! w->isUsingFisheyeRendering()) {
|
||||
@@ -361,9 +348,7 @@ void RenderEngine::render()
|
||||
++nr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RenderEngine::postDraw() {
|
||||
@@ -391,195 +376,21 @@ void RenderEngine::setSceneGraph(SceneGraph* sceneGraph)
|
||||
}
|
||||
|
||||
void RenderEngine::serialize(SyncBuffer* syncBuffer) {
|
||||
// TODO: This has to be redone properly (ab) [new class providing methods to serialize
|
||||
// variables]
|
||||
|
||||
// _viewRotation
|
||||
// _cameraDirection
|
||||
// camera->position
|
||||
// camera->viewRotationMatrix
|
||||
// camera->scaling
|
||||
|
||||
syncBuffer->encode(_mainCamera->scaling());
|
||||
syncBuffer->encode(_mainCamera->position());
|
||||
syncBuffer->encode(_mainCamera->viewRotationMatrix());
|
||||
//syncBuffer->encode(_mainCamera->lookUpVector());
|
||||
//syncBuffer->encode(_mainCamera->rotation());
|
||||
|
||||
|
||||
//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;
|
||||
|
||||
//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().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().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().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().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().w;
|
||||
//dataStream[offset++] = s.representation[0];
|
||||
//dataStream[offset++] = s.representation[1];
|
||||
//dataStream[offset++] = s.representation[2];
|
||||
//dataStream[offset++] = s.representation[3];
|
||||
}
|
||||
|
||||
void RenderEngine::deserialize(SyncBuffer* syncBuffer) {
|
||||
// TODO: This has to be redone properly (ab)
|
||||
|
||||
glm::vec2 scaling;
|
||||
psc position;
|
||||
glm::mat4 viewRotation;
|
||||
//glm::vec3 lookUpVector;
|
||||
syncBuffer->decode(scaling);
|
||||
syncBuffer->decode(position);
|
||||
syncBuffer->decode(viewRotation);
|
||||
|
||||
_mainCamera->setScaling(scaling);
|
||||
_mainCamera->setPosition(position);
|
||||
_mainCamera->setViewRotationMatrix(viewRotation);
|
||||
//_mainCamera->setLookUpVector(lookUpVector);
|
||||
//_mainCamera->compileViewRotationMatrix();
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
// 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);
|
||||
|
||||
// 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.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);
|
||||
|
||||
// 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.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;
|
||||
|
||||
//_mainCamera->setPosition(position);
|
||||
}
|
||||
|
||||
Camera* RenderEngine::camera() const {
|
||||
@@ -620,7 +431,6 @@ scripting::ScriptEngine::LuaLibrary RenderEngine::luaLibrary() {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user