bool Label::update(const glm::mat4& _mvp, const glm::vec2& _screenSize, float _zoomFract) { if (m_state == State::dead) { return false; } m_occluded = false; bool ruleSatisfied = updateScreenTransform(_mvp, _screenSize, true); // one of the label rules has not been satisfied if (!ruleSatisfied) { if (m_state == State::wait_occ) { // go to dead state, this breaks determinism, but reduce potential // label set since a lot of discarded labels are discared for line // exceed (lots of tiny small lines on a curve for example), which // won't have their rule satisfied enterState(State::dead, 0.0); pushTransform(); } else { enterState(State::sleep, 0.0); pushTransform(); } return false; } // update the view-space bouding box updateBBoxes(_zoomFract); // checks whether the label is out of the viewport if (offViewport(_screenSize)) { enterState(State::out_of_screen, 0.0); } return true; }
bool Label::updateState(const glm::mat4& _mvp, const glm::vec2& _screenSize, float _dt, float _zoomFract) { if (m_currentState == State::dead) { return false; } bool occludedLastFrame = m_occludedLastFrame; m_occludedLastFrame = false; bool ruleSatisfied = updateScreenTransform(_mvp, _screenSize); // one of the label rules has not been satisfied if (!ruleSatisfied) { // go to dead state, this breaks determinism, but reduce potential label set since a lot // of discarded labels are discared for line exceed (lots of tiny small lines on a curve // for example), which won't have their rule satisfied enterState(State::dead, 0.0); return false; } // update the view-space bouding box updateBBoxes(_zoomFract); // checks whether the label is out of the viewport if (offViewport(_screenSize)) { enterState(State::out_of_screen, 0.0); } bool animate = false; switch (m_currentState) { case State::visible: if (occludedLastFrame) { m_fade = FadeEffect(false, m_options.hideTransition.ease, m_options.hideTransition.time); enterState(State::fading_out, 1.0); } break; case State::fading_in: if (occludedLastFrame) { enterState(State::sleep, 0.0); break; } setAlpha(m_fade.update(_dt)); animate = true; if (m_fade.isFinished()) { enterState(State::visible, 1.0); } break; case State::fading_out: setAlpha(m_fade.update(_dt)); animate = true; if (m_fade.isFinished()) { enterState(State::sleep, 0.0); } break; case State::out_of_screen: if (!offViewport(_screenSize)) { enterState(State::wait_occ, 0.0); } break; case State::wait_occ: if (m_occlusionSolved) { if (occludedLastFrame) { enterState(State::dead, 0.0); // dead } else { m_fade = FadeEffect(true, m_options.showTransition.ease, m_options.showTransition.time); enterState(State::fading_in, 0.0); } } break; case State::sleep: if (!occludedLastFrame) { m_fade = FadeEffect(true, m_options.showTransition.ease, m_options.showTransition.time); enterState(State::fading_in, 0.0); } break; case State::dead: break; } return animate; }
bool Label::evalState(const glm::vec2& _screenSize, float _dt) { bool animate = false; switch (m_state) { case State::visible: if (m_occluded) { m_fade = FadeEffect(false, m_options.hideTransition.ease, m_options.hideTransition.time); enterState(State::fading_out, 1.0); animate = true; } break; case State::fading_in: if (m_occluded) { enterState(State::sleep, 0.0); // enterState(State::fading_out, m_transform.state.alpha); // animate = true; break; } setAlpha(m_fade.update(_dt)); animate = true; if (m_fade.isFinished()) { enterState(State::visible, 1.0); } break; case State::fading_out: setAlpha(m_fade.update(_dt)); animate = true; if (m_fade.isFinished()) { enterState(State::sleep, 0.0); } break; case State::out_of_screen: if (!offViewport(_screenSize)) { enterState(State::wait_occ, 0.0); } break; case State::wait_occ: if (m_occluded) { enterState(State::dead, 0.0); } else { m_fade = FadeEffect(true, m_options.showTransition.ease, m_options.showTransition.time); enterState(State::fading_in, 0.0); animate = true; } break; case State::skip_transition: if (m_occluded) { enterState(State::dead, 0.0); } else { enterState(State::visible, 1.0); } break; case State::sleep: if (!m_occluded) { m_fade = FadeEffect(true, m_options.showTransition.ease, m_options.showTransition.time); enterState(State::fading_in, 0.0); animate = true; } break; case State::dead: break; } m_occludedLastFrame = m_occluded; m_occluded = false; return animate; }