mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 19:29:04 -05:00
Solved merge conflict
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#########################################################################################
|
||||
|
||||
set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/openspace.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/engine/configurationmanager.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/engine/downloadmanager.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/engine/logfactory.cpp
|
||||
@@ -65,6 +66,7 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/renderengine.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/renderengine_lua.inl
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/screenspacerenderable.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/rendering/transferfunction.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scene/ephemeris.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scene/scene.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/scene/scene_lua.inl
|
||||
@@ -76,6 +78,7 @@ set(OPENSPACE_SOURCE
|
||||
${OPENSPACE_BASE_DIR}/src/util/boxgeometry.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/camera.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/factorymanager.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/keys.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/openspacemodule.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/powerscaledcoordinate.cpp
|
||||
${OPENSPACE_BASE_DIR}/src/util/powerscaledscalar.cpp
|
||||
@@ -89,6 +92,7 @@ set(OPENSPACE_SOURCE
|
||||
)
|
||||
|
||||
set(OPENSPACE_HEADER
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/openspace.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/engine/configurationmanager.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/engine/downloadmanager.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/engine/logfactory.h
|
||||
@@ -138,6 +142,7 @@ set(OPENSPACE_HEADER
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/volume.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/screenspacerenderable.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/volumeraycaster.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/rendering/transferfunction.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scene/ephemeris.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scene/scene.h
|
||||
${OPENSPACE_BASE_DIR}/include/openspace/scene/scenegraph.h
|
||||
|
||||
@@ -34,7 +34,7 @@ using std::string;
|
||||
|
||||
namespace {
|
||||
const string _configurationFile = "openspace.cfg";
|
||||
const string _keyBasePath = "BASE_PATH";
|
||||
const string _keyBasePath = "BASE_PATH";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -91,24 +91,24 @@ string ConfigurationManager::findConfiguration(const string& filename) {
|
||||
}
|
||||
|
||||
void ConfigurationManager::loadFromFile(const string& filename) {
|
||||
using ghoul::filesystem::FileSystem;
|
||||
using ghoul::filesystem::FileSystem;
|
||||
|
||||
if (!FileSys.fileExists(filename))
|
||||
throw ghoul::FileNotFoundError(filename, "ConfigurationManager");
|
||||
|
||||
// ${BASE_PATH}
|
||||
string basePathToken = FileSystem::TokenOpeningBraces + _keyBasePath
|
||||
// ${BASE_PATH}
|
||||
string basePathToken = FileSystem::TokenOpeningBraces + _keyBasePath
|
||||
+ FileSystem::TokenClosingBraces;
|
||||
|
||||
// Retrieving the directory in which the configuration file lies
|
||||
// Retrieving the directory in which the configuration file lies
|
||||
string absolutePath = FileSys.absolutePath(filename);
|
||||
string basePath = ghoul::filesystem::File(absolutePath).directoryName();
|
||||
FileSys.registerPathToken(basePathToken, basePath);
|
||||
string basePath = ghoul::filesystem::File(absolutePath).directoryName();
|
||||
FileSys.registerPathToken(basePathToken, basePath);
|
||||
|
||||
// Loading the configuration file into ourselves
|
||||
// Loading the configuration file into ourselves
|
||||
ghoul::lua::loadDictionaryFromFile(filename, *this);
|
||||
|
||||
// Register all the paths
|
||||
// Register all the paths
|
||||
ghoul::Dictionary dictionary = value<ghoul::Dictionary>(KeyPaths);
|
||||
|
||||
std::vector<std::string> pathKeys = dictionary.keys();
|
||||
@@ -118,8 +118,8 @@ void ConfigurationManager::loadFromFile(const string& filename) {
|
||||
std::string fullKey =
|
||||
FileSystem::TokenOpeningBraces + key + FileSystem::TokenClosingBraces;
|
||||
LDEBUGC("ConfigurationManager", "Registering path " << fullKey << ": " << p);
|
||||
|
||||
bool override = (basePathToken == fullKey);
|
||||
|
||||
bool override = (basePathToken == fullKey);
|
||||
if (override)
|
||||
LINFOC("ConfigurationManager", "Overriding base path with '" << p << "'");
|
||||
|
||||
@@ -132,7 +132,7 @@ void ConfigurationManager::loadFromFile(const string& filename) {
|
||||
}
|
||||
}
|
||||
|
||||
bool complete = checkCompleteness();
|
||||
bool complete = checkCompleteness();
|
||||
if (!complete) {
|
||||
throw ghoul::RuntimeError(
|
||||
"Configuration file '" + filename + "' was not complete",
|
||||
@@ -140,34 +140,34 @@ void ConfigurationManager::loadFromFile(const string& filename) {
|
||||
);
|
||||
}
|
||||
|
||||
// Remove the Paths dictionary from the configuration manager as those paths might
|
||||
// change later and we don't want to be forced to keep our local copy up to date
|
||||
removeKey(KeyPaths);
|
||||
// Remove the Paths dictionary from the configuration manager as those paths might
|
||||
// change later and we don't want to be forced to keep our local copy up to date
|
||||
removeKey(KeyPaths);
|
||||
}
|
||||
|
||||
bool ConfigurationManager::checkCompleteness() const {
|
||||
std::vector<std::string> requiredTokens = {
|
||||
KeyPaths,
|
||||
KeyPaths + "." + KeyCache,
|
||||
KeyFonts,
|
||||
KeyConfigSgct
|
||||
};
|
||||
std::vector<std::string> requiredTokens = {
|
||||
KeyPaths,
|
||||
KeyPaths + "." + KeyCache,
|
||||
KeyFonts,
|
||||
KeyConfigSgct
|
||||
};
|
||||
|
||||
bool totalSuccess = true;
|
||||
for (const std::string& token : requiredTokens) {
|
||||
bool success = hasKey(token);
|
||||
bool totalSuccess = true;
|
||||
for (const std::string& token : requiredTokens) {
|
||||
bool success = hasKey(token);
|
||||
|
||||
if (!success) {
|
||||
LFATALC(
|
||||
LFATALC(
|
||||
"ConfigurationManager",
|
||||
"Configuration file did not contain required key '" << token << "'"
|
||||
);
|
||||
}
|
||||
|
||||
totalSuccess &= success;
|
||||
}
|
||||
totalSuccess &= success;
|
||||
}
|
||||
|
||||
return totalSuccess;
|
||||
return totalSuccess;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -370,7 +370,7 @@ void DownloadManager::getFileExtension(const std::string& url,
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
//USING CURLOPT NOBODY
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY,1);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY,1);
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
char *ct;
|
||||
|
||||
+36
-36
@@ -31,48 +31,48 @@
|
||||
#include <ghoul/logging/textlog.h>
|
||||
|
||||
namespace {
|
||||
const std::string keyType = "Type";
|
||||
const std::string keyFilename = "FileName";
|
||||
const std::string keyAppend = "Append";
|
||||
const std::string keyTimeStamping = "TimeStamping";
|
||||
const std::string keyDateStamping = "DateStamping";
|
||||
const std::string keyCategoryStamping = "CategoryStamping";
|
||||
const std::string keyLogLevelStamping = "LogLevelStamping";
|
||||
const std::string keyType = "Type";
|
||||
const std::string keyFilename = "FileName";
|
||||
const std::string keyAppend = "Append";
|
||||
const std::string keyTimeStamping = "TimeStamping";
|
||||
const std::string keyDateStamping = "DateStamping";
|
||||
const std::string keyCategoryStamping = "CategoryStamping";
|
||||
const std::string keyLogLevelStamping = "LogLevelStamping";
|
||||
|
||||
const std::string valueHtmlLog = "HTML";
|
||||
const std::string valueTextLog = "Text";
|
||||
const std::string valueHtmlLog = "HTML";
|
||||
const std::string valueTextLog = "Text";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictionary) {
|
||||
std::string type;
|
||||
bool typeSuccess = dictionary.getValue(keyType, type);
|
||||
if (!typeSuccess) {
|
||||
std::string type;
|
||||
bool typeSuccess = dictionary.getValue(keyType, type);
|
||||
if (!typeSuccess) {
|
||||
throw ghoul::RuntimeError(
|
||||
"Requested log did not contain key '" + keyType + "'", "LogFactory"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
std::string filename;
|
||||
bool filenameSuccess = dictionary.getValue(keyFilename, filename);
|
||||
if (!filenameSuccess) {
|
||||
std::string filename;
|
||||
bool filenameSuccess = dictionary.getValue(keyFilename, filename);
|
||||
if (!filenameSuccess) {
|
||||
throw ghoul::RuntimeError(
|
||||
"Requested log did not contain key '" + keyFilename + "'", "LogFactory"
|
||||
);
|
||||
}
|
||||
filename = absPath(filename);
|
||||
}
|
||||
filename = absPath(filename);
|
||||
|
||||
bool append = true;
|
||||
dictionary.getValue(keyAppend, append);
|
||||
bool timeStamp = true;
|
||||
dictionary.getValue(keyTimeStamping, timeStamp);
|
||||
bool dateStamp = true;
|
||||
dictionary.getValue(keyDateStamping, dateStamp);
|
||||
bool categoryStamp = true;
|
||||
dictionary.getValue(keyCategoryStamping, categoryStamp);
|
||||
bool logLevelStamp = true;
|
||||
dictionary.getValue(keyLogLevelStamping, logLevelStamp);
|
||||
bool append = true;
|
||||
dictionary.getValue(keyAppend, append);
|
||||
bool timeStamp = true;
|
||||
dictionary.getValue(keyTimeStamping, timeStamp);
|
||||
bool dateStamp = true;
|
||||
dictionary.getValue(keyDateStamping, dateStamp);
|
||||
bool categoryStamp = true;
|
||||
dictionary.getValue(keyCategoryStamping, categoryStamp);
|
||||
bool logLevelStamp = true;
|
||||
dictionary.getValue(keyLogLevelStamping, logLevelStamp);
|
||||
|
||||
using Append = ghoul::logging::TextLog::Append;
|
||||
using TimeStamping = ghoul::logging::Log::TimeStamping;
|
||||
@@ -80,31 +80,31 @@ std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictiona
|
||||
using CategoryStamping = ghoul::logging::Log::CategoryStamping;
|
||||
using LogLevelStamping = ghoul::logging::Log::LogLevelStamping;
|
||||
|
||||
if (type == valueHtmlLog) {
|
||||
if (type == valueHtmlLog) {
|
||||
return std::make_unique<ghoul::logging::HTMLLog>(
|
||||
filename,
|
||||
filename,
|
||||
append ? Append::Yes : Append::No,
|
||||
timeStamp ? TimeStamping::Yes : TimeStamping::No,
|
||||
dateStamp ? DateStamping::Yes : DateStamping::No,
|
||||
categoryStamp ? CategoryStamping::Yes : CategoryStamping::No,
|
||||
logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No
|
||||
);
|
||||
}
|
||||
else if (type == valueTextLog) {
|
||||
}
|
||||
else if (type == valueTextLog) {
|
||||
return std::make_unique<ghoul::logging::TextLog>(
|
||||
filename,
|
||||
filename,
|
||||
append ? Append::Yes : Append::No,
|
||||
timeStamp ? TimeStamping::Yes : TimeStamping::No,
|
||||
dateStamp ? DateStamping::Yes : DateStamping::No,
|
||||
categoryStamp ? CategoryStamping::Yes : CategoryStamping::No,
|
||||
logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No
|
||||
);
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError(
|
||||
"Log with type '" + type + "' did not name a valid log", "LogFactory"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <openspace/version.h>
|
||||
#include <openspace/openspace.h>
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/logging/consolelog.h>
|
||||
#include <ghoul/logging/visualstudiooutputlog.h>
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <ghoul/systemcapabilities/systemcapabilities>
|
||||
@@ -71,6 +72,10 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <WinBase.h>
|
||||
#endif
|
||||
|
||||
using namespace openspace::scripting;
|
||||
using namespace ghoul::filesystem;
|
||||
using namespace ghoul::logging;
|
||||
@@ -579,6 +584,12 @@ void OpenSpaceEngine::configureLogging() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (IsDebuggerPresent()) {
|
||||
LogMgr.addLog(std::make_unique<VisualStudioOutputLog>());
|
||||
}
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::initializeGL() {
|
||||
@@ -629,7 +640,7 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
Time::ref().postSynchronizationPreDraw();
|
||||
|
||||
_scriptEngine->postSynchronizationPreDraw();
|
||||
_scriptEngine->postSynchronizationPreDraw();
|
||||
_renderEngine->postSynchronizationPreDraw();
|
||||
|
||||
if (_isMaster && _gui->isEnabled() && _windowWrapper->isRegularRendering()) {
|
||||
@@ -641,6 +652,22 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
|
||||
_gui->startFrame(static_cast<float>(dt), glm::vec2(drawBufferResolution), mousePosition, mouseButtons);
|
||||
}
|
||||
|
||||
// Testing this every frame has minimal impact on the performance --- abock
|
||||
// Debug build: 1-2 us ; Release build: <= 1 us
|
||||
using ghoul::logging::LogManager;
|
||||
int warningCounter = LogMgr.messageCounter(LogManager::LogLevel::Warning);
|
||||
int errorCounter = LogMgr.messageCounter(LogManager::LogLevel::Error);
|
||||
int fatalCounter = LogMgr.messageCounter(LogManager::LogLevel::Fatal);
|
||||
|
||||
if (warningCounter > 0)
|
||||
LWARNINGC("Logging", "Number of Warnings raised: " << warningCounter);
|
||||
if (errorCounter > 0)
|
||||
LWARNINGC("Logging", "Number of Errors raised: " << errorCounter);
|
||||
if (fatalCounter > 0)
|
||||
LWARNINGC("Logging", "Number of Fatals raised: " << fatalCounter);
|
||||
|
||||
LogMgr.resetMessageCounters();
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) {
|
||||
|
||||
@@ -90,7 +90,7 @@ glm::ivec2 SGCTWindowWrapper::currentDrawBufferResolution() const {
|
||||
if (viewport->hasSubViewports() && viewport->getNonLinearProjectionPtr()) {
|
||||
int res = viewport->getNonLinearProjectionPtr()->getCubemapResolution();
|
||||
return glm::ivec2(res, res);
|
||||
} else {
|
||||
} else {
|
||||
return currentWindowResolution();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,11 +61,11 @@ glm::ivec2 WindowWrapper::currentWindowResolution() const {
|
||||
}
|
||||
|
||||
glm::ivec2 WindowWrapper::currentDrawBufferResolution() const {
|
||||
return currentWindowSize();
|
||||
return currentWindowSize();
|
||||
}
|
||||
|
||||
int WindowWrapper::currentNumberOfAaSamples() const {
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool WindowWrapper::isRegularRendering() const {
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace interaction {
|
||||
|
||||
void Controller::setHandler(InteractionHandler* handler)
|
||||
{
|
||||
_handler = handler;
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
|
||||
@@ -11,130 +11,130 @@ DeviceIdentifier* DeviceIdentifier::this_ = nullptr;
|
||||
|
||||
DeviceIdentifier::DeviceIdentifier() {
|
||||
|
||||
// scan for devices on init
|
||||
devices_ = 0;
|
||||
for(int i = 0; i < MAXDEVICES; ++i) {
|
||||
inputDevice_[i] = InputDevice::NONE;
|
||||
}
|
||||
// scan for devices on init
|
||||
devices_ = 0;
|
||||
for(int i = 0; i < MAXDEVICES; ++i) {
|
||||
inputDevice_[i] = InputDevice::NONE;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceIdentifier::~DeviceIdentifier() {
|
||||
|
||||
// deallocates memory on exit
|
||||
for(int i = 0; i < MAXDEVICES; ++i) {
|
||||
if(inputDevice_[i] != InputDevice::NONE) {
|
||||
delete axesPos_[i];
|
||||
delete buttons_[i];
|
||||
}
|
||||
}
|
||||
// deallocates memory on exit
|
||||
for(int i = 0; i < MAXDEVICES; ++i) {
|
||||
if(inputDevice_[i] != InputDevice::NONE) {
|
||||
delete axesPos_[i];
|
||||
delete buttons_[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceIdentifier::init() {
|
||||
assert( ! this_);
|
||||
this_ = new DeviceIdentifier();
|
||||
assert( ! this_);
|
||||
this_ = new DeviceIdentifier();
|
||||
}
|
||||
|
||||
void DeviceIdentifier::deinit() {
|
||||
assert(this_);
|
||||
delete this_;
|
||||
this_ = nullptr;
|
||||
assert(this_);
|
||||
delete this_;
|
||||
this_ = nullptr;
|
||||
}
|
||||
|
||||
DeviceIdentifier& DeviceIdentifier::ref() {
|
||||
assert(this_);
|
||||
assert(this_);
|
||||
return *this_;
|
||||
}
|
||||
|
||||
bool DeviceIdentifier::isInitialized() {
|
||||
return this_ != nullptr;
|
||||
return this_ != nullptr;
|
||||
}
|
||||
|
||||
void DeviceIdentifier::scanDevices() {
|
||||
assert(this_);
|
||||
assert(this_);
|
||||
|
||||
// sgct/glfw supports 16 joysticks, scans all of them
|
||||
for (int i = 0; i < MAXDEVICES; ++i)
|
||||
{
|
||||
// sgct/glfw supports 16 joysticks, scans all of them
|
||||
for (int i = 0; i < MAXDEVICES; ++i)
|
||||
{
|
||||
void* joystickName = NULL;
|
||||
if( joystickName != NULL ) {
|
||||
if( joystickName != NULL ) {
|
||||
|
||||
// allocate
|
||||
axesPos_[i] = new float[numberOfAxes_[i]];
|
||||
buttons_[i] = new unsigned char[numberOfButtons_[i]];
|
||||
|
||||
// increment the device count
|
||||
++devices_;
|
||||
|
||||
// identify what device it is
|
||||
if(numberOfAxes_[i] == 6 && numberOfButtons_[i] == 10) {
|
||||
printf("XBOX controller ");
|
||||
inputDevice_[i] = InputDevice::XBOX;
|
||||
} else if(numberOfAxes_[i] == 6 && numberOfButtons_[i] == 4) {
|
||||
printf("SPACENAVIGATOR ");
|
||||
inputDevice_[i] = InputDevice::SPACENAVIGATOR;
|
||||
} else {
|
||||
printf("UNKNOWN device ");
|
||||
inputDevice_[i] = InputDevice::UNKNOWN;
|
||||
}
|
||||
printf("found at position %i, b=%i, a=%i\n", i, numberOfButtons_[i], numberOfAxes_[i]);
|
||||
|
||||
|
||||
} else {
|
||||
inputDevice_[i] = InputDevice::NONE;
|
||||
}
|
||||
|
||||
}
|
||||
// allocate
|
||||
axesPos_[i] = new float[numberOfAxes_[i]];
|
||||
buttons_[i] = new unsigned char[numberOfButtons_[i]];
|
||||
|
||||
// increment the device count
|
||||
++devices_;
|
||||
|
||||
// identify what device it is
|
||||
if(numberOfAxes_[i] == 6 && numberOfButtons_[i] == 10) {
|
||||
printf("XBOX controller ");
|
||||
inputDevice_[i] = InputDevice::XBOX;
|
||||
} else if(numberOfAxes_[i] == 6 && numberOfButtons_[i] == 4) {
|
||||
printf("SPACENAVIGATOR ");
|
||||
inputDevice_[i] = InputDevice::SPACENAVIGATOR;
|
||||
} else {
|
||||
printf("UNKNOWN device ");
|
||||
inputDevice_[i] = InputDevice::UNKNOWN;
|
||||
}
|
||||
printf("found at position %i, b=%i, a=%i\n", i, numberOfButtons_[i], numberOfAxes_[i]);
|
||||
|
||||
|
||||
} else {
|
||||
inputDevice_[i] = InputDevice::NONE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const int DeviceIdentifier::numberOfDevices() const {
|
||||
assert(this_);
|
||||
return devices_;
|
||||
assert(this_);
|
||||
return devices_;
|
||||
}
|
||||
|
||||
const InputDevice DeviceIdentifier::type(const int device) const {
|
||||
assert(this_);
|
||||
return inputDevice_[device];
|
||||
assert(this_);
|
||||
return inputDevice_[device];
|
||||
}
|
||||
|
||||
void DeviceIdentifier::update() {
|
||||
assert(this_);
|
||||
for(int i = 0; i < devices_; ++i) {
|
||||
update(i);
|
||||
}
|
||||
assert(this_);
|
||||
for(int i = 0; i < devices_; ++i) {
|
||||
update(i);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceIdentifier::update(const int device) {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
}
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
}
|
||||
}
|
||||
|
||||
const int DeviceIdentifier::getButtons(const int device, unsigned char **buttons) const {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
if(buttons)
|
||||
*buttons = buttons_[device];
|
||||
return numberOfButtons_[device];
|
||||
}
|
||||
return 0;
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
if(buttons)
|
||||
*buttons = buttons_[device];
|
||||
return numberOfButtons_[device];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int DeviceIdentifier::getAxes(const int device, float **axespos) const {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
if(axespos)
|
||||
*axespos = axesPos_[device];
|
||||
return numberOfAxes_[device];
|
||||
}
|
||||
return 0;
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
if(axespos)
|
||||
*axespos = axesPos_[device];
|
||||
return numberOfAxes_[device];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DeviceIdentifier::get(const int device, unsigned char **buttons, float **axespos) const {
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
*axespos = axesPos_[device];
|
||||
*buttons = buttons_[device];
|
||||
}
|
||||
assert(this_);
|
||||
if(inputDevice_[device] != InputDevice::NONE) {
|
||||
*axespos = axesPos_[device];
|
||||
*buttons = buttons_[device];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <openspace/interaction/externalcontrol/externalconnectioncontroller.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
ExternalConnectionController::ExternalConnectionController() {
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
ExternalControl::ExternalControl() {
|
||||
|
||||
}
|
||||
@@ -17,15 +17,15 @@ void ExternalControl::update() {
|
||||
}
|
||||
|
||||
void ExternalControl::rotate(const glm::quat &rotation) {
|
||||
//OsEng.interactionHandler().rotate(rotation);
|
||||
//OsEng.interactionHandler().rotate(rotation);
|
||||
}
|
||||
|
||||
void ExternalControl::orbit(const glm::quat &rotation) {
|
||||
//OsEng.interactionHandler().orbit(rotation);
|
||||
//OsEng.interactionHandler().orbit(rotation);
|
||||
}
|
||||
|
||||
void ExternalControl::distance(const PowerScaledScalar &distance) {
|
||||
//OsEng.interactionHandler().distance(distance);
|
||||
//OsEng.interactionHandler().distance(distance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,43 +17,43 @@
|
||||
//}
|
||||
//
|
||||
//void JoystickExternalControl::setInputDevice(const int device) {
|
||||
// if(device >= 0 && device <= 16) {
|
||||
// inputDevice_ = device;
|
||||
// numberOfButtons_ = DeviceIdentifier::ref().getButtons(inputDevice_);
|
||||
// numberOfAxes_ = DeviceIdentifier::ref().getAxes(inputDevice_);
|
||||
// clear();
|
||||
// pyarrSize_ = numberOfButtons_ + numberOfAxes_;
|
||||
// pyarr_ = new PyObject*[pyarrSize_];
|
||||
// }
|
||||
//
|
||||
// if(device >= 0 && device <= 16) {
|
||||
// inputDevice_ = device;
|
||||
// numberOfButtons_ = DeviceIdentifier::ref().getButtons(inputDevice_);
|
||||
// numberOfAxes_ = DeviceIdentifier::ref().getAxes(inputDevice_);
|
||||
// clear();
|
||||
// pyarrSize_ = numberOfButtons_ + numberOfAxes_;
|
||||
// pyarr_ = new PyObject*[pyarrSize_];
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//void JoystickExternalControl::update() {
|
||||
//
|
||||
// if(inputDevice_ != -1) {
|
||||
// float *axesPos;
|
||||
// unsigned char *buttons;
|
||||
// DeviceIdentifier::ref().getButtons(inputDevice_, &buttons);
|
||||
// DeviceIdentifier::ref().getAxes(inputDevice_, &axesPos);
|
||||
//
|
||||
// if(inputDevice_ != -1) {
|
||||
// float *axesPos;
|
||||
// unsigned char *buttons;
|
||||
// DeviceIdentifier::ref().getButtons(inputDevice_, &buttons);
|
||||
// DeviceIdentifier::ref().getAxes(inputDevice_, &axesPos);
|
||||
//
|
||||
// // init array
|
||||
// for(int i = 0; i < numberOfButtons_; ++i){
|
||||
// pyarr_[i] = PyLong_FromLong(buttons[i]);
|
||||
// }
|
||||
// for(int i = 0; i < numberOfAxes_; ++i){
|
||||
// pyarr_[i+numberOfButtons_] = PyFloat_FromDouble(axesPos[i]);
|
||||
// }
|
||||
// }
|
||||
// // init array
|
||||
// for(int i = 0; i < numberOfButtons_; ++i){
|
||||
// pyarr_[i] = PyLong_FromLong(buttons[i]);
|
||||
// }
|
||||
// for(int i = 0; i < numberOfAxes_; ++i){
|
||||
// pyarr_[i+numberOfButtons_] = PyFloat_FromDouble(axesPos[i]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// run();
|
||||
// run();
|
||||
//
|
||||
// if(inputDevice_ != -1) {
|
||||
// // cleanup
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// Py_DECREF(pyarr_[i]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(inputDevice_ != -1) {
|
||||
// // cleanup
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// Py_DECREF(pyarr_[i]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//JoystickExternalControl::~JoystickExternalControl() {
|
||||
|
||||
@@ -14,48 +14,48 @@
|
||||
//
|
||||
//
|
||||
//KeyboardExternalControl::KeyboardExternalControl(const char *filename): PythonExternalControl(filename) {
|
||||
// clear();
|
||||
// pyarrSize_ = 'Z' - 'A' + 80; // all letters, 69 special keys, space and 10 numbers
|
||||
// pyarr_ = new PyObject*[pyarrSize_];
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// pyarr_[i] = PyLong_FromLong(0);
|
||||
// }
|
||||
// clear();
|
||||
// pyarrSize_ = 'Z' - 'A' + 80; // all letters, 69 special keys, space and 10 numbers
|
||||
// pyarr_ = new PyObject*[pyarrSize_];
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// pyarr_[i] = PyLong_FromLong(0);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void KeyboardExternalControl::keyboardCallback(int key, int action) {
|
||||
//
|
||||
// //printf("key: %i\n",key);
|
||||
// int pos = -1;
|
||||
// if(key >= '0' && key <= '9') {
|
||||
// pos = key - '0';
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// } else if(key >= 'A' && key <= 'Z') {
|
||||
// pos = key - 'A' + 10;
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// } else if (key > 256 && key < 256+69) {
|
||||
// pos = key - 256 + 'Z'-'A' +10;
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// } else if (key == 32) {
|
||||
// pos = 'Z' - 'A' + 11;
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// }
|
||||
// //printf("pos: %i\n",pos);
|
||||
//
|
||||
// //printf("key: %i\n",key);
|
||||
// int pos = -1;
|
||||
// if(key >= '0' && key <= '9') {
|
||||
// pos = key - '0';
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// } else if(key >= 'A' && key <= 'Z') {
|
||||
// pos = key - 'A' + 10;
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// } else if (key > 256 && key < 256+69) {
|
||||
// pos = key - 256 + 'Z'-'A' +10;
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// } else if (key == 32) {
|
||||
// pos = 'Z' - 'A' + 11;
|
||||
// Py_XDECREF(pyarr_[pos]);
|
||||
// pyarr_[pos] = PyLong_FromLong(action);
|
||||
// }
|
||||
// //printf("pos: %i\n",pos);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
//void KeyboardExternalControl::update() {
|
||||
// run();
|
||||
// run();
|
||||
//}
|
||||
//
|
||||
//KeyboardExternalControl::~KeyboardExternalControl() {
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// Py_XDECREF(pyarr_[i]);
|
||||
// }
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// Py_XDECREF(pyarr_[i]);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//} // namespace openspace
|
||||
|
||||
@@ -14,65 +14,65 @@
|
||||
//
|
||||
//
|
||||
//MouseExternalControl::MouseExternalControl(const char *filename): PythonExternalControl(filename) {
|
||||
// clear();
|
||||
// pyarrSize_ = 6*2;
|
||||
// pyarr_ = new PyObject*[pyarrSize_];
|
||||
// x_ = 0;
|
||||
// y_ = 0;
|
||||
// pos_ = 0;
|
||||
// button1_ = 0;
|
||||
// button2_ = 0;
|
||||
// button3_ = 0;
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// pyarr_[i] = PyLong_FromLong(0);;
|
||||
// }
|
||||
// clear();
|
||||
// pyarrSize_ = 6*2;
|
||||
// pyarr_ = new PyObject*[pyarrSize_];
|
||||
// x_ = 0;
|
||||
// y_ = 0;
|
||||
// pos_ = 0;
|
||||
// button1_ = 0;
|
||||
// button2_ = 0;
|
||||
// button3_ = 0;
|
||||
// for(int i = 0; i < pyarrSize_; ++i) {
|
||||
// pyarr_[i] = PyLong_FromLong(0);;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//void MouseExternalControl::mouseButtonCallback(int key, int action) {
|
||||
// if(key == 0)
|
||||
// button1_ = action;
|
||||
// if(key == 1)
|
||||
// button2_ = action;
|
||||
// if(key == 2)
|
||||
// button3_ = action;
|
||||
// if(key == 0)
|
||||
// button1_ = action;
|
||||
// if(key == 1)
|
||||
// button2_ = action;
|
||||
// if(key == 2)
|
||||
// button3_ = action;
|
||||
//}
|
||||
//
|
||||
//void MouseExternalControl::mousePosCallback(int x, int y) {
|
||||
// x_ = x;
|
||||
// y_ = y;
|
||||
// x_ = x;
|
||||
// y_ = y;
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void MouseExternalControl::mouseScrollCallback(int pos) {
|
||||
// pos_ = pos;
|
||||
// pos_ = pos;
|
||||
//}
|
||||
//
|
||||
//void MouseExternalControl::update() {
|
||||
//
|
||||
// pyarr_[6] = pyarr_[0];
|
||||
// pyarr_[7] = pyarr_[1];
|
||||
// pyarr_[8] = pyarr_[2];
|
||||
// pyarr_[9] = pyarr_[3];
|
||||
// pyarr_[10] = pyarr_[4];
|
||||
// pyarr_[11] = pyarr_[5];
|
||||
// pyarr_[0] = PyLong_FromLong(button1_);
|
||||
// pyarr_[1] = PyLong_FromLong(button2_);
|
||||
// pyarr_[2] = PyLong_FromLong(button3_);
|
||||
// pyarr_[3] = PyLong_FromLong(pos_);
|
||||
// pyarr_[4] = PyLong_FromLong(x_);
|
||||
// pyarr_[5] = PyLong_FromLong(y_);
|
||||
//
|
||||
// pyarr_[6] = pyarr_[0];
|
||||
// pyarr_[7] = pyarr_[1];
|
||||
// pyarr_[8] = pyarr_[2];
|
||||
// pyarr_[9] = pyarr_[3];
|
||||
// pyarr_[10] = pyarr_[4];
|
||||
// pyarr_[11] = pyarr_[5];
|
||||
// pyarr_[0] = PyLong_FromLong(button1_);
|
||||
// pyarr_[1] = PyLong_FromLong(button2_);
|
||||
// pyarr_[2] = PyLong_FromLong(button3_);
|
||||
// pyarr_[3] = PyLong_FromLong(pos_);
|
||||
// pyarr_[4] = PyLong_FromLong(x_);
|
||||
// pyarr_[5] = PyLong_FromLong(y_);
|
||||
//
|
||||
// run();
|
||||
// run();
|
||||
//
|
||||
// // cleanup
|
||||
// for(int i = pyarrSize_ / 2; i < pyarrSize_; ++i) {
|
||||
// Py_XDECREF(pyarr_[i]);
|
||||
// }
|
||||
//
|
||||
// // cleanup
|
||||
// for(int i = pyarrSize_ / 2; i < pyarrSize_; ++i) {
|
||||
// Py_XDECREF(pyarr_[i]);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//MouseExternalControl::~MouseExternalControl() {
|
||||
//
|
||||
//
|
||||
//}
|
||||
//
|
||||
//} // namespace openspace
|
||||
|
||||
@@ -32,115 +32,115 @@
|
||||
//static PyObject* pyexcontrol_message(PyObject *self, PyObject *args)
|
||||
//{
|
||||
// char* text = 0;
|
||||
// if(!PyArg_ParseTuple(args, "s:pyexcontrol_yeah",&text))
|
||||
// if(!PyArg_ParseTuple(args, "s:pyexcontrol_yeah",&text))
|
||||
// Py_RETURN_NONE;
|
||||
//
|
||||
// PythonExternalControl * ext = 0;
|
||||
// ext->message(text);
|
||||
//
|
||||
// PythonExternalControl * ext = 0;
|
||||
// ext->message(text);
|
||||
//
|
||||
// Py_RETURN_NONE;
|
||||
// Py_RETURN_NONE;
|
||||
//}
|
||||
//
|
||||
//static PyObject* pyexcontrol_rotateCamera(PyObject *self, PyObject *args)
|
||||
//{
|
||||
// char* text = 0;
|
||||
// float f1 = 0;
|
||||
// float f2 = 0;
|
||||
// float f3 = 0;
|
||||
// float f4 = 0;
|
||||
// if(!PyArg_ParseTuple(args, "fff:pyexcontrol_rotateCamera",&f1,&f2,&f3))
|
||||
// Py_RETURN_NONE;
|
||||
//
|
||||
// double dt = InteractionHandler::ref().getDt();
|
||||
// glm::vec3 EulerAngles(f1*dt,f2*dt, f3*dt);
|
||||
// glm::quat rot = glm::quat(EulerAngles);
|
||||
// ExternalControl * ext = 0;
|
||||
// ext->rotate(rot);
|
||||
// char* text = 0;
|
||||
// float f1 = 0;
|
||||
// float f2 = 0;
|
||||
// float f3 = 0;
|
||||
// float f4 = 0;
|
||||
// if(!PyArg_ParseTuple(args, "fff:pyexcontrol_rotateCamera",&f1,&f2,&f3))
|
||||
// Py_RETURN_NONE;
|
||||
//
|
||||
// double dt = InteractionHandler::ref().getDt();
|
||||
// glm::vec3 EulerAngles(f1*dt,f2*dt, f3*dt);
|
||||
// glm::quat rot = glm::quat(EulerAngles);
|
||||
// ExternalControl * ext = 0;
|
||||
// ext->rotate(rot);
|
||||
//
|
||||
// Py_RETURN_NONE;
|
||||
// Py_RETURN_NONE;
|
||||
//}
|
||||
//
|
||||
//static PyObject* pyexcontrol_orbitCamera(PyObject *self, PyObject *args)
|
||||
//{
|
||||
// char* text = 0;
|
||||
// float f1 = 0;
|
||||
// float f2 = 0;
|
||||
// float f3 = 0;
|
||||
// if(!PyArg_ParseTuple(args, "fff:pyexcontrol_rotateCamera",&f1,&f2,&f3))
|
||||
// Py_RETURN_NONE;
|
||||
//
|
||||
// double dt = InteractionHandler::ref().getDt();
|
||||
// glm::vec3 EulerAngles(f1*dt,f2*dt, f3*dt);
|
||||
// glm::quat rot = glm::quat(EulerAngles);
|
||||
// ExternalControl * ext = 0;
|
||||
// ext->orbit(rot);
|
||||
//
|
||||
// Py_RETURN_NONE;
|
||||
// char* text = 0;
|
||||
// float f1 = 0;
|
||||
// float f2 = 0;
|
||||
// float f3 = 0;
|
||||
// if(!PyArg_ParseTuple(args, "fff:pyexcontrol_rotateCamera",&f1,&f2,&f3))
|
||||
// Py_RETURN_NONE;
|
||||
//
|
||||
// double dt = InteractionHandler::ref().getDt();
|
||||
// glm::vec3 EulerAngles(f1*dt,f2*dt, f3*dt);
|
||||
// glm::quat rot = glm::quat(EulerAngles);
|
||||
// ExternalControl * ext = 0;
|
||||
// ext->orbit(rot);
|
||||
//
|
||||
// Py_RETURN_NONE;
|
||||
//}
|
||||
//
|
||||
//static PyObject* pyexcontrol_distance(PyObject *self, PyObject *args)
|
||||
//{
|
||||
// char* text = 0;
|
||||
// float f1 = 0;
|
||||
// float f2 = 0;
|
||||
// if(!PyArg_ParseTuple(args, "ff:pyexcontrol_rotateCamera",&f1,&f2))
|
||||
// Py_RETURN_NONE;
|
||||
//
|
||||
// float dt = static_cast<float>(InteractionHandler::ref().getDt());
|
||||
// pss dist(f1*dt,f2);
|
||||
// ExternalControl * ext = 0;
|
||||
// ext->distance(dist);
|
||||
//
|
||||
// Py_RETURN_NONE;
|
||||
// char* text = 0;
|
||||
// float f1 = 0;
|
||||
// float f2 = 0;
|
||||
// if(!PyArg_ParseTuple(args, "ff:pyexcontrol_rotateCamera",&f1,&f2))
|
||||
// Py_RETURN_NONE;
|
||||
//
|
||||
// float dt = static_cast<float>(InteractionHandler::ref().getDt());
|
||||
// pss dist(f1*dt,f2);
|
||||
// ExternalControl * ext = 0;
|
||||
// ext->distance(dist);
|
||||
//
|
||||
// Py_RETURN_NONE;
|
||||
//}
|
||||
//
|
||||
//PyMethodDef* PythonExternalControl::getMethodDef() {
|
||||
// // creating the python callback function table
|
||||
// static PyMethodDef pyexcontrol_methods[] = {
|
||||
// {"numargs", pyexcontrol_numargs, METH_VARARGS, "function"},
|
||||
// {"message", pyexcontrol_message, METH_VARARGS, "function"},
|
||||
// {"rotate", pyexcontrol_rotateCamera, METH_VARARGS, "function"},
|
||||
// {"orbit", pyexcontrol_orbitCamera, METH_VARARGS, "function"},
|
||||
// {"distance", pyexcontrol_distance, METH_VARARGS, "function"},
|
||||
// {NULL, NULL, 0, NULL}
|
||||
// };
|
||||
// return pyexcontrol_methods;
|
||||
// // creating the python callback function table
|
||||
// static PyMethodDef pyexcontrol_methods[] = {
|
||||
// {"numargs", pyexcontrol_numargs, METH_VARARGS, "function"},
|
||||
// {"message", pyexcontrol_message, METH_VARARGS, "function"},
|
||||
// {"rotate", pyexcontrol_rotateCamera, METH_VARARGS, "function"},
|
||||
// {"orbit", pyexcontrol_orbitCamera, METH_VARARGS, "function"},
|
||||
// {"distance", pyexcontrol_distance, METH_VARARGS, "function"},
|
||||
// {NULL, NULL, 0, NULL}
|
||||
// };
|
||||
// return pyexcontrol_methods;
|
||||
//}
|
||||
//
|
||||
//void PythonExternalControl::message(const char *text) {
|
||||
//
|
||||
// printf("Input message from PythonScript: %s\n", text);
|
||||
//
|
||||
// printf("Input message from PythonScript: %s\n", text);
|
||||
//}
|
||||
//
|
||||
//PythonExternalControl::PythonExternalControl(const char *filename) {
|
||||
// pyarr_ = nullptr;
|
||||
// ps_.load(filename, true);
|
||||
// pyarr_ = nullptr;
|
||||
// ps_.load(filename, true);
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void PythonExternalControl::update() {
|
||||
// run();
|
||||
// run();
|
||||
//}
|
||||
//
|
||||
//void PythonExternalControl::run() {
|
||||
// if(pyarrSize_ > 0)
|
||||
// ps_.run(pyarrSize_, pyarr_);
|
||||
// else
|
||||
// ps_.run();
|
||||
// if(pyarrSize_ > 0)
|
||||
// ps_.run(pyarrSize_, pyarr_);
|
||||
// else
|
||||
// ps_.run();
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void PythonExternalControl::clear() {
|
||||
// if(pyarr_ != nullptr) {
|
||||
// // cleanup
|
||||
// delete pyarr_;
|
||||
// pyarr_ = nullptr;
|
||||
// pyarrSize_ = 0;
|
||||
// }
|
||||
// if(pyarr_ != nullptr) {
|
||||
// // cleanup
|
||||
// delete pyarr_;
|
||||
// pyarr_ = nullptr;
|
||||
// pyarrSize_ = 0;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//PythonExternalControl::~PythonExternalControl() {
|
||||
// clear();
|
||||
// clear();
|
||||
//}
|
||||
//
|
||||
//} // namespace openspace
|
||||
|
||||
@@ -2,58 +2,58 @@
|
||||
|
||||
#include <cstdio>
|
||||
#ifndef __WIN32__
|
||||
#include <unistd.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace openspace {
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool *keepGoing;
|
||||
double *dx;
|
||||
bool *keepGoing;
|
||||
double *dx;
|
||||
} parm;
|
||||
|
||||
void *updatedx(void * arg) {
|
||||
parm *p = (parm*) arg;
|
||||
bool *kg = p->keepGoing;
|
||||
double *dx = p->dx;
|
||||
while( *kg ) {
|
||||
//printf("Hello world!\n");
|
||||
*dx = *dx + 0.5;
|
||||
parm *p = (parm*) arg;
|
||||
bool *kg = p->keepGoing;
|
||||
double *dx = p->dx;
|
||||
while( *kg ) {
|
||||
//printf("Hello world!\n");
|
||||
*dx = *dx + 0.5;
|
||||
|
||||
|
||||
|
||||
#ifndef __WIN32__
|
||||
// random sleep time
|
||||
int diff = rand() % 200;
|
||||
|
||||
usleep(10000*diff);
|
||||
#endif
|
||||
}
|
||||
delete p;
|
||||
return NULL;
|
||||
}
|
||||
delete p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RandomExternalControl::RandomExternalControl() {
|
||||
/*
|
||||
inputGuard = PTHREAD_MUTEX_INITIALIZER;
|
||||
/*
|
||||
inputGuard = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
pthread_attr_t pthread_custom_attr;
|
||||
pthread_attr_init(&pthread_custom_attr);
|
||||
keepGoing_ = new bool;
|
||||
*keepGoing_ = true;
|
||||
parm *p = (parm*)malloc(sizeof(parm));
|
||||
p->keepGoing = keepGoing_;
|
||||
p->dx = &dx_;
|
||||
pthread_attr_t pthread_custom_attr;
|
||||
pthread_attr_init(&pthread_custom_attr);
|
||||
keepGoing_ = new bool;
|
||||
*keepGoing_ = true;
|
||||
parm *p = (parm*)malloc(sizeof(parm));
|
||||
p->keepGoing = keepGoing_;
|
||||
p->dx = &dx_;
|
||||
|
||||
pthread_create(&backgroundThread, &pthread_custom_attr, updatedx, (void*)p);
|
||||
*/
|
||||
pthread_create(&backgroundThread, &pthread_custom_attr, updatedx, (void*)p);
|
||||
*/
|
||||
}
|
||||
|
||||
RandomExternalControl::~RandomExternalControl() {
|
||||
*keepGoing_ = false;
|
||||
//pthread_join(backgroundThread, NULL);
|
||||
delete keepGoing_;
|
||||
*keepGoing_ = false;
|
||||
//pthread_join(backgroundThread, NULL);
|
||||
delete keepGoing_;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -35,96 +35,28 @@
|
||||
#include <ghoul/misc/interpolator.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "InteractionHandler";
|
||||
|
||||
openspace::Key stringToKey(std::string s) {
|
||||
// key only uppercase
|
||||
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
|
||||
|
||||
// default is unknown
|
||||
auto it = openspace::KeyMapping.find(s);
|
||||
if (it != openspace::KeyMapping.end())
|
||||
return it->second;
|
||||
else
|
||||
return openspace::Key::Unknown;
|
||||
}
|
||||
const std::string _loggerCat = "InteractionHandler";
|
||||
}
|
||||
|
||||
#include "interactionhandler_lua.inl"
|
||||
|
||||
namespace openspace {
|
||||
|
||||
//InteractionHandler::InteractionHandler() {
|
||||
// // initiate pointers
|
||||
// _camera = nullptr;
|
||||
// _enabled = true;
|
||||
// _node = nullptr;
|
||||
// _dt = 0.0;
|
||||
// _lastTrackballPos = glm::vec3(0.0, 0.0, 0.5);
|
||||
// _leftMouseButtonDown = false;
|
||||
// _isMouseBeingPressedAndHeld = false;
|
||||
//}
|
||||
//
|
||||
//InteractionHandler::~InteractionHandler() {
|
||||
// for (size_t i = 0; i < _controllers.size(); ++i) {
|
||||
// delete _controllers[i];
|
||||
// }
|
||||
//}
|
||||
//
|
||||
////void InteractionHandler::init() {
|
||||
//// assert( ! this_);
|
||||
//// this_ = new InteractionHandler();
|
||||
////}
|
||||
////
|
||||
////void InteractionHandler::deinit() {
|
||||
//// assert(this_);
|
||||
//// delete this_;
|
||||
//// this_ = nullptr;
|
||||
////}
|
||||
////
|
||||
////InteractionHandler& InteractionHandler::ref() {
|
||||
//// assert(this_);
|
||||
//// return *this_;
|
||||
////}
|
||||
//
|
||||
////bool InteractionHandler::isInitialized() {
|
||||
//// return this_ != nullptr;
|
||||
////}
|
||||
//
|
||||
//void InteractionHandler::enable() {
|
||||
// //assert(this_);
|
||||
// _enabled = true;
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::disable() {
|
||||
// //assert(this_);
|
||||
// _enabled = false;
|
||||
//}
|
||||
//
|
||||
//const bool InteractionHandler::isEnabled() const {
|
||||
// //assert(this_);
|
||||
// if (_camera)
|
||||
// return false;
|
||||
// return _enabled;
|
||||
//=======
|
||||
|
||||
//namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
InteractionHandler::InteractionHandler()
|
||||
: properties::PropertyOwner()
|
||||
, _camera(nullptr)
|
||||
, _focusNode(nullptr)
|
||||
, _camera(nullptr)
|
||||
, _focusNode(nullptr)
|
||||
, _deltaTime(0.0)
|
||||
, _validKeyLua(false)
|
||||
, _controllerSensitivity(1.f)
|
||||
, _invertRoll(false)
|
||||
, _invertRotation(false)
|
||||
, _keyboardController(nullptr)
|
||||
, _mouseController(nullptr)
|
||||
, _keyboardController(nullptr)
|
||||
, _mouseController(nullptr)
|
||||
, _origin("origin", "Origin", "")
|
||||
, _coordinateSystem("coordinateSystem", "Coordinate System", "")
|
||||
, _currentKeyframeTime(-1.0)
|
||||
, _currentKeyframeTime(-1.0)
|
||||
{
|
||||
setName("Interaction");
|
||||
|
||||
@@ -145,104 +77,51 @@ InteractionHandler::InteractionHandler()
|
||||
}
|
||||
|
||||
InteractionHandler::~InteractionHandler() {
|
||||
delete _keyboardController;
|
||||
delete _mouseController;
|
||||
for (size_t i = 0; i < _controllers.size(); ++i)
|
||||
delete _controllers[i];
|
||||
delete _keyboardController;
|
||||
delete _mouseController;
|
||||
for (size_t i = 0; i < _controllers.size(); ++i)
|
||||
delete _controllers[i];
|
||||
}
|
||||
|
||||
void InteractionHandler::setKeyboardController(KeyboardController* controller) {
|
||||
assert(controller);
|
||||
delete _keyboardController;
|
||||
_keyboardController = controller;
|
||||
_keyboardController->setHandler(this);
|
||||
assert(controller);
|
||||
delete _keyboardController;
|
||||
_keyboardController = controller;
|
||||
_keyboardController->setHandler(this);
|
||||
}
|
||||
|
||||
void InteractionHandler::setMouseController(MouseController* controller) {
|
||||
assert(controller);
|
||||
delete _mouseController;
|
||||
_mouseController = controller;
|
||||
_mouseController->setHandler(this);
|
||||
assert(controller);
|
||||
delete _mouseController;
|
||||
_mouseController = controller;
|
||||
_mouseController->setHandler(this);
|
||||
}
|
||||
|
||||
void InteractionHandler::addController(Controller* controller) {
|
||||
assert(controller);
|
||||
_controllers.push_back(controller);
|
||||
controller->setHandler(this);
|
||||
assert(controller);
|
||||
_controllers.push_back(controller);
|
||||
controller->setHandler(this);
|
||||
}
|
||||
|
||||
void InteractionHandler::lockControls() {
|
||||
_mutex.lock();
|
||||
_mutex.lock();
|
||||
}
|
||||
|
||||
void InteractionHandler::unlockControls() {
|
||||
_mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
//<<<<<<< HEAD
|
||||
//void InteractionHandler::addExternalControl(ExternalControl* controller) {
|
||||
// //assert(this_);
|
||||
// if (controller != nullptr) {
|
||||
// _controllers.push_back(controller);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::setCamera(Camera *camera) {
|
||||
// //assert(this_);
|
||||
// _camera = camera;
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::setOrigin(SceneGraphNode* node) {
|
||||
// if (node)
|
||||
// _node = node;
|
||||
//}
|
||||
//
|
||||
//Camera * InteractionHandler::getCamera() const {
|
||||
// //assert(this_);
|
||||
// if (_enabled) {
|
||||
// return _camera;
|
||||
// }
|
||||
// return nullptr;
|
||||
//}
|
||||
//
|
||||
//const psc InteractionHandler::getOrigin() const {
|
||||
// if (_node)
|
||||
// return _node->worldPosition();
|
||||
// return psc();
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::lockControls() {
|
||||
// //assert(this_);
|
||||
// _cameraGuard.lock();
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::unlockControls() {
|
||||
// //assert(this_);
|
||||
// _cameraGuard.unlock();
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::setFocusNode(SceneGraphNode *node) {
|
||||
// //assert(this_);
|
||||
// _node = node;
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::rotate(const glm::quat &rotation) {
|
||||
// //assert(this_);
|
||||
// lockControls();
|
||||
// _camera->rotate(rotation);
|
||||
// unlockControls();
|
||||
//=======
|
||||
void InteractionHandler::update(double deltaTime) {
|
||||
_deltaTime = deltaTime;
|
||||
_mouseController->update(deltaTime);
|
||||
_deltaTime = deltaTime;
|
||||
_mouseController->update(deltaTime);
|
||||
|
||||
bool hasKeys = false;
|
||||
psc pos;
|
||||
glm::quat q;
|
||||
|
||||
_keyframeMutex.lock();
|
||||
_keyframeMutex.lock();
|
||||
|
||||
if (_keyframes.size() > 4){ //wait until enough samples are buffered
|
||||
if (_keyframes.size() > 4){ //wait until enough samples are buffered
|
||||
hasKeys = true;
|
||||
|
||||
openspace::network::datamessagestructures::PositionKeyframe p0, p1, p2, p3;
|
||||
@@ -252,20 +131,20 @@ void InteractionHandler::update(double deltaTime) {
|
||||
p2 = _keyframes[2];
|
||||
p3 = _keyframes[3];
|
||||
|
||||
//interval check
|
||||
if (_currentKeyframeTime < p1._timeStamp){
|
||||
_currentKeyframeTime = p1._timeStamp;
|
||||
}
|
||||
//interval check
|
||||
if (_currentKeyframeTime < p1._timeStamp){
|
||||
_currentKeyframeTime = p1._timeStamp;
|
||||
}
|
||||
|
||||
double t0 = p1._timeStamp;
|
||||
double t1 = p2._timeStamp;
|
||||
double fact = (_currentKeyframeTime - t0) / (t1 - t0);
|
||||
double t0 = p1._timeStamp;
|
||||
double t1 = p2._timeStamp;
|
||||
double fact = (_currentKeyframeTime - t0) / (t1 - t0);
|
||||
|
||||
|
||||
|
||||
//glm::dvec4 v = positionInterpCR.interpolate(fact, _keyframes[0]._position.dvec4(), _keyframes[1]._position.dvec4(), _keyframes[2]._position.dvec4(), _keyframes[3]._position.dvec4());
|
||||
//glm::dvec4 v = positionInterpCR.interpolate(fact, _keyframes[0]._position.dvec4(), _keyframes[1]._position.dvec4(), _keyframes[2]._position.dvec4(), _keyframes[3]._position.dvec4());
|
||||
glm::dvec4 v = ghoul::interpolateLinear(fact, p1._position.dvec4(), p2._position.dvec4());
|
||||
|
||||
|
||||
pos = psc(v.x, v.y, v.z, v.w);
|
||||
q = ghoul::interpolateLinear(fact, p1._viewRotationQuat, p2._viewRotationQuat);
|
||||
|
||||
@@ -282,29 +161,29 @@ void InteractionHandler::update(double deltaTime) {
|
||||
_keyframeMutex.unlock();
|
||||
|
||||
if(hasKeys){
|
||||
_camera->setPosition(pos);
|
||||
_camera->setViewRotationMatrix(glm::mat4_cast(q));
|
||||
_camera->setPosition(pos);
|
||||
_camera->setViewRotationMatrix(glm::mat4_cast(q));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
|
||||
if (_focusNode == node){
|
||||
return;
|
||||
}
|
||||
|
||||
if (_focusNode == node){
|
||||
return;
|
||||
}
|
||||
|
||||
_focusNode = node;
|
||||
_focusNode = node;
|
||||
|
||||
//orient the camera to the new node
|
||||
psc focusPos = node->worldPosition();
|
||||
psc camToFocus = focusPos - _camera->position();
|
||||
glm::vec3 viewDir = glm::normalize(camToFocus.vec3());
|
||||
glm::vec3 cameraView = glm::normalize(_camera->viewDirection());
|
||||
//orient the camera to the new node
|
||||
psc focusPos = node->worldPosition();
|
||||
psc camToFocus = focusPos - _camera->position();
|
||||
glm::vec3 viewDir = glm::normalize(camToFocus.vec3());
|
||||
glm::vec3 cameraView = glm::normalize(_camera->viewDirection());
|
||||
//set new focus position
|
||||
_camera->setFocusPosition(node->worldPosition());
|
||||
float dot = glm::dot(viewDir, cameraView);
|
||||
@@ -313,213 +192,213 @@ void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
if (dot < 1.f && dot > -1.f) {
|
||||
//if (glm::length(viewDir - cameraView) < 0.001) {
|
||||
//if (viewDir != cameraView) {
|
||||
glm::vec3 rotAxis = glm::normalize(glm::cross(viewDir, cameraView));
|
||||
float angle = glm::angle(viewDir, cameraView);
|
||||
glm::quat q = glm::angleAxis(angle, rotAxis);
|
||||
glm::vec3 rotAxis = glm::normalize(glm::cross(viewDir, cameraView));
|
||||
float angle = glm::angle(viewDir, cameraView);
|
||||
glm::quat q = glm::angleAxis(angle, rotAxis);
|
||||
|
||||
//rotate view to target new focus
|
||||
_camera->rotate(q);
|
||||
//rotate view to target new focus
|
||||
_camera->rotate(q);
|
||||
}
|
||||
}
|
||||
|
||||
const SceneGraphNode* const InteractionHandler::focusNode() const {
|
||||
return _focusNode;
|
||||
return _focusNode;
|
||||
}
|
||||
|
||||
void InteractionHandler::setCamera(Camera* camera) {
|
||||
assert(camera);
|
||||
_camera = camera;
|
||||
assert(camera);
|
||||
_camera = camera;
|
||||
}
|
||||
const Camera* const InteractionHandler::camera() const {
|
||||
return _camera;
|
||||
return _camera;
|
||||
}
|
||||
|
||||
//void InteractionHandler::keyboardCallback(int key, int action) {
|
||||
// if (_keyboardController) {
|
||||
// auto start = ghoul::HighResClock::now();
|
||||
// _keyboardController->keyPressed(KeyAction(action), Key(key), KeyModifier::None);
|
||||
// auto end = ghoul::HighResClock::now();
|
||||
// LINFO("Keyboard timing: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "ns");
|
||||
// }
|
||||
// if (_keyboardController) {
|
||||
// auto start = ghoul::HighResClock::now();
|
||||
// _keyboardController->keyPressed(KeyAction(action), Key(key), KeyModifier::None);
|
||||
// auto end = ghoul::HighResClock::now();
|
||||
// LINFO("Keyboard timing: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "ns");
|
||||
// }
|
||||
//}
|
||||
|
||||
void InteractionHandler::mouseButtonCallback(MouseButton button, MouseAction action) {
|
||||
if (_mouseController)
|
||||
_mouseController->button(button, action);
|
||||
if (_mouseController)
|
||||
_mouseController->button(button, action);
|
||||
}
|
||||
|
||||
void InteractionHandler::mousePositionCallback(double x, double y) {
|
||||
if (_mouseController)
|
||||
// TODO Remap screen coordinates to [0,1]
|
||||
_mouseController->move(static_cast<float>(x), static_cast<float>(y));
|
||||
if (_mouseController)
|
||||
// TODO Remap screen coordinates to [0,1]
|
||||
_mouseController->move(static_cast<float>(x), static_cast<float>(y));
|
||||
}
|
||||
|
||||
void InteractionHandler::mouseScrollWheelCallback(double pos) {
|
||||
if (_mouseController)
|
||||
_mouseController->scrollWheel(static_cast<int>(pos));
|
||||
if (_mouseController)
|
||||
_mouseController->scrollWheel(static_cast<int>(pos));
|
||||
}
|
||||
|
||||
void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz, const float &dist){
|
||||
|
||||
lockControls();
|
||||
|
||||
glm::vec3 cameraUp = glm::normalize((glm::inverse(_camera->viewRotationMatrix()) * glm::vec4(_camera->lookUpVector(), 0))).xyz();
|
||||
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
|
||||
lockControls();
|
||||
|
||||
glm::vec3 cameraUp = glm::normalize((glm::inverse(_camera->viewRotationMatrix()) * glm::vec4(_camera->lookUpVector(), 0))).xyz();
|
||||
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
|
||||
|
||||
glm::mat4 transform;
|
||||
transform = glm::rotate(glm::radians(dx * 100.f), cameraUp) * transform;
|
||||
transform = glm::rotate(glm::radians(dy * 100.f), cameraRight) * transform;
|
||||
transform = glm::rotate(glm::radians(dz * 100.f), _camera->viewDirection()) * transform;
|
||||
glm::mat4 transform;
|
||||
transform = glm::rotate(glm::radians(dx * 100.f), cameraUp) * transform;
|
||||
transform = glm::rotate(glm::radians(dy * 100.f), cameraRight) * transform;
|
||||
transform = glm::rotate(glm::radians(dz * 100.f), _camera->viewDirection()) * transform;
|
||||
|
||||
|
||||
//get "old" focus position
|
||||
psc focus = _camera->focusPosition();
|
||||
|
||||
//// get camera position
|
||||
//psc relative = _camera->position();
|
||||
|
||||
//get "old" focus position
|
||||
psc focus = _camera->focusPosition();
|
||||
|
||||
//// get camera position
|
||||
//psc relative = _camera->position();
|
||||
|
||||
// get camera position (UNSYNCHRONIZED)
|
||||
psc relative = _camera->unsynchedPosition();
|
||||
// get camera position (UNSYNCHRONIZED)
|
||||
psc relative = _camera->unsynchedPosition();
|
||||
|
||||
//get relative vector
|
||||
psc relative_focus_coordinate = relative - focus;
|
||||
//rotate relative vector
|
||||
relative_focus_coordinate = glm::inverse(transform) * relative_focus_coordinate.vec4();
|
||||
|
||||
//get new new position of focus node
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
//get relative vector
|
||||
psc relative_focus_coordinate = relative - focus;
|
||||
//rotate relative vector
|
||||
relative_focus_coordinate = glm::inverse(transform) * relative_focus_coordinate.vec4();
|
||||
|
||||
//get new new position of focus node
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
|
||||
//new camera position
|
||||
relative = origin + relative_focus_coordinate;
|
||||
//new camera position
|
||||
relative = origin + relative_focus_coordinate;
|
||||
|
||||
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f) / 10.f;
|
||||
float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f) / 10.f;
|
||||
|
||||
psc target = relative + relative_focus_coordinate * dist;
|
||||
//don't fly into objects
|
||||
if ((target - origin).length() < bounds){
|
||||
target = relative;
|
||||
}
|
||||
psc target = relative + relative_focus_coordinate * dist;
|
||||
//don't fly into objects
|
||||
if ((target - origin).length() < bounds){
|
||||
target = relative;
|
||||
}
|
||||
|
||||
unlockControls();
|
||||
unlockControls();
|
||||
|
||||
_camera->setFocusPosition(origin);
|
||||
_camera->setPosition(target);
|
||||
_camera->rotate(glm::quat_cast(transform));
|
||||
|
||||
_camera->setPosition(target);
|
||||
_camera->rotate(glm::quat_cast(transform));
|
||||
|
||||
}
|
||||
|
||||
//void InteractionHandler::distance(const float &d){
|
||||
//
|
||||
// lockControls();
|
||||
// lockControls();
|
||||
//
|
||||
// psc relative = _camera->position();
|
||||
// const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
|
||||
// psc relative_origin_coordinate = relative - origin;
|
||||
// // addition 100% of bounds (fix later to something node specific?)
|
||||
// float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f);
|
||||
// psc relative = _camera->position();
|
||||
// const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
|
||||
// psc relative_origin_coordinate = relative - origin;
|
||||
// // addition 100% of bounds (fix later to something node specific?)
|
||||
// float bounds = 2.f * (_focusNode ? _focusNode->boundingSphere().lengthf() : 0.f);
|
||||
//
|
||||
// psc target = relative + relative_origin_coordinate * d;// *fmaxf(bounds, (1.f - d));
|
||||
// //don't fly into objects
|
||||
// if ((target - origin).length() < bounds){
|
||||
// target = relative;
|
||||
// }
|
||||
// _camera->setPosition(target);
|
||||
//
|
||||
// unlockControls();
|
||||
// psc target = relative + relative_origin_coordinate * d;// *fmaxf(bounds, (1.f - d));
|
||||
// //don't fly into objects
|
||||
// if ((target - origin).length() < bounds){
|
||||
// target = relative;
|
||||
// }
|
||||
// _camera->setPosition(target);
|
||||
//
|
||||
// unlockControls();
|
||||
//}
|
||||
|
||||
void InteractionHandler::orbitDelta(const glm::quat& rotation)
|
||||
{
|
||||
lockControls();
|
||||
lockControls();
|
||||
|
||||
// the camera position
|
||||
psc relative = _camera->position();
|
||||
// the camera position
|
||||
psc relative = _camera->position();
|
||||
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
// should be changed to something more dynamic =)
|
||||
psc origin;
|
||||
if (_focusNode) {
|
||||
origin = _focusNode->worldPosition();
|
||||
}
|
||||
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
//glm::mat4 rotation_matrix = glm::mat4_cast(glm::inverse(rotation));
|
||||
//relative_origin_coordinate = relative_origin_coordinate.vec4() * glm::inverse(rotation);
|
||||
relative_origin_coordinate = glm::inverse(rotation) * relative_origin_coordinate.vec4();
|
||||
relative = relative_origin_coordinate + origin;
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
//glm::mat4 rotation_matrix = glm::mat4_cast(glm::inverse(rotation));
|
||||
//relative_origin_coordinate = relative_origin_coordinate.vec4() * glm::inverse(rotation);
|
||||
relative_origin_coordinate = glm::inverse(rotation) * relative_origin_coordinate.vec4();
|
||||
relative = relative_origin_coordinate + origin;
|
||||
glm::mat4 la = glm::lookAt(_camera->position().vec3(), origin.vec3(), glm::rotate(rotation, _camera->lookUpVector()));
|
||||
|
||||
unlockControls();
|
||||
|
||||
_camera->setPosition(relative);
|
||||
//camera_->rotate(rotation);
|
||||
//camera_->setRotation(glm::mat4_cast(rotation));
|
||||
_camera->setPosition(relative);
|
||||
//camera_->rotate(rotation);
|
||||
//camera_->setRotation(glm::mat4_cast(rotation));
|
||||
|
||||
|
||||
_camera->setRotation(la);
|
||||
//camera_->setLookUpVector();
|
||||
|
||||
_camera->setRotation(la);
|
||||
//camera_->setLookUpVector();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//<<<<<<< HEAD
|
||||
//void InteractionHandler::distance(const PowerScaledScalar &dist, size_t iterations) {
|
||||
// if (iterations > 5)
|
||||
// return;
|
||||
// //assert(this_);
|
||||
// lockControls();
|
||||
//
|
||||
// psc relative = _camera->position();
|
||||
// const psc origin = (_node) ? _node->worldPosition() : psc();
|
||||
// if (iterations > 5)
|
||||
// return;
|
||||
// //assert(this_);
|
||||
// lockControls();
|
||||
//
|
||||
// psc relative = _camera->position();
|
||||
// const psc origin = (_node) ? _node->worldPosition() : psc();
|
||||
//
|
||||
// psc relative_origin_coordinate = relative - origin;
|
||||
// const glm::vec3 dir(relative_origin_coordinate.direction());
|
||||
// glm::vec3 newdir = dir * dist[0];
|
||||
// psc relative_origin_coordinate = relative - origin;
|
||||
// const glm::vec3 dir(relative_origin_coordinate.direction());
|
||||
// glm::vec3 newdir = dir * dist[0];
|
||||
//=======
|
||||
void InteractionHandler::rotateDelta(const glm::quat& rotation)
|
||||
{
|
||||
_camera->rotate(rotation);
|
||||
_camera->rotate(rotation);
|
||||
}
|
||||
|
||||
void InteractionHandler::distanceDelta(const PowerScaledScalar& distance, size_t iterations)
|
||||
{
|
||||
if (iterations > 5)
|
||||
return;
|
||||
//assert(this_);
|
||||
lockControls();
|
||||
|
||||
psc relative = _camera->position();
|
||||
const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
|
||||
|
||||
if (iterations > 5)
|
||||
return;
|
||||
//assert(this_);
|
||||
lockControls();
|
||||
|
||||
psc relative = _camera->position();
|
||||
const psc origin = (_focusNode) ? _focusNode->worldPosition() : psc();
|
||||
|
||||
unlockControls();
|
||||
|
||||
psc relative_origin_coordinate = relative - origin;
|
||||
const glm::vec3 dir(relative_origin_coordinate.direction());
|
||||
glm::vec3 newdir = dir * distance[0];
|
||||
const glm::vec3 dir(relative_origin_coordinate.direction());
|
||||
glm::vec3 newdir = dir * distance[0];
|
||||
|
||||
relative_origin_coordinate = newdir;
|
||||
relative_origin_coordinate[3] = distance[1];
|
||||
relative = relative + relative_origin_coordinate;
|
||||
relative_origin_coordinate = newdir;
|
||||
relative_origin_coordinate[3] = distance[1];
|
||||
relative = relative + relative_origin_coordinate;
|
||||
|
||||
relative_origin_coordinate = relative - origin;
|
||||
if (relative_origin_coordinate.vec4().x == 0.f && relative_origin_coordinate.vec4().y == 0.f && relative_origin_coordinate.vec4().z == 0.f)
|
||||
// TODO: this shouldn't be allowed to happen; a mechanism to prevent the camera to coincide with the origin is necessary (ab)
|
||||
return;
|
||||
relative_origin_coordinate = relative - origin;
|
||||
if (relative_origin_coordinate.vec4().x == 0.f && relative_origin_coordinate.vec4().y == 0.f && relative_origin_coordinate.vec4().z == 0.f)
|
||||
// TODO: this shouldn't be allowed to happen; a mechanism to prevent the camera to coincide with the origin is necessary (ab)
|
||||
return;
|
||||
|
||||
newdir = relative_origin_coordinate.direction();
|
||||
newdir = relative_origin_coordinate.direction();
|
||||
|
||||
// update only if on the same side of the origin
|
||||
if (glm::angle(newdir, dir) < 90.0f) {
|
||||
_camera->setPosition(relative);
|
||||
}
|
||||
else {
|
||||
PowerScaledScalar d2 = distance;
|
||||
d2[0] *= 0.75f;
|
||||
d2[1] *= 0.85f;
|
||||
distanceDelta(d2, iterations + 1);
|
||||
}
|
||||
// update only if on the same side of the origin
|
||||
if (glm::angle(newdir, dir) < 90.0f) {
|
||||
_camera->setPosition(relative);
|
||||
}
|
||||
else {
|
||||
PowerScaledScalar d2 = distance;
|
||||
d2[0] *= 0.75f;
|
||||
d2[1] *= 0.85f;
|
||||
distanceDelta(d2, iterations + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::lookAt(const glm::quat& rotation)
|
||||
@@ -529,127 +408,93 @@ void InteractionHandler::lookAt(const glm::quat& rotation)
|
||||
void InteractionHandler::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) {
|
||||
// TODO package in script
|
||||
const float speed = _controllerSensitivity;
|
||||
const float dt = static_cast<float>(_deltaTime);
|
||||
const float dt = static_cast<float>(_deltaTime);
|
||||
if (action == KeyAction::Press || action == KeyAction::Repeat) {
|
||||
if ((key == Key::Right) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(0.0, speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(0.0, speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::Left) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(0.0, -speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(0.0, -speed * dt*0.4, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::Down) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::Up) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec3 euler(-speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
glm::vec3 euler(-speed * dt*0.4, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
rotateDelta(rot);
|
||||
}
|
||||
if ((key == Key::KeypadSubtract) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] -= 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] -= 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
if ((key == Key::KeypadAdd) && (modifier == KeyModifier::NoModifier)) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] += 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] += 0.5f;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
|
||||
// iterate over key bindings
|
||||
_validKeyLua = true;
|
||||
auto ret = _keyLua.equal_range(key);
|
||||
for (auto it = ret.first; it != ret.second; ++it) {
|
||||
//OsEng.scriptEngine()->runScript(it->second);
|
||||
OsEng.scriptEngine().queueScript(it->second);
|
||||
if (!_validKeyLua) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// iterate over key bindings
|
||||
_validKeyLua = true;
|
||||
auto ret = _keyLua.equal_range({ key, modifier });
|
||||
for (auto it = ret.first; it != ret.second; ++it) {
|
||||
//OsEng.scriptEngine()->runScript(it->second);
|
||||
OsEng.scriptEngine().queueScript(it->second);
|
||||
if (!_validKeyLua) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//void InteractionHandler::mouseButtonCallback(int key, int action) {
|
||||
// //if(mouseControl_ != nullptr) {
|
||||
// // mouseControl_->mouseButtonCallback(key,action);
|
||||
// //}
|
||||
// if (key == SGCT_MOUSE_BUTTON_LEFT && action == SGCT_PRESS)
|
||||
// _leftMouseButtonDown = true;
|
||||
// else if (key == SGCT_MOUSE_BUTTON_LEFT && action == SGCT_RELEASE) {
|
||||
// _leftMouseButtonDown = false;
|
||||
// _isMouseBeingPressedAndHeld = false;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::mousePositionCallback(int x, int y) {
|
||||
// if (_leftMouseButtonDown)
|
||||
// trackballRotate(x,y);
|
||||
//
|
||||
// //if(mouseControl_ != nullptr) {
|
||||
// // mouseControl_->mousePosCallback(x,y);
|
||||
// //}
|
||||
//}
|
||||
//
|
||||
//void InteractionHandler::mouseScrollWheelCallback(int pos) {
|
||||
// //if(mouseControl_ != nullptr) {
|
||||
// // mouseControl_->mouseScrollCallback(pos);
|
||||
// //}
|
||||
// const float speed = 4.75f;
|
||||
// const float dt = static_cast<float>(_dt);
|
||||
// if(pos < 0) {
|
||||
// PowerScaledScalar dist(speed * dt, 0.0f);
|
||||
// distance(dist);
|
||||
// } else if(pos > 0) {
|
||||
// PowerScaledScalar dist(-speed * dt, 0.0f);
|
||||
// distance(dist);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
|
||||
void InteractionHandler::resetKeyBindings() {
|
||||
_keyLua.clear();
|
||||
_validKeyLua = false;
|
||||
_keyLua.clear();
|
||||
_validKeyLua = false;
|
||||
}
|
||||
|
||||
void InteractionHandler::bindKey(Key key, std::string lua) {
|
||||
_keyLua.insert(std::make_pair(key, lua));
|
||||
void InteractionHandler::bindKey(Key key, KeyModifier modifier, std::string lua) {
|
||||
_keyLua.insert({
|
||||
{key, modifier},
|
||||
lua
|
||||
});
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
|
||||
return {
|
||||
"",
|
||||
{
|
||||
{
|
||||
"clearKeys",
|
||||
&luascriptfunctions::clearKeys,
|
||||
"",
|
||||
"Clear all key bindings"
|
||||
},
|
||||
{
|
||||
"bindKey",
|
||||
&luascriptfunctions::bindKey,
|
||||
"string, string",
|
||||
"Binds a key by name to a lua string command"
|
||||
},
|
||||
{
|
||||
"dt",
|
||||
&luascriptfunctions::dt,
|
||||
"",
|
||||
"Get current frame time"
|
||||
},
|
||||
{
|
||||
"distance",
|
||||
&luascriptfunctions::distance,
|
||||
"number",
|
||||
"Change distance to origin",
|
||||
return {
|
||||
"",
|
||||
{
|
||||
{
|
||||
"clearKeys",
|
||||
&luascriptfunctions::clearKeys,
|
||||
"",
|
||||
"Clear all key bindings"
|
||||
},
|
||||
{
|
||||
"bindKey",
|
||||
&luascriptfunctions::bindKey,
|
||||
"string, string",
|
||||
"Binds a key by name to a lua string command"
|
||||
},
|
||||
{
|
||||
"dt",
|
||||
&luascriptfunctions::dt,
|
||||
"",
|
||||
"Get current frame time"
|
||||
},
|
||||
{
|
||||
"distance",
|
||||
&luascriptfunctions::distance,
|
||||
"number",
|
||||
"Change distance to origin",
|
||||
true
|
||||
},
|
||||
},
|
||||
{
|
||||
"setInteractionSensitivity",
|
||||
&luascriptfunctions::setInteractionSensitivity,
|
||||
@@ -687,18 +532,17 @@ scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
|
||||
"Returns the status of rotation movement inversion"
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//=======
|
||||
void InteractionHandler::setRotation(const glm::quat& rotation)
|
||||
{
|
||||
_camera->setRotation(rotation);
|
||||
_camera->setRotation(rotation);
|
||||
}
|
||||
|
||||
double InteractionHandler::deltaTime() const {
|
||||
return _deltaTime;
|
||||
return _deltaTime;
|
||||
}
|
||||
|
||||
void InteractionHandler::setInteractionSensitivity(float sensitivity) {
|
||||
@@ -726,15 +570,15 @@ bool InteractionHandler::invertRotation() const {
|
||||
}
|
||||
|
||||
void InteractionHandler::addKeyframe(const network::datamessagestructures::PositionKeyframe &kf){
|
||||
_keyframeMutex.lock();
|
||||
_keyframeMutex.lock();
|
||||
|
||||
//save a maximum of 10 samples (1 seconds of buffer)
|
||||
if (_keyframes.size() >= 10){
|
||||
_keyframes.erase(_keyframes.begin());
|
||||
}
|
||||
//save a maximum of 10 samples (1 seconds of buffer)
|
||||
if (_keyframes.size() >= 10){
|
||||
_keyframes.erase(_keyframes.begin());
|
||||
}
|
||||
_keyframes.push_back(kf);
|
||||
|
||||
_keyframeMutex.unlock();
|
||||
_keyframeMutex.unlock();
|
||||
}
|
||||
|
||||
void InteractionHandler::clearKeyframes(){
|
||||
|
||||
@@ -32,28 +32,28 @@ namespace luascriptfunctions {
|
||||
* Set the origin of the camera
|
||||
*/
|
||||
int setOrigin(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.setOrigin";
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.setOrigin";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
if (type != LUA_TSTRING)
|
||||
return luaL_error(L, "Expected string, got %i", type);
|
||||
const int type = lua_type(L, -1);
|
||||
if (type != LUA_TSTRING)
|
||||
return luaL_error(L, "Expected string, got %i", type);
|
||||
|
||||
std::string s = luaL_checkstring(L, -1);
|
||||
std::string s = luaL_checkstring(L, -1);
|
||||
|
||||
SceneGraphNode* node = sceneGraphNode(s);
|
||||
if (!node) {
|
||||
LWARNING("Could not find a node in scenegraph called '" << s <<"'");
|
||||
return 0;
|
||||
}
|
||||
SceneGraphNode* node = sceneGraphNode(s);
|
||||
if (!node) {
|
||||
LWARNING("Could not find a node in scenegraph called '" << s <<"'");
|
||||
return 0;
|
||||
}
|
||||
|
||||
OsEng.interactionHandler().setFocusNode(node);
|
||||
OsEng.interactionHandler().setFocusNode(node);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,31 +62,35 @@ int setOrigin(lua_State* L) {
|
||||
* Binds a key to Lua command
|
||||
*/
|
||||
int bindKey(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.bindKey";
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.bindKey";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
|
||||
|
||||
std::string key = luaL_checkstring(L, -2);
|
||||
std::string command = luaL_checkstring(L, -1);
|
||||
std::string key = luaL_checkstring(L, -2);
|
||||
std::string command = luaL_checkstring(L, -1);
|
||||
|
||||
if (command.empty())
|
||||
return luaL_error(L, "Command string is empty");
|
||||
if (command.empty())
|
||||
return luaL_error(L, "Command string is empty");
|
||||
|
||||
openspace::Key iKey = stringToKey(key);
|
||||
openspace::KeyWithModifier iKey = openspace::stringToKey(key);
|
||||
|
||||
if (iKey == openspace::Key::Unknown) {
|
||||
LERROR("Could not find key '"<< key <<"'");
|
||||
return 0;
|
||||
}
|
||||
if (iKey.key == openspace::Key::Unknown) {
|
||||
LERROR("Could not find key '"<< key <<"'");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
OsEng.interactionHandler().bindKey(iKey, command);
|
||||
|
||||
return 0;
|
||||
OsEng.interactionHandler().bindKey(
|
||||
iKey.key,
|
||||
iKey.modifier,
|
||||
command
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,16 +99,16 @@ int bindKey(lua_State* L) {
|
||||
* Clears all key bindings
|
||||
*/
|
||||
int clearKeys(lua_State* L) {
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.clearKeys";
|
||||
using ghoul::lua::luaTypeToString;
|
||||
const std::string _loggerCat = "lua.clearKeys";
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
OsEng.interactionHandler().resetKeyBindings();
|
||||
OsEng.interactionHandler().resetKeyBindings();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,12 +117,12 @@ int clearKeys(lua_State* L) {
|
||||
* Get current frame time
|
||||
*/
|
||||
int dt(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
|
||||
lua_pushnumber(L,OsEng.interactionHandler().deltaTime());
|
||||
return 1;
|
||||
lua_pushnumber(L,OsEng.interactionHandler().deltaTime());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,15 +131,15 @@ int dt(lua_State* L) {
|
||||
* Change distance to origin
|
||||
*/
|
||||
int distance(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 2)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
|
||||
|
||||
double d1 = luaL_checknumber(L, -2);
|
||||
double d2 = luaL_checknumber(L, -1);
|
||||
PowerScaledScalar dist(static_cast<float>(d1), static_cast<float>(d2));
|
||||
OsEng.interactionHandler().distanceDelta(dist);
|
||||
return 0;
|
||||
double d1 = luaL_checknumber(L, -2);
|
||||
double d2 = luaL_checknumber(L, -1);
|
||||
PowerScaledScalar dist(static_cast<float>(d1), static_cast<float>(d2));
|
||||
OsEng.interactionHandler().distanceDelta(dist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,291 +36,291 @@
|
||||
#include <chrono>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "KeyboardController";
|
||||
const std::string _loggerCat = "KeyboardController";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
void KeyboardControllerFixed::keyPressed(KeyAction action, Key key, KeyModifier modifier) {
|
||||
// TODO package in script
|
||||
const float dt = static_cast<float>( _handler->deltaTime());
|
||||
if(action == KeyAction::Press|| action == KeyAction::Repeat) {
|
||||
// TODO package in script
|
||||
const float dt = static_cast<float>( _handler->deltaTime());
|
||||
if(action == KeyAction::Press|| action == KeyAction::Repeat) {
|
||||
const float speed = 2.75;
|
||||
if (key == Key::S) {
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::W) {
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::A) {
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::D) {
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::Q) {
|
||||
Time::ref().advanceTime(dt);
|
||||
}
|
||||
if (key == Key::Right) {
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Left) {
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Down) {
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Up) {
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::R) {
|
||||
PowerScaledScalar dist(-speed * dt, 0.0);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::F) {
|
||||
PowerScaledScalar dist(speed * dt, 0.0);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::T) {
|
||||
PowerScaledScalar dist(-speed * pow(10.0f, 11.0f) * dt, 0.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
//if (key == Keys::G) {
|
||||
// acc += 0.001;
|
||||
// PowerScaledScalar dist(speed * pow(10, 8 * acc) * dt, 0.0);
|
||||
// distanceDelta(dist);
|
||||
//}
|
||||
if (key == Key::Y) {
|
||||
PowerScaledScalar dist(-speed * 100.0f * dt, 6.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::H) {
|
||||
PowerScaledScalar dist(speed * 100.0f * dt, 6.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
|
||||
if (key == Key::KeypadSubtract) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] -= 0.5;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
if (key == Key::KeypadAdd) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] += 0.5;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (key == '1') {
|
||||
SceneGraphNode* node = getSceneGraphNode("sun");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 0.5, 10.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
if (key == '2') {
|
||||
SceneGraphNode* node = getSceneGraphNode("earth");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 1.0, 8.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
|
||||
if (key == '3') {
|
||||
SceneGraphNode* node = getSceneGraphNode("moon");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 0.5, 8.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
*/
|
||||
if (key == Key::S) {
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::W) {
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::A) {
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::D) {
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->orbitDelta(rot);
|
||||
}
|
||||
if (key == Key::Q) {
|
||||
Time::ref().advanceTime(dt);
|
||||
}
|
||||
if (key == Key::Right) {
|
||||
glm::vec3 euler(0.0, speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Left) {
|
||||
glm::vec3 euler(0.0, -speed * dt, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Down) {
|
||||
glm::vec3 euler(speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::Up) {
|
||||
glm::vec3 euler(-speed * dt, 0.0, 0.0);
|
||||
glm::quat rot = glm::quat(euler);
|
||||
_handler->rotateDelta(rot);
|
||||
}
|
||||
if (key == Key::R) {
|
||||
PowerScaledScalar dist(-speed * dt, 0.0);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::F) {
|
||||
PowerScaledScalar dist(speed * dt, 0.0);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::T) {
|
||||
PowerScaledScalar dist(-speed * pow(10.0f, 11.0f) * dt, 0.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
//if (key == Keys::G) {
|
||||
// acc += 0.001;
|
||||
// PowerScaledScalar dist(speed * pow(10, 8 * acc) * dt, 0.0);
|
||||
// distanceDelta(dist);
|
||||
//}
|
||||
if (key == Key::Y) {
|
||||
PowerScaledScalar dist(-speed * 100.0f * dt, 6.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
if (key == Key::H) {
|
||||
PowerScaledScalar dist(speed * 100.0f * dt, 6.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
|
||||
if (key == Key::KeypadSubtract) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] -= 0.5;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
if (key == Key::KeypadAdd) {
|
||||
glm::vec2 s = OsEng.renderEngine().camera()->scaling();
|
||||
s[1] += 0.5;
|
||||
OsEng.renderEngine().camera()->setScaling(s);
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (key == '1') {
|
||||
SceneGraphNode* node = getSceneGraphNode("sun");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 0.5, 10.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
if (key == '2') {
|
||||
SceneGraphNode* node = getSceneGraphNode("earth");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 1.0, 8.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
|
||||
|
||||
if (key == '3') {
|
||||
SceneGraphNode* node = getSceneGraphNode("moon");
|
||||
|
||||
setFocusNode(node);
|
||||
getCamera()->setPosition(node->getWorldPosition() + psc(0.0, 0.0, 0.5, 8.0));
|
||||
getCamera()->setCameraDirection(glm::vec3(0.0, 0.0, -1.0));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void KeyboardControllerLua::keyPressed(KeyAction action, Key key, KeyModifier modifier) {
|
||||
lua_State* s = luaL_newstate();
|
||||
luaL_openlibs(s);
|
||||
|
||||
int status = luaL_loadfile(s, absPath("${SCRIPTS}/default_keybinding.lua").c_str());
|
||||
if (status != LUA_OK) {
|
||||
LERROR("Error loading script: '" << lua_tostring(s, -1) << "'");
|
||||
return;
|
||||
}
|
||||
lua_State* s = luaL_newstate();
|
||||
luaL_openlibs(s);
|
||||
|
||||
int status = luaL_loadfile(s, absPath("${SCRIPTS}/default_keybinding.lua").c_str());
|
||||
if (status != LUA_OK) {
|
||||
LERROR("Error loading script: '" << lua_tostring(s, -1) << "'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lua_pcall(s, 0, LUA_MULTRET, 0)) {
|
||||
LERROR("Error executing script: " << lua_tostring(s, -1));
|
||||
return;
|
||||
}
|
||||
if (lua_pcall(s, 0, LUA_MULTRET, 0)) {
|
||||
LERROR("Error executing script: " << lua_tostring(s, -1));
|
||||
return;
|
||||
}
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
lua_getfield(s, -1, keyToString(key, modifier).c_str());
|
||||
if (!lua_isnil(s, -1))
|
||||
lua_pcall(s, 0, 0, 0);
|
||||
else
|
||||
LINFO("Key not found");
|
||||
lua_getfield(s, -1, keyToString(key, modifier).c_str());
|
||||
if (!lua_isnil(s, -1))
|
||||
lua_pcall(s, 0, 0, 0);
|
||||
else
|
||||
LINFO("Key not found");
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
LINFO("Keyboard timing: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "ns");
|
||||
LINFO("Keyboard timing: " << std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() << "ns");
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::string KeyboardControllerLua::keyToString(Key key, KeyModifier mod) const {
|
||||
std::string result = "";
|
||||
int intMod = static_cast<int>(mod);
|
||||
if (intMod & static_cast<int>(KeyModifier::Control))
|
||||
result += "CTRL + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Super))
|
||||
result += "SUPER + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Alt))
|
||||
result += "ALT + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Shift))
|
||||
result += "SHIFT + ";
|
||||
std::string result = "";
|
||||
int intMod = static_cast<int>(mod);
|
||||
if (intMod & static_cast<int>(KeyModifier::Control))
|
||||
result += "CTRL + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Super))
|
||||
result += "SUPER + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Alt))
|
||||
result += "ALT + ";
|
||||
if (intMod & static_cast<int>(KeyModifier::Shift))
|
||||
result += "SHIFT + ";
|
||||
|
||||
switch (key) {
|
||||
case Key::Unknown: result += "Unknown"; break;
|
||||
case Key::Space: result += "Space"; break;
|
||||
case Key::Apostrophe: result += "Apostrophe"; break;
|
||||
case Key::Comma: result += "Comma"; break;
|
||||
case Key::Minus: result += "Minus"; break;
|
||||
case Key::Period: result += "Period"; break;
|
||||
case Key::Slash: result += "Slash"; break;
|
||||
case Key::Num0: result += "0"; break;
|
||||
case Key::Num1: result += "1"; break;
|
||||
case Key::Num2: result += "2"; break;
|
||||
case Key::Num3: result += "3"; break;
|
||||
case Key::Num4: result += "4"; break;
|
||||
case Key::Num5: result += "5"; break;
|
||||
case Key::Num6: result += "6"; break;
|
||||
case Key::Num7: result += "7"; break;
|
||||
case Key::Num8: result += "8"; break;
|
||||
case Key::Num9: result += "9"; break;
|
||||
case Key::SemiColon: result += "SemiColon"; break;
|
||||
case Key::Equal: result += "Equal"; break;
|
||||
case Key::A: result += "A"; break;
|
||||
case Key::B: result += "B"; break;
|
||||
case Key::C: result += "C"; break;
|
||||
case Key::D: result += "D"; break;
|
||||
case Key::E: result += "E"; break;
|
||||
case Key::F: result += "F"; break;
|
||||
case Key::G: result += "G"; break;
|
||||
case Key::H: result += "H"; break;
|
||||
case Key::I: result += "I"; break;
|
||||
case Key::J: result += "J"; break;
|
||||
case Key::K: result += "K"; break;
|
||||
case Key::L: result += "L"; break;
|
||||
case Key::M: result += "M"; break;
|
||||
case Key::N: result += "N"; break;
|
||||
case Key::O: result += "O"; break;
|
||||
case Key::P: result += "P"; break;
|
||||
case Key::Q: result += "Q"; break;
|
||||
case Key::R: result += "R"; break;
|
||||
case Key::S: result += "S"; break;
|
||||
case Key::T: result += "T"; break;
|
||||
case Key::U: result += "U"; break;
|
||||
case Key::V: result += "V"; break;
|
||||
case Key::W: result += "W"; break;
|
||||
case Key::X: result += "X"; break;
|
||||
case Key::Y: result += "Y"; break;
|
||||
case Key::Z: result += "Z"; break;
|
||||
case Key::LeftBracket: result += "LeftBracket"; break;
|
||||
case Key::BackSlash: result += "BackSlash"; break;
|
||||
case Key::RightBracket: result += "RightBracket"; break;
|
||||
case Key::GraveAccent: result += "GraveAccent"; break;
|
||||
case Key::World1: result += "World1"; break;
|
||||
case Key::World2: result += "World2"; break;
|
||||
case Key::Escape: result += "Escape"; break;
|
||||
case Key::Enter: result += "Enter"; break;
|
||||
case Key::Tab: result += "Tab"; break;
|
||||
case Key::BackSpace: result += "BackSpace"; break;
|
||||
case Key::Insert: result += "Insert"; break;
|
||||
case Key::Delete: result += "Delete"; break;
|
||||
case Key::Right: result += "Right"; break;
|
||||
case Key::Left: result += "Left"; break;
|
||||
case Key::Down: result += "Down"; break;
|
||||
case Key::Up: result += "Up"; break;
|
||||
case Key::PageUp: result += "PageUp"; break;
|
||||
case Key::PageDown: result += "PageDown"; break;
|
||||
case Key::Home: result += "Home"; break;
|
||||
case Key::End: result += "End"; break;
|
||||
case Key::CapsLock: result += "CapsLock"; break;
|
||||
case Key::ScrollLock: result += "ScrollLock"; break;
|
||||
case Key::NumLock: result += "NumLock"; break;
|
||||
case Key::PrintScreen: result += "PrintScreen"; break;
|
||||
case Key::Pause: result += "Pause"; break;
|
||||
case Key::F1: result += "F1"; break;
|
||||
case Key::F2: result += "F2"; break;
|
||||
case Key::F3: result += "F3"; break;
|
||||
case Key::F4: result += "F4"; break;
|
||||
case Key::F5: result += "F5"; break;
|
||||
case Key::F6: result += "F6"; break;
|
||||
case Key::F7: result += "F7"; break;
|
||||
case Key::F8: result += "F8"; break;
|
||||
case Key::F9: result += "F9"; break;
|
||||
case Key::F10: result += "F10"; break;
|
||||
case Key::F11: result += "F11"; break;
|
||||
case Key::F12: result += "F12"; break;
|
||||
case Key::F13: result += "F13"; break;
|
||||
case Key::F14: result += "F14"; break;
|
||||
case Key::F15: result += "F15"; break;
|
||||
case Key::F16: result += "F16"; break;
|
||||
case Key::F17: result += "F17"; break;
|
||||
case Key::F18: result += "F18"; break;
|
||||
case Key::F19: result += "F19"; break;
|
||||
case Key::F20: result += "F20"; break;
|
||||
case Key::F21: result += "F21"; break;
|
||||
case Key::F22: result += "F22"; break;
|
||||
case Key::F23: result += "F23"; break;
|
||||
case Key::F24: result += "F24"; break;
|
||||
case Key::F25: result += "F25"; break;
|
||||
case Key::Keypad0: result += "Keypad0"; break;
|
||||
case Key::Keypad1: result += "Keypad1"; break;
|
||||
case Key::Keypad2: result += "Keypad2"; break;
|
||||
case Key::Keypad3: result += "Keypad3"; break;
|
||||
case Key::Keypad4: result += "Keypad4"; break;
|
||||
case Key::Keypad5: result += "Keypad5"; break;
|
||||
case Key::Keypad6: result += "Keypad6"; break;
|
||||
case Key::Keypad7: result += "Keypad7"; break;
|
||||
case Key::Keypad8: result += "Keypad8"; break;
|
||||
case Key::Keypad9: result += "Keypad9"; break;
|
||||
case Key::KeypadDecimal: result += "KeypadDecimal"; break;
|
||||
case Key::KeypadDivide: result += "KeypadDivide"; break;
|
||||
case Key::KeypadMultiply: result += "KeypadMultiply"; break;
|
||||
case Key::KeypadSubtract: result += "KeypadSubtract"; break;
|
||||
case Key::KeypadAdd: result += "KeypadAdd"; break;
|
||||
case Key::KeypadEnter: result += "KeypadEnter"; break;
|
||||
case Key::LeftShift: result += "LeftShift"; break;
|
||||
case Key::LeftControl: result += "LeftControl"; break;
|
||||
case Key::LeftAlt: result += "LeftAlt"; break;
|
||||
case Key::LeftSuper: result += "LeftSuper"; break;
|
||||
case Key::RightShift: result += "RightShift"; break;
|
||||
case Key::RightControl: result += "RightControl"; break;
|
||||
case Key::RightAlt: result += "RightAlt"; break;
|
||||
case Key::RightSuper: result += "RightSuper"; break;
|
||||
case Key::Menu: result += "Menu"; break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
return result;
|
||||
switch (key) {
|
||||
case Key::Unknown: result += "Unknown"; break;
|
||||
case Key::Space: result += "Space"; break;
|
||||
case Key::Apostrophe: result += "Apostrophe"; break;
|
||||
case Key::Comma: result += "Comma"; break;
|
||||
case Key::Minus: result += "Minus"; break;
|
||||
case Key::Period: result += "Period"; break;
|
||||
case Key::Slash: result += "Slash"; break;
|
||||
case Key::Num0: result += "0"; break;
|
||||
case Key::Num1: result += "1"; break;
|
||||
case Key::Num2: result += "2"; break;
|
||||
case Key::Num3: result += "3"; break;
|
||||
case Key::Num4: result += "4"; break;
|
||||
case Key::Num5: result += "5"; break;
|
||||
case Key::Num6: result += "6"; break;
|
||||
case Key::Num7: result += "7"; break;
|
||||
case Key::Num8: result += "8"; break;
|
||||
case Key::Num9: result += "9"; break;
|
||||
case Key::SemiColon: result += "SemiColon"; break;
|
||||
case Key::Equal: result += "Equal"; break;
|
||||
case Key::A: result += "A"; break;
|
||||
case Key::B: result += "B"; break;
|
||||
case Key::C: result += "C"; break;
|
||||
case Key::D: result += "D"; break;
|
||||
case Key::E: result += "E"; break;
|
||||
case Key::F: result += "F"; break;
|
||||
case Key::G: result += "G"; break;
|
||||
case Key::H: result += "H"; break;
|
||||
case Key::I: result += "I"; break;
|
||||
case Key::J: result += "J"; break;
|
||||
case Key::K: result += "K"; break;
|
||||
case Key::L: result += "L"; break;
|
||||
case Key::M: result += "M"; break;
|
||||
case Key::N: result += "N"; break;
|
||||
case Key::O: result += "O"; break;
|
||||
case Key::P: result += "P"; break;
|
||||
case Key::Q: result += "Q"; break;
|
||||
case Key::R: result += "R"; break;
|
||||
case Key::S: result += "S"; break;
|
||||
case Key::T: result += "T"; break;
|
||||
case Key::U: result += "U"; break;
|
||||
case Key::V: result += "V"; break;
|
||||
case Key::W: result += "W"; break;
|
||||
case Key::X: result += "X"; break;
|
||||
case Key::Y: result += "Y"; break;
|
||||
case Key::Z: result += "Z"; break;
|
||||
case Key::LeftBracket: result += "LeftBracket"; break;
|
||||
case Key::BackSlash: result += "BackSlash"; break;
|
||||
case Key::RightBracket: result += "RightBracket"; break;
|
||||
case Key::GraveAccent: result += "GraveAccent"; break;
|
||||
case Key::World1: result += "World1"; break;
|
||||
case Key::World2: result += "World2"; break;
|
||||
case Key::Escape: result += "Escape"; break;
|
||||
case Key::Enter: result += "Enter"; break;
|
||||
case Key::Tab: result += "Tab"; break;
|
||||
case Key::BackSpace: result += "BackSpace"; break;
|
||||
case Key::Insert: result += "Insert"; break;
|
||||
case Key::Delete: result += "Delete"; break;
|
||||
case Key::Right: result += "Right"; break;
|
||||
case Key::Left: result += "Left"; break;
|
||||
case Key::Down: result += "Down"; break;
|
||||
case Key::Up: result += "Up"; break;
|
||||
case Key::PageUp: result += "PageUp"; break;
|
||||
case Key::PageDown: result += "PageDown"; break;
|
||||
case Key::Home: result += "Home"; break;
|
||||
case Key::End: result += "End"; break;
|
||||
case Key::CapsLock: result += "CapsLock"; break;
|
||||
case Key::ScrollLock: result += "ScrollLock"; break;
|
||||
case Key::NumLock: result += "NumLock"; break;
|
||||
case Key::PrintScreen: result += "PrintScreen"; break;
|
||||
case Key::Pause: result += "Pause"; break;
|
||||
case Key::F1: result += "F1"; break;
|
||||
case Key::F2: result += "F2"; break;
|
||||
case Key::F3: result += "F3"; break;
|
||||
case Key::F4: result += "F4"; break;
|
||||
case Key::F5: result += "F5"; break;
|
||||
case Key::F6: result += "F6"; break;
|
||||
case Key::F7: result += "F7"; break;
|
||||
case Key::F8: result += "F8"; break;
|
||||
case Key::F9: result += "F9"; break;
|
||||
case Key::F10: result += "F10"; break;
|
||||
case Key::F11: result += "F11"; break;
|
||||
case Key::F12: result += "F12"; break;
|
||||
case Key::F13: result += "F13"; break;
|
||||
case Key::F14: result += "F14"; break;
|
||||
case Key::F15: result += "F15"; break;
|
||||
case Key::F16: result += "F16"; break;
|
||||
case Key::F17: result += "F17"; break;
|
||||
case Key::F18: result += "F18"; break;
|
||||
case Key::F19: result += "F19"; break;
|
||||
case Key::F20: result += "F20"; break;
|
||||
case Key::F21: result += "F21"; break;
|
||||
case Key::F22: result += "F22"; break;
|
||||
case Key::F23: result += "F23"; break;
|
||||
case Key::F24: result += "F24"; break;
|
||||
case Key::F25: result += "F25"; break;
|
||||
case Key::Keypad0: result += "Keypad0"; break;
|
||||
case Key::Keypad1: result += "Keypad1"; break;
|
||||
case Key::Keypad2: result += "Keypad2"; break;
|
||||
case Key::Keypad3: result += "Keypad3"; break;
|
||||
case Key::Keypad4: result += "Keypad4"; break;
|
||||
case Key::Keypad5: result += "Keypad5"; break;
|
||||
case Key::Keypad6: result += "Keypad6"; break;
|
||||
case Key::Keypad7: result += "Keypad7"; break;
|
||||
case Key::Keypad8: result += "Keypad8"; break;
|
||||
case Key::Keypad9: result += "Keypad9"; break;
|
||||
case Key::KeypadDecimal: result += "KeypadDecimal"; break;
|
||||
case Key::KeypadDivide: result += "KeypadDivide"; break;
|
||||
case Key::KeypadMultiply: result += "KeypadMultiply"; break;
|
||||
case Key::KeypadSubtract: result += "KeypadSubtract"; break;
|
||||
case Key::KeypadAdd: result += "KeypadAdd"; break;
|
||||
case Key::KeypadEnter: result += "KeypadEnter"; break;
|
||||
case Key::LeftShift: result += "LeftShift"; break;
|
||||
case Key::LeftControl: result += "LeftControl"; break;
|
||||
case Key::LeftAlt: result += "LeftAlt"; break;
|
||||
case Key::LeftSuper: result += "LeftSuper"; break;
|
||||
case Key::RightShift: result += "RightShift"; break;
|
||||
case Key::RightControl: result += "RightControl"; break;
|
||||
case Key::RightAlt: result += "RightAlt"; break;
|
||||
case Key::RightSuper: result += "RightSuper"; break;
|
||||
case Key::Menu: result += "Menu"; break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
|
||||
+134
-136
@@ -41,11 +41,9 @@
|
||||
#include <iterator>
|
||||
#include <fstream>
|
||||
|
||||
#include <sgct.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "LuaConsole";
|
||||
const std::string historyFile = "ConsoleHistory";
|
||||
const std::string _loggerCat = "LuaConsole";
|
||||
const std::string historyFile = "ConsoleHistory";
|
||||
|
||||
const int NoAutoComplete = -1;
|
||||
}
|
||||
@@ -55,14 +53,14 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
LuaConsole::LuaConsole()
|
||||
: _inputPosition(0)
|
||||
, _activeCommand(0)
|
||||
, _filename("")
|
||||
: _inputPosition(0)
|
||||
, _activeCommand(0)
|
||||
, _filename("")
|
||||
, _autoCompleteInfo({NoAutoComplete, false, ""})
|
||||
, _isVisible(false)
|
||||
, _isVisible(false)
|
||||
{
|
||||
// _commands.push_back("");
|
||||
// _activeCommand = _commands.size() - 1;
|
||||
// _commands.push_back("");
|
||||
// _activeCommand = _commands.size() - 1;
|
||||
}
|
||||
|
||||
void LuaConsole::initialize() {
|
||||
@@ -111,73 +109,73 @@ void LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
const bool modifierControl = (modifier == KeyModifier::Control);
|
||||
const bool modifierShift = (modifier == KeyModifier::Shift);
|
||||
|
||||
// Paste from clipboard
|
||||
// Paste from clipboard
|
||||
if (modifierControl && (key == Key::V))
|
||||
addToCommand(ghoul::clipboardText());
|
||||
addToCommand(ghoul::clipboardText());
|
||||
|
||||
// Copy to clipboard
|
||||
// Copy to clipboard
|
||||
if (modifierControl && (key == Key::C))
|
||||
ghoul::setClipboardText(_commands.at(_activeCommand));
|
||||
ghoul::setClipboardText(_commands.at(_activeCommand));
|
||||
|
||||
// Go to the previous character
|
||||
// Go to the previous character
|
||||
if ((key == Key::Left) && (_inputPosition > 0))
|
||||
--_inputPosition;
|
||||
--_inputPosition;
|
||||
|
||||
// Go to the next character
|
||||
// Go to the next character
|
||||
if ((key == Key::Right) && _inputPosition < _commands.at(_activeCommand).length())
|
||||
++_inputPosition;
|
||||
++_inputPosition;
|
||||
|
||||
// Go to previous command
|
||||
// Go to previous command
|
||||
if (key == Key::Up) {
|
||||
if (_activeCommand > 0)
|
||||
--_activeCommand;
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
}
|
||||
if (_activeCommand > 0)
|
||||
--_activeCommand;
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
}
|
||||
|
||||
// Go to next command (the last is empty)
|
||||
// Go to next command (the last is empty)
|
||||
if (key == Key::Down) {
|
||||
if (_activeCommand < _commands.size() - 1)
|
||||
++_activeCommand;
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
}
|
||||
if (_activeCommand < _commands.size() - 1)
|
||||
++_activeCommand;
|
||||
_inputPosition = _commands.at(_activeCommand).length();
|
||||
}
|
||||
|
||||
// Remove character before _inputPosition
|
||||
// Remove character before _inputPosition
|
||||
if (key == Key::BackSpace) {
|
||||
if (_inputPosition > 0) {
|
||||
_commands.at(_activeCommand).erase(_inputPosition - 1, 1);
|
||||
--_inputPosition;
|
||||
}
|
||||
}
|
||||
if (_inputPosition > 0) {
|
||||
_commands.at(_activeCommand).erase(_inputPosition - 1, 1);
|
||||
--_inputPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove character after _inputPosition
|
||||
// Remove character after _inputPosition
|
||||
if (key == Key::Delete) {
|
||||
if (_inputPosition <= _commands.at(_activeCommand).size())
|
||||
_commands.at(_activeCommand).erase(_inputPosition, 1);
|
||||
}
|
||||
|
||||
// Go to the beginning of command string
|
||||
// Go to the beginning of command string
|
||||
if (key == Key::Home)
|
||||
_inputPosition = 0;
|
||||
_inputPosition = 0;
|
||||
|
||||
// Go to the end of command string
|
||||
// Go to the end of command string
|
||||
if (key == Key::End)
|
||||
_inputPosition = _commands.at(_activeCommand).size();
|
||||
_inputPosition = _commands.at(_activeCommand).size();
|
||||
|
||||
if (key == Key::Enter) {
|
||||
// SHIFT+ENTER == new line
|
||||
if (modifierShift)
|
||||
addToCommand("\n");
|
||||
// ENTER == run lua script
|
||||
else {
|
||||
// SHIFT+ENTER == new line
|
||||
if (modifierShift)
|
||||
addToCommand("\n");
|
||||
// ENTER == run lua script
|
||||
else {
|
||||
std::string cmd = _commands.at(_activeCommand);
|
||||
if (cmd != "") {
|
||||
OsEng.scriptEngine().queueScript(cmd);
|
||||
if (cmd != "") {
|
||||
OsEng.scriptEngine().queueScript(cmd);
|
||||
|
||||
// Only add the current command to the history if it hasn't been
|
||||
// executed before. We don't want two of the same commands in a row
|
||||
if (_commandsHistory.empty() || (cmd != _commandsHistory.back()))
|
||||
_commandsHistory.push_back(_commands.at(_activeCommand));
|
||||
}
|
||||
_commandsHistory.push_back(_commands.at(_activeCommand));
|
||||
}
|
||||
|
||||
// Some clean up after the execution of the command
|
||||
_commands = _commandsHistory;
|
||||
@@ -185,8 +183,8 @@ void LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
_activeCommand = _commands.size() - 1;
|
||||
_inputPosition = 0;
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (key == Key::Tab) {
|
||||
// We get a list of all the available commands and initially find the first
|
||||
@@ -282,28 +280,28 @@ void LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
if (!modifierShift)
|
||||
_autoCompleteInfo = { NoAutoComplete, false, ""};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LuaConsole::charCallback(unsigned int codepoint, KeyModifier modifier) {
|
||||
if (codepoint == static_cast<unsigned int>(commandInputButton()))
|
||||
return;
|
||||
if (codepoint == static_cast<unsigned int>(commandInputButton()))
|
||||
return;
|
||||
|
||||
#ifndef WIN32
|
||||
const bool modifierControl = (modifier == KeyModifier::Control);
|
||||
|
||||
const int codepoint_C = 99;
|
||||
const int codepoint_V = 118;
|
||||
if (modifierControl && (codepoint == codepoint_C || codepoint == codepoint_V)) {
|
||||
return;
|
||||
}
|
||||
const int codepoint_C = 99;
|
||||
const int codepoint_V = 118;
|
||||
if (modifierControl && (codepoint == codepoint_C || codepoint == codepoint_V)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
addToCommand(UnicodeToUTF8(codepoint));
|
||||
addToCommand(UnicodeToUTF8(codepoint));
|
||||
|
||||
}
|
||||
|
||||
void LuaConsole::render() {
|
||||
const float font_size = 10.0f;
|
||||
const float font_size = 10.0f;
|
||||
|
||||
glm::ivec4 viewportPixelCoordinates = OsEng.windowWrapper().viewportPixelCoordinates();
|
||||
int x1 = viewportPixelCoordinates.x;
|
||||
@@ -311,12 +309,12 @@ void LuaConsole::render() {
|
||||
int y1 = viewportPixelCoordinates.z;
|
||||
int ySize = viewportPixelCoordinates.w;
|
||||
|
||||
float startY = static_cast<float>(ySize) - 2.0f * font_size;
|
||||
startY = startY - font_size * 15.0f * 2.0f;
|
||||
float startY = static_cast<float>(ySize) - 2.0f * font_size;
|
||||
startY = startY - font_size * 15.0f * 2.0f;
|
||||
|
||||
const glm::vec4 red(1, 0, 0, 1);
|
||||
const glm::vec4 green(0, 1, 0, 1);
|
||||
const glm::vec4 white(1, 1, 1, 1);
|
||||
const glm::vec4 red(1, 0, 0, 1);
|
||||
const glm::vec4 green(0, 1, 0, 1);
|
||||
const glm::vec4 white(1, 1, 1, 1);
|
||||
std::shared_ptr<ghoul::fontrendering::Font> font = OsEng.fontManager().font("Mono", font_size);
|
||||
|
||||
using ghoul::fontrendering::RenderFont;
|
||||
@@ -324,106 +322,106 @@ void LuaConsole::render() {
|
||||
RenderFont(*font, glm::vec2(15.f, startY), red, "$");
|
||||
RenderFont(*font, glm::vec2(15.f + font_size, startY), white, "%s", _commands.at(_activeCommand).c_str());
|
||||
|
||||
size_t n = std::count(_commands.at(_activeCommand).begin(), _commands.at(_activeCommand).begin() + _inputPosition, '\n');
|
||||
size_t p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition);
|
||||
size_t linepos = _inputPosition;
|
||||
size_t n = std::count(_commands.at(_activeCommand).begin(), _commands.at(_activeCommand).begin() + _inputPosition, '\n');
|
||||
size_t p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition);
|
||||
size_t linepos = _inputPosition;
|
||||
|
||||
if (n>0) {
|
||||
if (p == _inputPosition) {
|
||||
p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition - 1);
|
||||
if (p != std::string::npos) {
|
||||
linepos -= p + 1;
|
||||
}
|
||||
else {
|
||||
linepos = _inputPosition - 1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
linepos -= p + 1;
|
||||
}
|
||||
}
|
||||
if (n>0) {
|
||||
if (p == _inputPosition) {
|
||||
p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition - 1);
|
||||
if (p != std::string::npos) {
|
||||
linepos -= p + 1;
|
||||
}
|
||||
else {
|
||||
linepos = _inputPosition - 1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
linepos -= p + 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "%" << linepos + 1 << "s";
|
||||
std::stringstream ss;
|
||||
ss << "%" << linepos + 1 << "s";
|
||||
RenderFont(*font, glm::vec2(15.f + font_size * 0.5f, startY - (font_size)*(n + 1)*3.0f / 2.0f), green, ss.str().c_str(), "^");
|
||||
|
||||
// sgct_text::print(font, 15.0f + font_size*0.5f, startY - (font_size)*(n + 1)*3.0f / 2.0f, green, ss.str().c_str(), "^");
|
||||
}
|
||||
|
||||
Key LuaConsole::commandInputButton() {
|
||||
// Button left of 1 and above TAB
|
||||
// Button left of 1 and above TAB
|
||||
// How to deal with different keyboard languages? ---abock
|
||||
return Key::GraveAccent;
|
||||
}
|
||||
|
||||
void LuaConsole::addToCommand(std::string c) {
|
||||
size_t length = c.length();
|
||||
_commands.at(_activeCommand).insert(_inputPosition, c);
|
||||
_inputPosition += length;
|
||||
size_t length = c.length();
|
||||
_commands.at(_activeCommand).insert(_inputPosition, c);
|
||||
_inputPosition += length;
|
||||
}
|
||||
|
||||
std::string LuaConsole::UnicodeToUTF8(unsigned int codepoint) {
|
||||
std::string out;
|
||||
std::string out;
|
||||
|
||||
if (codepoint <= 0x7f)
|
||||
out.append(1, static_cast<char>(codepoint));
|
||||
else if (codepoint <= 0x7ff)
|
||||
{
|
||||
out.append(1, static_cast<char>(0xc0 | ((codepoint >> 6) & 0x1f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
else if (codepoint <= 0xffff)
|
||||
{
|
||||
out.append(1, static_cast<char>(0xe0 | ((codepoint >> 12) & 0x0f)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.append(1, static_cast<char>(0xf0 | ((codepoint >> 18) & 0x07)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 12) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
return out;
|
||||
if (codepoint <= 0x7f)
|
||||
out.append(1, static_cast<char>(codepoint));
|
||||
else if (codepoint <= 0x7ff)
|
||||
{
|
||||
out.append(1, static_cast<char>(0xc0 | ((codepoint >> 6) & 0x1f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
else if (codepoint <= 0xffff)
|
||||
{
|
||||
out.append(1, static_cast<char>(0xe0 | ((codepoint >> 12) & 0x0f)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.append(1, static_cast<char>(0xf0 | ((codepoint >> 18) & 0x07)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 12) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
|
||||
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool LuaConsole::isVisible() const {
|
||||
return _isVisible;
|
||||
return _isVisible;
|
||||
}
|
||||
|
||||
void LuaConsole::setVisible(bool visible) {
|
||||
_isVisible = visible;
|
||||
_isVisible = visible;
|
||||
}
|
||||
|
||||
void LuaConsole::toggleVisibility() {
|
||||
_isVisible = !_isVisible;
|
||||
_isVisible = !_isVisible;
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary LuaConsole::luaLibrary() {
|
||||
return {
|
||||
"console",
|
||||
{
|
||||
{
|
||||
"show",
|
||||
&luascriptfunctions::show,
|
||||
"",
|
||||
"Shows the console"
|
||||
},
|
||||
{
|
||||
"hide",
|
||||
&luascriptfunctions::hide,
|
||||
"",
|
||||
"Hides the console"
|
||||
},
|
||||
{
|
||||
"toggle",
|
||||
&luascriptfunctions::toggle,
|
||||
"",
|
||||
"Toggles the console"
|
||||
}
|
||||
}
|
||||
};
|
||||
return {
|
||||
"console",
|
||||
{
|
||||
{
|
||||
"show",
|
||||
&luascriptfunctions::show,
|
||||
"",
|
||||
"Shows the console"
|
||||
},
|
||||
{
|
||||
"hide",
|
||||
&luascriptfunctions::hide,
|
||||
"",
|
||||
"Hides the console"
|
||||
},
|
||||
{
|
||||
"toggle",
|
||||
&luascriptfunctions::toggle,
|
||||
"",
|
||||
"Toggles the console"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
+127
-127
@@ -33,112 +33,112 @@ namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
MouseController::MouseController()
|
||||
: _lastTrackballPos(0.f)
|
||||
, _isMouseBeingPressedAndHeld(false)
|
||||
: _lastTrackballPos(0.f)
|
||||
, _isMouseBeingPressedAndHeld(false)
|
||||
{}
|
||||
|
||||
glm::vec3 MouseController::mapToTrackball(glm::vec2 mousePos) {
|
||||
const float RADIUS = 0.5; // Sphere radius
|
||||
glm::vec3 out = glm::vec3(mousePos.x - 0.5, -1.0*(mousePos.y - 0.5), 0);
|
||||
const float RADIUS = 0.5; // Sphere radius
|
||||
glm::vec3 out = glm::vec3(mousePos.x - 0.5, -1.0*(mousePos.y - 0.5), 0);
|
||||
|
||||
// Mapping according to Holroyds trackball
|
||||
// Piece-wise sphere + hyperbolic sheet
|
||||
if (out.x*out.x + out.y*out.y <= RADIUS*RADIUS / 2.0) {
|
||||
//Spherical Region
|
||||
out.z = RADIUS*RADIUS - (out.x*out.x + out.y*out.y);
|
||||
out.z = out.z > 0.0f ? sqrtf(out.z) : 0.0f;
|
||||
}
|
||||
else { //Hyperbolic Region - for smooth z values
|
||||
out.z = (RADIUS*RADIUS) / (2.0f*sqrt(out.x*out.x + out.y*out.y));
|
||||
}
|
||||
// Mapping according to Holroyds trackball
|
||||
// Piece-wise sphere + hyperbolic sheet
|
||||
if (out.x*out.x + out.y*out.y <= RADIUS*RADIUS / 2.0) {
|
||||
//Spherical Region
|
||||
out.z = RADIUS*RADIUS - (out.x*out.x + out.y*out.y);
|
||||
out.z = out.z > 0.0f ? sqrtf(out.z) : 0.0f;
|
||||
}
|
||||
else { //Hyperbolic Region - for smooth z values
|
||||
out.z = (RADIUS*RADIUS) / (2.0f*sqrt(out.x*out.x + out.y*out.y));
|
||||
}
|
||||
|
||||
return glm::normalize(out);
|
||||
return glm::normalize(out);
|
||||
}
|
||||
|
||||
glm::vec3 MouseController::mapToCamera(glm::vec3 trackballPos) {
|
||||
//Get x,y,z axis vectors of current camera view
|
||||
glm::vec3 currentViewYaxis = glm::normalize(_handler->camera()->lookUpVector());
|
||||
psc viewDir = _handler->camera()->position() - _handler->focusNode()->worldPosition();
|
||||
glm::vec3 currentViewZaxis = glm::normalize(viewDir.vec3());
|
||||
glm::vec3 currentViewXaxis = glm::normalize(glm::cross(currentViewYaxis, currentViewZaxis));
|
||||
//Get x,y,z axis vectors of current camera view
|
||||
glm::vec3 currentViewYaxis = glm::normalize(_handler->camera()->lookUpVector());
|
||||
psc viewDir = _handler->camera()->position() - _handler->focusNode()->worldPosition();
|
||||
glm::vec3 currentViewZaxis = glm::normalize(viewDir.vec3());
|
||||
glm::vec3 currentViewXaxis = glm::normalize(glm::cross(currentViewYaxis, currentViewZaxis));
|
||||
|
||||
//mapping to camera co-ordinate
|
||||
currentViewXaxis *= trackballPos.x;
|
||||
currentViewYaxis *= trackballPos.y;
|
||||
currentViewZaxis *= trackballPos.z;
|
||||
return (currentViewXaxis + currentViewYaxis + currentViewZaxis);
|
||||
//mapping to camera co-ordinate
|
||||
currentViewXaxis *= trackballPos.x;
|
||||
currentViewYaxis *= trackballPos.y;
|
||||
currentViewZaxis *= trackballPos.z;
|
||||
return (currentViewXaxis + currentViewYaxis + currentViewZaxis);
|
||||
}
|
||||
|
||||
void MouseController::trackballRotate(int x, int y) {
|
||||
// Normalize mouse coordinates to [0,1]
|
||||
// Normalize mouse coordinates to [0,1]
|
||||
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
|
||||
glm::vec2 mousePos = glm::vec2((float)x / res.x, (float)y / res.y);
|
||||
glm::vec2 mousePos = glm::vec2((float)x / res.x, (float)y / res.y);
|
||||
|
||||
mousePos = glm::clamp(mousePos, -0.5f, 1.5f); // Ugly fix #1: Camera position becomes NaN on mouse values outside [-0.5, 1.5]
|
||||
//mousePos[1] = 0.5; // Ugly fix #2: Tempoarily only allow rotation around y
|
||||
mousePos = glm::clamp(mousePos, -0.5f, 1.5f); // Ugly fix #1: Camera position becomes NaN on mouse values outside [-0.5, 1.5]
|
||||
//mousePos[1] = 0.5; // Ugly fix #2: Tempoarily only allow rotation around y
|
||||
|
||||
glm::vec3 curTrackballPos = mapToTrackball(mousePos);
|
||||
// LDEBUG(mousePos.x << ", " << mousePos.y << " = " << curTrackballPos.x << ", " << curTrackballPos.y << ", " << curTrackballPos.z);
|
||||
glm::vec3 curTrackballPos = mapToTrackball(mousePos);
|
||||
// LDEBUG(mousePos.x << ", " << mousePos.y << " = " << curTrackballPos.x << ", " << curTrackballPos.y << ", " << curTrackballPos.z);
|
||||
|
||||
// Disable movement on the first click for extra smoothness
|
||||
if (!_isMouseBeingPressedAndHeld) {
|
||||
_lastTrackballPos = curTrackballPos;
|
||||
_isMouseBeingPressedAndHeld = true;
|
||||
}
|
||||
// Disable movement on the first click for extra smoothness
|
||||
if (!_isMouseBeingPressedAndHeld) {
|
||||
_lastTrackballPos = curTrackballPos;
|
||||
_isMouseBeingPressedAndHeld = true;
|
||||
}
|
||||
|
||||
if (curTrackballPos != _lastTrackballPos) {
|
||||
// calculate rotation angle (in radians)
|
||||
float rotationAngle = glm::angle(curTrackballPos, _lastTrackballPos);
|
||||
rotationAngle *= static_cast<float>(_handler->deltaTime()) * 100.0f;
|
||||
if (curTrackballPos != _lastTrackballPos) {
|
||||
// calculate rotation angle (in radians)
|
||||
float rotationAngle = glm::angle(curTrackballPos, _lastTrackballPos);
|
||||
rotationAngle *= static_cast<float>(_handler->deltaTime()) * 100.0f;
|
||||
|
||||
// Map trackballpos to camera
|
||||
// glm::vec3 trackballMappedToCamera = mapToCamera(_lastTrackballPos - curTrackballPos);
|
||||
// psc currentCamPos = camera_->getPosition();
|
||||
// glm::vec3 nextCamPos = currentCamPos.getVec3f() + trackballMappedToCamera;
|
||||
// glm::vec3 rotationAxis = glm::cross(currentCamPos.getVec3f(), nextCamPos);
|
||||
// Map trackballpos to camera
|
||||
// glm::vec3 trackballMappedToCamera = mapToCamera(_lastTrackballPos - curTrackballPos);
|
||||
// psc currentCamPos = camera_->getPosition();
|
||||
// glm::vec3 nextCamPos = currentCamPos.getVec3f() + trackballMappedToCamera;
|
||||
// glm::vec3 rotationAxis = glm::cross(currentCamPos.getVec3f(), nextCamPos);
|
||||
|
||||
glm::vec3 rotationAxis = glm::cross(_lastTrackballPos, curTrackballPos);
|
||||
rotationAxis = glm::normalize(rotationAxis);
|
||||
glm::quat quaternion = glm::angleAxis(rotationAngle, rotationAxis);
|
||||
glm::vec3 rotationAxis = glm::cross(_lastTrackballPos, curTrackballPos);
|
||||
rotationAxis = glm::normalize(rotationAxis);
|
||||
glm::quat quaternion = glm::angleAxis(rotationAngle, rotationAxis);
|
||||
|
||||
// Apply quaternion to camera
|
||||
_handler->orbitDelta(quaternion);
|
||||
// Apply quaternion to camera
|
||||
_handler->orbitDelta(quaternion);
|
||||
|
||||
_lastTrackballPos = curTrackballPos;
|
||||
}
|
||||
_lastTrackballPos = curTrackballPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TrackballMouseController::TrackballMouseController()
|
||||
: MouseController()
|
||||
, _leftMouseButtonDown(false)
|
||||
: MouseController()
|
||||
, _leftMouseButtonDown(false)
|
||||
{}
|
||||
|
||||
void TrackballMouseController::button(MouseButton button, MouseAction action) {
|
||||
if (button == MouseButton::Left && action == MouseAction::Press)
|
||||
_leftMouseButtonDown = true;
|
||||
else if (button == MouseButton::Left && action == MouseAction::Release) {
|
||||
_leftMouseButtonDown = false;
|
||||
_isMouseBeingPressedAndHeld = false;
|
||||
}
|
||||
if (button == MouseButton::Left && action == MouseAction::Press)
|
||||
_leftMouseButtonDown = true;
|
||||
else if (button == MouseButton::Left && action == MouseAction::Release) {
|
||||
_leftMouseButtonDown = false;
|
||||
_isMouseBeingPressedAndHeld = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TrackballMouseController::move(float x, float y) {
|
||||
if (_leftMouseButtonDown)
|
||||
trackballRotate(static_cast<int>(x), static_cast<int>(y));
|
||||
if (_leftMouseButtonDown)
|
||||
trackballRotate(static_cast<int>(x), static_cast<int>(y));
|
||||
}
|
||||
|
||||
void TrackballMouseController::scrollWheel(int pos) {
|
||||
const float speed = 4.75f;
|
||||
const float dt = static_cast<float>(_handler->deltaTime());
|
||||
if (pos < 0) {
|
||||
PowerScaledScalar dist(speed * dt, 0.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
else if (pos > 0) {
|
||||
PowerScaledScalar dist(-speed * dt, 0.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
const float speed = 4.75f;
|
||||
const float dt = static_cast<float>(_handler->deltaTime());
|
||||
if (pos < 0) {
|
||||
PowerScaledScalar dist(speed * dt, 0.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
else if (pos > 0) {
|
||||
PowerScaledScalar dist(-speed * dt, 0.0f);
|
||||
_handler->distanceDelta(dist);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackballMouseController::update(const double& dt){
|
||||
@@ -155,63 +155,63 @@ OrbitalMouseController::OrbitalMouseController()
|
||||
, _rotationSpeed(10.f)
|
||||
, _navigationSpeed(3.f)
|
||||
{
|
||||
for (int n = 0; n < 3; ++n){
|
||||
_previousCursorPos[n] = glm::vec2(0);
|
||||
}
|
||||
for (int n = 0; n < 3; ++n){
|
||||
_previousCursorPos[n] = glm::vec2(0);
|
||||
}
|
||||
}
|
||||
|
||||
void OrbitalMouseController::button(MouseButton button, MouseAction action) {
|
||||
if (button == MouseButton::Left){
|
||||
if (action == MouseAction::Press){
|
||||
_leftMouseButtonDown = true;
|
||||
if (button == MouseButton::Left){
|
||||
if (action == MouseAction::Press){
|
||||
_leftMouseButtonDown = true;
|
||||
_previousCursorPos[MouseButtons::ButtonLeft] = OsEng.windowWrapper().mousePosition();
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_leftMouseButtonDown = false;
|
||||
_currentCursorDiff[MouseButtons::ButtonLeft] = glm::vec2(0);
|
||||
}
|
||||
}
|
||||
else if (button == MouseButton::Right){
|
||||
if (action == MouseAction::Press){
|
||||
_rightMouseButtonDown = true;
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_leftMouseButtonDown = false;
|
||||
_currentCursorDiff[MouseButtons::ButtonLeft] = glm::vec2(0);
|
||||
}
|
||||
}
|
||||
else if (button == MouseButton::Right){
|
||||
if (action == MouseAction::Press){
|
||||
_rightMouseButtonDown = true;
|
||||
_previousCursorPos[MouseButtons::ButtonRight] = OsEng.windowWrapper().mousePosition();
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_rightMouseButtonDown = false;
|
||||
_currentCursorDiff[MouseButtons::ButtonRight] = glm::vec2(0);
|
||||
}
|
||||
}
|
||||
else if (button == MouseButton::Middle){
|
||||
if (action == MouseAction::Press){
|
||||
_middleMouseButtonDown = true;
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_rightMouseButtonDown = false;
|
||||
_currentCursorDiff[MouseButtons::ButtonRight] = glm::vec2(0);
|
||||
}
|
||||
}
|
||||
else if (button == MouseButton::Middle){
|
||||
if (action == MouseAction::Press){
|
||||
_middleMouseButtonDown = true;
|
||||
_previousCursorPos[MouseButtons::ButtonMiddle] = OsEng.windowWrapper().mousePosition();
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_middleMouseButtonDown = false;
|
||||
_currentCursorDiff[MouseButtons::ButtonMiddle] = glm::vec2(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action == MouseAction::Release) {
|
||||
_middleMouseButtonDown = false;
|
||||
_currentCursorDiff[MouseButtons::ButtonMiddle] = glm::vec2(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OrbitalMouseController::move(float x, float y) {
|
||||
_currentCursorPos = OsEng.windowWrapper().mousePosition();
|
||||
|
||||
if (_leftMouseButtonDown) {
|
||||
if (_leftMouseButtonDown) {
|
||||
glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonLeft];
|
||||
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
|
||||
_currentCursorDiff[MouseButtons::ButtonLeft] = diff / res;
|
||||
}
|
||||
if (_rightMouseButtonDown) {
|
||||
}
|
||||
if (_rightMouseButtonDown) {
|
||||
glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonRight];
|
||||
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
|
||||
_currentCursorDiff[MouseButtons::ButtonRight] = diff / res;
|
||||
}
|
||||
if (_middleMouseButtonDown) {
|
||||
}
|
||||
if (_middleMouseButtonDown) {
|
||||
glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonMiddle];
|
||||
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
|
||||
_currentCursorDiff[MouseButtons::ButtonMiddle] = diff / res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OrbitalMouseController::scrollWheel(int pos) {
|
||||
@@ -222,25 +222,25 @@ void OrbitalMouseController::update(const double& dt){
|
||||
const float interactionSpeed = OsEng.interactionHandler().interactionSensitivity();
|
||||
const bool rotationInvert = OsEng.interactionHandler().invertRotation();
|
||||
const bool rollInvert = OsEng.interactionHandler().invertRoll();
|
||||
|
||||
//if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
|
||||
_handler->orbit(
|
||||
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].x * interactionSpeed * (rotationInvert ? -1.f : 1.f),
|
||||
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].y * interactionSpeed * (rotationInvert ? -1.f : 1.f),
|
||||
static_cast<float>(_middleMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonMiddle].x * interactionSpeed * (rollInvert ? -1.f : 1.f),
|
||||
static_cast<float>(_rightMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonRight].y * _navigationSpeed);
|
||||
//}
|
||||
|
||||
// if (_leftMouseButtonDown){
|
||||
// _handler->orbit(static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed, static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].y * _rotationSpeed, 0.f);
|
||||
// }
|
||||
// if (_middleMouseButtonDown){
|
||||
// _handler->orbit(0.f, 0.f, static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonMiddle].x * _rotationSpeed);
|
||||
// }
|
||||
// if (_rightMouseButtonDown){
|
||||
// _handler->distance(static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonRight].y * _navigationSpeed);
|
||||
// }
|
||||
|
||||
//if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
|
||||
_handler->orbit(
|
||||
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].x * interactionSpeed * (rotationInvert ? -1.f : 1.f),
|
||||
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].y * interactionSpeed * (rotationInvert ? -1.f : 1.f),
|
||||
static_cast<float>(_middleMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonMiddle].x * interactionSpeed * (rollInvert ? -1.f : 1.f),
|
||||
static_cast<float>(_rightMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonRight].y * _navigationSpeed);
|
||||
//}
|
||||
|
||||
// if (_leftMouseButtonDown){
|
||||
// _handler->orbit(static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed, static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonLeft].y * _rotationSpeed, 0.f);
|
||||
// }
|
||||
// if (_middleMouseButtonDown){
|
||||
// _handler->orbit(0.f, 0.f, static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonMiddle].x * _rotationSpeed);
|
||||
// }
|
||||
// if (_rightMouseButtonDown){
|
||||
// _handler->distance(static_cast<float>(dt)* _currentCursorDiff[MouseButtons::ButtonRight].y * _navigationSpeed);
|
||||
// }
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
|
||||
+230
-230
@@ -57,14 +57,14 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/version.h>
|
||||
#include <openspace/openspace.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
//lua functions
|
||||
#include "parallelconnection_lua.inl"
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ParallelConnection";
|
||||
const std::string _loggerCat = "ParallelConnection";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -219,29 +219,29 @@ void ParallelConnection::clientConnect(){
|
||||
return;
|
||||
}
|
||||
|
||||
if (!initNetworkAPI()){
|
||||
if (!initNetworkAPI()){
|
||||
LERROR("Failed to initialize network API for Parallel Connection");
|
||||
return;
|
||||
}
|
||||
|
||||
struct addrinfo *addresult = NULL, *ptr = NULL, hints;
|
||||
#ifdef __WIN32__ //WinSock
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
#else
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
#endif
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
}
|
||||
|
||||
struct addrinfo *addresult = NULL, *ptr = NULL, hints;
|
||||
#ifdef __WIN32__ //WinSock
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
#else
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
#endif
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
// Resolve the local address and port to be used by the server
|
||||
int result = getaddrinfo(_address.c_str(), _port.c_str(), &hints, &addresult);
|
||||
if (result != 0)
|
||||
{
|
||||
// Resolve the local address and port to be used by the server
|
||||
int result = getaddrinfo(_address.c_str(), _port.c_str(), &hints, &addresult);
|
||||
if (result != 0)
|
||||
{
|
||||
LERROR("Failed to parse hints for Parallel Connection");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//we're not connected
|
||||
_isConnected.store(false);
|
||||
@@ -250,8 +250,8 @@ void ParallelConnection::clientConnect(){
|
||||
_tryConnect.store(true);
|
||||
|
||||
//start connection thread
|
||||
_connectionThread = new (std::nothrow) std::thread(&ParallelConnection::establishConnection, this, addresult);
|
||||
|
||||
_connectionThread = new (std::nothrow) std::thread(&ParallelConnection::establishConnection, this, addresult);
|
||||
|
||||
}
|
||||
|
||||
void ParallelConnection::establishConnection(addrinfo *info){
|
||||
@@ -349,60 +349,60 @@ void ParallelConnection::establishConnection(addrinfo *info){
|
||||
#endif
|
||||
}
|
||||
|
||||
//cleanup
|
||||
freeaddrinfo(info);
|
||||
//cleanup
|
||||
freeaddrinfo(info);
|
||||
}
|
||||
|
||||
void ParallelConnection::sendAuthentication(){
|
||||
//length of this nodes name
|
||||
uint16_t namelen = static_cast<uint16_t>(_name.length());
|
||||
uint16_t namelen = static_cast<uint16_t>(_name.length());
|
||||
|
||||
//total size of the buffer, header + size of passcodde + namelength + size of namelength
|
||||
int size = headerSize() + sizeof(uint32_t) + sizeof(namelen) + static_cast<int>(namelen);
|
||||
int size = headerSize() + sizeof(uint32_t) + sizeof(namelen) + static_cast<int>(namelen);
|
||||
|
||||
//create and reserve buffer
|
||||
std::vector<char> buffer;
|
||||
buffer.reserve(size);
|
||||
buffer.reserve(size);
|
||||
|
||||
//write header to buffer
|
||||
writeHeader(buffer, MessageTypes::Authentication);
|
||||
|
||||
//write passcode to buffer
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_passCode), reinterpret_cast<char*>(&_passCode) + sizeof(uint32_t));
|
||||
//write passcode to buffer
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&_passCode), reinterpret_cast<char*>(&_passCode) + sizeof(uint32_t));
|
||||
|
||||
//write the length of the nodes name to buffer
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&namelen), reinterpret_cast<char*>(&namelen) + sizeof(uint16_t));
|
||||
//write the length of the nodes name to buffer
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&namelen), reinterpret_cast<char*>(&namelen) + sizeof(uint16_t));
|
||||
|
||||
//write this nodes name to buffer
|
||||
buffer.insert(buffer.end(), _name.begin(), _name.end());
|
||||
//write this nodes name to buffer
|
||||
buffer.insert(buffer.end(), _name.begin(), _name.end());
|
||||
|
||||
//send buffer
|
||||
queueMessage(buffer);
|
||||
queueMessage(buffer);
|
||||
}
|
||||
|
||||
void ParallelConnection::delegateDecoding(uint32_t type){
|
||||
switch (type){
|
||||
case MessageTypes::Authentication:
|
||||
switch (type){
|
||||
case MessageTypes::Authentication:
|
||||
//not used
|
||||
break;
|
||||
case MessageTypes::Initialization:
|
||||
initializationMessageReceived();
|
||||
break;
|
||||
case MessageTypes::Data:
|
||||
dataMessageReceived();
|
||||
break;
|
||||
case MessageTypes::Initialization:
|
||||
initializationMessageReceived();
|
||||
break;
|
||||
case MessageTypes::Data:
|
||||
dataMessageReceived();
|
||||
break;
|
||||
case MessageTypes::Script:
|
||||
//not used
|
||||
break;
|
||||
case MessageTypes::HostInfo:
|
||||
hostInfoMessageReceived();
|
||||
break;
|
||||
case MessageTypes::InitializationRequest:
|
||||
initializationRequestMessageReceived();
|
||||
break;
|
||||
default:
|
||||
//unknown message type
|
||||
break;
|
||||
break;
|
||||
case MessageTypes::HostInfo:
|
||||
hostInfoMessageReceived();
|
||||
break;
|
||||
case MessageTypes::InitializationRequest:
|
||||
initializationRequestMessageReceived();
|
||||
break;
|
||||
default:
|
||||
//unknown message type
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,28 +410,28 @@ void ParallelConnection::initializationMessageReceived(){
|
||||
|
||||
int result;
|
||||
|
||||
uint32_t id, datasize;
|
||||
uint32_t id, datasize;
|
||||
uint16_t numscripts;
|
||||
|
||||
std::vector<char> buffer;
|
||||
buffer.resize(sizeof(id));
|
||||
buffer.resize(sizeof(id));
|
||||
|
||||
//read id
|
||||
result = receiveData(_clientSocket, buffer, sizeof(id), 0);
|
||||
if (result < 0){
|
||||
//error
|
||||
}
|
||||
id = *(reinterpret_cast<uint32_t*>(buffer.data()));
|
||||
//read id
|
||||
result = receiveData(_clientSocket, buffer, sizeof(id), 0);
|
||||
if (result < 0){
|
||||
//error
|
||||
}
|
||||
id = *(reinterpret_cast<uint32_t*>(buffer.data()));
|
||||
|
||||
//read datalength
|
||||
result = receiveData(_clientSocket, buffer, sizeof(datasize), 0);
|
||||
if (result < 0){
|
||||
//error
|
||||
}
|
||||
datasize = *(reinterpret_cast<uint32_t*>(buffer.data()));
|
||||
//read datalength
|
||||
result = receiveData(_clientSocket, buffer, sizeof(datasize), 0);
|
||||
if (result < 0){
|
||||
//error
|
||||
}
|
||||
datasize = *(reinterpret_cast<uint32_t*>(buffer.data()));
|
||||
|
||||
buffer.clear();
|
||||
buffer.resize(sizeof(uint16_t));
|
||||
buffer.clear();
|
||||
buffer.resize(sizeof(uint16_t));
|
||||
//read number of scripts
|
||||
result = receiveData(_clientSocket, buffer, sizeof(numscripts), 0);
|
||||
if(result < 0){
|
||||
@@ -484,22 +484,22 @@ void ParallelConnection::initializationMessageReceived(){
|
||||
}
|
||||
|
||||
void ParallelConnection::dataMessageReceived(){
|
||||
int result;
|
||||
uint16_t msglen;
|
||||
int result;
|
||||
uint16_t msglen;
|
||||
uint16_t type;
|
||||
|
||||
//create a buffer to hold the size of streamdata message
|
||||
std::vector<char> buffer;
|
||||
buffer.resize(sizeof(type));
|
||||
buffer.resize(sizeof(type));
|
||||
|
||||
//read type of data message
|
||||
result = receiveData(_clientSocket, buffer, sizeof(type), 0);
|
||||
result = receiveData(_clientSocket, buffer, sizeof(type), 0);
|
||||
|
||||
if (result <= 0){
|
||||
//error
|
||||
if (result <= 0){
|
||||
//error
|
||||
LERROR("Failed to read type of data message received.");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//the type of data message received
|
||||
type =(*(reinterpret_cast<uint16_t*>(buffer.data())));
|
||||
@@ -514,20 +514,20 @@ void ParallelConnection::dataMessageReceived(){
|
||||
}
|
||||
|
||||
//the size in bytes of the streamdata message
|
||||
msglen = (*(reinterpret_cast<uint16_t*>(buffer.data())));
|
||||
msglen = (*(reinterpret_cast<uint16_t*>(buffer.data())));
|
||||
|
||||
//resize the buffer to be able to read the streamdata
|
||||
buffer.clear();
|
||||
buffer.resize(msglen);
|
||||
buffer.clear();
|
||||
buffer.resize(msglen);
|
||||
|
||||
//read the data into buffer
|
||||
result = receiveData(_clientSocket, buffer, msglen, 0);
|
||||
result = receiveData(_clientSocket, buffer, msglen, 0);
|
||||
|
||||
if (result <= 0){
|
||||
//error
|
||||
if (result <= 0){
|
||||
//error
|
||||
LERROR("Failed to read data message.");
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//which type of data message was received?
|
||||
switch(type){
|
||||
@@ -634,50 +634,50 @@ void ParallelConnection::sendFunc(){
|
||||
|
||||
void ParallelConnection::hostInfoMessageReceived(){
|
||||
//create buffer
|
||||
std::vector<char> hostflag;
|
||||
std::vector<char> hostflag;
|
||||
//resize to hold a flag saying if we're host or not
|
||||
hostflag.resize(1);
|
||||
hostflag.resize(1);
|
||||
|
||||
//read data into buffer
|
||||
int result = receiveData(_clientSocket, hostflag, 1, 0);
|
||||
int result = receiveData(_clientSocket, hostflag, 1, 0);
|
||||
|
||||
//enough data was read
|
||||
if (result > 0){
|
||||
if (result > 0){
|
||||
|
||||
//we've been assigned as host
|
||||
if (hostflag.at(0) == 1){
|
||||
if (hostflag.at(0) == 1){
|
||||
|
||||
//we're already host, do nothing (dummy check)
|
||||
if (_isHost.load()){
|
||||
return;
|
||||
}
|
||||
else{
|
||||
//we're already host, do nothing (dummy check)
|
||||
if (_isHost.load()){
|
||||
return;
|
||||
}
|
||||
else{
|
||||
|
||||
//we're the host
|
||||
_isHost.store(true);
|
||||
//we're the host
|
||||
_isHost.store(true);
|
||||
|
||||
//start broadcasting
|
||||
_broadcastThread = new (std::nothrow) std::thread(&ParallelConnection::broadcast, this);
|
||||
}
|
||||
}
|
||||
else{ //we've been assigned as client
|
||||
//start broadcasting
|
||||
_broadcastThread = new (std::nothrow) std::thread(&ParallelConnection::broadcast, this);
|
||||
}
|
||||
}
|
||||
else{ //we've been assigned as client
|
||||
|
||||
//we were broadcasting but should stop now
|
||||
if (_isHost.load()){
|
||||
//we were broadcasting but should stop now
|
||||
if (_isHost.load()){
|
||||
|
||||
//stop broadcast loop
|
||||
_isHost.store(false);
|
||||
|
||||
_isHost.store(false);
|
||||
|
||||
//and delete broadcasting thread
|
||||
if (_broadcastThread != nullptr){
|
||||
_broadcastThread->join();
|
||||
delete _broadcastThread;
|
||||
_broadcastThread = nullptr;
|
||||
}
|
||||
}
|
||||
else{
|
||||
//we were not broadcasting so nothing to do
|
||||
}
|
||||
_broadcastThread->join();
|
||||
delete _broadcastThread;
|
||||
_broadcastThread = nullptr;
|
||||
}
|
||||
}
|
||||
else{
|
||||
//we were not broadcasting so nothing to do
|
||||
}
|
||||
|
||||
//clear buffered any keyframes
|
||||
OsEng.interactionHandler().clearKeyframes();
|
||||
@@ -691,13 +691,13 @@ void ParallelConnection::hostInfoMessageReceived(){
|
||||
writeHeader(buffer, MessageTypes::InitializationRequest);
|
||||
|
||||
//send message
|
||||
queueMessage(buffer);
|
||||
}
|
||||
}
|
||||
else{
|
||||
queueMessage(buffer);
|
||||
}
|
||||
}
|
||||
else{
|
||||
LERROR("Error " << _ERRNO << " detected in connection, disconnecting.");
|
||||
signalDisconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParallelConnection::initializationRequestMessageReceived(){
|
||||
@@ -771,74 +771,74 @@ void ParallelConnection::initializationRequestMessageReceived(){
|
||||
}
|
||||
|
||||
void ParallelConnection::listenCommunication(){
|
||||
|
||||
//create basic buffer for receiving first part of messages
|
||||
std::vector<char> buffer;
|
||||
//size of the header
|
||||
buffer.resize(headerSize());
|
||||
|
||||
int result;
|
||||
//create basic buffer for receiving first part of messages
|
||||
std::vector<char> buffer;
|
||||
//size of the header
|
||||
buffer.resize(headerSize());
|
||||
|
||||
int result;
|
||||
|
||||
//while we're still connected
|
||||
while (_isConnected.load()){
|
||||
while (_isConnected.load()){
|
||||
//receive the first parts of a message
|
||||
result = receiveData(_clientSocket, buffer, headerSize(), 0);
|
||||
result = receiveData(_clientSocket, buffer, headerSize(), 0);
|
||||
|
||||
//if enough data was received
|
||||
if (result > 0){
|
||||
if (result > 0){
|
||||
|
||||
//make sure that header matches this version of OpenSpace
|
||||
if (buffer[0] == 'O' && //Open
|
||||
buffer[1] == 'S' && //Space
|
||||
buffer[2] == OPENSPACE_VERSION_MAJOR && // major version
|
||||
buffer[3] == OPENSPACE_VERSION_MINOR // minor version
|
||||
)
|
||||
{
|
||||
//parse type
|
||||
uint32_t type = (*(reinterpret_cast<uint32_t*>(&buffer[4])));
|
||||
if (buffer[0] == 'O' && //Open
|
||||
buffer[1] == 'S' && //Space
|
||||
buffer[2] == OPENSPACE_VERSION_MAJOR && // major version
|
||||
buffer[3] == OPENSPACE_VERSION_MINOR // minor version
|
||||
)
|
||||
{
|
||||
//parse type
|
||||
uint32_t type = (*(reinterpret_cast<uint32_t*>(&buffer[4])));
|
||||
|
||||
//and delegate decoding depending on type
|
||||
delegateDecoding(type);
|
||||
}
|
||||
delegateDecoding(type);
|
||||
}
|
||||
else{
|
||||
LERROR("Error: Client OpenSpace version " << OPENSPACE_VERSION_MAJOR << ", " << OPENSPACE_VERSION_MINOR << " does not match server version " << buffer[2] <<", " << buffer[3] << std::endl << "Message not decoded.");
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (result == 0){
|
||||
//connection rejected
|
||||
LERROR("Parallel connection rejected, disconnecting...");
|
||||
}
|
||||
else{
|
||||
LERROR("Error " << _ERRNO << " detected in connection, disconnecting!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (result == 0){
|
||||
//connection rejected
|
||||
LERROR("Parallel connection rejected, disconnecting...");
|
||||
}
|
||||
else{
|
||||
LERROR("Error " << _ERRNO << " detected in connection, disconnecting!");
|
||||
}
|
||||
|
||||
//signal that a disconnect should be performed
|
||||
signalDisconnect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int ParallelConnection::receiveData(_SOCKET & socket, std::vector<char> &buffer, int length, int flags){
|
||||
int result = 0;
|
||||
int received = 0;
|
||||
while (result < length){
|
||||
received = recv(socket, buffer.data() + result, length - result, flags);
|
||||
int result = 0;
|
||||
int received = 0;
|
||||
while (result < length){
|
||||
received = recv(socket, buffer.data() + result, length - result, flags);
|
||||
|
||||
if (received > 0){
|
||||
result += received;
|
||||
received = 0;
|
||||
}
|
||||
else{
|
||||
//error receiving
|
||||
result = received;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (received > 0){
|
||||
result += received;
|
||||
received = 0;
|
||||
}
|
||||
else{
|
||||
//error receiving
|
||||
result = received;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ParallelConnection::setPort(const std::string &port){
|
||||
@@ -870,37 +870,37 @@ void ParallelConnection::requestHostship(const std::string &password){
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&passcode), reinterpret_cast<char*>(&passcode) + sizeof(uint32_t));
|
||||
|
||||
//send message
|
||||
queueMessage(buffer);
|
||||
queueMessage(buffer);
|
||||
}
|
||||
|
||||
void ParallelConnection::setPassword(const std::string& pwd){
|
||||
_passCode = hash(pwd);
|
||||
_passCode = hash(pwd);
|
||||
}
|
||||
|
||||
bool ParallelConnection::initNetworkAPI(){
|
||||
#if defined(__WIN32__)
|
||||
WSADATA wsaData;
|
||||
WORD version;
|
||||
int error;
|
||||
#if defined(__WIN32__)
|
||||
WSADATA wsaData;
|
||||
WORD version;
|
||||
int error;
|
||||
|
||||
version = MAKEWORD(2, 2);
|
||||
version = MAKEWORD(2, 2);
|
||||
|
||||
error = WSAStartup(version, &wsaData);
|
||||
error = WSAStartup(version, &wsaData);
|
||||
|
||||
if (error != 0 ||
|
||||
LOBYTE(wsaData.wVersion) != 2 ||
|
||||
HIBYTE(wsaData.wVersion) != 2)
|
||||
{
|
||||
/* incorrect WinSock version */
|
||||
LERROR("Failed to init winsock API.");
|
||||
//WSACleanup();
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
//No init needed on unix
|
||||
#endif
|
||||
if (error != 0 ||
|
||||
LOBYTE(wsaData.wVersion) != 2 ||
|
||||
HIBYTE(wsaData.wVersion) != 2)
|
||||
{
|
||||
/* incorrect WinSock version */
|
||||
LERROR("Failed to init winsock API.");
|
||||
//WSACleanup();
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
//No init needed on unix
|
||||
#endif
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParallelConnection::preSynchronization(){
|
||||
@@ -1029,18 +1029,18 @@ std::string ParallelConnection::scriptFromPropertyAndValue(const std::string pro
|
||||
}
|
||||
|
||||
void ParallelConnection::broadcast(){
|
||||
|
||||
|
||||
//while we're still connected and we're the host
|
||||
while (_isConnected.load() && _isHost.load()){
|
||||
while (_isConnected.load() && _isHost.load()){
|
||||
|
||||
//create a keyframe with current position and orientation of camera
|
||||
network::datamessagestructures::PositionKeyframe kf;
|
||||
kf._position = OsEng.interactionHandler().camera()->position();
|
||||
kf._viewRotationQuat = glm::quat_cast(OsEng.interactionHandler().camera()->viewRotationMatrix());
|
||||
|
||||
kf._position = OsEng.interactionHandler().camera()->position();
|
||||
kf._viewRotationQuat = glm::quat_cast(OsEng.interactionHandler().camera()->viewRotationMatrix());
|
||||
|
||||
//timestamp as current runtime of OpenSpace instance
|
||||
kf._timeStamp = OsEng.runTime();
|
||||
|
||||
|
||||
//create a buffer for the keyframe
|
||||
std::vector<char> kfBuffer;
|
||||
|
||||
@@ -1048,33 +1048,33 @@ void ParallelConnection::broadcast(){
|
||||
kf.serialize(kfBuffer);
|
||||
|
||||
//get the size of the keyframebuffer
|
||||
uint16_t msglen = static_cast<uint16_t>(kfBuffer.size());
|
||||
uint16_t msglen = static_cast<uint16_t>(kfBuffer.size());
|
||||
|
||||
//the type of message
|
||||
uint16_t type = static_cast<uint16_t>(network::datamessagestructures::PositionData);
|
||||
|
||||
//create the full buffer
|
||||
std::vector<char> buffer;
|
||||
buffer.reserve(headerSize() + sizeof(type) + sizeof(msglen) + msglen);
|
||||
|
||||
//write header
|
||||
std::vector<char> buffer;
|
||||
buffer.reserve(headerSize() + sizeof(type) + sizeof(msglen) + msglen);
|
||||
|
||||
//write header
|
||||
writeHeader(buffer, MessageTypes::Data);
|
||||
|
||||
//type of message
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&type), reinterpret_cast<char*>(&type) + sizeof(type));
|
||||
|
||||
//size of message
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&msglen), reinterpret_cast<char*>(&msglen) + sizeof(msglen));
|
||||
//size of message
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&msglen), reinterpret_cast<char*>(&msglen) + sizeof(msglen));
|
||||
|
||||
//actual message
|
||||
buffer.insert(buffer.end(), kfBuffer.begin(), kfBuffer.end());
|
||||
//actual message
|
||||
buffer.insert(buffer.end(), kfBuffer.begin(), kfBuffer.end());
|
||||
|
||||
//send message
|
||||
queueMessage(buffer);
|
||||
//send message
|
||||
queueMessage(buffer);
|
||||
|
||||
//100 ms sleep - send keyframes 10 times per second
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
//100 ms sleep - send keyframes 10 times per second
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
void ParallelConnection::writeHeader(std::vector<char> &buffer, uint32_t messageType){
|
||||
@@ -1110,30 +1110,30 @@ scripting::ScriptEngine::LuaLibrary ParallelConnection::luaLibrary() {
|
||||
"number",
|
||||
"Set the port for the parallel connection"
|
||||
},
|
||||
{
|
||||
"setAddress",
|
||||
&luascriptfunctions::setAddress,
|
||||
"string",
|
||||
"Set the address for the parallel connection"
|
||||
},
|
||||
{
|
||||
"setPassword",
|
||||
&luascriptfunctions::setPassword,
|
||||
"string",
|
||||
"Set the password for the parallel connection"
|
||||
},
|
||||
{
|
||||
"setDisplayName",
|
||||
&luascriptfunctions::setDisplayName,
|
||||
"string",
|
||||
"Set your display name for the parallel connection"
|
||||
},
|
||||
{
|
||||
"connect",
|
||||
&luascriptfunctions::connect,
|
||||
"",
|
||||
"Connect to parallel"
|
||||
},
|
||||
{
|
||||
"setAddress",
|
||||
&luascriptfunctions::setAddress,
|
||||
"string",
|
||||
"Set the address for the parallel connection"
|
||||
},
|
||||
{
|
||||
"setPassword",
|
||||
&luascriptfunctions::setPassword,
|
||||
"string",
|
||||
"Set the password for the parallel connection"
|
||||
},
|
||||
{
|
||||
"setDisplayName",
|
||||
&luascriptfunctions::setDisplayName,
|
||||
"string",
|
||||
"Set your display name for the parallel connection"
|
||||
},
|
||||
{
|
||||
"connect",
|
||||
&luascriptfunctions::connect,
|
||||
"",
|
||||
"Connect to parallel"
|
||||
},
|
||||
{
|
||||
"disconnect",
|
||||
&luascriptfunctions::disconnect,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/openspace.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
std::string licenseText() {
|
||||
return "OpenSpace\n\
|
||||
\n\
|
||||
Copyright (c) 2014-2016\n\
|
||||
\n\
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this\n\
|
||||
software and associated documentation files (the \"Software\"), to deal in the Software\n\
|
||||
without restriction, including without limitation the rights to use, copy, modify,\n\
|
||||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n\
|
||||
permit persons to whom the Software is furnished to do so, subject to the following\n\
|
||||
conditions:\n\
|
||||
\n\
|
||||
The above copyright notice and this permission notice shall be included in all copies\n\
|
||||
or substantial portions of the Software.\n\
|
||||
\n\
|
||||
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\n\
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\n\
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n\
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF\n\
|
||||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE\n\
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
+424
-424
@@ -115,21 +115,21 @@ namespace properties {
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x2(
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x2),
|
||||
@@ -138,25 +138,25 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x3),
|
||||
@@ -165,29 +165,29 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x4),
|
||||
@@ -196,25 +196,25 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x2(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x2),
|
||||
@@ -223,32 +223,32 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x3),
|
||||
@@ -257,38 +257,38 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x4),
|
||||
@@ -297,29 +297,29 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x2(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x2),
|
||||
@@ -328,38 +328,38 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x3(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x3),
|
||||
@@ -368,47 +368,47 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x4),
|
||||
@@ -417,21 +417,21 @@ REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
0.01, 0.01,
|
||||
0.01, 0.01
|
||||
),
|
||||
0.01, 0.01,
|
||||
0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x2),
|
||||
@@ -440,25 +440,25 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x3),
|
||||
@@ -467,29 +467,29 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0)
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x4),
|
||||
@@ -498,25 +498,25 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0)
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x2),
|
||||
@@ -525,32 +525,32 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0)
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x3),
|
||||
@@ -559,38 +559,38 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0),
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x4),
|
||||
@@ -599,29 +599,29 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0)
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x2),
|
||||
@@ -630,38 +630,38 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0)
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x3),
|
||||
@@ -670,47 +670,47 @@ REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0)
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4Property, glm::dmat4x4, glm::dmat4x4(0),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x4),
|
||||
|
||||
@@ -25,69 +25,69 @@
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "OptionProperty";
|
||||
const std::string _loggerCat = "OptionProperty";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
|
||||
const std::string OptionProperty::OptionsKey = "Options";
|
||||
|
||||
OptionProperty::OptionProperty(std::string identifier, std::string guiName)
|
||||
: IntProperty(std::move(identifier), std::move(guiName))
|
||||
: IntProperty(std::move(identifier), std::move(guiName))
|
||||
{}
|
||||
|
||||
std::string OptionProperty::className() const {
|
||||
return "OptionProperty";
|
||||
return "OptionProperty";
|
||||
}
|
||||
|
||||
const std::vector<OptionProperty::Option>& OptionProperty::options() const {
|
||||
return _options;
|
||||
return _options;
|
||||
}
|
||||
|
||||
void OptionProperty::addOption(int value, std::string desc) {
|
||||
Option option;
|
||||
option.value = value;
|
||||
option.description = desc;
|
||||
Option option;
|
||||
option.value = value;
|
||||
option.description = desc;
|
||||
|
||||
for (auto o : _options) {
|
||||
if (o.value == option.value) {
|
||||
LWARNING("The value of option {" << o.value << " -> " << o.description <<
|
||||
"} was already registered when trying to add option {" << option.value <<
|
||||
" -> " << option.description << "}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
_options.push_back(std::move(option));
|
||||
for (auto o : _options) {
|
||||
if (o.value == option.value) {
|
||||
LWARNING("The value of option {" << o.value << " -> " << o.description <<
|
||||
"} was already registered when trying to add option {" << option.value <<
|
||||
" -> " << option.description << "}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
_options.push_back(std::move(option));
|
||||
}
|
||||
|
||||
void OptionProperty::setValue(int value) {
|
||||
// Check if the passed value belongs to any option
|
||||
for (auto o : _options) {
|
||||
if (o.value == value) {
|
||||
// If it does, set it by calling the superclasses setValue method
|
||||
NumericalProperty::setValue(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Check if the passed value belongs to any option
|
||||
for (auto o : _options) {
|
||||
if (o.value == value) {
|
||||
// If it does, set it by calling the superclasses setValue method
|
||||
NumericalProperty::setValue(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, log an error
|
||||
LERROR("Could not find an option for value '" << value << "' in OptionProperty");
|
||||
// Otherwise, log an error
|
||||
LERROR("Could not find an option for value '" << value << "' in OptionProperty");
|
||||
}
|
||||
|
||||
std::string OptionProperty::generateAdditionalDescription() const {
|
||||
// @REFACTOR from selectionproperty.cpp, possible refactoring? ---abock
|
||||
std::string result;
|
||||
result += OptionsKey + " = {";
|
||||
for (size_t i = 0; i < _options.size(); ++i) {
|
||||
const Option& o = _options[i];
|
||||
result += "[\"" + std::to_string(o.value) + "\"] = \"" + o.description + "\"";
|
||||
if (i != _options.size() - 1)
|
||||
result += ",";
|
||||
}
|
||||
// @REFACTOR from selectionproperty.cpp, possible refactoring? ---abock
|
||||
std::string result;
|
||||
result += OptionsKey + " = {";
|
||||
for (size_t i = 0; i < _options.size(); ++i) {
|
||||
const Option& o = _options[i];
|
||||
result += "[\"" + std::to_string(o.value) + "\"] = \"" + o.description + "\"";
|
||||
if (i != _options.size() - 1)
|
||||
result += ",";
|
||||
}
|
||||
|
||||
result += "}";
|
||||
return result;
|
||||
result += "}";
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
|
||||
+42
-42
@@ -32,13 +32,13 @@ namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "Property";
|
||||
const std::string _metaDataKeyGuiName = "guiName";
|
||||
const std::string _loggerCat = "Property";
|
||||
const std::string _metaDataKeyGuiName = "guiName";
|
||||
const std::string _metaDataKeyGroup = "Group";
|
||||
const std::string _metaDataKeyVisible = "isVisible";
|
||||
const std::string _metaDataKeyReadOnly = "isReadOnly";
|
||||
|
||||
const std::string _metaDataKeyViewPrefix = "view.";
|
||||
const std::string _metaDataKeyViewPrefix = "view.";
|
||||
}
|
||||
|
||||
const std::string Property::ViewOptions::Color = "color";
|
||||
@@ -52,16 +52,16 @@ const std::string Property::TypeKey = "Type";
|
||||
const std::string Property::MetaDataKey = "MetaData";
|
||||
|
||||
Property::Property(std::string identifier, std::string guiName)
|
||||
: _owner(nullptr)
|
||||
: _owner(nullptr)
|
||||
, _identifier(std::move(identifier))
|
||||
{
|
||||
if (_identifier.empty())
|
||||
LWARNING("Property identifier is empty");
|
||||
if (guiName.empty())
|
||||
LWARNING("Property GUI name is empty");
|
||||
if (_identifier.empty())
|
||||
LWARNING("Property identifier is empty");
|
||||
if (guiName.empty())
|
||||
LWARNING("Property GUI name is empty");
|
||||
|
||||
setVisible(true);
|
||||
_metaData.setValue(_metaDataKeyGuiName, std::move(guiName));
|
||||
_metaData.setValue(_metaDataKeyGuiName, std::move(guiName));
|
||||
}
|
||||
|
||||
Property::~Property() {}
|
||||
@@ -71,15 +71,15 @@ const std::string& Property::identifier() const {
|
||||
}
|
||||
|
||||
std::string Property::fullyQualifiedIdentifier() const {
|
||||
std::string identifier = _identifier;
|
||||
PropertyOwner* currentOwner = owner();
|
||||
while (currentOwner) {
|
||||
std::string ownerId = currentOwner->name();
|
||||
std::string identifier = _identifier;
|
||||
PropertyOwner* currentOwner = owner();
|
||||
while (currentOwner) {
|
||||
std::string ownerId = currentOwner->name();
|
||||
if (!ownerId.empty())
|
||||
identifier = ownerId + "." + identifier;
|
||||
currentOwner = currentOwner->owner();
|
||||
}
|
||||
return identifier;
|
||||
identifier = ownerId + "." + identifier;
|
||||
currentOwner = currentOwner->owner();
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
||||
ghoul::any Property::get() const {
|
||||
@@ -87,13 +87,13 @@ ghoul::any Property::get() const {
|
||||
}
|
||||
|
||||
bool Property::getLuaValue(lua_State* state) const {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Property::set(ghoul::any value) {}
|
||||
|
||||
bool Property::setLuaValue(lua_State* state) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::type_info& Property::type() const {
|
||||
@@ -101,7 +101,7 @@ const std::type_info& Property::type() const {
|
||||
}
|
||||
|
||||
int Property::typeLua() const {
|
||||
return LUA_TNIL;
|
||||
return LUA_TNIL;
|
||||
}
|
||||
|
||||
bool Property::getStringValue(std::string& value) const {
|
||||
@@ -113,13 +113,13 @@ bool Property::setStringValue(std::string value) {
|
||||
}
|
||||
|
||||
std::string Property::guiName() const {
|
||||
std::string result;
|
||||
_metaData.getValue(_metaDataKeyGuiName, result);
|
||||
std::string result;
|
||||
_metaData.getValue(_metaDataKeyGuiName, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Property::description() const {
|
||||
return "return {" + generateBaseDescription() + "}";
|
||||
return "return {" + generateBaseDescription() + "}";
|
||||
}
|
||||
|
||||
void Property::setGroupIdentifier(std::string groupId) {
|
||||
@@ -127,8 +127,8 @@ void Property::setGroupIdentifier(std::string groupId) {
|
||||
}
|
||||
|
||||
std::string Property::groupIdentifier() const {
|
||||
std::string result;
|
||||
_metaData.getValue(_metaDataKeyGroup, result);
|
||||
std::string result;
|
||||
_metaData.getValue(_metaDataKeyGroup, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -167,33 +167,33 @@ void Property::setPropertyOwner(PropertyOwner* owner)
|
||||
}
|
||||
|
||||
void Property::notifyListener() {
|
||||
if (_onChangeCallback)
|
||||
_onChangeCallback();
|
||||
if (_onChangeCallback)
|
||||
_onChangeCallback();
|
||||
}
|
||||
|
||||
std::string Property::generateBaseDescription() const {
|
||||
return
|
||||
TypeKey + " = \"" + className() + "\", " +
|
||||
IdentifierKey + " = \"" + fullyQualifiedIdentifier() + "\", " +
|
||||
NameKey + " = \"" + guiName() + "\", " +
|
||||
generateMetaDataDescription() + ", " +
|
||||
generateAdditionalDescription();
|
||||
return
|
||||
TypeKey + " = \"" + className() + "\", " +
|
||||
IdentifierKey + " = \"" + fullyQualifiedIdentifier() + "\", " +
|
||||
NameKey + " = \"" + guiName() + "\", " +
|
||||
generateMetaDataDescription() + ", " +
|
||||
generateAdditionalDescription();
|
||||
}
|
||||
|
||||
std::string Property::generateMetaDataDescription() const {
|
||||
bool isVisible, isReadOnly;
|
||||
_metaData.getValue(_metaDataKeyVisible, isVisible);
|
||||
_metaData.getValue(_metaDataKeyReadOnly, isReadOnly);
|
||||
bool isVisible, isReadOnly;
|
||||
_metaData.getValue(_metaDataKeyVisible, isVisible);
|
||||
_metaData.getValue(_metaDataKeyReadOnly, isReadOnly);
|
||||
|
||||
return
|
||||
MetaDataKey + " = {" +
|
||||
_metaDataKeyGroup + " = '" + groupIdentifier() + "'," +
|
||||
_metaDataKeyVisible + " = " + (isVisible ? "true" : "false") + "," +
|
||||
_metaDataKeyReadOnly +" = " + (isReadOnly ? "true" : "false") + "}";
|
||||
return
|
||||
MetaDataKey + " = {" +
|
||||
_metaDataKeyGroup + " = '" + groupIdentifier() + "'," +
|
||||
_metaDataKeyVisible + " = " + (isVisible ? "true" : "false") + "," +
|
||||
_metaDataKeyReadOnly +" = " + (isReadOnly ? "true" : "false") + "}";
|
||||
}
|
||||
|
||||
std::string Property::generateAdditionalDescription() const {
|
||||
return "";
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
|
||||
@@ -48,13 +48,13 @@ bool subOwnerLess(PropertyOwner* lhs, PropertyOwner* rhs) {
|
||||
|
||||
PropertyOwner::PropertyOwner()
|
||||
: _name("")
|
||||
, _owner(nullptr)
|
||||
, _owner(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
PropertyOwner::~PropertyOwner() {
|
||||
_properties.clear();
|
||||
_subOwners.clear();
|
||||
_properties.clear();
|
||||
_subOwners.clear();
|
||||
}
|
||||
|
||||
const std::vector<Property*>& PropertyOwner::properties() const {
|
||||
@@ -62,20 +62,20 @@ const std::vector<Property*>& PropertyOwner::properties() const {
|
||||
}
|
||||
|
||||
std::vector<Property*> PropertyOwner::propertiesRecursive() const {
|
||||
std::vector<Property*> props = properties();
|
||||
std::vector<Property*> props = properties();
|
||||
|
||||
for (const PropertyOwner* owner : _subOwners) {
|
||||
std::vector<Property*> p = owner->propertiesRecursive();
|
||||
props.insert(props.end(), p.begin(), p.end());
|
||||
}
|
||||
for (const PropertyOwner* owner : _subOwners) {
|
||||
std::vector<Property*> p = owner->propertiesRecursive();
|
||||
props.insert(props.end(), p.begin(), p.end());
|
||||
}
|
||||
|
||||
return props;
|
||||
return props;
|
||||
}
|
||||
|
||||
Property* PropertyOwner::property(const std::string& id) const {
|
||||
assert(std::is_sorted(_properties.begin(), _properties.end(), propertyLess));
|
||||
|
||||
// As the _properties list is sorted, just finding the lower bound is sufficient
|
||||
// As the _properties list is sorted, just finding the lower bound is sufficient
|
||||
std::vector<Property*>::const_iterator it
|
||||
= std::lower_bound(_properties.begin(), _properties.end(), id,
|
||||
[](Property* prop, const std::string& str) {
|
||||
@@ -119,7 +119,7 @@ const std::vector<PropertyOwner*>& PropertyOwner::propertySubOwners() const {
|
||||
PropertyOwner* PropertyOwner::propertySubOwner(const std::string& name) const {
|
||||
assert(std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess));
|
||||
|
||||
// As the _subOwners list is sorted, getting the lower bound is sufficient
|
||||
// As the _subOwners list is sorted, getting the lower bound is sufficient
|
||||
std::vector<PropertyOwner*>::const_iterator it
|
||||
= std::lower_bound(_subOwners.begin(), _subOwners.end(), name,
|
||||
[](PropertyOwner* owner, const std::string& str) {
|
||||
@@ -152,7 +152,7 @@ void PropertyOwner::addProperty(Property* prop)
|
||||
{
|
||||
assert(prop != nullptr);
|
||||
assert(std::is_sorted(_properties.begin(), _properties.end(), propertyLess));
|
||||
assert(std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess));
|
||||
assert(std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess));
|
||||
|
||||
if (prop->identifier().empty()) {
|
||||
LERROR("No property identifier specified");
|
||||
@@ -160,7 +160,7 @@ void PropertyOwner::addProperty(Property* prop)
|
||||
}
|
||||
|
||||
// See if we can find the identifier of the property to add in the properties list
|
||||
// The _properties list is sorted, so getting the lower bound is sufficient
|
||||
// The _properties list is sorted, so getting the lower bound is sufficient
|
||||
std::vector<Property*>::iterator it
|
||||
= std::lower_bound(_properties.begin(), _properties.end(), prop->identifier(),
|
||||
[](Property* prop, const std::string& str) {
|
||||
@@ -175,17 +175,17 @@ void PropertyOwner::addProperty(Property* prop)
|
||||
return;
|
||||
} else {
|
||||
// Otherwise we still have to look if there is a PropertyOwner with the same name
|
||||
const bool hasOwner = hasPropertySubOwner(prop->identifier());
|
||||
if (hasOwner) {
|
||||
LERROR("Property identifier '" << prop->identifier() << "' already names a"
|
||||
<< "registed PropertyOwner");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// now have found the correct position to add it in
|
||||
_properties.insert(it, prop);
|
||||
prop->setPropertyOwner(this);
|
||||
}
|
||||
const bool hasOwner = hasPropertySubOwner(prop->identifier());
|
||||
if (hasOwner) {
|
||||
LERROR("Property identifier '" << prop->identifier() << "' already names a"
|
||||
<< "registed PropertyOwner");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// now have found the correct position to add it in
|
||||
_properties.insert(it, prop);
|
||||
prop->setPropertyOwner(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ void PropertyOwner::addProperty(Property& prop) {
|
||||
|
||||
void PropertyOwner::addPropertySubOwner(openspace::properties::PropertyOwner* owner) {
|
||||
assert(owner != nullptr);
|
||||
assert(std::is_sorted(_properties.begin(), _properties.end(), propertyLess));
|
||||
assert(std::is_sorted(_properties.begin(), _properties.end(), propertyLess));
|
||||
assert(std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess));
|
||||
|
||||
if (owner->name().empty()) {
|
||||
@@ -216,18 +216,18 @@ void PropertyOwner::addPropertySubOwner(openspace::properties::PropertyOwner* ow
|
||||
<< "' already present in PropertyOwner '" << name() << "'");
|
||||
return;
|
||||
} else {
|
||||
// We still need to check if the PropertyOwners name is used in a Property
|
||||
const bool hasProp = hasProperty(owner->name());
|
||||
if (hasProp) {
|
||||
LERROR("PropertyOwner '" << owner->name() << "'s name already names a "
|
||||
<< "Property");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Otherwise we have found the correct position to add it in
|
||||
_subOwners.insert(it, owner);
|
||||
owner->setPropertyOwner(this);
|
||||
}
|
||||
// We still need to check if the PropertyOwners name is used in a Property
|
||||
const bool hasProp = hasProperty(owner->name());
|
||||
if (hasProp) {
|
||||
LERROR("PropertyOwner '" << owner->name() << "'s name already names a "
|
||||
<< "Property");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Otherwise we have found the correct position to add it in
|
||||
_subOwners.insert(it, owner);
|
||||
owner->setPropertyOwner(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,19 +35,19 @@ namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
else \
|
||||
return DEFAULT_VALUE; \
|
||||
}
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
else \
|
||||
return DEFAULT_VALUE; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string value, bool& success) -> TYPE { \
|
||||
@@ -69,24 +69,24 @@ namespace properties {
|
||||
// be equal to unsigned short and unsigned int which causes a compile error
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BoolProperty, bool, false,
|
||||
[](lua_State* state, bool& success) -> bool {
|
||||
success = (lua_isboolean(state, -1) == 1);
|
||||
if (success)
|
||||
return lua_toboolean(state, -1) == 1;
|
||||
else
|
||||
return false;
|
||||
},
|
||||
[](lua_State* state, bool value) -> bool {
|
||||
lua_pushboolean(state, value);
|
||||
return true;
|
||||
},
|
||||
[](lua_State* state, bool& success) -> bool {
|
||||
success = (lua_isboolean(state, -1) == 1);
|
||||
if (success)
|
||||
return lua_toboolean(state, -1) == 1;
|
||||
else
|
||||
return false;
|
||||
},
|
||||
[](lua_State* state, bool value) -> bool {
|
||||
lua_pushboolean(state, value);
|
||||
return true;
|
||||
},
|
||||
DEFAULT_FROM_STRING_LAMBDA(bool, false),
|
||||
[](std::string& outValue, bool inValue) -> bool {
|
||||
outValue = inValue ? "true" : "false";
|
||||
return true;
|
||||
},
|
||||
LUA_TBOOLEAN
|
||||
);
|
||||
LUA_TBOOLEAN
|
||||
);
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(CharProperty, char, char(0),
|
||||
numeric_limits<char>::lowest(),
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "SelectionProperty";
|
||||
const std::string _loggerCat = "SelectionProperty";
|
||||
|
||||
const std::string Delimiter = ",";
|
||||
}
|
||||
@@ -36,79 +36,79 @@ namespace properties {
|
||||
const std::string SelectionProperty::OptionsKey = "Options";
|
||||
|
||||
SelectionProperty::SelectionProperty(std::string identifier, std::string guiName)
|
||||
: TemplateProperty(std::move(identifier), std::move(guiName), std::vector<int>())
|
||||
: TemplateProperty(std::move(identifier), std::move(guiName), std::vector<int>())
|
||||
{}
|
||||
|
||||
void SelectionProperty::addOption(Option option) {
|
||||
// @REFACTOR from optionproperty.cpp, possible refactoring? ---abock
|
||||
for (const Option& o : _options) {
|
||||
if (o.value == option.value) {
|
||||
LWARNING("The value of option {" << o.value << " -> " << o.description <<
|
||||
"} was already registered when trying to add option {" << option.value <<
|
||||
" -> " << option.description << "}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
_options.push_back(std::move(option));
|
||||
// @REFACTOR from optionproperty.cpp, possible refactoring? ---abock
|
||||
for (const Option& o : _options) {
|
||||
if (o.value == option.value) {
|
||||
LWARNING("The value of option {" << o.value << " -> " << o.description <<
|
||||
"} was already registered when trying to add option {" << option.value <<
|
||||
" -> " << option.description << "}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
_options.push_back(std::move(option));
|
||||
}
|
||||
|
||||
const std::vector<SelectionProperty::Option>& SelectionProperty::options() const {
|
||||
return _options;
|
||||
return _options;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string PropertyDelegate<TemplateProperty<std::vector<int>>>::className() {
|
||||
return "SelectionProperty";
|
||||
return "SelectionProperty";
|
||||
}
|
||||
|
||||
template <>
|
||||
template <>
|
||||
std::vector<int> PropertyDelegate<TemplateProperty<std::vector<int>>>::fromLuaValue(lua_State* state, bool& success) {
|
||||
static const int KEY = -2;
|
||||
static const int VAL = -1;
|
||||
static const int KEY = -2;
|
||||
static const int VAL = -1;
|
||||
|
||||
std::vector<int> result;
|
||||
std::vector<int> result;
|
||||
|
||||
if (!lua_istable(state, VAL)) {
|
||||
LERROR("Parameter passed to the property is not a table");
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
if (!lua_istable(state, VAL)) {
|
||||
LERROR("Parameter passed to the property is not a table");
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
lua_pushnil(state);
|
||||
while (lua_next(state, KEY) != 0) {
|
||||
if (lua_isnumber(state, VAL)) {
|
||||
int number = static_cast<int>(lua_tonumber(state, VAL));
|
||||
result.push_back(number);
|
||||
}
|
||||
else {
|
||||
success = false;
|
||||
return std::vector<int>();
|
||||
}
|
||||
lua_pushnil(state);
|
||||
while (lua_next(state, KEY) != 0) {
|
||||
if (lua_isnumber(state, VAL)) {
|
||||
int number = static_cast<int>(lua_tonumber(state, VAL));
|
||||
result.push_back(number);
|
||||
}
|
||||
else {
|
||||
success = false;
|
||||
return std::vector<int>();
|
||||
}
|
||||
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
|
||||
success = true;
|
||||
return result;
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
template <>
|
||||
bool PropertyDelegate<TemplateProperty<std::vector<int>>>::toLuaValue(lua_State* state, std::vector<int> value) {
|
||||
//@NOTE Untested ---abock
|
||||
lua_newtable(state);
|
||||
for (int i = 0; i < value.size(); ++i) {
|
||||
int v = value[i];
|
||||
lua_pushinteger(state, v);
|
||||
lua_setfield(state, -2, std::to_string(i).c_str());
|
||||
}
|
||||
return true;
|
||||
//@NOTE Untested ---abock
|
||||
lua_newtable(state);
|
||||
for (int i = 0; i < value.size(); ++i) {
|
||||
int v = value[i];
|
||||
lua_pushinteger(state, v);
|
||||
lua_setfield(state, -2, std::to_string(i).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
int PropertyDelegate<TemplateProperty<std::vector<int>>>::typeLua() {
|
||||
return LUA_TTABLE;
|
||||
return LUA_TTABLE;
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -135,17 +135,17 @@ bool PropertyDelegate<TemplateProperty<std::vector<int>>>::toString(std::string&
|
||||
}
|
||||
|
||||
std::string SelectionProperty::generateAdditionalDescription() const {
|
||||
std::string result;
|
||||
result += OptionsKey + " = {";
|
||||
for (size_t i = 0; i < _options.size(); ++i) {
|
||||
const Option& o = _options[i];
|
||||
result += "[\"" + std::to_string(o.value) + "\"] = \"" + o.description + "\"";
|
||||
if (i != _options.size() - 1)
|
||||
result += ",";
|
||||
}
|
||||
std::string result;
|
||||
result += OptionsKey + " = {";
|
||||
for (size_t i = 0; i < _options.size(); ++i) {
|
||||
const Option& o = _options[i];
|
||||
result += "[\"" + std::to_string(o.value) + "\"] = \"" + o.description + "\"";
|
||||
if (i != _options.size() - 1)
|
||||
result += ",";
|
||||
}
|
||||
|
||||
result += "}";
|
||||
return result;
|
||||
result += "}";
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
|
||||
@@ -31,16 +31,16 @@ namespace properties {
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(StringProperty, std::string, "",
|
||||
[](lua_State* state, bool& success) -> std::string {
|
||||
success = lua_isstring(state, -1) == 1;
|
||||
if (success)
|
||||
return lua_tostring(state, -1);
|
||||
else
|
||||
return "";
|
||||
},
|
||||
success = lua_isstring(state, -1) == 1;
|
||||
if (success)
|
||||
return lua_tostring(state, -1);
|
||||
else
|
||||
return "";
|
||||
},
|
||||
[](lua_State* state, std::string value) -> bool {
|
||||
lua_pushstring(state, value.c_str());
|
||||
return true;
|
||||
},
|
||||
lua_pushstring(state, value.c_str());
|
||||
return true;
|
||||
},
|
||||
[](std::string value, bool& success) -> std::string {
|
||||
// An incoming string is of the form
|
||||
// "value"
|
||||
|
||||
@@ -28,20 +28,20 @@ namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
TriggerProperty::TriggerProperty(std::string identifier, std::string guiName)
|
||||
: Property(std::move(identifier), std::move(guiName))
|
||||
: Property(std::move(identifier), std::move(guiName))
|
||||
{}
|
||||
|
||||
std::string TriggerProperty::className() const {
|
||||
return "TriggerProperty";
|
||||
return "TriggerProperty";
|
||||
}
|
||||
|
||||
bool TriggerProperty::setLuaValue(lua_State* state) {
|
||||
notifyListener();
|
||||
return true;
|
||||
notifyListener();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TriggerProperty::set(ghoul::any value) {
|
||||
notifyListener();
|
||||
notifyListener();
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
|
||||
@@ -45,12 +45,12 @@ namespace properties {
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
@@ -110,8 +110,8 @@ namespace properties {
|
||||
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec2Property, glm::bvec2, glm::bvec2(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec2, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec2, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec2),
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@ SceneGraphNode* sceneGraphNode(const std::string& name) {
|
||||
}
|
||||
|
||||
Renderable* renderable(const std::string& name) {
|
||||
SceneGraphNode* node = sceneGraphNode(name);
|
||||
return node->renderable();
|
||||
SceneGraphNode* node = sceneGraphNode(name);
|
||||
return node->renderable();
|
||||
}
|
||||
|
||||
properties::Property* property(const std::string& uri) {
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <iterator>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "ABufferRenderer";
|
||||
const std::string _loggerCat = "ABufferRenderer";
|
||||
const std::string BoundsFragmentShaderPath = "${SHADERS}/abuffer/boundsabuffer.frag";
|
||||
const std::string RenderFragmentShaderPath = "${SHADERS}/abuffer/renderabuffer.frag";
|
||||
const int MaxRaycasters = 32;
|
||||
@@ -70,13 +70,13 @@ void ABufferRenderer::initialize() {
|
||||
LINFO("Initializing ABufferRenderer");
|
||||
const GLfloat size = 1.0f;
|
||||
const GLfloat vertex_data[] = {
|
||||
// x y s t
|
||||
// x y s t
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
-size, size, 0.0f, 1.0f,
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
};
|
||||
|
||||
|
||||
@@ -90,12 +90,12 @@ void ABufferRenderer::initialize() {
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, reinterpret_cast<void*>(0));
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glGenTextures(1, &_anchorPointerTexture);
|
||||
glGenBuffers(1, &_anchorPointerTextureInitializer);
|
||||
glGenBuffers(1, &_atomicCounterBuffer);
|
||||
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, _atomicCounterBuffer);
|
||||
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint), NULL, GL_DYNAMIC_COPY);
|
||||
glGenBuffers(1, &_fragmentBuffer);
|
||||
glGenTextures(1, &_anchorPointerTexture);
|
||||
glGenBuffers(1, &_anchorPointerTextureInitializer);
|
||||
glGenBuffers(1, &_atomicCounterBuffer);
|
||||
glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, _atomicCounterBuffer);
|
||||
glBufferData(GL_ATOMIC_COUNTER_BUFFER, sizeof(GLuint), NULL, GL_DYNAMIC_COPY);
|
||||
glGenBuffers(1, &_fragmentBuffer);
|
||||
glGenTextures(1, &_fragmentTexture);
|
||||
|
||||
_nAaSamples = OsEng.windowWrapper().currentNumberOfAaSamples();
|
||||
@@ -126,12 +126,12 @@ void ABufferRenderer::initialize() {
|
||||
|
||||
void ABufferRenderer::deinitialize() {
|
||||
LINFO("Deinitializing ABufferRenderer");
|
||||
glDeleteBuffers(1, &_fragmentBuffer);
|
||||
glDeleteBuffers(1, &_fragmentBuffer);
|
||||
glDeleteTextures(1, &_fragmentTexture);
|
||||
|
||||
glDeleteTextures(1, &_anchorPointerTexture);
|
||||
glDeleteBuffers(1, &_anchorPointerTextureInitializer);
|
||||
glDeleteBuffers(1, &_atomicCounterBuffer);
|
||||
glDeleteTextures(1, &_anchorPointerTexture);
|
||||
glDeleteBuffers(1, &_anchorPointerTextureInitializer);
|
||||
glDeleteBuffers(1, &_atomicCounterBuffer);
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
glDeleteVertexArrays(1, &_screenQuad);
|
||||
@@ -283,42 +283,42 @@ void ABufferRenderer::setResolution(glm::ivec2 res) {
|
||||
}
|
||||
|
||||
void ABufferRenderer::clear() {
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer);
|
||||
glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer);
|
||||
glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, _resolution.x, _resolution.y, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, _resolution.x, _resolution.y, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
|
||||
static const GLuint zero = 1;
|
||||
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, _atomicCounterBuffer);
|
||||
glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(zero), &zero);
|
||||
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, 0);
|
||||
static const GLuint zero = 1;
|
||||
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, _atomicCounterBuffer);
|
||||
glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(zero), &zero);
|
||||
glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, 0);
|
||||
}
|
||||
|
||||
void ABufferRenderer::updateResolution() {
|
||||
int totalPixels = _resolution.x * _resolution.y;
|
||||
glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, _resolution.x, _resolution.y, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
|
||||
glBindTexture(GL_TEXTURE_2D, _anchorPointerTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI, _resolution.x, _resolution.y, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _anchorPointerTextureInitializer);
|
||||
glBufferData(GL_PIXEL_UNPACK_BUFFER, totalPixels * sizeof(GLuint), NULL, GL_STATIC_DRAW);
|
||||
|
||||
GLuint* data = (GLuint*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
|
||||
memset(data, 0x00, totalPixels * sizeof(GLuint));
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
GLuint* data = (GLuint*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
|
||||
memset(data, 0x00, totalPixels * sizeof(GLuint));
|
||||
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, _fragmentBuffer);
|
||||
glBufferData(GL_TEXTURE_BUFFER, MaxAverageLayers*totalPixels*sizeof(GLuint) * 4, NULL, GL_DYNAMIC_COPY);
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, _fragmentBuffer);
|
||||
glBufferData(GL_TEXTURE_BUFFER, MaxAverageLayers*totalPixels*sizeof(GLuint) * 4, NULL, GL_DYNAMIC_COPY);
|
||||
|
||||
glBindTexture(GL_TEXTURE_BUFFER, _fragmentTexture);
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32UI, _fragmentBuffer);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, _fragmentTexture);
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32UI, _fragmentBuffer);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
||||
|
||||
glBindImageTexture(1, _fragmentTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI);
|
||||
glBindImageTexture(1, _fragmentTexture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32UI);
|
||||
|
||||
|
||||
_dirtyResolution = false;
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "FramebufferRenderer";
|
||||
const std::string _loggerCat = "FramebufferRenderer";
|
||||
const std::string ExitFragmentShaderPath = "${SHADERS}/framebuffer/exitframebuffer.frag";
|
||||
const std::string RaycastFragmentShaderPath = "${SHADERS}/framebuffer/raycastframebuffer.frag";
|
||||
const std::string RenderFragmentShaderPath = "${SHADERS}/framebuffer/renderframebuffer.frag";
|
||||
@@ -61,13 +61,13 @@ void FramebufferRenderer::initialize() {
|
||||
|
||||
const GLfloat size = 1.0f;
|
||||
const GLfloat vertex_data[] = {
|
||||
// x y s t
|
||||
// x y s t
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f,
|
||||
-size, size, 0.0f, 1.0f,
|
||||
-size, -size, 0.0f, 1.0f,
|
||||
size, -size, 0.0f, 1.0f,
|
||||
size, size, 0.0f, 1.0f
|
||||
size, size, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
glGenVertexArrays(1, &_screenQuad);
|
||||
@@ -80,13 +80,13 @@ void FramebufferRenderer::initialize() {
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*4, reinterpret_cast<void*>(0));
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
GLint defaultFbo;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFbo);
|
||||
GLint defaultFbo;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFbo);
|
||||
|
||||
// Main framebuffer
|
||||
glGenTextures(1, &_mainColorTexture);
|
||||
glGenTextures(1, &_mainDepthTexture);
|
||||
glGenFramebuffers(1, &_mainFramebuffer);
|
||||
glGenFramebuffers(1, &_mainFramebuffer);
|
||||
|
||||
// Exit framebuffer
|
||||
glGenTextures(1, &_exitColorTexture);
|
||||
@@ -220,12 +220,12 @@ void FramebufferRenderer::updateResolution() {
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_RGBA16,
|
||||
GLsizei(_resolution.x),
|
||||
GLsizei(_resolution.y),
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_BYTE,
|
||||
GL_UNSIGNED_SHORT,
|
||||
nullptr);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RaycasterManager";
|
||||
const std::string _loggerCat = "RaycasterManager";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -46,17 +46,17 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary) {
|
||||
// The name is passed down from the SceneGraphNode
|
||||
// The name is passed down from the SceneGraphNode
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
assert(success);
|
||||
assert(success);
|
||||
|
||||
std::string renderableType;
|
||||
success = dictionary.getValue(KeyType, renderableType);
|
||||
if (!success) {
|
||||
if (!success) {
|
||||
LERROR("Renderable '" << name << "' did not have key '" << KeyType << "'");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ghoul::TemplateFactory<Renderable>* factory
|
||||
= FactoryManager::ref().factory<Renderable>();
|
||||
@@ -70,7 +70,7 @@ Renderable* Renderable::createFromDictionary(const ghoul::Dictionary& dictionary
|
||||
}
|
||||
|
||||
Renderable::Renderable(const ghoul::Dictionary& dictionary)
|
||||
: _enabled("enabled", "Is Enabled", true)
|
||||
: _enabled("enabled", "Is Enabled", true)
|
||||
, _startTime("")
|
||||
, _endTime("")
|
||||
, _targetBody("")
|
||||
@@ -79,18 +79,19 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary)
|
||||
{
|
||||
setName("renderable");
|
||||
#ifndef NDEBUG
|
||||
std::string name;
|
||||
ghoul_assert(dictionary.getValue(SceneGraphNode::KeyName, name),
|
||||
std::string name;
|
||||
ghoul_assert(dictionary.getValue(SceneGraphNode::KeyName, name),
|
||||
"Scenegraphnode need to specify '" << SceneGraphNode::KeyName
|
||||
<< "' because renderables is going to use this for debugging!");
|
||||
<< "' because renderables is going to use this for debugging!");
|
||||
#endif
|
||||
dictionary.getValue(keyStart, _startTime);
|
||||
dictionary.getValue(keyEnd, _endTime);
|
||||
|
||||
if (_startTime != "" && _endTime != "")
|
||||
_hasTimeInterval = true;
|
||||
dictionary.getValue(keyStart, _startTime);
|
||||
dictionary.getValue(keyEnd, _endTime);
|
||||
|
||||
addProperty(_enabled);
|
||||
if (_startTime != "" && _endTime != "")
|
||||
_hasTimeInterval = true;
|
||||
|
||||
addProperty(_enabled);
|
||||
}
|
||||
|
||||
Renderable::~Renderable() {
|
||||
@@ -121,58 +122,58 @@ void Renderable::render(const RenderData& data)
|
||||
}
|
||||
|
||||
void Renderable::setPscUniforms(
|
||||
ghoul::opengl::ProgramObject& program,
|
||||
const Camera& camera,
|
||||
const PowerScaledCoordinate& position)
|
||||
ghoul::opengl::ProgramObject& program,
|
||||
const Camera& camera,
|
||||
const PowerScaledCoordinate& position)
|
||||
{
|
||||
program.setUniform("campos", camera.position().vec4());
|
||||
program.setUniform("objpos", position.vec4());
|
||||
program.setUniform("camrot", camera.viewRotationMatrix());
|
||||
program.setUniform("scaling", camera.scaling());
|
||||
program.setUniform("campos", camera.position().vec4());
|
||||
program.setUniform("objpos", position.vec4());
|
||||
program.setUniform("camrot", camera.viewRotationMatrix());
|
||||
program.setUniform("scaling", camera.scaling());
|
||||
}
|
||||
|
||||
bool Renderable::isVisible() const {
|
||||
return _enabled;
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
bool Renderable::hasTimeInterval() {
|
||||
return _hasTimeInterval;
|
||||
return _hasTimeInterval;
|
||||
}
|
||||
|
||||
bool Renderable::hasBody() {
|
||||
return _hasBody;
|
||||
return _hasBody;
|
||||
}
|
||||
|
||||
bool Renderable::getInterval(double& start, double& end) {
|
||||
if (_startTime != "" && _endTime != "") {
|
||||
if (_startTime != "" && _endTime != "") {
|
||||
start = SpiceManager::ref().ephemerisTimeFromDate(_startTime);
|
||||
end = SpiceManager::ref().ephemerisTimeFromDate(_endTime);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Renderable::getBody(std::string& body) {
|
||||
if (_hasBody) {
|
||||
body = _targetBody;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
if (_hasBody) {
|
||||
body = _targetBody;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void Renderable::setBody(std::string& body) {
|
||||
_targetBody = body;
|
||||
_hasBody = true;
|
||||
_targetBody = body;
|
||||
_hasBody = true;
|
||||
}
|
||||
|
||||
bool Renderable::isReady() const {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Renderable::isEnabled() const {
|
||||
return _enabled;
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
void Renderable::onEnabledChange(std::function<void(bool)> callback) {
|
||||
|
||||
+881
-880
File diff suppressed because it is too large
Load Diff
@@ -26,32 +26,32 @@
|
||||
|
||||
namespace openspace {
|
||||
ScreenSpaceRenderable::ScreenSpaceRenderable()
|
||||
: _enabled("enabled", "Is Enabled", true)
|
||||
, _useFlatScreen("flatScreen", "Flat Screen", false)
|
||||
, _euclideanPosition("euclideanPosition", "Euclidean coordinates", glm::vec2(0),glm::vec2(-4),glm::vec2(4))
|
||||
, _sphericalPosition("sphericalPosition", "Spherical coordinates", glm::vec2(0),glm::vec2(-M_PI),glm::vec2(M_PI))
|
||||
, _depth("depth", "Depth", 0, 0, 1)
|
||||
, _scale("scale", "Scale" , 0.5, 0, 2)
|
||||
, _alpha("alpha", "Alpha" , 1, 0, 1)
|
||||
,_delete("delete", "Delete")
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
,_rendererPath("${SHADERS}/framebuffer/renderframebuffer.frag")
|
||||
,_vertexPath("${MODULE_BASE}/shaders/screnspace_vs.glsl")
|
||||
,_fragmentPath("${MODULE_BASE}/shaders/screnspace_fs.glsl")
|
||||
,_texture(nullptr)
|
||||
,_shader(nullptr)
|
||||
: _enabled("enabled", "Is Enabled", true)
|
||||
, _useFlatScreen("flatScreen", "Flat Screen", false)
|
||||
, _euclideanPosition("euclideanPosition", "Euclidean coordinates", glm::vec2(0),glm::vec2(-4),glm::vec2(4))
|
||||
, _sphericalPosition("sphericalPosition", "Spherical coordinates", glm::vec2(0),glm::vec2(-M_PI),glm::vec2(M_PI))
|
||||
, _depth("depth", "Depth", 0, 0, 1)
|
||||
, _scale("scale", "Scale" , 0.5, 0, 2)
|
||||
, _alpha("alpha", "Alpha" , 1, 0, 1)
|
||||
,_delete("delete", "Delete")
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
,_rendererPath("${SHADERS}/framebuffer/renderframebuffer.frag")
|
||||
,_vertexPath("${MODULE_BASE}/shaders/screnspace_vs.glsl")
|
||||
,_fragmentPath("${MODULE_BASE}/shaders/screnspace_fs.glsl")
|
||||
,_texture(nullptr)
|
||||
,_shader(nullptr)
|
||||
{
|
||||
addProperty(_enabled);
|
||||
addProperty(_useFlatScreen);
|
||||
addProperty(_euclideanPosition);
|
||||
addProperty(_sphericalPosition);
|
||||
addProperty(_depth);
|
||||
addProperty(_scale);
|
||||
addProperty(_alpha);
|
||||
addProperty(_delete);
|
||||
addProperty(_enabled);
|
||||
addProperty(_useFlatScreen);
|
||||
addProperty(_euclideanPosition);
|
||||
addProperty(_sphericalPosition);
|
||||
addProperty(_depth);
|
||||
addProperty(_scale);
|
||||
addProperty(_alpha);
|
||||
addProperty(_delete);
|
||||
|
||||
_rendererData = ghoul::Dictionary();
|
||||
_rendererData = ghoul::Dictionary();
|
||||
_rendererData.setValue("fragmentRendererPath", _rendererPath);
|
||||
_rendererData.setValue("windowWidth", OsEng.windowWrapper().currentWindowResolution().x);
|
||||
_rendererData.setValue("windowHeight", OsEng.windowWrapper().currentWindowResolution().y);
|
||||
@@ -60,36 +60,36 @@ ScreenSpaceRenderable::ScreenSpaceRenderable()
|
||||
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
});
|
||||
|
||||
_sphericalPosition.onChange([this](){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
});
|
||||
_euclideanPosition.onChange([this](){
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
});
|
||||
|
||||
_sphericalPosition.onChange([this](){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
});
|
||||
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
// Setting spherical/euclidean onchange handler
|
||||
_useFlatScreen.onChange([this](){
|
||||
useEuclideanCoordinates(_useFlatScreen.value());
|
||||
});
|
||||
|
||||
_delete.onChange([this](){OsEng.renderEngine().unregisterScreenSpaceRenderable(name());});
|
||||
_delete.onChange([this](){OsEng.renderEngine().unregisterScreenSpaceRenderable(name());});
|
||||
}
|
||||
|
||||
ScreenSpaceRenderable::~ScreenSpaceRenderable(){}
|
||||
|
||||
bool ScreenSpaceRenderable::isEnabled() const {
|
||||
return _enabled;
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::createPlane() {
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
// ============================
|
||||
// GEOMETRY (quad)
|
||||
// GEOMETRY (quad)
|
||||
// ============================
|
||||
const GLfloat vertex_data[] = { // square of two triangles (sigh)
|
||||
// x y z w s t
|
||||
// x y z w s t
|
||||
-1, -1, 0.0f, 1, 0, 1,
|
||||
1, 1, 0.0f, 1, 1, 0,
|
||||
-1, 1, 0.0f, 1, 0, 0,
|
||||
@@ -108,122 +108,122 @@ void ScreenSpaceRenderable::createPlane() {
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::useEuclideanCoordinates(bool b){
|
||||
_useEuclideanCoordinates = b;
|
||||
if(_useEuclideanCoordinates){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
} else {
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
}
|
||||
_useEuclideanCoordinates = b;
|
||||
if(_useEuclideanCoordinates){
|
||||
_euclideanPosition.set(toEuclidean(_sphericalPosition.value(), _radius));
|
||||
} else {
|
||||
_sphericalPosition.set(toSpherical(_euclideanPosition.value()));
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec2 ScreenSpaceRenderable::toEuclidean(glm::vec2 polar, float r){
|
||||
float x = r*sin(polar[0])*sin(polar[1]);
|
||||
float y = r*cos(polar[1]);
|
||||
|
||||
return glm::vec2(x, y);
|
||||
float x = r*sin(polar[0])*sin(polar[1]);
|
||||
float y = r*cos(polar[1]);
|
||||
|
||||
return glm::vec2(x, y);
|
||||
}
|
||||
|
||||
glm::vec2 ScreenSpaceRenderable::toSpherical(glm::vec2 euclidean){
|
||||
_radius = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(_planeDepth,2));
|
||||
float theta = atan2(-_planeDepth,euclidean[0])-M_PI/2.0;
|
||||
float phi = acos(euclidean[1]/_radius);
|
||||
glm::vec2 ScreenSpaceRenderable::toSpherical(glm::vec2 euclidean){
|
||||
_radius = -sqrt(pow(euclidean[0],2)+pow(euclidean[1],2)+pow(_planeDepth,2));
|
||||
float theta = atan2(-_planeDepth,euclidean[0])-M_PI/2.0;
|
||||
float phi = acos(euclidean[1]/_radius);
|
||||
|
||||
return glm::vec2(theta, phi);
|
||||
return glm::vec2(theta, phi);
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::registerProperties(){
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_enabled);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_useFlatScreen);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_sphericalPosition);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_depth);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_scale);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_alpha);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_delete);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_enabled);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_useFlatScreen);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_euclideanPosition);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_sphericalPosition);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_depth);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_scale);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_alpha);
|
||||
OsEng.gui()._screenSpaceProperty.registerProperty(&_delete);
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::unregisterProperties(){
|
||||
OsEng.gui()._screenSpaceProperty.unregisterProperties(name());
|
||||
OsEng.gui()._screenSpaceProperty.unregisterProperties(name());
|
||||
}
|
||||
|
||||
void ScreenSpaceRenderable::createShaders(){
|
||||
if(!_shader) {
|
||||
if(!_shader) {
|
||||
|
||||
ghoul::Dictionary dict = ghoul::Dictionary();
|
||||
|
||||
dict.setValue("rendererData", _rendererData);
|
||||
dict.setValue("fragmentPath", _fragmentPath);
|
||||
_shader = ghoul::opengl::ProgramObject::Build("ScreenSpaceProgram",
|
||||
_vertexPath,
|
||||
"${SHADERS}/render.frag",
|
||||
dict
|
||||
);
|
||||
}
|
||||
_shader = ghoul::opengl::ProgramObject::Build("ScreenSpaceProgram",
|
||||
_vertexPath,
|
||||
"${SHADERS}/render.frag",
|
||||
dict
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 ScreenSpaceRenderable::scaleMatrix(){
|
||||
glm::mat4 scale(1.0);
|
||||
glm::mat4 scale(1.0);
|
||||
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
glm::vec2 resolution = OsEng.windowWrapper().currentWindowResolution();
|
||||
|
||||
//to scale the plane
|
||||
float textureRatio = (float(_texture->height())/float(_texture->width()));
|
||||
float scalingRatioX = _originalViewportSize[0]/ resolution[0];
|
||||
float scalingRatioY = _originalViewportSize[1]/ resolution[1];
|
||||
scale = glm::scale(scale, glm::vec3(_scale.value() * scalingRatioX,
|
||||
_scale.value() * scalingRatioY * textureRatio,
|
||||
1));
|
||||
return scale;
|
||||
//to scale the plane
|
||||
float textureRatio = (float(_texture->height())/float(_texture->width()));
|
||||
float scalingRatioX = _originalViewportSize[0]/ resolution[0];
|
||||
float scalingRatioY = _originalViewportSize[1]/ resolution[1];
|
||||
scale = glm::scale(scale, glm::vec3(_scale.value() * scalingRatioX,
|
||||
_scale.value() * scalingRatioY * textureRatio,
|
||||
1));
|
||||
return scale;
|
||||
}
|
||||
|
||||
glm::mat4 ScreenSpaceRenderable::rotationMatrix(){
|
||||
glm::mat4 rotation(1.0);
|
||||
if(!_useEuclideanCoordinates){
|
||||
glm::vec2 position = _sphericalPosition.value();
|
||||
glm::mat4 rotation(1.0);
|
||||
if(!_useEuclideanCoordinates){
|
||||
glm::vec2 position = _sphericalPosition.value();
|
||||
|
||||
float theta = position.x;
|
||||
float phi = position.y - M_PI/2.0;
|
||||
float theta = position.x;
|
||||
float phi = position.y - M_PI/2.0;
|
||||
|
||||
rotation = glm::rotate(rotation, position.x, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotation = glm::rotate(rotation, (float) (position.y - M_PI/2.0) , glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
}
|
||||
rotation = glm::rotate(rotation, position.x, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
rotation = glm::rotate(rotation, (float) (position.y - M_PI/2.0) , glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
return rotation;
|
||||
return rotation;
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 ScreenSpaceRenderable::translationMatrix(){
|
||||
glm::mat4 translation(1.0);
|
||||
if(!_useEuclideanCoordinates){
|
||||
translation = glm::translate(translation, glm::vec3(0.0f, 0.0f, _planeDepth));
|
||||
}else{
|
||||
translation = glm::translate(glm::mat4(1.f), glm::vec3(_euclideanPosition.value(), _planeDepth));
|
||||
}
|
||||
glm::mat4 translation(1.0);
|
||||
if(!_useEuclideanCoordinates){
|
||||
translation = glm::translate(translation, glm::vec3(0.0f, 0.0f, _planeDepth));
|
||||
}else{
|
||||
translation = glm::translate(glm::mat4(1.f), glm::vec3(_euclideanPosition.value(), _planeDepth));
|
||||
}
|
||||
|
||||
return translation;
|
||||
return translation;
|
||||
}
|
||||
|
||||
|
||||
void ScreenSpaceRenderable::draw(glm::mat4 modelTransform){
|
||||
float occlusionDepth = 1-_depth.value();
|
||||
float occlusionDepth = 1-_depth.value();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
_shader->activate();
|
||||
_shader->setUniform("OcclusionDepth", occlusionDepth);
|
||||
_shader->setUniform("Alpha", _alpha);
|
||||
_shader->setUniform("ModelTransform",modelTransform);
|
||||
_shader->setUniform("ViewProjectionMatrix", OsEng.renderEngine().camera()->viewProjectionMatrix());
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
_shader->activate();
|
||||
_shader->setUniform("OcclusionDepth", occlusionDepth);
|
||||
_shader->setUniform("Alpha", _alpha);
|
||||
_shader->setUniform("ModelTransform",modelTransform);
|
||||
_shader->setUniform("ViewProjectionMatrix", OsEng.renderEngine().camera()->viewProjectionMatrix());
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
_shader->setUniform("texture1", unit);
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
_shader->deactivate();
|
||||
_shader->deactivate();
|
||||
}
|
||||
}// namespace openspace
|
||||
@@ -0,0 +1,227 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/transferfunction.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TransferFunction";
|
||||
|
||||
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
|
||||
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
|
||||
|
||||
bool hasExtension (std::string const &filepath, std::string const &extension)
|
||||
{
|
||||
std::string ending = "." + extension;
|
||||
if (filepath.length() > ending.length()) {
|
||||
return (0 == filepath.compare (filepath.length() - ending.length(), ending.length(), ending));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace openspace {
|
||||
TransferFunction::TransferFunction(const std::string& filepath, TfChangedCallback tfChangedCallback) : _filepath(filepath) {
|
||||
setPath(filepath);
|
||||
setCallback(tfChangedCallback);
|
||||
}
|
||||
|
||||
void TransferFunction::setPath(const std::string& filepath) {
|
||||
if (_file) {
|
||||
_file = nullptr;
|
||||
}
|
||||
std::string f = absPath(filepath);
|
||||
if (!FileSys.fileExists(f)) {
|
||||
LERROR("Could not find transfer function file.");
|
||||
_file = nullptr;
|
||||
}
|
||||
_filepath = f;
|
||||
_file = std::make_unique<ghoul::filesystem::File>(filepath, ghoul::filesystem::File::RawPath::Yes);
|
||||
_needsUpdate = true;
|
||||
_file->setCallback([this](const ghoul::filesystem::File& file) {
|
||||
_needsUpdate = true;
|
||||
});
|
||||
}
|
||||
|
||||
ghoul::opengl::Texture& TransferFunction::getTexture() {
|
||||
ghoul_assert(_texture != nullptr, "Transfer function is null");
|
||||
update();
|
||||
return *_texture.get();
|
||||
}
|
||||
|
||||
void TransferFunction::update() {
|
||||
if (_needsUpdate) {
|
||||
if (hasExtension(_filepath, "txt")) {
|
||||
setTextureFromTxt();
|
||||
} else {
|
||||
setTextureFromImage();
|
||||
}
|
||||
_texture->uploadTexture();
|
||||
_needsUpdate = false;
|
||||
if (_tfChangedCallback) {
|
||||
_tfChangedCallback(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TransferFunction::setCallback(TfChangedCallback callback) {
|
||||
_tfChangedCallback = std::move(callback);
|
||||
}
|
||||
|
||||
void TransferFunction::setTextureFromTxt() {
|
||||
std::ifstream in;
|
||||
in.open(_filepath.c_str());
|
||||
|
||||
if (!in.is_open()) {
|
||||
LERROR("Could not open file " << _filepath);
|
||||
return;
|
||||
}
|
||||
|
||||
int width = 512;
|
||||
float lower = 0.0f;
|
||||
float upper = 1.0f;
|
||||
|
||||
std::vector<MappingKey> mappingKeys;
|
||||
|
||||
std::string line;
|
||||
|
||||
while (std::getline(in, line)) {
|
||||
std::istringstream iss(line);
|
||||
std::string key;
|
||||
iss >> key;
|
||||
|
||||
if(key == "width") {
|
||||
iss >> width;
|
||||
} else if(key == "lower") {
|
||||
iss >> lower;
|
||||
lower = glm::clamp(lower, 0.0f, 1.0f);
|
||||
} else if(key == "upper") {
|
||||
iss >> upper;
|
||||
upper = glm::clamp(upper, lower, 1.0f);
|
||||
} else if(key == "mappingkey") {
|
||||
float intensity;
|
||||
glm::vec4 rgba = glm::vec4(0.0f);
|
||||
iss >> intensity;
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
iss >> rgba[i];
|
||||
}
|
||||
mappingKeys.push_back({intensity, rgba});
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (mappingKeys.size() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mappingKeys.front().position > lower) {
|
||||
mappingKeys.insert(mappingKeys.begin(), {lower,mappingKeys.front().color});
|
||||
}
|
||||
|
||||
if (mappingKeys.back().position < upper) {
|
||||
mappingKeys.push_back({upper,mappingKeys.back().color});
|
||||
}
|
||||
|
||||
// allocate new float array with zeros
|
||||
float* transferFunction = new float[width*4]();
|
||||
for (int i = 0; i < 4*width; ++i) {
|
||||
transferFunction[i] = 0.0f;
|
||||
}
|
||||
|
||||
size_t lowerIndex = static_cast<size_t>(floorf(lower*static_cast<float>(width-1)));
|
||||
size_t upperIndex = static_cast<size_t>(floorf(upper*static_cast<float>(width-1)));
|
||||
|
||||
auto prevKey = mappingKeys.begin();
|
||||
auto currentKey = prevKey + 1;
|
||||
auto lastKey = mappingKeys.end() -1;
|
||||
|
||||
for (size_t i=lowerIndex; i<=upperIndex; i++) {
|
||||
float fpos = static_cast<float>(i)/static_cast<float>(width-1);
|
||||
if (fpos > (*currentKey).position) {
|
||||
prevKey = currentKey;
|
||||
currentKey++;
|
||||
if (currentKey == mappingKeys.end()) {
|
||||
currentKey = lastKey;
|
||||
}
|
||||
}
|
||||
|
||||
float dist = fpos-(*prevKey).position;
|
||||
float weight = dist/((*currentKey).position-(*prevKey).position);
|
||||
|
||||
for (size_t channel=0; channel<4; ++channel) {
|
||||
size_t position = 4*i + channel;
|
||||
// Interpolate linearly between prev and next mapping key
|
||||
|
||||
float value =
|
||||
((*prevKey).color[channel]*(1.f-weight) + (*currentKey).color[channel]*weight)/255.f;
|
||||
transferFunction[position] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// no need to deallocate transferFunction. Ownership is transferred to the Texture.
|
||||
_texture = std::make_unique<ghoul::opengl::Texture>(transferFunction,
|
||||
glm::size3_t(width,1,1),ghoul::opengl::Texture::Format::RGBA,
|
||||
GL_RGBA, GL_FLOAT, filtermode, wrappingmode);
|
||||
}
|
||||
|
||||
void TransferFunction::setTextureFromImage() {
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(_filepath);
|
||||
_texture->setWrapping(wrappingmode);
|
||||
}
|
||||
|
||||
glm::vec4 TransferFunction::sample(size_t offset) {
|
||||
if (!_texture) return glm::vec4(0.0);
|
||||
|
||||
int nPixels = _texture->width();
|
||||
|
||||
// Clamp to range.
|
||||
if (offset >= nPixels) offset = nPixels - 1;
|
||||
if (offset < 0) offset = 0;
|
||||
|
||||
return _texture->texelAsFloat(offset);
|
||||
}
|
||||
|
||||
size_t TransferFunction::width() {
|
||||
update();
|
||||
return _texture->width();
|
||||
}
|
||||
}
|
||||
+39
-38
@@ -113,11 +113,12 @@ void Scene::update(const UpdateData& data) {
|
||||
if (!_sceneGraphToLoad.empty()) {
|
||||
OsEng.renderEngine().scene()->clearSceneGraph();
|
||||
try {
|
||||
bool success = loadSceneInternal(_sceneGraphToLoad);
|
||||
loadSceneInternal(_sceneGraphToLoad);
|
||||
_sceneGraphToLoad = "";
|
||||
}
|
||||
catch (const ghoul::RuntimeError& e) {
|
||||
LERROR(e.what());
|
||||
_sceneGraphToLoad = "";
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -184,9 +185,9 @@ void Scene::clearSceneGraph() {
|
||||
// deallocate the scene graph. Recursive deallocation will occur
|
||||
_graph.clear();
|
||||
//if (_root) {
|
||||
// _root->deinitialize();
|
||||
// delete _root;
|
||||
// _root = nullptr;
|
||||
// _root->deinitialize();
|
||||
// delete _root;
|
||||
// _root = nullptr;
|
||||
//}
|
||||
|
||||
// _nodes.erase(_nodes.begin(), _nodes.end());
|
||||
@@ -374,34 +375,34 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
|
||||
}
|
||||
|
||||
//void Scene::loadModules(
|
||||
// const std::string& directory,
|
||||
// const ghoul::Dictionary& dictionary)
|
||||
// const std::string& directory,
|
||||
// const ghoul::Dictionary& dictionary)
|
||||
//{
|
||||
// // Struct containing dependencies and nodes
|
||||
// LoadMaps m;
|
||||
// // Struct containing dependencies and nodes
|
||||
// LoadMaps m;
|
||||
//
|
||||
// // Get the common directory
|
||||
// std::string commonDirectory(_defaultCommonDirectory);
|
||||
// dictionary.getValue(constants::scenegraph::keyCommonFolder, commonDirectory);
|
||||
// FileSys.registerPathToken(_commonModuleToken, commonDirectory);
|
||||
// // Get the common directory
|
||||
// std::string commonDirectory(_defaultCommonDirectory);
|
||||
// dictionary.getValue(constants::scenegraph::keyCommonFolder, commonDirectory);
|
||||
// FileSys.registerPathToken(_commonModuleToken, commonDirectory);
|
||||
//
|
||||
// lua_State* state = ghoul::lua::createNewLuaState();
|
||||
// OsEng.scriptEngine()->initializeLuaState(state);
|
||||
//
|
||||
// LDEBUG("Loading common module folder '" << commonDirectory << "'");
|
||||
// // Load common modules into LoadMaps struct
|
||||
// loadModule(m, FileSys.pathByAppendingComponent(directory, commonDirectory), state);
|
||||
// LDEBUG("Loading common module folder '" << commonDirectory << "'");
|
||||
// // Load common modules into LoadMaps struct
|
||||
// loadModule(m, FileSys.pathByAppendingComponent(directory, commonDirectory), state);
|
||||
//
|
||||
// // Load the rest of the modules into LoadMaps struct
|
||||
// // Load the rest of the modules into LoadMaps struct
|
||||
// ghoul::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)) {
|
||||
// if (moduleDictionary.getValue(key, moduleFolder)) {
|
||||
// loadModule(m, FileSys.pathByAppendingComponent(directory, moduleFolder), state);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
@@ -410,19 +411,19 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
|
||||
//
|
||||
// // Remove loaded nodes from dependency list
|
||||
// for(const auto& name: m.loadedNodes) {
|
||||
// m.dependencies.erase(name);
|
||||
// m.dependencies.erase(name);
|
||||
// }
|
||||
//
|
||||
// // Check to see what dependencies are not resolved.
|
||||
// for(auto& node: m.dependencies) {
|
||||
// LWARNING(
|
||||
// "'" << node.second << "'' not loaded, parent '"
|
||||
// << node.first << "' not defined!");
|
||||
// LWARNING(
|
||||
// "'" << node.second << "'' not loaded, parent '"
|
||||
// << node.first << "' not defined!");
|
||||
// }
|
||||
//}
|
||||
|
||||
//void Scene::loadModule(LoadMaps& m,const std::string& modulePath, lua_State* state) {
|
||||
// auto pos = modulePath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator);
|
||||
// auto pos = modulePath.find_last_of(ghoul::filesystem::FileSystem::PathSeparator);
|
||||
// if (pos == modulePath.npos) {
|
||||
// LERROR("Bad format for module path: " << modulePath);
|
||||
// return;
|
||||
@@ -449,33 +450,33 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
|
||||
// std::string parentName;
|
||||
//
|
||||
// moduleDictionary.getValue(key, element);
|
||||
// element.setValue(constants::scenegraph::keyPathModule, modulePath);
|
||||
// element.setValue(constants::scenegraph::keyPathModule, modulePath);
|
||||
//
|
||||
// element.getValue(constants::scenegraphnode::keyName, nodeName);
|
||||
// element.getValue(constants::scenegraphnode::keyParentName, parentName);
|
||||
// element.getValue(constants::scenegraphnode::keyName, nodeName);
|
||||
// element.getValue(constants::scenegraphnode::keyParentName, parentName);
|
||||
//
|
||||
// m.nodes[nodeName] = element;
|
||||
// m.dependencies.emplace(parentName,nodeName);
|
||||
// m.nodes[nodeName] = element;
|
||||
// m.dependencies.emplace(parentName,nodeName);
|
||||
// }
|
||||
//
|
||||
// FileSys.setCurrentDirectory(oldDirectory);
|
||||
//}
|
||||
|
||||
//void Scene::loadNodes(const std::string& parentName, LoadMaps& m) {
|
||||
// auto eqRange = m.dependencies.equal_range(parentName);
|
||||
// for (auto it = eqRange.first; it != eqRange.second; ++it) {
|
||||
// auto node = m.nodes.find((*it).second);
|
||||
// loadNode(node->second);
|
||||
// loadNodes((*it).second, m);
|
||||
// }
|
||||
// m.loadedNodes.emplace_back(parentName);
|
||||
// auto eqRange = m.dependencies.equal_range(parentName);
|
||||
// for (auto it = eqRange.first; it != eqRange.second; ++it) {
|
||||
// auto node = m.nodes.find((*it).second);
|
||||
// loadNode(node->second);
|
||||
// loadNodes((*it).second, m);
|
||||
// }
|
||||
// m.loadedNodes.emplace_back(parentName);
|
||||
//}
|
||||
//
|
||||
//void Scene::loadNode(const ghoul::Dictionary& dictionary) {
|
||||
// SceneGraphNode* node = SceneGraphNode::createFromDictionary(dictionary);
|
||||
// if(node) {
|
||||
// _allNodes.emplace(node->name(), node);
|
||||
// _nodes.push_back(node);
|
||||
// _allNodes.emplace(node->name(), node);
|
||||
// _nodes.push_back(node);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -507,7 +508,7 @@ bool Scene::loadSceneInternal(const std::string& sceneDescriptionFilePath) {
|
||||
//
|
||||
// element.setValue(constants::scenegraph::keyPathModule, modulePath);
|
||||
//
|
||||
// //each element in this new dictionary becomes a scenegraph node.
|
||||
// //each element in this new dictionary becomes a scenegraph node.
|
||||
// SceneGraphNode* node = SceneGraphNode::createFromDictionary(element);
|
||||
//
|
||||
// _allNodes.emplace(node->name(), node);
|
||||
|
||||
+135
-58
@@ -128,10 +128,16 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
if (!success)
|
||||
// There are no modules that are loaded
|
||||
return true;
|
||||
|
||||
|
||||
lua_State* state = ghoul::lua::createNewLuaState();
|
||||
OsEng.scriptEngine().initializeLuaState(state);
|
||||
|
||||
// Above we generated a ghoul::Dictionary from the scene file; now we run the scene
|
||||
// file again to load any variables defined inside into the state that is passed to
|
||||
// the modules. This allows us to specify global variables that can then be used
|
||||
// inside the modules to toggle settings
|
||||
ghoul::lua::runScriptFile(state, absSceneFile);
|
||||
|
||||
// Get the common directory
|
||||
bool commonFolderSpecified = sceneDictionary.hasKey(KeyCommonFolder);
|
||||
bool commonFolderCorrectType = sceneDictionary.hasKeyAndValue<std::string>(KeyCommonFolder);
|
||||
@@ -171,9 +177,17 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
std::sort(keys.begin(), keys.end());
|
||||
ghoul::filesystem::Directory oldDirectory = FileSys.currentDirectory();
|
||||
for (const std::string& key : keys) {
|
||||
std::string moduleName = moduleDictionary.value<std::string>(key);
|
||||
std::string modulePath = FileSys.pathByAppendingComponent(sceneDirectory, moduleName);
|
||||
std::string fullModuleName = moduleDictionary.value<std::string>(key);
|
||||
|
||||
std::replace(fullModuleName.begin(), fullModuleName.end(), '/', FileSys.PathSeparator);
|
||||
|
||||
std::string modulePath = FileSys.pathByAppendingComponent(sceneDirectory, fullModuleName);
|
||||
|
||||
std::string moduleName = fullModuleName;
|
||||
std::string::size_type pos = fullModuleName.find_last_of(FileSys.PathSeparator);
|
||||
if (pos != std::string::npos)
|
||||
moduleName = fullModuleName.substr(pos + 1);
|
||||
|
||||
if (!FileSys.directoryExists(modulePath)) {
|
||||
LERROR("Could not load module '" << moduleName << "'. Directory did not exist");
|
||||
continue;
|
||||
@@ -184,70 +198,132 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
moduleName + _moduleExtension
|
||||
);
|
||||
|
||||
if (!FileSys.fileExists(moduleFile)) {
|
||||
LERROR("Could not load module file '" << moduleFile << "'. File did not exist");
|
||||
continue;
|
||||
}
|
||||
|
||||
ghoul::Dictionary moduleDictionary;
|
||||
try {
|
||||
ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state);
|
||||
}
|
||||
catch (...) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<std::string> keys = moduleDictionary.keys();
|
||||
for (const std::string& key : keys) {
|
||||
if (!moduleDictionary.hasValue<ghoul::Dictionary>(key)) {
|
||||
LERROR("SceneGraphNode '" << key << "' is not a table in module '"
|
||||
<< moduleFile << "'");
|
||||
struct ModuleInformation {
|
||||
ghoul::Dictionary dictionary;
|
||||
std::string moduleFile;
|
||||
std::string modulePath;
|
||||
std::string moduleName;
|
||||
};
|
||||
std::vector<ModuleInformation> moduleDictionaries;
|
||||
if (FileSys.fileExists(moduleFile)) {
|
||||
// We have a module file, so it is a direct include
|
||||
try {
|
||||
ghoul::Dictionary moduleDictionary;
|
||||
ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state);
|
||||
moduleDictionaries.push_back({
|
||||
moduleDictionary,
|
||||
moduleFile,
|
||||
modulePath,
|
||||
moduleName
|
||||
});
|
||||
}
|
||||
catch (const ghoul::lua::LuaRuntimeException& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// If we do not have a module file, we have to include all subdirectories
|
||||
using ghoul::filesystem::Directory;
|
||||
using std::string;
|
||||
std::vector<string> directories = Directory(modulePath).readDirectories();
|
||||
|
||||
for (const string& s : directories) {
|
||||
std::string::size_type pos = s.find_last_of(FileSys.PathSeparator);
|
||||
if (pos == std::string::npos) {
|
||||
LERROR("Error parsing subdirectory name '" << s << "'");
|
||||
continue;
|
||||
}
|
||||
string moduleName = s.substr(pos+1);
|
||||
|
||||
string submodulePath = s;
|
||||
string moduleFile = FileSys.pathByAppendingComponent(submodulePath, moduleName) + _moduleExtension;
|
||||
// string moduleName = s;
|
||||
|
||||
ghoul::Dictionary element;
|
||||
std::string nodeName;
|
||||
std::string parentName;
|
||||
|
||||
moduleDictionary.getValue(key, element);
|
||||
element.setValue(KeyPathModule, modulePath);
|
||||
|
||||
element.getValue(SceneGraphNode::KeyName, nodeName);
|
||||
element.getValue(SceneGraphNode::KeyParentName, parentName);
|
||||
|
||||
FileSys.setCurrentDirectory(modulePath);
|
||||
SceneGraphNode* node = SceneGraphNode::createFromDictionary(element);
|
||||
if (node == nullptr) {
|
||||
LERROR("Error loading SceneGraphNode '" << nodeName << "' in module '" << moduleName << "'");
|
||||
continue;
|
||||
//clear();
|
||||
//return false;
|
||||
if (!FileSys.fileExists(moduleFile)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have a module file, so it is a direct include
|
||||
try {
|
||||
ghoul::Dictionary moduleDictionary;
|
||||
ghoul::lua::loadDictionaryFromFile(moduleFile, moduleDictionary, state);
|
||||
moduleDictionaries.push_back({
|
||||
moduleDictionary,
|
||||
moduleFile,
|
||||
submodulePath,
|
||||
moduleName
|
||||
});
|
||||
}
|
||||
catch (const ghoul::lua::LuaRuntimeException& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies[nodeName].push_back(parentName);
|
||||
parents[nodeName] = parentName;
|
||||
// Also include loaded dependencies
|
||||
|
||||
if (element.hasKey(SceneGraphNode::KeyDependencies)) {
|
||||
if (element.hasValue<ghoul::Dictionary>(SceneGraphNode::KeyDependencies)) {
|
||||
ghoul::Dictionary nodeDependencies;
|
||||
element.getValue(SceneGraphNode::KeyDependencies, nodeDependencies);
|
||||
|
||||
std::vector<std::string> keys = nodeDependencies.keys();
|
||||
for (const std::string& key : keys) {
|
||||
std::string value = nodeDependencies.value<std::string>(key);
|
||||
dependencies[nodeName].push_back(value);
|
||||
auto addModule = [this, &dependencies, &parents](const ModuleInformation& moduleInformation) {
|
||||
const ghoul::Dictionary& moduleDictionary = moduleInformation.dictionary;
|
||||
const std::string& moduleFile = moduleInformation.moduleFile;
|
||||
const std::string& modulePath = moduleInformation.modulePath;
|
||||
const std::string& moduleName = moduleInformation.moduleName;
|
||||
|
||||
std::vector<std::string> keys = moduleDictionary.keys();
|
||||
for (const std::string& key : keys) {
|
||||
if (!moduleDictionary.hasValue<ghoul::Dictionary>(key)) {
|
||||
LERROR("SceneGraphNode '" << key << "' is not a table in module '"
|
||||
<< moduleFile << "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
ghoul::Dictionary element;
|
||||
std::string nodeName;
|
||||
std::string parentName;
|
||||
|
||||
moduleDictionary.getValue(key, element);
|
||||
element.setValue(KeyPathModule, modulePath);
|
||||
|
||||
element.getValue(SceneGraphNode::KeyName, nodeName);
|
||||
element.getValue(SceneGraphNode::KeyParentName, parentName);
|
||||
|
||||
FileSys.setCurrentDirectory(modulePath);
|
||||
SceneGraphNode* node = SceneGraphNode::createFromDictionary(element);
|
||||
if (node == nullptr) {
|
||||
LERROR("Error loading SceneGraphNode '" << nodeName << "' in module '" << moduleName << "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
dependencies[nodeName].push_back(parentName);
|
||||
parents[nodeName] = parentName;
|
||||
// Also include loaded dependencies
|
||||
|
||||
if (element.hasKey(SceneGraphNode::KeyDependencies)) {
|
||||
if (element.hasValue<ghoul::Dictionary>(SceneGraphNode::KeyDependencies)) {
|
||||
ghoul::Dictionary nodeDependencies;
|
||||
element.getValue(SceneGraphNode::KeyDependencies, nodeDependencies);
|
||||
|
||||
std::vector<std::string> keys = nodeDependencies.keys();
|
||||
for (const std::string& key : keys) {
|
||||
std::string value = nodeDependencies.value<std::string>(key);
|
||||
dependencies[nodeName].push_back(value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
LERROR("Dependencies did not have the corrent type");
|
||||
}
|
||||
}
|
||||
else {
|
||||
LERROR("Dependencies did not have the corrent type");
|
||||
}
|
||||
|
||||
|
||||
SceneGraphNodeInternal* internalNode = new SceneGraphNodeInternal;
|
||||
internalNode->node = node;
|
||||
_nodes.push_back(internalNode);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SceneGraphNodeInternal* internalNode = new SceneGraphNodeInternal;
|
||||
internalNode->node = node;
|
||||
_nodes.push_back(internalNode);
|
||||
for (const ModuleInformation& i : moduleDictionaries) {
|
||||
addModule(i);
|
||||
}
|
||||
}
|
||||
ghoul::lua::destroyLuaState(state);
|
||||
@@ -260,6 +336,7 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
|
||||
SceneGraphNode* parentNode = sceneGraphNode(parent);
|
||||
if (parentNode == nullptr) {
|
||||
LERROR("Could not find parent '" << parent << "' for '" << node->node->name() << "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
node->node->setParent(parentNode);
|
||||
|
||||
@@ -156,8 +156,8 @@ bool SceneGraphNode::deinitialize() {
|
||||
_ephemeris = nullptr;
|
||||
|
||||
// for (SceneGraphNode* child : _children) {
|
||||
// child->deinitialize();
|
||||
// delete child;
|
||||
// child->deinitialize();
|
||||
// delete child;
|
||||
//}
|
||||
_children.clear();
|
||||
|
||||
@@ -289,14 +289,14 @@ void SceneGraphNode::addChild(SceneGraphNode* child) {
|
||||
|
||||
//not used anymore @AA
|
||||
//bool SceneGraphNode::abandonChild(SceneGraphNode* child) {
|
||||
// std::vector < SceneGraphNode* >::iterator it = std::find(_children.begin(), _children.end(), child);
|
||||
// std::vector < SceneGraphNode* >::iterator it = std::find(_children.begin(), _children.end(), child);
|
||||
//
|
||||
// if (it != _children.end()){
|
||||
// _children.erase(it);
|
||||
// return true;
|
||||
// }
|
||||
// if (it != _children.end()){
|
||||
// _children.erase(it);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// return false;
|
||||
//}
|
||||
|
||||
const psc& SceneGraphNode::position() const
|
||||
|
||||
+279
-281
@@ -52,7 +52,7 @@ namespace {
|
||||
}
|
||||
|
||||
bool ScriptEngine::LuaLibrary::operator<(const LuaLibrary& rhs) const {
|
||||
return name < rhs.name;
|
||||
return name < rhs.name;
|
||||
}
|
||||
|
||||
void ScriptEngine::initialize() {
|
||||
@@ -61,7 +61,7 @@ void ScriptEngine::initialize() {
|
||||
LDEBUG("Creating new Lua state");
|
||||
_state = ghoul::lua::createNewLuaState();
|
||||
LDEBUG("Initializing Lua state");
|
||||
initializeLuaState(_state);
|
||||
initializeLuaState(_state);
|
||||
LDEBUG("Remapping Print functions");
|
||||
remapPrintFunction();
|
||||
}
|
||||
@@ -84,46 +84,46 @@ void ScriptEngine::initializeLuaState(lua_State* state) {
|
||||
}
|
||||
|
||||
void ScriptEngine::addLibrary(LuaLibrary library) {
|
||||
auto sortFunc = [](const LuaLibrary::Function& lhs, const LuaLibrary::Function& rhs)
|
||||
{
|
||||
return lhs.name < rhs.name;
|
||||
};
|
||||
auto sortFunc = [](const LuaLibrary::Function& lhs, const LuaLibrary::Function& rhs)
|
||||
{
|
||||
return lhs.name < rhs.name;
|
||||
};
|
||||
|
||||
// do we have a library with the same name as the incoming one
|
||||
auto it = std::find_if(_registeredLibraries.begin(), _registeredLibraries.end(),
|
||||
[&library](const LuaLibrary& lib) { return lib.name == library.name; });
|
||||
// do we have a library with the same name as the incoming one
|
||||
auto it = std::find_if(_registeredLibraries.begin(), _registeredLibraries.end(),
|
||||
[&library](const LuaLibrary& lib) { return lib.name == library.name; });
|
||||
|
||||
if (it == _registeredLibraries.end()) {
|
||||
// If not, we can add it after we sorted it
|
||||
std::sort(library.functions.begin(), library.functions.end(), sortFunc);
|
||||
_registeredLibraries.insert(std::move(library));
|
||||
}
|
||||
else {
|
||||
// otherwise, we merge the libraries
|
||||
if (it == _registeredLibraries.end()) {
|
||||
// If not, we can add it after we sorted it
|
||||
std::sort(library.functions.begin(), library.functions.end(), sortFunc);
|
||||
_registeredLibraries.insert(std::move(library));
|
||||
}
|
||||
else {
|
||||
// otherwise, we merge the libraries
|
||||
|
||||
LuaLibrary merged = *it;
|
||||
for (const LuaLibrary::Function& fun : library.functions) {
|
||||
auto it = std::find_if(merged.functions.begin(), merged.functions.end(),
|
||||
[&fun](const LuaLibrary::Function& function) {
|
||||
return fun.name == function.name;
|
||||
});
|
||||
if (it != merged.functions.end()) {
|
||||
// the function with the desired name is already present, but we don't
|
||||
// want to overwrite it
|
||||
LERROR("Lua function '" << fun.name << "' in library '" << library.name <<
|
||||
"' has been defined twice");
|
||||
return;
|
||||
}
|
||||
else
|
||||
merged.functions.push_back(fun);
|
||||
}
|
||||
LuaLibrary merged = *it;
|
||||
for (const LuaLibrary::Function& fun : library.functions) {
|
||||
auto it = std::find_if(merged.functions.begin(), merged.functions.end(),
|
||||
[&fun](const LuaLibrary::Function& function) {
|
||||
return fun.name == function.name;
|
||||
});
|
||||
if (it != merged.functions.end()) {
|
||||
// the function with the desired name is already present, but we don't
|
||||
// want to overwrite it
|
||||
LERROR("Lua function '" << fun.name << "' in library '" << library.name <<
|
||||
"' has been defined twice");
|
||||
return;
|
||||
}
|
||||
else
|
||||
merged.functions.push_back(fun);
|
||||
}
|
||||
|
||||
_registeredLibraries.erase(it);
|
||||
_registeredLibraries.erase(it);
|
||||
|
||||
// Sort the merged library before inserting it
|
||||
std::sort(merged.functions.begin(), merged.functions.end(), sortFunc);
|
||||
_registeredLibraries.insert(std::move(merged));
|
||||
}
|
||||
// Sort the merged library before inserting it
|
||||
std::sort(merged.functions.begin(), merged.functions.end(), sortFunc);
|
||||
_registeredLibraries.insert(std::move(merged));
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptEngine::hasLibrary(const std::string& name) {
|
||||
@@ -136,33 +136,31 @@ bool ScriptEngine::hasLibrary(const std::string& name) {
|
||||
}
|
||||
|
||||
bool ScriptEngine::runScript(const std::string& script) {
|
||||
if (script.empty()){
|
||||
LWARNING("Script was empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
int status = luaL_loadstring(_state, script.c_str());
|
||||
if (status != LUA_OK) {
|
||||
LERROR("Error loading script: '" << lua_tostring(_state, -1) << "'");
|
||||
if (script.empty()){
|
||||
LWARNING("Script was empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
//LDEBUG("Executing script");
|
||||
//LINFO(script);
|
||||
if (lua_pcall(_state, 0, LUA_MULTRET, 0)) {
|
||||
LERROR("Error executing script: " << lua_tostring(_state, -1));
|
||||
try {
|
||||
ghoul::lua::runScript(_state, script);
|
||||
}
|
||||
catch (const ghoul::lua::LuaLoadingException& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
return false;
|
||||
}
|
||||
catch (const ghoul::lua::LuaExecutionException& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
//if we're currently hosting the parallel session, find out if script should be synchronized.
|
||||
if (OsEng.parallelConnection().isHost()){
|
||||
|
||||
std::string lib, func;
|
||||
if (parseLibraryAndFunctionNames(lib, func, script) && shouldScriptBeSent(lib, func)){
|
||||
// if we're currently hosting the parallel session, find out if script should be synchronized.
|
||||
if (OsEng.parallelConnection().isHost()) {
|
||||
std::string lib, func;
|
||||
if (parseLibraryAndFunctionNames(lib, func, script) && shouldScriptBeSent(lib, func)){
|
||||
// OsEng.parallelConnection()->sendScript(script);
|
||||
// cacheScript(lib, func, script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -177,18 +175,18 @@ bool ScriptEngine::runScriptFile(const std::string& filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int status = luaL_loadfile(_state, filename.c_str());
|
||||
if (status != LUA_OK) {
|
||||
LERROR("Error loading script: '" << lua_tostring(_state, -1) << "'");
|
||||
try {
|
||||
ghoul::lua::runScriptFile(_state, filename);
|
||||
}
|
||||
catch (const ghoul::lua::LuaLoadingException& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
return false;
|
||||
}
|
||||
catch (const ghoul::lua::LuaExecutionException& e) {
|
||||
LERRORC(e.component, e.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
LDEBUG("Executing script '" << filename << "'");
|
||||
if (lua_pcall(_state, 0, LUA_MULTRET, 0)) {
|
||||
LERROR("Error executing script: " << lua_tostring(_state, -1));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -237,55 +235,55 @@ std::vector<std::string> ScriptEngine::cachedScripts(){
|
||||
for(innerIt = outerIt->second.cbegin();
|
||||
innerIt != outerIt->second.cend();
|
||||
++innerIt){
|
||||
retVal.push_back(innerIt->second);
|
||||
retVal.push_back(innerIt->second);
|
||||
}
|
||||
}
|
||||
|
||||
_cachedScriptsMutex.unlock();
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool ScriptEngine::parseLibraryAndFunctionNames(std::string &library, std::string &function, const std::string &script){
|
||||
|
||||
//"deconstruct the script to find library and function name
|
||||
//assuming a script looks like: "openspace.library.function()"
|
||||
//or openspace.funcion()
|
||||
std::string sub;
|
||||
library.clear();
|
||||
function.clear();
|
||||
//find first "."
|
||||
std::size_t pos = script.find(".");
|
||||
|
||||
if (pos != std::string::npos){
|
||||
//strip "openspace."
|
||||
sub = script.substr(pos + 1, script.size());
|
||||
pos = sub.find(".");
|
||||
//one more "." was found, if the "." comes before first "(" we have a library name
|
||||
if (pos != std::string::npos && pos < sub.find("(")){
|
||||
//assing library name
|
||||
library = sub.substr(0, pos);
|
||||
//strip "library."
|
||||
sub = sub.substr(pos + 1, sub.size());
|
||||
|
||||
//"deconstruct the script to find library and function name
|
||||
//assuming a script looks like: "openspace.library.function()"
|
||||
//or openspace.funcion()
|
||||
std::string sub;
|
||||
library.clear();
|
||||
function.clear();
|
||||
//find first "."
|
||||
std::size_t pos = script.find(".");
|
||||
|
||||
if (pos != std::string::npos){
|
||||
//strip "openspace."
|
||||
sub = script.substr(pos + 1, script.size());
|
||||
pos = sub.find(".");
|
||||
//one more "." was found, if the "." comes before first "(" we have a library name
|
||||
if (pos != std::string::npos && pos < sub.find("(")){
|
||||
//assing library name
|
||||
library = sub.substr(0, pos);
|
||||
//strip "library."
|
||||
sub = sub.substr(pos + 1, sub.size());
|
||||
|
||||
pos = sub.find("(");
|
||||
if (pos != std::string::npos && pos > 0){
|
||||
//strip the () and we're left with function name
|
||||
function = sub.substr(0, pos);
|
||||
}
|
||||
}
|
||||
else{
|
||||
//no more "." was found, we have the case of "openspace.funcion()"
|
||||
pos = sub.find("(");
|
||||
if (pos != std::string::npos && pos > 0){
|
||||
//strip the () and we're left with function name
|
||||
function = sub.substr(0, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
pos = sub.find("(");
|
||||
if (pos != std::string::npos && pos > 0){
|
||||
//strip the () and we're left with function name
|
||||
function = sub.substr(0, pos);
|
||||
}
|
||||
}
|
||||
else{
|
||||
//no more "." was found, we have the case of "openspace.funcion()"
|
||||
pos = sub.find("(");
|
||||
if (pos != std::string::npos && pos > 0){
|
||||
//strip the () and we're left with function name
|
||||
function = sub.substr(0, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if we found a function all is good
|
||||
return !function.empty();
|
||||
//if we found a function all is good
|
||||
return !function.empty();
|
||||
}
|
||||
|
||||
bool ScriptEngine::isLibraryNameAllowed(lua_State* state, const std::string& name) {
|
||||
@@ -338,26 +336,26 @@ bool ScriptEngine::isLibraryNameAllowed(lua_State* state, const std::string& nam
|
||||
}
|
||||
|
||||
void ScriptEngine::addLibraryFunctions(lua_State* state, const LuaLibrary& library, bool replace) {
|
||||
assert(state);
|
||||
assert(state);
|
||||
for (LuaLibrary::Function p : library.functions) {
|
||||
if (!replace) {
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_getfield(state, -1, p.name.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
const bool isNil = lua_isnil(state, -1);
|
||||
if (!isNil) {
|
||||
LERROR("Function name '" << p.name << "' was already assigned");
|
||||
return;
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_pushstring(state, p.name.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_pushcfunction(state, p.function);
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_settable(state, _setTableOffset);
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,105 +364,105 @@ void ScriptEngine::addBaseLibrary() {
|
||||
"",
|
||||
{
|
||||
{
|
||||
"printDebug",
|
||||
&luascriptfunctions::printDebug,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
"LogLevel of 'Debug'"
|
||||
},
|
||||
{
|
||||
"printInfo",
|
||||
&luascriptfunctions::printInfo,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
" LogLevel of 'Info'"
|
||||
},
|
||||
{
|
||||
"printWarning",
|
||||
&luascriptfunctions::printWarning,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with "
|
||||
"a LogLevel of 'Warning'"
|
||||
},
|
||||
{
|
||||
"printError",
|
||||
&luascriptfunctions::printError,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
"LogLevel of 'Error'"
|
||||
},
|
||||
{
|
||||
"printFatal",
|
||||
&luascriptfunctions::printFatal,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
"LogLevel of 'Fatal'"
|
||||
},
|
||||
{
|
||||
"absPath",
|
||||
&luascriptfunctions::absolutePath,
|
||||
"string",
|
||||
"Returns the absolute path to the passed path, resolving"
|
||||
" path tokens as well as resolving relative paths"
|
||||
},
|
||||
{
|
||||
"setPathToken",
|
||||
&luascriptfunctions::setPathToken,
|
||||
"string, string",
|
||||
"Registers a new path token provided by the"
|
||||
" first argument to the path provided in the second argument"
|
||||
}
|
||||
"printDebug",
|
||||
&luascriptfunctions::printDebug,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
"LogLevel of 'Debug'"
|
||||
},
|
||||
{
|
||||
"printInfo",
|
||||
&luascriptfunctions::printInfo,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
" LogLevel of 'Info'"
|
||||
},
|
||||
{
|
||||
"printWarning",
|
||||
&luascriptfunctions::printWarning,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with "
|
||||
"a LogLevel of 'Warning'"
|
||||
},
|
||||
{
|
||||
"printError",
|
||||
&luascriptfunctions::printError,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
"LogLevel of 'Error'"
|
||||
},
|
||||
{
|
||||
"printFatal",
|
||||
&luascriptfunctions::printFatal,
|
||||
"*",
|
||||
"Logs the passed value to the installed LogManager with a "
|
||||
"LogLevel of 'Fatal'"
|
||||
},
|
||||
{
|
||||
"absPath",
|
||||
&luascriptfunctions::absolutePath,
|
||||
"string",
|
||||
"Returns the absolute path to the passed path, resolving"
|
||||
" path tokens as well as resolving relative paths"
|
||||
},
|
||||
{
|
||||
"setPathToken",
|
||||
&luascriptfunctions::setPathToken,
|
||||
"string, string",
|
||||
"Registers a new path token provided by the"
|
||||
" first argument to the path provided in the second argument"
|
||||
}
|
||||
}
|
||||
};
|
||||
addLibrary(lib);
|
||||
}
|
||||
|
||||
void ScriptEngine::remapPrintFunction() {
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_getglobal(_state, _luaGlobalNamespace.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_pushstring(_state, _printFunctionName.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_pushcfunction(_state, _printFunctionReplacement);
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_settable(_state, _setTableOffset);
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
}
|
||||
|
||||
bool ScriptEngine::registerLuaLibrary(lua_State* state, const LuaLibrary& library) {
|
||||
assert(state);
|
||||
assert(state);
|
||||
if (library.functions.empty()) {
|
||||
LERROR("Lua library '" << library.name << "' does not have any functions");
|
||||
return false;
|
||||
}
|
||||
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_getglobal(state, _openspaceLibraryName.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
if (library.name.empty()) {
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
addLibraryFunctions(state, library, true);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_pop(state, 1);
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_pop(state, 1);
|
||||
//ghoul::lua::logStack(_state);
|
||||
}
|
||||
else {
|
||||
const bool allowed = isLibraryNameAllowed(state, library.name);
|
||||
if (!allowed)
|
||||
return false;
|
||||
|
||||
//ghoul::lua::logStack(_state);
|
||||
|
||||
//ghoul::lua::logStack(_state);
|
||||
|
||||
lua_pushstring(state, library.name.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_newtable(state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
addLibraryFunctions(state, library, false);
|
||||
lua_settable(state, _setTableOffset);
|
||||
//ghoul::lua::logStack(_state);
|
||||
|
||||
//_registeredLibraries.insert(library);
|
||||
//_registeredLibraries.push_back(library);
|
||||
//_registeredLibraries.push_back(library);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -486,138 +484,138 @@ std::vector<std::string> ScriptEngine::allLuaFunctions() const {
|
||||
}
|
||||
|
||||
bool ScriptEngine::writeDocumentation(const std::string& filename, const std::string& type) const {
|
||||
if (type == "text") {
|
||||
// The additional space between the longest function name and the descriptions
|
||||
LDEBUG("Writing Lua documentation of type '" << type <<
|
||||
"' to file '" << filename << "'");
|
||||
std::ofstream file(filename);
|
||||
if (!file.good()) {
|
||||
LERROR("Could not open file '" << filename << "' for writing documentation");
|
||||
return false;
|
||||
}
|
||||
if (type == "text") {
|
||||
// The additional space between the longest function name and the descriptions
|
||||
LDEBUG("Writing Lua documentation of type '" << type <<
|
||||
"' to file '" << filename << "'");
|
||||
std::ofstream file(filename);
|
||||
if (!file.good()) {
|
||||
LERROR("Could not open file '" << filename << "' for writing documentation");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto concatenate = [](std::string library, std::string function) {
|
||||
std::string total = "openspace.";
|
||||
if (!library.empty())
|
||||
total += std::move(library) + ".";
|
||||
total += std::move(function);
|
||||
return total;
|
||||
};
|
||||
auto concatenate = [](std::string library, std::string function) {
|
||||
std::string total = "openspace.";
|
||||
if (!library.empty())
|
||||
total += std::move(library) + ".";
|
||||
total += std::move(function);
|
||||
return total;
|
||||
};
|
||||
|
||||
// Settings
|
||||
const unsigned int lineWidth = 80;
|
||||
static const std::string whitespace = " \t";
|
||||
static const std::string padding = " ";
|
||||
const bool commandListArguments = true;
|
||||
// Settings
|
||||
const unsigned int lineWidth = 80;
|
||||
static const std::string whitespace = " \t";
|
||||
static const std::string padding = " ";
|
||||
const bool commandListArguments = true;
|
||||
|
||||
file << "Available commands:\n";
|
||||
// Now write out the functions
|
||||
for (const LuaLibrary& library : _registeredLibraries) {
|
||||
for (const LuaLibrary::Function& function : library.functions) {
|
||||
file << "Available commands:\n";
|
||||
// Now write out the functions
|
||||
for (const LuaLibrary& library : _registeredLibraries) {
|
||||
for (const LuaLibrary::Function& function : library.functions) {
|
||||
|
||||
std::string functionName = concatenate(library.name, function.name);
|
||||
file << padding << functionName;
|
||||
if (commandListArguments)
|
||||
file << "(" << function.argumentText << ")";
|
||||
file << std::endl;
|
||||
}
|
||||
}
|
||||
file << std::endl;
|
||||
std::string functionName = concatenate(library.name, function.name);
|
||||
file << padding << functionName;
|
||||
if (commandListArguments)
|
||||
file << "(" << function.argumentText << ")";
|
||||
file << std::endl;
|
||||
}
|
||||
}
|
||||
file << std::endl;
|
||||
|
||||
// Now write out the functions definitions
|
||||
for (const LuaLibrary& library : _registeredLibraries) {
|
||||
for (const LuaLibrary::Function& function : library.functions) {
|
||||
// Now write out the functions definitions
|
||||
for (const LuaLibrary& library : _registeredLibraries) {
|
||||
for (const LuaLibrary::Function& function : library.functions) {
|
||||
|
||||
std::string functionName = concatenate(library.name, function.name);
|
||||
file << functionName << "(" << function.argumentText << "):" << std::endl;
|
||||
std::string functionName = concatenate(library.name, function.name);
|
||||
file << functionName << "(" << function.argumentText << "):" << std::endl;
|
||||
|
||||
std::string remainingHelptext = function.helpText;
|
||||
std::string remainingHelptext = function.helpText;
|
||||
|
||||
// @CLEANUP This needs to become a bit prettier ---abock
|
||||
while (!remainingHelptext.empty()) {
|
||||
const auto length = remainingHelptext.length();
|
||||
const auto paddingLength = padding.length();
|
||||
if ((length + paddingLength) > lineWidth) {
|
||||
auto lastSpace = remainingHelptext.find_last_of(whitespace, lineWidth - 1 - paddingLength);
|
||||
if (lastSpace == remainingHelptext.npos)
|
||||
lastSpace = lineWidth;
|
||||
file << padding << remainingHelptext.substr(0, lastSpace) << std::endl;
|
||||
auto firstNotSpace = remainingHelptext.find_first_not_of(whitespace, lastSpace);
|
||||
if (firstNotSpace == remainingHelptext.npos)
|
||||
firstNotSpace = lastSpace;
|
||||
remainingHelptext = remainingHelptext.substr(firstNotSpace);
|
||||
}
|
||||
else {
|
||||
file << padding << remainingHelptext << std::endl;
|
||||
remainingHelptext = "";
|
||||
}
|
||||
}
|
||||
file << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
LERROR("Undefined type '" << type << "' for Lua documentation");
|
||||
return false;
|
||||
}
|
||||
// @CLEANUP This needs to become a bit prettier ---abock
|
||||
while (!remainingHelptext.empty()) {
|
||||
const auto length = remainingHelptext.length();
|
||||
const auto paddingLength = padding.length();
|
||||
if ((length + paddingLength) > lineWidth) {
|
||||
auto lastSpace = remainingHelptext.find_last_of(whitespace, lineWidth - 1 - paddingLength);
|
||||
if (lastSpace == remainingHelptext.npos)
|
||||
lastSpace = lineWidth;
|
||||
file << padding << remainingHelptext.substr(0, lastSpace) << std::endl;
|
||||
auto firstNotSpace = remainingHelptext.find_first_not_of(whitespace, lastSpace);
|
||||
if (firstNotSpace == remainingHelptext.npos)
|
||||
firstNotSpace = lastSpace;
|
||||
remainingHelptext = remainingHelptext.substr(firstNotSpace);
|
||||
}
|
||||
else {
|
||||
file << padding << remainingHelptext << std::endl;
|
||||
remainingHelptext = "";
|
||||
}
|
||||
}
|
||||
file << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
LERROR("Undefined type '" << type << "' for Lua documentation");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::serialize(SyncBuffer* syncBuffer){
|
||||
syncBuffer->encode(_currentSyncedScript);
|
||||
_currentSyncedScript.clear();
|
||||
syncBuffer->encode(_currentSyncedScript);
|
||||
_currentSyncedScript.clear();
|
||||
}
|
||||
|
||||
void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
|
||||
syncBuffer->decode(_currentSyncedScript);
|
||||
syncBuffer->decode(_currentSyncedScript);
|
||||
|
||||
if (!_currentSyncedScript.empty()){
|
||||
_mutex.lock();
|
||||
_receivedScripts.push_back(_currentSyncedScript);
|
||||
_mutex.unlock();
|
||||
}
|
||||
if (!_currentSyncedScript.empty()){
|
||||
_mutex.lock();
|
||||
_receivedScripts.push_back(_currentSyncedScript);
|
||||
_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::postSynchronizationPreDraw(){
|
||||
|
||||
std::vector<std::string> scripts;
|
||||
|
||||
std::vector<std::string> scripts;
|
||||
|
||||
_mutex.lock();
|
||||
scripts.assign(_receivedScripts.begin(), _receivedScripts.end());
|
||||
_receivedScripts.clear();
|
||||
_mutex.unlock();
|
||||
|
||||
while (!scripts.empty()){
|
||||
runScript(scripts.back());
|
||||
scripts.pop_back();
|
||||
}
|
||||
|
||||
_mutex.lock();
|
||||
scripts.assign(_receivedScripts.begin(), _receivedScripts.end());
|
||||
_receivedScripts.clear();
|
||||
_mutex.unlock();
|
||||
|
||||
while (!scripts.empty()){
|
||||
runScript(scripts.back());
|
||||
scripts.pop_back();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ScriptEngine::preSynchronization(){
|
||||
|
||||
_mutex.lock();
|
||||
|
||||
if (!_queuedScripts.empty()){
|
||||
_currentSyncedScript = _queuedScripts.back();
|
||||
_queuedScripts.pop_back();
|
||||
|
||||
//Not really a received script but the master also needs to run the script...
|
||||
_receivedScripts.push_back(_currentSyncedScript);
|
||||
}
|
||||
|
||||
_mutex.unlock();
|
||||
|
||||
_mutex.lock();
|
||||
|
||||
if (!_queuedScripts.empty()){
|
||||
_currentSyncedScript = _queuedScripts.back();
|
||||
_queuedScripts.pop_back();
|
||||
|
||||
//Not really a received script but the master also needs to run the script...
|
||||
_receivedScripts.push_back(_currentSyncedScript);
|
||||
}
|
||||
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void ScriptEngine::queueScript(const std::string &script){
|
||||
if (script.empty())
|
||||
return;
|
||||
if (script.empty())
|
||||
return;
|
||||
|
||||
_mutex.lock();
|
||||
_mutex.lock();
|
||||
|
||||
_queuedScripts.insert(_queuedScripts.begin(), script);
|
||||
_queuedScripts.insert(_queuedScripts.begin(), script);
|
||||
|
||||
_mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
} // namespace scripting
|
||||
|
||||
+57
-57
@@ -32,26 +32,26 @@
|
||||
namespace openspace {
|
||||
|
||||
Camera::Camera()
|
||||
: _maxFov(0.f)
|
||||
, _sinMaxFov(0.f)
|
||||
, _viewProjectionMatrix()
|
||||
, _modelMatrix()
|
||||
, _viewMatrix()
|
||||
, _projectionMatrix()
|
||||
: _maxFov(0.f)
|
||||
, _sinMaxFov(0.f)
|
||||
, _viewProjectionMatrix()
|
||||
, _modelMatrix()
|
||||
, _viewMatrix()
|
||||
, _projectionMatrix()
|
||||
, _dirtyViewProjectionMatrix(true)
|
||||
, _viewDirection(0,0,-1)
|
||||
, _viewDirection(0,0,-1)
|
||||
, _cameraDirection(0.f, 0.f, 0.f)
|
||||
, _focusPosition()
|
||||
//, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
|
||||
, _localViewRotationMatrix(1.f)
|
||||
//, _viewRotation(glm::quat(glm::vec3(0.f, 0.f, 0.f)))
|
||||
, _localViewRotationMatrix(1.f)
|
||||
, _localScaling(1.f, 0.f)
|
||||
, _localPosition()
|
||||
, _sharedScaling(1.f, 0.f)
|
||||
, _sharedPosition()
|
||||
, _sharedViewRotationMatrix(1.f)
|
||||
, _syncedScaling(1.f, 0.f)
|
||||
, _sharedPosition()
|
||||
, _sharedViewRotationMatrix(1.f)
|
||||
, _syncedScaling(1.f, 0.f)
|
||||
, _syncedPosition()
|
||||
, _syncedViewRotationMatrix(1.f)
|
||||
, _syncedViewRotationMatrix(1.f)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -62,45 +62,45 @@ Camera::~Camera()
|
||||
void Camera::setPosition(psc pos)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_localPosition = std::move(pos);
|
||||
_localPosition = std::move(pos);
|
||||
}
|
||||
|
||||
const psc& Camera::position() const
|
||||
{
|
||||
return _syncedPosition;
|
||||
return _syncedPosition;
|
||||
}
|
||||
|
||||
const psc& Camera::unsynchedPosition() const{
|
||||
return _localPosition;
|
||||
return _localPosition;
|
||||
}
|
||||
|
||||
void Camera::setModelMatrix(glm::mat4 modelMatrix){
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_modelMatrix = std::move(modelMatrix);
|
||||
_modelMatrix = std::move(modelMatrix);
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::modelMatrix() const{
|
||||
return _modelMatrix;
|
||||
return _modelMatrix;
|
||||
}
|
||||
|
||||
void Camera::setViewMatrix(glm::mat4 viewMatrix){
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_viewMatrix = std::move(viewMatrix);
|
||||
_viewMatrix = std::move(viewMatrix);
|
||||
_dirtyViewProjectionMatrix = true;
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewMatrix() const{
|
||||
return _viewMatrix;
|
||||
return _viewMatrix;
|
||||
}
|
||||
|
||||
void Camera::setProjectionMatrix(glm::mat4 projectionMatrix){
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_projectionMatrix = std::move(projectionMatrix);
|
||||
_projectionMatrix = std::move(projectionMatrix);
|
||||
_dirtyViewProjectionMatrix = true;
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::projectionMatrix() const{
|
||||
return _projectionMatrix;
|
||||
return _projectionMatrix;
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewProjectionMatrix() const {
|
||||
@@ -125,13 +125,13 @@ glm::vec3 Camera::cameraDirection() const
|
||||
|
||||
void Camera::setViewRotationMatrix(glm::mat4 m) {
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_localViewRotationMatrix = m;
|
||||
_localViewRotationMatrix = m;
|
||||
}
|
||||
|
||||
const glm::mat4& Camera::viewRotationMatrix() const
|
||||
{
|
||||
//return _localViewRotationMatrix;
|
||||
return _syncedViewRotationMatrix;
|
||||
//return _localViewRotationMatrix;
|
||||
return _syncedViewRotationMatrix;
|
||||
}
|
||||
|
||||
void Camera::compileViewRotationMatrix()
|
||||
@@ -142,16 +142,16 @@ void Camera::compileViewRotationMatrix()
|
||||
|
||||
// the camera matrix needs to be rotated inverse to the world
|
||||
// _viewDirection = glm::rotate(glm::inverse(_viewRotation), _cameraDirection);
|
||||
//_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz;
|
||||
_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz();
|
||||
//_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz;
|
||||
_viewDirection = (glm::inverse(_localViewRotationMatrix) * glm::vec4(_cameraDirection, 0.f)).xyz();
|
||||
_viewDirection = glm::normalize(_viewDirection);
|
||||
}
|
||||
|
||||
void Camera::rotate(const glm::quat& rotation)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
glm::mat4 tmp = glm::mat4_cast(rotation);
|
||||
_localViewRotationMatrix = _localViewRotationMatrix * tmp;
|
||||
glm::mat4 tmp = glm::mat4_cast(rotation);
|
||||
_localViewRotationMatrix = _localViewRotationMatrix * tmp;
|
||||
//_viewRotation = rotation * _viewRotation;
|
||||
//_viewRotation = glm::normalize(_viewRotation);
|
||||
}
|
||||
@@ -160,13 +160,13 @@ void Camera::setRotation(glm::quat rotation)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
//_viewRotation = glm::normalize(std::move(rotation));
|
||||
_localViewRotationMatrix = glm::mat4_cast(rotation);
|
||||
_localViewRotationMatrix = glm::mat4_cast(rotation);
|
||||
}
|
||||
|
||||
void Camera::setRotation(glm::mat4 rotation)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_localViewRotationMatrix = std::move(rotation);
|
||||
_localViewRotationMatrix = std::move(rotation);
|
||||
}
|
||||
|
||||
//const glm::quat& Camera::rotation() const
|
||||
@@ -176,11 +176,11 @@ void Camera::setRotation(glm::mat4 rotation)
|
||||
|
||||
void Camera::setFocusPosition(psc pos){
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_focusPosition = pos;
|
||||
_focusPosition = pos;
|
||||
}
|
||||
|
||||
const psc& Camera::focusPosition() const{
|
||||
return _focusPosition;
|
||||
return _focusPosition;
|
||||
}
|
||||
|
||||
|
||||
@@ -209,13 +209,13 @@ void Camera::setMaxFov(float fov)
|
||||
void Camera::setScaling(glm::vec2 scaling)
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(_mutex);
|
||||
_localScaling = std::move(scaling);
|
||||
_localScaling = std::move(scaling);
|
||||
}
|
||||
|
||||
const glm::vec2& Camera::scaling() const
|
||||
{
|
||||
//return _localScaling;
|
||||
return _syncedScaling;
|
||||
//return _localScaling;
|
||||
return _syncedScaling;
|
||||
}
|
||||
|
||||
void Camera::setLookUpVector(glm::vec3 lookUp)
|
||||
@@ -230,43 +230,43 @@ const glm::vec3& Camera::lookUpVector() const
|
||||
}
|
||||
|
||||
void Camera::serialize(SyncBuffer* syncBuffer){
|
||||
_mutex.lock();
|
||||
_mutex.lock();
|
||||
|
||||
syncBuffer->encode(_sharedViewRotationMatrix);
|
||||
syncBuffer->encode(_sharedPosition);
|
||||
syncBuffer->encode(_sharedScaling);
|
||||
syncBuffer->encode(_sharedViewRotationMatrix);
|
||||
syncBuffer->encode(_sharedPosition);
|
||||
syncBuffer->encode(_sharedScaling);
|
||||
|
||||
_mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void Camera::deserialize(SyncBuffer* syncBuffer){
|
||||
_mutex.lock();
|
||||
void Camera::deserialize(SyncBuffer* syncBuffer){
|
||||
_mutex.lock();
|
||||
|
||||
syncBuffer->decode(_sharedViewRotationMatrix);
|
||||
syncBuffer->decode(_sharedPosition);
|
||||
syncBuffer->decode(_sharedScaling);
|
||||
syncBuffer->decode(_sharedViewRotationMatrix);
|
||||
syncBuffer->decode(_sharedPosition);
|
||||
syncBuffer->decode(_sharedScaling);
|
||||
|
||||
_mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void Camera::postSynchronizationPreDraw(){
|
||||
_mutex.lock();
|
||||
_mutex.lock();
|
||||
|
||||
_syncedViewRotationMatrix = _sharedViewRotationMatrix;
|
||||
_syncedPosition = _sharedPosition;
|
||||
_syncedScaling = _sharedScaling;
|
||||
_syncedViewRotationMatrix = _sharedViewRotationMatrix;
|
||||
_syncedPosition = _sharedPosition;
|
||||
_syncedScaling = _sharedScaling;
|
||||
|
||||
_mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void Camera::preSynchronization(){
|
||||
_mutex.lock();
|
||||
_mutex.lock();
|
||||
|
||||
_sharedViewRotationMatrix = _localViewRotationMatrix;
|
||||
_sharedPosition = _localPosition;
|
||||
_sharedScaling = _localScaling;
|
||||
_sharedViewRotationMatrix = _localViewRotationMatrix;
|
||||
_sharedPosition = _localPosition;
|
||||
_sharedScaling = _localScaling;
|
||||
|
||||
_mutex.unlock();
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "Keys";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
KeyAction operator|(KeyAction lhs, KeyAction rhs) {
|
||||
return static_cast<KeyAction>(
|
||||
static_cast<std::underlying_type_t<KeyAction>>(lhs) |
|
||||
static_cast<std::underlying_type_t<KeyAction>>(rhs)
|
||||
);
|
||||
}
|
||||
|
||||
KeyAction operator|=(KeyAction& lhs, KeyAction rhs) {
|
||||
lhs = (lhs | rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
KeyModifier operator|(KeyModifier lhs, KeyModifier rhs) {
|
||||
return static_cast<KeyModifier>(
|
||||
static_cast<std::underlying_type_t<KeyModifier>>(lhs) |
|
||||
static_cast<std::underlying_type_t<KeyModifier>>(rhs)
|
||||
);
|
||||
}
|
||||
|
||||
KeyModifier operator|=(KeyModifier& lhs, KeyModifier rhs) {
|
||||
lhs = (lhs | rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
KeyWithModifier stringToKey(std::string str) {
|
||||
// key only uppercase
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
|
||||
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(str, '+');
|
||||
|
||||
// default is unknown
|
||||
Key k = Key::Unknown;
|
||||
auto it = KeyMapping.find(tokens.back());
|
||||
if (it != KeyMapping.end())
|
||||
k = it->second;
|
||||
|
||||
|
||||
KeyModifier m = KeyModifier::NoModifier;
|
||||
std::for_each(
|
||||
tokens.begin(),
|
||||
tokens.end() - 1,
|
||||
[&m](const std::string& s) {
|
||||
auto it = KeyModifierMapping.find(s);
|
||||
if (it != KeyModifierMapping.end())
|
||||
m |= it->second;
|
||||
else
|
||||
LERROR("Unknown modifier key '" << s << "'");
|
||||
}
|
||||
);
|
||||
|
||||
return { k, m };
|
||||
}
|
||||
|
||||
bool operator<(const KeyWithModifier& lhs, const KeyWithModifier& rhs) {
|
||||
if (lhs.modifier == rhs.modifier)
|
||||
return lhs.key < rhs.key;
|
||||
else
|
||||
return lhs.modifier < rhs.modifier;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -64,7 +64,7 @@ PowerScaledCoordinate::PowerScaledCoordinate(float f1, float f2, float f3, float
|
||||
}
|
||||
|
||||
PowerScaledCoordinate::PowerScaledCoordinate(const PowerScaledCoordinate& rhs) {
|
||||
_vec = rhs._vec;
|
||||
_vec = rhs._vec;
|
||||
|
||||
}
|
||||
|
||||
@@ -89,15 +89,15 @@ PowerScaledCoordinate
|
||||
#endif
|
||||
size_t digits = strlen(buff);
|
||||
|
||||
//digits += 3;
|
||||
//digits += 3;
|
||||
|
||||
// rescale and return
|
||||
double tp = 1.0 / pow(k, digits);
|
||||
return PowerScaledCoordinate(
|
||||
static_cast<float>(d1 * tp),
|
||||
static_cast<float>(d2 * tp),
|
||||
static_cast<float>(d3 * tp),
|
||||
static_cast<float>(digits));
|
||||
static_cast<float>(d1 * tp),
|
||||
static_cast<float>(d2 * tp),
|
||||
static_cast<float>(d3 * tp),
|
||||
static_cast<float>(digits));
|
||||
}
|
||||
|
||||
const glm::vec4& PowerScaledCoordinate::vec4() const
|
||||
@@ -113,14 +113,14 @@ glm::vec3 PowerScaledCoordinate::vec3() const
|
||||
|
||||
glm::dvec4 PowerScaledCoordinate::dvec4() const
|
||||
{
|
||||
//return _vec;
|
||||
return glm::dvec4(_vec);
|
||||
//return _vec;
|
||||
return glm::dvec4(_vec);
|
||||
}
|
||||
|
||||
glm::dvec3 PowerScaledCoordinate::dvec3() const
|
||||
{
|
||||
return glm::dvec3(_vec[0] * pow(k, _vec[3]), _vec[1] * pow(k, _vec[3]),
|
||||
_vec[2] * pow(k, _vec[3]));
|
||||
return glm::dvec3(_vec[0] * pow(k, _vec[3]), _vec[1] * pow(k, _vec[3]),
|
||||
_vec[2] * pow(k, _vec[3]));
|
||||
}
|
||||
|
||||
PowerScaledScalar PowerScaledCoordinate::length() const
|
||||
@@ -176,14 +176,14 @@ PowerScaledCoordinate& PowerScaledCoordinate::operator+=(const PowerScaledCoordi
|
||||
double ds = _vec[3] - rhs._vec[3];
|
||||
if (ds >= 0.0) {
|
||||
double p = pow(k, -ds);
|
||||
*this = PowerScaledCoordinate(static_cast<float>(rhs._vec[0] * p + _vec[0]),
|
||||
static_cast<float>(rhs._vec[1] * p + _vec[1]),
|
||||
static_cast<float>(rhs._vec[2] * p + _vec[2]), _vec[3]);
|
||||
*this = PowerScaledCoordinate(static_cast<float>(rhs._vec[0] * p + _vec[0]),
|
||||
static_cast<float>(rhs._vec[1] * p + _vec[1]),
|
||||
static_cast<float>(rhs._vec[2] * p + _vec[2]), _vec[3]);
|
||||
} else {
|
||||
double p = pow(k, ds);
|
||||
*this = PowerScaledCoordinate(static_cast<float>(rhs._vec[0] + _vec[0] * p),
|
||||
*this = PowerScaledCoordinate(static_cast<float>(rhs._vec[0] + _vec[0] * p),
|
||||
static_cast<float>(rhs._vec[1] + _vec[1] * p),
|
||||
static_cast<float>(rhs._vec[2] + _vec[2] * p), rhs._vec[3]);
|
||||
static_cast<float>(rhs._vec[2] + _vec[2] * p), rhs._vec[3]);
|
||||
}
|
||||
|
||||
return *this;
|
||||
@@ -200,14 +200,14 @@ PowerScaledCoordinate& PowerScaledCoordinate::operator-=(const PowerScaledCoordi
|
||||
double ds = this->_vec[3] - rhs._vec[3];
|
||||
if (ds >= 0.0) {
|
||||
double p = pow(k, -ds);
|
||||
*this = PowerScaledCoordinate(static_cast<float>(-rhs._vec[0] * p + _vec[0]),
|
||||
*this = PowerScaledCoordinate(static_cast<float>(-rhs._vec[0] * p + _vec[0]),
|
||||
static_cast<float>(-rhs._vec[1] * p + _vec[1]),
|
||||
static_cast<float>(-rhs._vec[2] * p + _vec[2]), _vec[3]);
|
||||
static_cast<float>(-rhs._vec[2] * p + _vec[2]), _vec[3]);
|
||||
} else {
|
||||
double p = pow(k, ds);
|
||||
*this = PowerScaledCoordinate(static_cast<float>(-rhs._vec[0] + _vec[0] * p),
|
||||
*this = PowerScaledCoordinate(static_cast<float>(-rhs._vec[0] + _vec[0] * p),
|
||||
static_cast<float>(-rhs._vec[1] + _vec[1] * p),
|
||||
static_cast<float>(-rhs._vec[2] + _vec[2] * p), rhs._vec[3]);
|
||||
static_cast<float>(-rhs._vec[2] + _vec[2] * p), rhs._vec[3]);
|
||||
}
|
||||
|
||||
return *this;
|
||||
@@ -215,9 +215,9 @@ PowerScaledCoordinate& PowerScaledCoordinate::operator-=(const PowerScaledCoordi
|
||||
|
||||
PowerScaledCoordinate PowerScaledCoordinate::operator*(const double& rhs) const
|
||||
{
|
||||
return PowerScaledCoordinate(static_cast<float>(_vec[0] * rhs),
|
||||
static_cast<float>(_vec[1] * rhs),
|
||||
static_cast<float>(_vec[2] * rhs), _vec[3]);
|
||||
return PowerScaledCoordinate(static_cast<float>(_vec[0] * rhs),
|
||||
static_cast<float>(_vec[1] * rhs),
|
||||
static_cast<float>(_vec[2] * rhs), _vec[3]);
|
||||
}
|
||||
|
||||
PowerScaledCoordinate PowerScaledCoordinate::operator*(const float& rhs) const
|
||||
@@ -231,15 +231,15 @@ PowerScaledCoordinate& PowerScaledCoordinate::operator*=(const PowerScaledScalar
|
||||
if (ds >= 0.0) {
|
||||
double p = pow(k, -ds);
|
||||
*this = PowerScaledCoordinate(
|
||||
static_cast<float>(rhs._data[0] * p * _vec[0]),
|
||||
static_cast<float>(rhs._data[0] * p * _vec[1]),
|
||||
static_cast<float>(rhs._data[0] * p * _vec[2]), this->_vec[3] + _vec[3]);
|
||||
static_cast<float>(rhs._data[0] * p * _vec[0]),
|
||||
static_cast<float>(rhs._data[0] * p * _vec[1]),
|
||||
static_cast<float>(rhs._data[0] * p * _vec[2]), this->_vec[3] + _vec[3]);
|
||||
} else {
|
||||
double p = pow(k, ds);
|
||||
*this = PowerScaledCoordinate(
|
||||
static_cast<float>(rhs._data[0] * _vec[0] * p),
|
||||
static_cast<float>(rhs._data[0] * _vec[1] * p),
|
||||
static_cast<float>(rhs._data[0] * _vec[2] * p), rhs._data[1] + rhs._data[1]);
|
||||
static_cast<float>(rhs._data[0] * _vec[0] * p),
|
||||
static_cast<float>(rhs._data[0] * _vec[1] * p),
|
||||
static_cast<float>(rhs._data[0] * _vec[2] * p), rhs._data[1] + rhs._data[1]);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
+113
-113
@@ -42,222 +42,222 @@ PowerScaledScalar::PowerScaledScalar() : _data(0.f) {
|
||||
}
|
||||
|
||||
PowerScaledScalar::PowerScaledScalar(const glm::vec2 &v) {
|
||||
_data = std::move(v);
|
||||
_data = std::move(v);
|
||||
}
|
||||
|
||||
PowerScaledScalar::PowerScaledScalar(float f1, float f2) {
|
||||
_data = glm::vec2(f1, f2);
|
||||
_data = glm::vec2(f1, f2);
|
||||
}
|
||||
|
||||
PowerScaledScalar PowerScaledScalar::CreatePSS(double d1) {
|
||||
char buff[30];
|
||||
char buff[30];
|
||||
|
||||
// find the number with maximum number of digits
|
||||
// find the number with maximum number of digits
|
||||
double ad1 = std::abs(d1);
|
||||
|
||||
// find out how many digits
|
||||
// find out how many digits
|
||||
#ifdef _MSC_VER
|
||||
sprintf_s(buff, 30, "%.0f", ad1);
|
||||
#else
|
||||
sprintf(buff, "%.0f", ad1);
|
||||
#endif
|
||||
size_t digits = strlen(buff)-1;
|
||||
size_t digits = strlen(buff)-1;
|
||||
|
||||
// rescale and return
|
||||
double tp = 1.0 / pow(k, digits);
|
||||
return PowerScaledScalar(static_cast<float>(d1*tp), static_cast<float>(digits));
|
||||
// rescale and return
|
||||
double tp = 1.0 / pow(k, digits);
|
||||
return PowerScaledScalar(static_cast<float>(d1*tp), static_cast<float>(digits));
|
||||
}
|
||||
|
||||
const glm::vec2& PowerScaledScalar::vec2() const {
|
||||
return _data;
|
||||
return _data;
|
||||
}
|
||||
|
||||
float PowerScaledScalar::lengthf() const {
|
||||
return static_cast<float>(_data[0] * pow(k,_data[1]));
|
||||
return static_cast<float>(_data[0] * pow(k,_data[1]));
|
||||
}
|
||||
|
||||
PowerScaledScalar& PowerScaledScalar::operator=(const PowerScaledScalar &rhs) {
|
||||
if (this != &rhs){
|
||||
this->_data = rhs._data;
|
||||
}
|
||||
return *this; // Return a reference to myself.
|
||||
if (this != &rhs){
|
||||
this->_data = rhs._data;
|
||||
}
|
||||
return *this; // Return a reference to myself.
|
||||
}
|
||||
|
||||
PowerScaledScalar & PowerScaledScalar::operator=(const glm::vec2 &rhs) {
|
||||
this->_data = glm::vec2(rhs);
|
||||
return *this; // Return a reference to myself.
|
||||
this->_data = glm::vec2(rhs);
|
||||
return *this; // Return a reference to myself.
|
||||
}
|
||||
|
||||
PowerScaledScalar & PowerScaledScalar::operator=(float rhs) {
|
||||
this->_data = glm::vec2(rhs,0.0);
|
||||
return *this; // Return a reference to myself.
|
||||
this->_data = glm::vec2(rhs,0.0);
|
||||
return *this; // Return a reference to myself.
|
||||
}
|
||||
|
||||
PowerScaledScalar & PowerScaledScalar::operator+=(const PowerScaledScalar &rhs) {
|
||||
|
||||
double ds = this->_data[1] - rhs._data[1];
|
||||
if(ds >= 0.0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] * pow(k, -ds) + this->_data[0]),
|
||||
this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] + this->_data[0] * pow(k, ds)),
|
||||
rhs._data[1]);
|
||||
}
|
||||
double ds = this->_data[1] - rhs._data[1];
|
||||
if(ds >= 0.0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] * pow(k, -ds) + this->_data[0]),
|
||||
this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] + this->_data[0] * pow(k, ds)),
|
||||
rhs._data[1]);
|
||||
}
|
||||
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const PowerScaledScalar PowerScaledScalar::operator+(const PowerScaledScalar &rhs) const {
|
||||
return PowerScaledScalar(*this) += rhs;
|
||||
return PowerScaledScalar(*this) += rhs;
|
||||
}
|
||||
|
||||
PowerScaledScalar & PowerScaledScalar::operator-=(const PowerScaledScalar &rhs) {
|
||||
|
||||
double ds = this->_data[1] - rhs._data[1];
|
||||
if(ds >= 0.0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(-rhs._data[0] * pow(k, -ds) + this->_data[0]),
|
||||
this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(-rhs._data[0] + this->_data[0] * pow(k, ds)),
|
||||
rhs._data[1]);
|
||||
}
|
||||
double ds = this->_data[1] - rhs._data[1];
|
||||
if(ds >= 0.0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(-rhs._data[0] * pow(k, -ds) + this->_data[0]),
|
||||
this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(-rhs._data[0] + this->_data[0] * pow(k, ds)),
|
||||
rhs._data[1]);
|
||||
}
|
||||
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const PowerScaledScalar PowerScaledScalar::operator-(const PowerScaledScalar &rhs) const {
|
||||
return PowerScaledScalar(*this) -= rhs;
|
||||
return PowerScaledScalar(*this) -= rhs;
|
||||
}
|
||||
|
||||
PowerScaledScalar & PowerScaledScalar::operator*=(const PowerScaledScalar &rhs) {
|
||||
double ds = this->_data[1] - rhs._data[1];
|
||||
if(ds >= 0.0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] * pow(k, -ds) * this->_data[0]),
|
||||
this->_data[1] + this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] * this->_data[0] * pow(k, ds)),
|
||||
rhs._data[1] + rhs._data[1]);
|
||||
}
|
||||
double ds = this->_data[1] - rhs._data[1];
|
||||
if(ds >= 0.0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] * pow(k, -ds) * this->_data[0]),
|
||||
this->_data[1] + this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs._data[0] * this->_data[0] * pow(k, ds)),
|
||||
rhs._data[1] + rhs._data[1]);
|
||||
}
|
||||
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const PowerScaledScalar PowerScaledScalar::operator*(const PowerScaledScalar &rhs) const {
|
||||
return PowerScaledScalar(*this) *= rhs;
|
||||
return PowerScaledScalar(*this) *= rhs;
|
||||
}
|
||||
|
||||
|
||||
PowerScaledScalar & PowerScaledScalar::operator*=(const float &rhs) {
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs*pow(k, -ds) * this->_data[0]),
|
||||
this->_data[1] + this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs * this->_data[0] * pow(k, ds)), 0.0f);
|
||||
}
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs*pow(k, -ds) * this->_data[0]),
|
||||
this->_data[1] + this->_data[1]);
|
||||
} else {
|
||||
*this = PowerScaledScalar(
|
||||
static_cast<float>(rhs * this->_data[0] * pow(k, ds)), 0.0f);
|
||||
}
|
||||
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const PowerScaledScalar PowerScaledScalar::operator*(const float &rhs) const {
|
||||
return PowerScaledScalar(*this) *= rhs;
|
||||
return PowerScaledScalar(*this) *= rhs;
|
||||
}
|
||||
|
||||
float& PowerScaledScalar::operator[](unsigned int idx) {
|
||||
return _data[idx];
|
||||
return _data[idx];
|
||||
}
|
||||
|
||||
float PowerScaledScalar::operator[](unsigned int idx) const {
|
||||
return _data[idx];
|
||||
return _data[idx];
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator==(const PowerScaledScalar &other) const {
|
||||
return _data == other._data;
|
||||
return _data == other._data;
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator<(const PowerScaledScalar &other) const {
|
||||
double ds = this->_data[1] - other._data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other._data[0]*pow(k,-ds);
|
||||
double ds = this->_data[1] - other._data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other._data[0]*pow(k,-ds);
|
||||
return _data[0] < upscaled;
|
||||
/*
|
||||
bool retur =(vec_[0] < upscaled);
|
||||
std::printf("this: %f, upscaled: %f, this<upscaled: %i\n", vec_[0], upscaled, retur);
|
||||
return retur;
|
||||
return retur;
|
||||
*/
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other._data[0] > upscaled;
|
||||
}
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other._data[0] > upscaled;
|
||||
}
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator>(const PowerScaledScalar &other) const {
|
||||
double ds = this->_data[1] - other._data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other._data[0]*pow(k,-ds);
|
||||
return _data[0] > upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other._data[0] < upscaled;
|
||||
}
|
||||
double ds = this->_data[1] - other._data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other._data[0]*pow(k,-ds);
|
||||
return _data[0] > upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other._data[0] < upscaled;
|
||||
}
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator<=(const PowerScaledScalar &other) const {
|
||||
return *this < other || *this == other;
|
||||
return *this < other || *this == other;
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator>=(const PowerScaledScalar &other) const {
|
||||
return *this > other || *this == other;
|
||||
return *this > other || *this == other;
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator==(double other) const {
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other*pow(k,-ds);
|
||||
return _data[0] == upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other == upscaled;
|
||||
}
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other*pow(k,-ds);
|
||||
return _data[0] == upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other == upscaled;
|
||||
}
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator<(double other) const {
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other*pow(k,-ds);
|
||||
return _data[0] < upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other > upscaled;
|
||||
}
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other*pow(k,-ds);
|
||||
return _data[0] < upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other > upscaled;
|
||||
}
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator>(double other) const {
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other*pow(k,-ds);
|
||||
return _data[0] > upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other < upscaled;
|
||||
}
|
||||
double ds = this->_data[1];
|
||||
if(ds >= 0) {
|
||||
double upscaled = other*pow(k,-ds);
|
||||
return _data[0] > upscaled;
|
||||
} else {
|
||||
double upscaled = _data[0]*pow(k,-ds);
|
||||
return other < upscaled;
|
||||
}
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator<=(double other) const {
|
||||
return *this < other || *this == other;
|
||||
return *this < other || *this == other;
|
||||
}
|
||||
|
||||
bool PowerScaledScalar::operator>=(double other) const {
|
||||
return *this > other || *this == other;
|
||||
return *this > other || *this == other;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(::std::ostream& os, const PowerScaledScalar& rhs) {
|
||||
|
||||
+100
-100
@@ -71,10 +71,10 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen
|
||||
if (!(x == 0.f && y == 0.f && z == 0.f))
|
||||
normal = glm::normalize(normal);
|
||||
|
||||
const float t1 = fj / fsegments;
|
||||
const float t2 = fi / fsegments;
|
||||
const float t1 = (fj / fsegments);
|
||||
const float t2 = 1.f - (fi / fsegments);
|
||||
|
||||
//double tp = 1.0 / pow(10, static_cast<GLfloat>(radius[1]));
|
||||
//double tp = 1.0 / pow(10, static_cast<GLfloat>(radius[1]));
|
||||
|
||||
_varray[nr].location[0] = x;
|
||||
_varray[nr].location[1] = y;
|
||||
@@ -108,37 +108,37 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen
|
||||
++nr;
|
||||
_iarray[nr] = t * (i - 1) + j + 1; //6
|
||||
++nr;
|
||||
|
||||
/*
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //1
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 0; //2
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 1; //3
|
||||
++nr;
|
||||
_iarray[nr] = t * (i - 1) + j + 1; //6
|
||||
++nr;
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //4
|
||||
++nr;
|
||||
*/
|
||||
|
||||
/*
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //1
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 0; //2
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 1; //3
|
||||
++nr;
|
||||
_iarray[nr] = t * (i - 1) + j + 1; //6
|
||||
++nr;
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //4
|
||||
++nr;
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alternative Constructor for using accurate triaxial ellipsoid
|
||||
PowerScaledSphere::PowerScaledSphere(properties::Vec4Property &radius, int segments, std::string planetName)
|
||||
: _vaoID(0)
|
||||
, _vBufferID(0)
|
||||
, _iBufferID(0)
|
||||
, _isize(6 * segments * segments)
|
||||
, _vsize((segments + 1) * (segments + 1))
|
||||
, _varray(new Vertex[_vsize])
|
||||
, _iarray(new int[_isize])
|
||||
: _vaoID(0)
|
||||
, _vBufferID(0)
|
||||
, _iBufferID(0)
|
||||
, _isize(6 * segments * segments)
|
||||
, _vsize((segments + 1) * (segments + 1))
|
||||
, _varray(new Vertex[_vsize])
|
||||
, _iarray(new int[_isize])
|
||||
{
|
||||
static_assert(sizeof(Vertex) == 64,
|
||||
"The size of the Vertex needs to be 64 for performance");
|
||||
static_assert(sizeof(Vertex) == 64,
|
||||
"The size of the Vertex needs to be 64 for performance");
|
||||
|
||||
float a, b, c, powerscale;
|
||||
float a, b, c, powerscale;
|
||||
bool accutareRadius;
|
||||
try {
|
||||
glm::dvec3 radii;
|
||||
@@ -153,85 +153,85 @@ PowerScaledSphere::PowerScaledSphere(properties::Vec4Property &radius, int segme
|
||||
accutareRadius = false;
|
||||
}
|
||||
|
||||
if (accutareRadius) {
|
||||
PowerScaledCoordinate powerScaledRadii = psc::CreatePowerScaledCoordinate(a, b, c);
|
||||
powerScaledRadii[3] += 3; // SPICE returns radii in km
|
||||
|
||||
std::swap(powerScaledRadii[1], powerScaledRadii[2]); // c is equivalent to y in our coordinate system
|
||||
radius.set(powerScaledRadii.vec4());
|
||||
a = powerScaledRadii[0];
|
||||
b = powerScaledRadii[1];
|
||||
c = powerScaledRadii[2];
|
||||
powerscale = powerScaledRadii[3];
|
||||
}
|
||||
else {
|
||||
if (accutareRadius) {
|
||||
PowerScaledCoordinate powerScaledRadii = psc::CreatePowerScaledCoordinate(a, b, c);
|
||||
powerScaledRadii[3] += 3; // SPICE returns radii in km
|
||||
|
||||
std::swap(powerScaledRadii[1], powerScaledRadii[2]); // c is equivalent to y in our coordinate system
|
||||
radius.set(powerScaledRadii.vec4());
|
||||
a = powerScaledRadii[0];
|
||||
b = powerScaledRadii[1];
|
||||
c = powerScaledRadii[2];
|
||||
powerscale = powerScaledRadii[3];
|
||||
}
|
||||
else {
|
||||
ghoul::any r = radius.get();
|
||||
glm::vec4 modRadius = ghoul::any_cast<glm::vec4>(r);
|
||||
a = modRadius[0];
|
||||
b = modRadius[1];
|
||||
c = modRadius[2];
|
||||
powerscale = modRadius[3];
|
||||
}
|
||||
glm::vec4 modRadius = ghoul::any_cast<glm::vec4>(r);
|
||||
a = modRadius[0];
|
||||
b = modRadius[1];
|
||||
c = modRadius[2];
|
||||
powerscale = modRadius[3];
|
||||
}
|
||||
|
||||
int nr = 0;
|
||||
const float fsegments = static_cast<float>(segments);
|
||||
int nr = 0;
|
||||
const float fsegments = static_cast<float>(segments);
|
||||
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
// define an extra vertex around the y-axis due to texture mapping
|
||||
for (int j = 0; j <= segments; j++) {
|
||||
const float fi = static_cast<float>(i);
|
||||
const float fj = static_cast<float>(j);
|
||||
// inclination angle (north to south)
|
||||
const float theta = fi * float(M_PI) / fsegments; // 0 -> PI
|
||||
// azimuth angle (east to west)
|
||||
const float phi = fj * float(M_PI) * 2.0f / fsegments; // 0 -> 2*PI
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
// define an extra vertex around the y-axis due to texture mapping
|
||||
for (int j = 0; j <= segments; j++) {
|
||||
const float fi = static_cast<float>(i);
|
||||
const float fj = static_cast<float>(j);
|
||||
// inclination angle (north to south)
|
||||
const float theta = fi * float(M_PI) / fsegments; // 0 -> PI
|
||||
// azimuth angle (east to west)
|
||||
const float phi = fj * float(M_PI) * 2.0f / fsegments; // 0 -> 2*PI
|
||||
|
||||
const float x = a * sin(phi) * sin(theta); //
|
||||
const float y = b * cos(theta); // up
|
||||
const float z = c * cos(phi) * sin(theta); //
|
||||
const float x = a * sin(phi) * sin(theta); //
|
||||
const float y = b * cos(theta); // up
|
||||
const float z = c * cos(phi) * sin(theta); //
|
||||
|
||||
_varray[nr].location[0] = x;
|
||||
_varray[nr].location[1] = y;
|
||||
_varray[nr].location[2] = z;
|
||||
_varray[nr].location[3] = powerscale;
|
||||
_varray[nr].location[0] = x;
|
||||
_varray[nr].location[1] = y;
|
||||
_varray[nr].location[2] = z;
|
||||
_varray[nr].location[3] = powerscale;
|
||||
|
||||
glm::vec3 normal = glm::vec3(x, y, z);
|
||||
if (!(x == 0.f && y == 0.f && z == 0.f))
|
||||
normal = glm::normalize(normal);
|
||||
glm::vec3 normal = glm::vec3(x, y, z);
|
||||
if (!(x == 0.f && y == 0.f && z == 0.f))
|
||||
normal = glm::normalize(normal);
|
||||
|
||||
_varray[nr].normal[0] = normal[0];
|
||||
_varray[nr].normal[1] = normal[1];
|
||||
_varray[nr].normal[2] = normal[2];
|
||||
_varray[nr].normal[0] = normal[0];
|
||||
_varray[nr].normal[1] = normal[1];
|
||||
_varray[nr].normal[2] = normal[2];
|
||||
|
||||
const float t1 = fj / fsegments;
|
||||
const float t2 = fi / fsegments;
|
||||
const float t1 = fj / fsegments;
|
||||
const float t2 = 1.f - (fi / fsegments);
|
||||
|
||||
_varray[nr].tex[0] = t1;
|
||||
_varray[nr].tex[1] = t2;
|
||||
++nr;
|
||||
}
|
||||
}
|
||||
_varray[nr].tex[0] = t1;
|
||||
_varray[nr].tex[1] = t2;
|
||||
++nr;
|
||||
}
|
||||
}
|
||||
|
||||
nr = 0;
|
||||
// define indices for all triangles
|
||||
for (int i = 1; i <= segments; ++i) {
|
||||
for (int j = 0; j < segments; ++j) {
|
||||
const int t = segments + 1;
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //1
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 0; //2
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 1; //3
|
||||
++nr;
|
||||
nr = 0;
|
||||
// define indices for all triangles
|
||||
for (int i = 1; i <= segments; ++i) {
|
||||
for (int j = 0; j < segments; ++j) {
|
||||
const int t = segments + 1;
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //1
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 0; //2
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 1; //3
|
||||
++nr;
|
||||
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //4
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 1; //5
|
||||
++nr;
|
||||
_iarray[nr] = t * (i - 1) + j + 1; //6
|
||||
++nr;
|
||||
}
|
||||
}
|
||||
_iarray[nr] = t * (i - 1) + j + 0; //4
|
||||
++nr;
|
||||
_iarray[nr] = t * (i + 0) + j + 1; //5
|
||||
++nr;
|
||||
_iarray[nr] = t * (i - 1) + j + 1; //6
|
||||
++nr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PowerScaledSphere::PowerScaledSphere(const PowerScaledSphere& cpy)
|
||||
@@ -250,13 +250,13 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledSphere& cpy)
|
||||
}
|
||||
|
||||
PowerScaledSphere::~PowerScaledSphere() {
|
||||
if (_varray)
|
||||
delete[] _varray;
|
||||
if (_iarray)
|
||||
delete[] _iarray;
|
||||
if (_varray)
|
||||
delete[] _varray;
|
||||
if (_iarray)
|
||||
delete[] _iarray;
|
||||
|
||||
_varray = 0;
|
||||
_iarray = 0;
|
||||
_varray = 0;
|
||||
_iarray = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vBufferID);
|
||||
glDeleteBuffers(1, &_iBufferID);
|
||||
|
||||
+17
-17
@@ -29,30 +29,30 @@
|
||||
namespace openspace {
|
||||
|
||||
ProgressBar::ProgressBar(int end, int width, std::ostream& stream)
|
||||
: _width(width)
|
||||
, _previous(-1)
|
||||
, _end(end)
|
||||
, _stream(stream)
|
||||
: _width(width)
|
||||
, _previous(-1)
|
||||
, _end(end)
|
||||
, _stream(stream)
|
||||
{
|
||||
print(0);
|
||||
print(0);
|
||||
}
|
||||
|
||||
ProgressBar::~ProgressBar() {
|
||||
_stream << "\n";
|
||||
_stream << "\n";
|
||||
}
|
||||
|
||||
void ProgressBar::print(int current) {
|
||||
float progress = static_cast<float>(current) / static_cast<float>(_end - 1);
|
||||
int iprogress = static_cast<int>(progress*100.0f);
|
||||
if (iprogress != _previous) {
|
||||
int pos = static_cast<int>(static_cast<float>(_width)* progress);
|
||||
int eqWidth = pos + 1;
|
||||
int spWidth = _width - pos + 2;
|
||||
_stream << "[" << std::setfill('=') << std::setw(eqWidth)
|
||||
<< ">" << std::setfill(' ') << std::setw(spWidth)
|
||||
<< "] " << std::setfill(' ') << std::setw(3) << iprogress << " % \r" << std::flush;
|
||||
}
|
||||
_previous = iprogress;
|
||||
float progress = static_cast<float>(current) / static_cast<float>(_end - 1);
|
||||
int iprogress = static_cast<int>(progress*100.0f);
|
||||
if (iprogress != _previous) {
|
||||
int pos = static_cast<int>(static_cast<float>(_width)* progress);
|
||||
int eqWidth = pos + 1;
|
||||
int spWidth = _width - pos + 2;
|
||||
_stream << "[" << std::setfill('=') << std::setw(eqWidth)
|
||||
<< ">" << std::setfill(' ') << std::setw(spWidth)
|
||||
<< "] " << std::setfill(' ') << std::setw(3) << iprogress << " % \r" << std::flush;
|
||||
}
|
||||
_previous = iprogress;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
+90
-90
@@ -35,7 +35,7 @@
|
||||
#include <cppformat/format.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "SpiceManager";
|
||||
const std::string _loggerCat = "SpiceManager";
|
||||
|
||||
// The value comes from
|
||||
// http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getmsg_c.html
|
||||
@@ -189,7 +189,7 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(string filePath) {
|
||||
)
|
||||
);
|
||||
|
||||
string path = absPath(filePath);
|
||||
string path = absPath(filePath);
|
||||
auto it = std::find_if(
|
||||
_loadedKernels.begin(),
|
||||
_loadedKernels.end(),
|
||||
@@ -213,11 +213,11 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(string filePath) {
|
||||
ghoul::filesystem::Directory currentDirectory = FileSys.currentDirectory();
|
||||
using RawPath = ghoul::filesystem::File::RawPath;
|
||||
string fileDirectory = ghoul::filesystem::File(path, RawPath::Yes).directoryName();
|
||||
FileSys.setCurrentDirectory(fileDirectory);
|
||||
FileSys.setCurrentDirectory(fileDirectory);
|
||||
|
||||
LINFO("Loading SPICE kernel '" << path << "'");
|
||||
// Load the kernel
|
||||
furnsh_c(path.c_str());
|
||||
furnsh_c(path.c_str());
|
||||
|
||||
// Reset the current directory to the previous one
|
||||
FileSys.setCurrentDirectory(currentDirectory);
|
||||
@@ -226,9 +226,9 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(string filePath) {
|
||||
|
||||
string fileExtension = ghoul::filesystem::File(path, RawPath::Yes).fileExtension();
|
||||
if (fileExtension == "bc" || fileExtension == "BC")
|
||||
findCkCoverage(path); // binary ck kernel
|
||||
else if (fileExtension == "bsp" || fileExtension == "BSP")
|
||||
findSpkCoverage(path); // binary spk kernel
|
||||
findCkCoverage(path); // binary ck kernel
|
||||
else if (fileExtension == "bsp" || fileExtension == "BSP")
|
||||
findSpkCoverage(path); // binary spk kernel
|
||||
|
||||
KernelHandle kernelId = ++_lastAssignedKernel;
|
||||
ghoul_assert(kernelId != 0, fmt::format("Kernel Handle wrapped around to 0"));
|
||||
@@ -240,23 +240,23 @@ void SpiceManager::unloadKernel(KernelHandle kernelId) {
|
||||
ghoul_assert(kernelId <= _lastAssignedKernel, "Invalid unassigned kernel");
|
||||
ghoul_assert(kernelId != KernelHandle(0), "Invalid zero handle");
|
||||
|
||||
auto it = std::find_if(_loadedKernels.begin(), _loadedKernels.end(),
|
||||
[&kernelId](const KernelInformation& info) { return info.id == kernelId; });
|
||||
auto it = std::find_if(_loadedKernels.begin(), _loadedKernels.end(),
|
||||
[&kernelId](const KernelInformation& info) { return info.id == kernelId; });
|
||||
|
||||
if (it != _loadedKernels.end()) {
|
||||
if (it != _loadedKernels.end()) {
|
||||
// If there was only one part interested in the kernel, we can unload it
|
||||
if (it->refCount == 1) {
|
||||
// No need to check for errors as we do not allow empty path names
|
||||
// No need to check for errors as we do not allow empty path names
|
||||
LINFO(format("Unloading SPICE kernel '{}'", it->path));
|
||||
unload_c(it->path.c_str());
|
||||
_loadedKernels.erase(it);
|
||||
unload_c(it->path.c_str());
|
||||
_loadedKernels.erase(it);
|
||||
}
|
||||
// Otherwise, we hold on to it, but reduce the reference counter by 1
|
||||
else {
|
||||
it->refCount--;
|
||||
LDEBUG(format("Reducing reference counter to: {}", it->refCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpiceManager::unloadKernel(std::string filePath) {
|
||||
@@ -264,15 +264,15 @@ void SpiceManager::unloadKernel(std::string filePath) {
|
||||
|
||||
string path = absPath(filePath);
|
||||
|
||||
auto it = std::find_if(_loadedKernels.begin(), _loadedKernels.end(),
|
||||
[&path](const KernelInformation& info) { return info.path == path; });
|
||||
auto it = std::find_if(_loadedKernels.begin(), _loadedKernels.end(),
|
||||
[&path](const KernelInformation& info) { return info.path == path; });
|
||||
|
||||
if (it == _loadedKernels.end()) {
|
||||
throw SpiceException(
|
||||
format("'{}' did not correspond to a loaded kernel", path)
|
||||
);
|
||||
}
|
||||
else {
|
||||
else {
|
||||
// If there was only one part interested in the kernel, we can unload it
|
||||
if (it->refCount == 1) {
|
||||
LINFO(format("Unloading SPICE kernel '{}'", path));
|
||||
@@ -284,7 +284,7 @@ void SpiceManager::unloadKernel(std::string filePath) {
|
||||
it->refCount--;
|
||||
LDEBUG(format("Reducing reference counter to: {}", it->refCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SpiceManager::hasSpkCoverage(const string& target, double et) const {
|
||||
@@ -319,14 +319,14 @@ bool SpiceManager::hasCkCoverage(const string& frame, double et) const {
|
||||
}
|
||||
|
||||
bool SpiceManager::hasValue(int naifId, const std::string& item) const {
|
||||
return bodfnd_c(naifId, item.c_str());
|
||||
return bodfnd_c(naifId, item.c_str());
|
||||
}
|
||||
|
||||
bool SpiceManager::hasValue(const std::string& body, const std::string& item) const {
|
||||
ghoul_assert(!body.empty(), "Empty body");
|
||||
ghoul_assert(!item.empty(), "Empty item");
|
||||
|
||||
int id = naifId(body);
|
||||
int id = naifId(body);
|
||||
return hasValue(id, item);
|
||||
}
|
||||
|
||||
@@ -370,14 +370,14 @@ bool SpiceManager::hasFrameId(const std::string& frame) const {
|
||||
}
|
||||
|
||||
void getValueInternal(const std::string& body, const std::string& value, int size,
|
||||
double* v)
|
||||
double* v)
|
||||
{
|
||||
ghoul_assert(!body.empty(), "Empty body");
|
||||
ghoul_assert(!value.empty(), "Empty value");
|
||||
ghoul_assert(v != nullptr, "Empty value pointer");
|
||||
|
||||
SpiceInt n;
|
||||
bodvrd_c(body.c_str(), value.c_str(), size, &n, v);
|
||||
SpiceInt n;
|
||||
bodvrd_c(body.c_str(), value.c_str(), size, &n, v);
|
||||
|
||||
throwOnSpiceError(
|
||||
format("Error getting value '{}' for body '{}'",
|
||||
@@ -390,7 +390,7 @@ void getValueInternal(const std::string& body, const std::string& value, int siz
|
||||
void SpiceManager::getValue(const std::string& body, const std::string& value,
|
||||
double& v) const
|
||||
{
|
||||
getValueInternal(body, value, 1, &v);
|
||||
getValueInternal(body, value, 1, &v);
|
||||
}
|
||||
|
||||
void SpiceManager::getValue(const std::string& body, const std::string& value,
|
||||
@@ -402,17 +402,17 @@ void SpiceManager::getValue(const std::string& body, const std::string& value,
|
||||
void SpiceManager::getValue(const std::string& body, const std::string& value,
|
||||
glm::dvec3& v) const
|
||||
{
|
||||
getValueInternal(body, value, 3, glm::value_ptr(v));
|
||||
getValueInternal(body, value, 3, glm::value_ptr(v));
|
||||
}
|
||||
|
||||
void SpiceManager::getValue(const std::string& body, const std::string& value,
|
||||
glm::dvec4& v) const
|
||||
glm::dvec4& v) const
|
||||
{
|
||||
getValueInternal(body, value, 4, glm::value_ptr(v));
|
||||
getValueInternal(body, value, 4, glm::value_ptr(v));
|
||||
}
|
||||
|
||||
void SpiceManager::getValue(const std::string& body, const std::string& value,
|
||||
std::vector<double>& v) const
|
||||
std::vector<double>& v) const
|
||||
{
|
||||
ghoul_assert(!v.empty(), "Array for values has to be preallocaed");
|
||||
|
||||
@@ -424,19 +424,19 @@ double SpiceManager::spacecraftClockToET(const std::string& craft, double craftT
|
||||
|
||||
int craftId = naifId(craft);
|
||||
double et;
|
||||
sct2e_c(craftId, craftTicks, &et);
|
||||
sct2e_c(craftId, craftTicks, &et);
|
||||
throwOnSpiceError(format(
|
||||
"Error transforming spacecraft clock of '{}' at time {}",
|
||||
craft, craftTicks)
|
||||
);
|
||||
return et;
|
||||
return et;
|
||||
}
|
||||
|
||||
double SpiceManager::ephemerisTimeFromDate(const std::string& timeString) const {
|
||||
ghoul_assert(!timeString.empty(), "Empty timeString");
|
||||
|
||||
double et;
|
||||
str2et_c(timeString.c_str(), &et);
|
||||
str2et_c(timeString.c_str(), &et);
|
||||
throwOnSpiceError(format("Error converting date '{}'", timeString));
|
||||
return et;
|
||||
}
|
||||
@@ -469,26 +469,26 @@ glm::dvec3 SpiceManager::targetPosition(const std::string& target,
|
||||
ghoul_assert(!observer.empty(), "Observer is not empty");
|
||||
ghoul_assert(!referenceFrame.empty(), "Reference frame is not empty");
|
||||
|
||||
bool targetHasCoverage = hasSpkCoverage(target, ephemerisTime);
|
||||
bool observerHasCoverage = hasSpkCoverage(observer, ephemerisTime);
|
||||
if (!targetHasCoverage && !observerHasCoverage){
|
||||
bool targetHasCoverage = hasSpkCoverage(target, ephemerisTime);
|
||||
bool observerHasCoverage = hasSpkCoverage(observer, ephemerisTime);
|
||||
if (!targetHasCoverage && !observerHasCoverage){
|
||||
throw SpiceException(
|
||||
format("Neither the target '{}' nor observer '{}' has SPK coverage",
|
||||
target,
|
||||
observer
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (targetHasCoverage && observerHasCoverage) {
|
||||
}
|
||||
else if (targetHasCoverage && observerHasCoverage) {
|
||||
glm::dvec3 position;
|
||||
spkpos_c(
|
||||
spkpos_c(
|
||||
target.c_str(),
|
||||
ephemerisTime,
|
||||
referenceFrame.c_str(),
|
||||
aberrationCorrection,
|
||||
observer.c_str(),
|
||||
glm::value_ptr(position),
|
||||
&lightTime
|
||||
&lightTime
|
||||
);
|
||||
throwOnSpiceError(format(
|
||||
"Error getting target position from '{}' to '{}' in reference frame '{}",
|
||||
@@ -497,7 +497,7 @@ glm::dvec3 SpiceManager::targetPosition(const std::string& target,
|
||||
referenceFrame
|
||||
));
|
||||
return position;
|
||||
}
|
||||
}
|
||||
else if (targetHasCoverage) {
|
||||
// observer has no coverage
|
||||
return getEstimatedPosition(
|
||||
@@ -531,13 +531,13 @@ glm::dmat3 SpiceManager::frameTransformationMatrix(const std::string& from,
|
||||
|
||||
// get rotation matrix from frame A - frame B
|
||||
glm::dmat3 transform;
|
||||
pxform_c(
|
||||
pxform_c(
|
||||
from.c_str(),
|
||||
to.c_str(),
|
||||
ephemerisTime,
|
||||
reinterpret_cast<double(*)[3]>(glm::value_ptr(transform))
|
||||
);
|
||||
|
||||
|
||||
throwOnSpiceError(
|
||||
format("Error converting from frame '{}' to frame '{}' at time '{}'",
|
||||
from, to, ephemerisTime
|
||||
@@ -601,8 +601,8 @@ bool SpiceManager::isTargetInFieldOfView(const std::string& target,
|
||||
ghoul_assert(!referenceFrame.empty(), "Reference frame must not be empty");
|
||||
ghoul_assert(!instrument.empty(), "Instrument must not be empty");
|
||||
|
||||
int visible;
|
||||
fovtrg_c(instrument.c_str(),
|
||||
int visible;
|
||||
fovtrg_c(instrument.c_str(),
|
||||
target.c_str(),
|
||||
toString(method),
|
||||
referenceFrame.c_str(),
|
||||
@@ -617,7 +617,7 @@ bool SpiceManager::isTargetInFieldOfView(const std::string& target,
|
||||
target, instrument
|
||||
));
|
||||
|
||||
return visible == SPICETRUE;
|
||||
return visible == SPICETRUE;
|
||||
}
|
||||
|
||||
bool SpiceManager::isTargetInFieldOfView(const std::string& target,
|
||||
@@ -648,7 +648,7 @@ SpiceManager::TargetStateResult SpiceManager::targetState(const std::string& tar
|
||||
|
||||
double buffer[6];
|
||||
|
||||
spkezr_c(
|
||||
spkezr_c(
|
||||
target.c_str(),
|
||||
ephemerisTime,
|
||||
referenceFrame.c_str(),
|
||||
@@ -676,7 +676,7 @@ SpiceManager::TransformMatrix SpiceManager::stateTransformMatrix(const string& f
|
||||
ghoul_assert(!toFrame.empty(), "toFrame must not be empty");
|
||||
|
||||
TransformMatrix m;
|
||||
sxform_c(
|
||||
sxform_c(
|
||||
fromFrame.c_str(),
|
||||
toFrame.c_str(),
|
||||
ephemerisTime,
|
||||
@@ -697,7 +697,7 @@ glm::dmat3 SpiceManager::positionTransformMatrix(const std::string& fromFrame,
|
||||
ghoul_assert(!toFrame.empty(), "toFrame must not be empty");
|
||||
|
||||
glm::dmat3 result;
|
||||
pxform_c(
|
||||
pxform_c(
|
||||
fromFrame.c_str(),
|
||||
toFrame.c_str(),
|
||||
ephemerisTime,
|
||||
@@ -705,11 +705,11 @@ glm::dmat3 SpiceManager::positionTransformMatrix(const std::string& fromFrame,
|
||||
);
|
||||
|
||||
throwOnSpiceError("");
|
||||
SpiceBoolean success = !(failed_c());
|
||||
SpiceBoolean success = !(failed_c());
|
||||
reset_c();
|
||||
bool estimated = false;
|
||||
if (!success)
|
||||
result = getEstimatedTransformMatrix(fromFrame, toFrame, ephemerisTime);
|
||||
if (!success)
|
||||
result = getEstimatedTransformMatrix(fromFrame, toFrame, ephemerisTime);
|
||||
|
||||
return glm::transpose(result);
|
||||
}
|
||||
@@ -722,7 +722,7 @@ glm::dmat3 SpiceManager::positionTransformMatrix(const std::string& fromFrame,
|
||||
|
||||
glm::dmat3 result;
|
||||
|
||||
pxfrm2_c(
|
||||
pxfrm2_c(
|
||||
fromFrame.c_str(),
|
||||
toFrame.c_str(),
|
||||
ephemerisTimeFrom,
|
||||
@@ -745,24 +745,24 @@ SpiceManager::fieldOfView(const std::string& instrument) const
|
||||
}
|
||||
|
||||
SpiceManager::FieldOfViewResult SpiceManager::fieldOfView(int instrument) const {
|
||||
static const int MaxBoundsSize = 64;
|
||||
static const int BufferSize = 128;
|
||||
static const int MaxBoundsSize = 64;
|
||||
static const int BufferSize = 128;
|
||||
|
||||
FieldOfViewResult res;
|
||||
|
||||
SpiceInt nrReturned;
|
||||
double boundsArr[MaxBoundsSize][3];
|
||||
SpiceInt nrReturned;
|
||||
double boundsArr[MaxBoundsSize][3];
|
||||
char fovShapeBuffer[BufferSize];
|
||||
char frameNameBuffer[BufferSize];
|
||||
getfov_c(instrument, // instrument id
|
||||
getfov_c(instrument, // instrument id
|
||||
MaxBoundsSize, // maximum size for the bounds vector
|
||||
BufferSize, // maximum size for the fov shape buffer
|
||||
BufferSize, // maximum size for the frame name buffer
|
||||
fovShapeBuffer, // the fov shape buffer
|
||||
frameNameBuffer, // the frame name buffer
|
||||
glm::value_ptr(res.boresightVector), // the boresight vector
|
||||
&nrReturned, // the number of returned array values
|
||||
boundsArr // the bounds
|
||||
BufferSize, // maximum size for the frame name buffer
|
||||
fovShapeBuffer, // the fov shape buffer
|
||||
frameNameBuffer, // the frame name buffer
|
||||
glm::value_ptr(res.boresightVector), // the boresight vector
|
||||
&nrReturned, // the number of returned array values
|
||||
boundsArr // the bounds
|
||||
);
|
||||
|
||||
throwOnSpiceError(format(
|
||||
@@ -770,7 +770,7 @@ SpiceManager::FieldOfViewResult SpiceManager::fieldOfView(int instrument) const
|
||||
));
|
||||
|
||||
res.bounds.reserve(nrReturned);
|
||||
for (int i = 0; i < nrReturned; ++i)
|
||||
for (int i = 0; i < nrReturned; ++i)
|
||||
res.bounds.emplace_back(boundsArr[i][0], boundsArr[i][1], boundsArr[i][2]);
|
||||
|
||||
string shape = string(fovShapeBuffer);
|
||||
@@ -783,7 +783,7 @@ SpiceManager::FieldOfViewResult SpiceManager::fieldOfView(int instrument) const
|
||||
res.shape = Map.at(shape);
|
||||
res.frameName = string(frameNameBuffer);
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
SpiceManager::TerminatorEllipseResult SpiceManager::terminatorEllipse(
|
||||
@@ -803,24 +803,24 @@ SpiceManager::TerminatorEllipseResult SpiceManager::terminatorEllipse(
|
||||
// Warning: This assumes std::vector<glm::dvec3> to have all values memory contiguous
|
||||
res.terminatorPoints.resize(numberOfTerminatorPoints);
|
||||
|
||||
edterm_c(toString(terminatorType),
|
||||
lightSource.c_str(),
|
||||
target.c_str(),
|
||||
ephemerisTime,
|
||||
frame.c_str(),
|
||||
aberrationCorrection,
|
||||
observer.c_str(),
|
||||
numberOfTerminatorPoints,
|
||||
&res.targetEphemerisTime,
|
||||
glm::value_ptr(res.observerPosition),
|
||||
(double(*)[3])res.terminatorPoints.data()
|
||||
edterm_c(toString(terminatorType),
|
||||
lightSource.c_str(),
|
||||
target.c_str(),
|
||||
ephemerisTime,
|
||||
frame.c_str(),
|
||||
aberrationCorrection,
|
||||
observer.c_str(),
|
||||
numberOfTerminatorPoints,
|
||||
&res.targetEphemerisTime,
|
||||
glm::value_ptr(res.observerPosition),
|
||||
(double(*)[3])res.terminatorPoints.data()
|
||||
);
|
||||
throwOnSpiceError(format(
|
||||
"Error getting terminator ellipse for target '{}' from observer '{}' in frame "
|
||||
"'{}' with light source '{}' at time '{}'",
|
||||
target, observer, frame, lightSource, ephemerisTime
|
||||
));
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool SpiceManager::addFrame(std::string body, std::string frame) {
|
||||
@@ -832,22 +832,22 @@ bool SpiceManager::addFrame(std::string body, std::string frame) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string SpiceManager::frameFromBody(const std::string body) const {
|
||||
for (auto pair : _frameByBody) {
|
||||
if (pair.first == body) {
|
||||
return pair.second;
|
||||
}
|
||||
}
|
||||
std::string SpiceManager::frameFromBody(const std::string& body) const {
|
||||
for (auto pair : _frameByBody) {
|
||||
if (pair.first == body) {
|
||||
return pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
std::string unionPrefix = "IAU_";
|
||||
std::string frame = "";
|
||||
std::string unionPrefix = "IAU_";
|
||||
std::string frame = "";
|
||||
|
||||
if (body.find(unionPrefix) == std::string::npos)
|
||||
frame = unionPrefix + body;
|
||||
else
|
||||
frame = body;
|
||||
if (body.find(unionPrefix) == std::string::npos)
|
||||
frame = unionPrefix + body;
|
||||
else
|
||||
frame = body;
|
||||
|
||||
return frame;
|
||||
return frame;
|
||||
}
|
||||
|
||||
void SpiceManager::findCkCoverage(const std::string& path) {
|
||||
@@ -919,7 +919,7 @@ void SpiceManager::findSpkCoverage(const std::string& path) {
|
||||
_spkCoverageTimes[obj].insert(e);
|
||||
_spkCoverageTimes[obj].insert(b);
|
||||
_spkIntervals[obj].emplace_back(b, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -27,25 +27,25 @@
|
||||
namespace openspace {
|
||||
|
||||
SyncBuffer::SyncBuffer(size_t n)
|
||||
: _n(n)
|
||||
, _encodeOffset(0)
|
||||
, _decodeOffset(0)
|
||||
: _n(n)
|
||||
, _encodeOffset(0)
|
||||
, _decodeOffset(0)
|
||||
{
|
||||
_dataStream.resize(_n);
|
||||
_dataStream.resize(_n);
|
||||
}
|
||||
|
||||
void SyncBuffer::write() {
|
||||
_synchronizationBuffer.setVal(_dataStream);
|
||||
sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
_synchronizationBuffer.setVal(_dataStream);
|
||||
sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
}
|
||||
|
||||
void SyncBuffer::read() {
|
||||
sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
|
||||
_dataStream = std::move(_synchronizationBuffer.getVal());
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
|
||||
_dataStream = std::move(_synchronizationBuffer.getVal());
|
||||
_encodeOffset = 0;
|
||||
_decodeOffset = 0;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
+72
-72
@@ -53,31 +53,31 @@ Time& Time::ref() {
|
||||
}
|
||||
|
||||
bool Time::isInitialized() {
|
||||
return (_instance != nullptr);
|
||||
return (_instance != nullptr);
|
||||
}
|
||||
|
||||
void Time::setTime(double value, bool requireJump) {
|
||||
_time = value;
|
||||
_timeJumped = requireJump;
|
||||
_time = value;
|
||||
_timeJumped = requireJump;
|
||||
}
|
||||
|
||||
double Time::currentTime() const {
|
||||
return _syncedTime;
|
||||
return _syncedTime;
|
||||
}
|
||||
|
||||
double Time::advanceTime(double tickTime) {
|
||||
if (_timePaused)
|
||||
return _time;
|
||||
else
|
||||
return _time += _dt * tickTime;
|
||||
return _time += _dt * tickTime;
|
||||
}
|
||||
|
||||
void Time::setDeltaTime(double deltaT) {
|
||||
_dt = deltaT;
|
||||
_dt = deltaT;
|
||||
}
|
||||
|
||||
double Time::deltaTime() const {
|
||||
return _syncedDt;
|
||||
return _syncedDt;
|
||||
}
|
||||
|
||||
void Time::setPause(bool pause) {
|
||||
@@ -91,7 +91,7 @@ bool Time::togglePause() {
|
||||
|
||||
void Time::setTime(std::string time, bool requireJump) {
|
||||
_time = SpiceManager::ref().ephemerisTimeFromDate(std::move(time));
|
||||
_timeJumped = requireJump;
|
||||
_timeJumped = requireJump;
|
||||
}
|
||||
|
||||
std::string Time::currentTimeUTC() const {
|
||||
@@ -99,33 +99,33 @@ std::string Time::currentTimeUTC() const {
|
||||
}
|
||||
|
||||
void Time::serialize(SyncBuffer* syncBuffer) {
|
||||
_syncMutex.lock();
|
||||
_syncMutex.lock();
|
||||
|
||||
syncBuffer->encode(_sharedTime);
|
||||
syncBuffer->encode(_sharedDt);
|
||||
syncBuffer->encode(_sharedTimeJumped);
|
||||
syncBuffer->encode(_sharedTime);
|
||||
syncBuffer->encode(_sharedDt);
|
||||
syncBuffer->encode(_sharedTimeJumped);
|
||||
|
||||
_syncMutex.unlock();
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::deserialize(SyncBuffer* syncBuffer) {
|
||||
_syncMutex.lock();
|
||||
_syncMutex.lock();
|
||||
|
||||
syncBuffer->decode(_sharedTime);
|
||||
syncBuffer->decode(_sharedDt);
|
||||
syncBuffer->decode(_sharedTimeJumped);
|
||||
syncBuffer->decode(_sharedTime);
|
||||
syncBuffer->decode(_sharedDt);
|
||||
syncBuffer->decode(_sharedTimeJumped);
|
||||
|
||||
if (_sharedTimeJumped)
|
||||
_jockeHasToFixThisLater = true;
|
||||
|
||||
_syncMutex.unlock();
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::postSynchronizationPreDraw() {
|
||||
_syncMutex.lock();
|
||||
_syncMutex.lock();
|
||||
|
||||
_syncedTime = _sharedTime;
|
||||
_syncedDt = _sharedDt;
|
||||
_syncedTime = _sharedTime;
|
||||
_syncedDt = _sharedDt;
|
||||
_syncedTimeJumped = _sharedTimeJumped;
|
||||
|
||||
if (_jockeHasToFixThisLater) {
|
||||
@@ -133,25 +133,25 @@ void Time::postSynchronizationPreDraw() {
|
||||
_jockeHasToFixThisLater = false;
|
||||
}
|
||||
|
||||
_syncMutex.unlock();
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
void Time::preSynchronization() {
|
||||
_syncMutex.lock();
|
||||
_syncMutex.lock();
|
||||
|
||||
_sharedTime = _time;
|
||||
_sharedDt = _dt;
|
||||
_sharedTimeJumped = _timeJumped;
|
||||
_sharedTime = _time;
|
||||
_sharedDt = _dt;
|
||||
_sharedTimeJumped = _timeJumped;
|
||||
|
||||
_syncMutex.unlock();
|
||||
_syncMutex.unlock();
|
||||
}
|
||||
|
||||
bool Time::timeJumped() const {
|
||||
return _syncedTimeJumped;
|
||||
return _syncedTimeJumped;
|
||||
}
|
||||
|
||||
void Time::setTimeJumped(bool jumped) {
|
||||
_timeJumped = jumped;
|
||||
_timeJumped = jumped;
|
||||
}
|
||||
|
||||
bool Time::paused() const {
|
||||
@@ -159,24 +159,24 @@ bool Time::paused() const {
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary Time::luaLibrary() {
|
||||
scripting::ScriptEngine::LuaLibrary timeLibrary = {
|
||||
"time",
|
||||
{
|
||||
{
|
||||
"setDeltaTime",
|
||||
&luascriptfunctions::time_setDeltaTime,
|
||||
"number",
|
||||
"Sets the amount of simulation time that happens "
|
||||
"in one second of real time",
|
||||
scripting::ScriptEngine::LuaLibrary timeLibrary = {
|
||||
"time",
|
||||
{
|
||||
{
|
||||
"setDeltaTime",
|
||||
&luascriptfunctions::time_setDeltaTime,
|
||||
"number",
|
||||
"Sets the amount of simulation time that happens "
|
||||
"in one second of real time",
|
||||
true
|
||||
},
|
||||
{
|
||||
"deltaTime",
|
||||
&luascriptfunctions::time_deltaTime,
|
||||
"",
|
||||
"Returns the amount of simulated time that passes in one "
|
||||
"second of real time"
|
||||
},
|
||||
},
|
||||
{
|
||||
"deltaTime",
|
||||
&luascriptfunctions::time_deltaTime,
|
||||
"",
|
||||
"Returns the amount of simulated time that passes in one "
|
||||
"second of real time"
|
||||
},
|
||||
{
|
||||
"setPause",
|
||||
&luascriptfunctions::time_setPause,
|
||||
@@ -192,33 +192,33 @@ scripting::ScriptEngine::LuaLibrary Time::luaLibrary() {
|
||||
" and restoring it afterwards",
|
||||
true
|
||||
},
|
||||
{
|
||||
"setTime",
|
||||
&luascriptfunctions::time_setTime,
|
||||
"{number, string}",
|
||||
"Sets the current simulation time to the "
|
||||
"specified value. If the parameter is a number, the value is the number "
|
||||
"of seconds past the J2000 epoch. If it is a string, it has to be a "
|
||||
"valid ISO 8601 date string (YYYY-MM-DDTHH:MN:SS)",
|
||||
{
|
||||
"setTime",
|
||||
&luascriptfunctions::time_setTime,
|
||||
"{number, string}",
|
||||
"Sets the current simulation time to the "
|
||||
"specified value. If the parameter is a number, the value is the number "
|
||||
"of seconds past the J2000 epoch. If it is a string, it has to be a "
|
||||
"valid ISO 8601 date string (YYYY-MM-DDTHH:MN:SS)",
|
||||
true
|
||||
},
|
||||
{
|
||||
"currentTime",
|
||||
&luascriptfunctions::time_currentTime,
|
||||
"",
|
||||
"Returns the current time as the number of seconds since "
|
||||
"the J2000 epoch"
|
||||
},
|
||||
{
|
||||
"currentTimeUTC",
|
||||
&luascriptfunctions::time_currentTimeUTC,
|
||||
"",
|
||||
"Returns the current time as an ISO 8601 date string "
|
||||
"(YYYY-MM-DDTHH:MN:SS)"
|
||||
}
|
||||
}
|
||||
};
|
||||
return timeLibrary;
|
||||
},
|
||||
{
|
||||
"currentTime",
|
||||
&luascriptfunctions::time_currentTime,
|
||||
"",
|
||||
"Returns the current time as the number of seconds since "
|
||||
"the J2000 epoch"
|
||||
},
|
||||
{
|
||||
"currentTimeUTC",
|
||||
&luascriptfunctions::time_currentTimeUTC,
|
||||
"",
|
||||
"Returns the current time as an ISO 8601 date string "
|
||||
"(YYYY-MM-DDTHH:MN:SS)"
|
||||
}
|
||||
}
|
||||
};
|
||||
return timeLibrary;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user