| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include "NavigationAnimation.h" |
| | #include <Inventor/nodes/SoCamera.h> |
| |
|
| | #include <numbers> |
| |
|
| | using namespace Gui; |
| |
|
| | NavigationAnimation::NavigationAnimation(NavigationStyle* navigation) |
| | : navigation(navigation) |
| | {} |
| |
|
| | void NavigationAnimation::updateCurrentValue(const QVariant& value) |
| | { |
| | if (state() != QAbstractAnimation::State::Running) { |
| | return; |
| | } |
| | update(value); |
| | } |
| |
|
| | void NavigationAnimation::onStop([[maybe_unused]] bool finished) |
| | {} |
| |
|
| | FixedTimeAnimation::FixedTimeAnimation( |
| | NavigationStyle* navigation, |
| | const SbRotation& orientation, |
| | const SbVec3f& rotationCenter, |
| | const SbVec3f& translation, |
| | int duration, |
| | const QEasingCurve::Type easingCurve |
| | ) |
| | : NavigationAnimation(navigation) |
| | , targetOrientation(orientation) |
| | , targetTranslation(translation) |
| | , rotationCenter(rotationCenter) |
| | { |
| | setDuration(duration); |
| | setStartValue(0.0); |
| | setEndValue(duration * 1.0); |
| | setEasingCurve(easingCurve); |
| | } |
| |
|
| | void FixedTimeAnimation::initialize() |
| | { |
| | #if (COIN_MAJOR_VERSION * 100 + COIN_MINOR_VERSION * 10 + COIN_MICRO_VERSION < 403) |
| | navigation->findBoundingSphere(); |
| | #endif |
| |
|
| | prevAngle = 0; |
| | prevTranslation = SbVec3f(0, 0, 0); |
| |
|
| | |
| | |
| | SbVec3f rotationAxisPost; |
| | float angle; |
| | SbRotation(navigation->getCamera()->orientation.getValue().inverse() * targetOrientation) |
| | .getValue(rotationAxisPost, angle); |
| | if (angle > std::numbers::pi) { |
| | angle -= float(2 * std::numbers::pi); |
| | } |
| |
|
| | |
| | navigation->getCamera()->orientation.getValue().inverse().multVec(rotationAxisPost, rotationAxis); |
| |
|
| | angularVelocity = angle / duration(); |
| | linearVelocity = targetTranslation / duration(); |
| | } |
| |
|
| | |
| | |
| | |
| | void FixedTimeAnimation::update(const QVariant& value) |
| | { |
| | SoCamera* camera = navigation->getCamera(); |
| | if (!camera) { |
| | return; |
| | } |
| |
|
| | float angle = value.toFloat() * angularVelocity; |
| | SbVec3f translation = value.toFloat() * linearVelocity; |
| |
|
| | SbRotation rotation(rotationAxis, angle - prevAngle); |
| |
|
| | camera->position = camera->position.getValue() - prevTranslation; |
| | navigation->reorientCamera(camera, rotation, rotationCenter); |
| | camera->position = camera->position.getValue() + translation; |
| |
|
| | prevAngle = angle; |
| | prevTranslation = translation; |
| | } |
| |
|
| | |
| | |
| | |
| | void FixedTimeAnimation::onStop(bool finished) |
| | { |
| | if (finished) { |
| | SoCamera* camera = navigation->getCamera(); |
| | if (!camera) { |
| | return; |
| | } |
| |
|
| | |
| | camera->orientation = targetOrientation; |
| | camera->position = camera->position.getValue() + targetTranslation - prevTranslation; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | SpinningAnimation::SpinningAnimation(NavigationStyle* navigation, const SbVec3f& axis, float velocity) |
| | : NavigationAnimation(navigation) |
| | , rotationAxis(axis) |
| | { |
| | setDuration((2 * std::numbers::pi / velocity) * 1000.0); |
| | setStartValue(0.0); |
| | setEndValue(2 * std::numbers::pi); |
| | setLoopCount(-1); |
| | } |
| |
|
| | void SpinningAnimation::initialize() |
| | { |
| | #if (COIN_MAJOR_VERSION * 100 + COIN_MINOR_VERSION * 10 + COIN_MICRO_VERSION < 403) |
| | navigation->findBoundingSphere(); |
| | #endif |
| |
|
| | prevAngle = 0; |
| |
|
| | navigation->setViewing(true); |
| | navigation->setViewingMode(NavigationStyle::SPINNING); |
| | } |
| |
|
| | |
| | |
| | |
| | void SpinningAnimation::update(const QVariant& value) |
| | { |
| | SoCamera* camera = navigation->getCamera(); |
| | if (!camera) { |
| | return; |
| | } |
| |
|
| | SbRotation deltaRotation = SbRotation(rotationAxis, value.toFloat() - prevAngle); |
| | navigation->reorientCamera(camera, deltaRotation); |
| |
|
| | prevAngle = value.toFloat(); |
| | } |
| |
|
| | |
| | |
| | |
| | void SpinningAnimation::onStop([[maybe_unused]] bool finished) |
| | { |
| | if (navigation->getViewingMode() != NavigationStyle::SPINNING) { |
| | return; |
| | } |
| | navigation->setViewingMode( |
| | navigation->isViewing() ? NavigationStyle::IDLE : NavigationStyle::INTERACT |
| | ); |
| | } |
| |
|