Rename boolean functions and variables to adhere to code style

This commit is contained in:
sylvass
2021-11-10 09:33:30 -05:00
parent 89e483c748
commit 206fc43f74
12 changed files with 83 additions and 79 deletions
+2 -5
View File
@@ -40,9 +40,6 @@ public:
constexpr static const float AcceptableDiff = 0.01f;
Pair(ScreenSpaceSkyBrowser* browser, ScreenSpaceSkyTarget* target);
Pair(Pair const&) = default;
Pair& operator=(Pair other);
void lock();
void unlock();
@@ -54,11 +51,11 @@ public:
void enable();
void disable();
void startAnimation(glm::dvec3 coordsEnd, float FOVEnd, bool shouldLockAfter = true);
void startAnimation(glm::dvec3 coordsEnd, float fovEnd, bool shouldLockAfter = true);
void centerTargetOnScreen();
void incrementallyAnimateToCoordinate(double deltaTime);
void incrementallyFade(float goalState, float fadeTime, float deltaTime);
bool isFinishedFading(float goalState);
bool hasFinishedFading(float goalState);
bool isCoordOnPair(glm::vec2 mousePosition);
bool isEnabled();
bool isLocked();
@@ -98,7 +98,7 @@ namespace openspace {
// Flags
bool _isUrlDirty = false;
bool _isDimensionsDirty = false;
bool _syncViewWithWwt;
bool _isSyncedWithWwt;
float _verticalFov;
std::thread _threadWwtMessages;
@@ -91,8 +91,8 @@ namespace openspace {
// Flags
bool _hasLoadedImages{ false };
bool _syncViewWithWwt{ false };
bool _fovIsAnimated{ false };
bool _isSyncedWithWwt{ false };
bool _isFovAnimated{ false };
float _endVfov{ 0.f };
float _fovDiff{ 0.01f };
@@ -34,7 +34,7 @@ namespace openspace {
void createShaders();
// Sky browser functionality
bool findSkyBrowser();
bool connectoToSkyBrowser();
void matchAppearanceToSkyBrowser();
// Getters
@@ -59,8 +59,8 @@ namespace openspace {
// Animation
bool isAnimated();
void startAnimation(glm::dvec3 end, bool lockAfter);
void animateToCoordinate(float deltaTime);
void startAnimation(glm::dvec3 end, bool shouldLockAfter);
void incrementallyAnimateToCoordinate(float deltaTime);
// Display
void highlight(glm::ivec3 addition);
void removeHighlight(glm::ivec3 removal);
@@ -76,7 +76,7 @@ namespace openspace {
// Flags
bool _isLocked{ false };
bool _isAnimated{ false };
bool _lockAfterAnimation{ false };
bool _shouldLockAfterAnimation{ false };
// Shader
UniformCache(
+2 -2
View File
@@ -42,7 +42,7 @@ namespace openspace {
// Camera roll and direction
// Camera roll is with respect to the equatorial North Pole
bool coordinateIsInView(glm::dvec3 equatorial);
bool isCoordinateInView(glm::dvec3 equatorial);
float windowRatio();
double cameraRoll();
glm::vec2 pixelToScreenSpace(glm::vec2& mouseCoordinate);
@@ -58,7 +58,7 @@ namespace openspace {
namespace wwtmessage {
inline int messageCounter{ 0 };
ghoul::Dictionary moveCamera(const glm::dvec2 celestCoords,
const double fov, const double roll, const bool moveInstantly = true);
const double fov, const double roll, const bool shouldMoveInstantly = true);
ghoul::Dictionary loadCollection(const std::string& url);
ghoul::Dictionary setForeground(const std::string& name);
ghoul::Dictionary addImage(const std::string& id, const std::string& url);
+5 -5
View File
@@ -629,7 +629,7 @@ void SkyBrowserModule::selectImage2dBrowser(int i)
LINFO("Loading image " + image.name);
selected->selectImage(image, i);
bool isInView = skybrowser::coordinateIsInView(image.equatorialCartesian);
bool isInView = skybrowser::isCoordinateInView(image.equatorialCartesian);
// If the coordinate is not in view, rotate camera
if (image.hasCelestialCoords) {
if(!isInView) {
@@ -774,10 +774,10 @@ void SkyBrowserModule::incrementallyFadeBrowserTargets(Transparency goal, float
{
float transparency = static_cast<float>(goal);
bool isAllFinished{ false };
for (Pair pair : _targetsBrowsers) {
for (Pair& pair : _targetsBrowsers) {
if (pair.isEnabled()) {
pair.incrementallyFade(transparency, _fadingTime, deltaTime);
bool isPairFinished = pair.isFinishedFading(transparency);
bool isPairFinished = pair.hasFinishedFading(transparency);
if (isPairFinished && goal == Transparency::Transparent) {
pair.disable();
@@ -794,9 +794,9 @@ void SkyBrowserModule::incrementallyFadeBrowserTargets(Transparency goal, float
void SkyBrowserModule::incrementallyAnimateTargets(double deltaTime)
{
for (Pair pair : _targetsBrowsers) {
for (Pair& pair : _targetsBrowsers) {
if (pair.isEnabled()) {
pair.animateToCoordinate(deltaTime);
pair.incrementallyAnimateToCoordinate(deltaTime);
}
}
}
+2 -2
View File
@@ -81,8 +81,8 @@ public:
void lookAtTarget(std::string id);
void incrementallyRotateCamera(double deltaTime);
void fadeBrowserTargets(Transparency goal, float deltaTime);
void animateTargets(double deltaTime);
void incrementallyFadeBrowserTargets(Transparency goal, float deltaTime);
void incrementallyAnimateTargets(double deltaTime);
void lookAt3dBrowser();
// Boolean functions
+8 -14
View File
@@ -38,14 +38,7 @@ namespace openspace {
assert(browser != nullptr, "Sky browser is null pointer!");
assert(target != nullptr, "Sky target is null pointer!");
}
Pair& Pair::operator=(Pair other)
{
std::swap(_target, other._target);
std::swap(_browser, other._browser);
return *this;
}
void Pair::lock() {
_target->lock();
}
@@ -61,7 +54,7 @@ namespace openspace {
void Pair::connectPair()
{
_browser->connectToSkyTarget();
_target->findSkyBrowser();
_target->connectoToSkyBrowser();
}
void Pair::synchronizeWithWwt()
@@ -206,21 +199,22 @@ namespace openspace {
{
_browser->sendIdToBrowser();
}
#pragma optimize("", off)
void Pair::incrementallyAnimateToCoordinate(double deltaTime)
{
// Animate the target before the field of view starts to animate
if (_target->isAnimated()) {
_target->animateToCoordinate(deltaTime);
_target->incrementallyAnimateToCoordinate(deltaTime);
}
else if (_browser->isAnimated()) {
_browser->incrementallyAnimateToFov(deltaTime);
}
}
void Pair::startAnimation(glm::dvec3 coordsEnd, float FOVEnd, bool lockAfter)
void Pair::startAnimation(glm::dvec3 coordsEnd, float fovEnd, bool lockAfter)
{
_target->startAnimation(coordsEnd, lockAfter);
_browser->startFovAnimation(FOVEnd);
_browser->startFovAnimation(fovEnd);
}
void Pair::centerTargetOnScreen()
@@ -234,7 +228,7 @@ namespace openspace {
startAnimation(viewDirection, currentFov, false);
}
bool Pair::isFinishedFading(float goalState)
bool Pair::hasFinishedFading(float goalState)
{
return isTargetFadeFinished(goalState) && isBrowserFadeFinished(goalState);
}
@@ -71,7 +71,7 @@ namespace openspace {
, _dimensions(DimensionsInfo, glm::vec2(0.f), glm::vec2(0.f), glm::vec2(3000.f))
, _reload(ReloadInfo)
, _verticalFov(70.f)
, _syncViewWithWwt(false)
, _isSyncedWithWwt(false)
{
// Handle target dimension property
const Parameters p = codegen::bake<Parameters>(dictionary);
@@ -231,11 +231,11 @@ namespace openspace {
void RenderableSkyBrowser::syncWwtView() {
// If the camera is already synced, the browser is already initialized
if (!_syncViewWithWwt) {
_syncViewWithWwt = true;
if (!_isSyncedWithWwt) {
_isSyncedWithWwt = true;
// Start a thread to enable user interaction while sending the calls to WWT
_threadWwtMessages = std::thread([&] {
while (_syncViewWithWwt) {
while (_isSyncedWithWwt) {
glm::dvec2 aim{ 0.0 };
// Send a message just to establish contact
@@ -255,7 +255,7 @@ namespace openspace {
}
void RenderableSkyBrowser::stopSyncingWwtView() {
_syncViewWithWwt = false;
_isSyncedWithWwt = false;
if (_threadWwtMessages.joinable()) {
_threadWwtMessages.join();
@@ -151,7 +151,7 @@ namespace openspace {
ScreenSpaceSkyBrowser::~ScreenSpaceSkyBrowser() {
// Set flag to false so the thread can exit
_syncViewWithWwt = false;
_isSyncedWithWwt = false;
if (_threadWwtMessages.joinable()) {
_threadWwtMessages.join();
LINFO("Joined thread");
@@ -181,8 +181,8 @@ namespace openspace {
void ScreenSpaceSkyBrowser::startSyncingWithWwt() {
// If the camera is already synced, the browser is already syncing
if (!_syncViewWithWwt) {
_syncViewWithWwt = true;
if (!_isSyncedWithWwt) {
_isSyncedWithWwt = true;
// Set border color
setWebpageBorderColor(_borderColor.value());
// Track target
@@ -204,10 +204,14 @@ namespace openspace {
glm::dvec2 result = - convertToScreenSpace * resultRelativeOs;
return result;
}
/*
void ScreenSpaceBrowser::setXCallback(std::function<void()> callback) {
_originalDimensions.onChange(std::move(callback));
}
*/
bool ScreenSpaceSkyBrowser::deinitializeGL() {
// Set flag to false so the thread can exit
_syncViewWithWwt = false;
_isSyncedWithWwt = false;
if (_threadWwtMessages.joinable()) {
_threadWwtMessages.join();
LINFO("Joined thread");
@@ -223,24 +227,26 @@ namespace openspace {
bool ScreenSpaceSkyBrowser::isAnimated()
{
return _fovIsAnimated;
return _isFovAnimated;
}
void ScreenSpaceSkyBrowser::startFovAnimation(float fov)
{
_fovIsAnimated = true;
_isFovAnimated = true;
_endVfov = fov;
}
void ScreenSpaceSkyBrowser::incrementallyAnimateToFov(float deltaTime)
{
// If distance is small enough, stop animating
// If distance too large, keep animating. Else, stop animation
float diff = verticalFov() - _endVfov;
if (abs(diff) > _fovDiff) {
bool shouldAnimate = abs(diff) > _fovDiff;
if (shouldAnimate) {
setVerticalFovWithScroll(diff);
}
else {
_fovIsAnimated = false;
_isFovAnimated = false;
}
}
@@ -320,7 +326,7 @@ namespace openspace {
// Start a thread to enable user interaction while sending the calls to WWT
_threadWwtMessages = std::thread([&] {
while (_syncViewWithWwt) {
while (_isSyncedWithWwt) {
if (_skyTarget) {
// Message WorldWide Telescope current view
glm::dvec3 cartesian = _skyTarget->directionEquatorial();
+32 -25
View File
@@ -121,7 +121,7 @@ namespace openspace {
// If the ID changes for the corresponding browser, update
_skyBrowserId.onChange([&]() {
findSkyBrowser();
connectoToSkyBrowser();
});
// Always make sure that the target and browser are visible together
@@ -160,7 +160,7 @@ namespace openspace {
}
bool ScreenSpaceSkyTarget::findSkyBrowser() {
bool ScreenSpaceSkyTarget::connectoToSkyBrowser() {
_skyBrowser = dynamic_cast<ScreenSpaceSkyBrowser*>(
global::renderEngine->screenSpaceRenderable(_skyBrowserId.value()));
matchAppearanceToSkyBrowser();
@@ -277,8 +277,10 @@ namespace openspace {
}
glm::dvec3 ScreenSpaceSkyTarget::directionGalactic() const {
glm::dmat4 rotation = glm::inverse(
global::navigationHandler->camera()->viewRotationMatrix());
global::navigationHandler->camera()->viewRotationMatrix()
);
glm::dvec4 position = glm::dvec4(_cartesianPosition.value(), 1.0);
return glm::normalize(rotation * position);
@@ -330,43 +332,48 @@ namespace openspace {
return _isAnimated;
}
void ScreenSpaceSkyTarget::startAnimation(glm::dvec3 end, bool lockAfter)
void ScreenSpaceSkyTarget::startAnimation(glm::dvec3 end, bool shouldLockAfter)
{
_animationStart = glm::normalize(directionEquatorial());
_animationEnd = glm::normalize(end);
_lockAfterAnimation = lockAfter;
_shouldLockAfterAnimation = shouldLockAfter;
_isAnimated = true;
}
void ScreenSpaceSkyTarget::animateToCoordinate(float deltaTime)
void ScreenSpaceSkyTarget::incrementallyAnimateToCoordinate(float deltaTime)
{
// Find smallest angle between the two vectors
double smallestAngle = skybrowser::angleVector(_animationStart, _animationEnd);
// Only keep animating when target is not at final position
if (smallestAngle <= _stopAnimationThreshold) {
bool shouldAnimate = smallestAngle > _stopAnimationThreshold;
// Only keep animating when target is not at goal position
if (shouldAnimate) {
glm::dmat4 rotMat = skybrowser::incrementalAnimationMatrix(
_animationStart,
_animationEnd,
deltaTime,
_animationSpeed
);
// Rotate target direction
glm::dvec3 newDir = rotMat * glm::dvec4(_animationStart, 1.0);
// Convert to screen space
_cartesianPosition = skybrowser::equatorialToScreenSpace(newDir);
// Update position
_animationStart = glm::normalize(newDir);
}
else {
// Set the exact target position
_cartesianPosition = skybrowser::equatorialToScreenSpace(_animationEnd);
_isAnimated = false;
// Lock target when it first arrives to the position
if (!isLocked() && _lockAfterAnimation) {
if (!isLocked() && _shouldLockAfterAnimation) {
lock();
}
return;
}
glm::dmat4 rotMat = skybrowser::incrementalAnimationMatrix(
_animationStart,
_animationEnd,
deltaTime,
_animationSpeed
);
// Rotate target direction
glm::dvec3 newDir = rotMat * glm::dvec4(_animationStart, 1.0);
// Convert to screen space
_cartesianPosition = skybrowser::equatorialToScreenSpace(newDir);
// Update position
_animationStart = glm::normalize(newDir);
}
}
glm::dvec3 ScreenSpaceSkyTarget::directionEquatorial() const {
+3 -3
View File
@@ -131,7 +131,7 @@ namespace openspace::skybrowser {
return windowRatio.x / windowRatio.y;
}
bool coordinateIsInView(glm::dvec3 equatorial) {
bool isCoordinateInView(glm::dvec3 equatorial) {
// Check if image coordinate is within current FOV
glm::dvec3 coordsScreen = equatorialToScreenSpace(equatorial);
double r = static_cast<float>(windowRatio());
@@ -191,7 +191,7 @@ namespace openspace::skybrowser {
namespace openspace::wwtmessage {
// WWT messages
ghoul::Dictionary moveCamera(const glm::dvec2 celestCoords, const double fov,
const double roll, const bool moveInstantly) {
const double roll, const bool shouldMoveInstantly) {
using namespace std::string_literals;
ghoul::Dictionary msg;
@@ -201,7 +201,7 @@ namespace openspace::wwtmessage {
msg.setValue("dec", celestCoords.y);
msg.setValue("fov", fov);
msg.setValue("roll", roll);
msg.setValue("instant", moveInstantly);
msg.setValue("instant", shouldMoveInstantly);
return msg;
}