forked from FreeCAD/FreeCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Animations are played through an Animator - Animations now have a fixed duration - The animation duration can be changed in the preferences - Fix animations when using the two arrows above the NaviCube
- Loading branch information
Showing
12 changed files
with
503 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
/**************************************************************************** | ||
* * | ||
* Copyright (c) 2023 Bas Ruigrok (Rexbas) <rexbasie@gmail.com> * | ||
* * | ||
* This file is part of FreeCAD. * | ||
* * | ||
* FreeCAD is free software: you can redistribute it and/or modify it * | ||
* under the terms of the GNU Lesser General Public License as * | ||
* published by the Free Software Foundation, either version 2.1 of the * | ||
* License, or (at your option) any later version. * | ||
* * | ||
* FreeCAD is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||
* Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public * | ||
* License along with FreeCAD. If not, see * | ||
* <https://www.gnu.org/licenses/>. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "PreCompiled.h" | ||
#include "NavigationAnimation.h" | ||
#include <App/Application.h> | ||
#include "View3DInventorViewer.h" | ||
|
||
using namespace Gui; | ||
|
||
NavigationAnimation::NavigationAnimation() | ||
{ | ||
animationDuration = App::GetApplication() | ||
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") | ||
->GetFloat("AnimationDuration", 0.25f); | ||
} | ||
|
||
void NavigationAnimation::reset(const SoCamera* camera) | ||
{ | ||
targetOrientation = camera->orientation.getValue(); | ||
targetTranslation = SbVec3f(0, 0, 0); | ||
totalTranslation = SbVec3f(0, 0, 0); | ||
} | ||
|
||
void NavigationAnimation::setDuration(float duration) | ||
{ | ||
animationDuration = duration; | ||
} | ||
|
||
void NavigationAnimation::setTargetOrientation(const SbRotation& orientation) | ||
{ | ||
targetOrientation = orientation; | ||
} | ||
|
||
void NavigationAnimation::translate(SbVec3f translation) | ||
{ | ||
targetTranslation = translation; | ||
} | ||
|
||
void NavigationAnimation::initialize(const NavigationStyle* navigation) | ||
{ | ||
// Remember the start time of the animation | ||
startTime = SbTime::getTimeOfDay(); | ||
|
||
cameraStartOrientation = navigation->getCamera()->orientation.getValue(); | ||
|
||
// Get rotation center | ||
rotationCenter = navigation->getFocalPoint(); | ||
|
||
// Find an axis and angle to rotate from the camera orientation to the target orientation | ||
float angle; | ||
SbRotation(navigation->getCamera()->orientation.getValue().inverse() * targetOrientation).getValue(rotationAxis, angle); | ||
if (angle > M_PI) { | ||
angle -= 2 * M_PI; | ||
} | ||
|
||
angularVelocity = angle / animationDuration; | ||
linearVelocity = targetTranslation / animationDuration; | ||
} | ||
|
||
void NavigationAnimation::animate(NavigationStyle* navigation) | ||
{ | ||
// Calculate time since start of animation | ||
float activeDuration = (SbTime::getTimeOfDay() - startTime).getValue(); | ||
|
||
// Calculate the angle | ||
float angle = (activeDuration >= animationDuration ? animationDuration : activeDuration) * angularVelocity; | ||
SbRotation rotation(rotationAxis, angle); | ||
|
||
// Calculate the translation delta | ||
SbVec3f translationDelta = (activeDuration >= animationDuration ? animationDuration : activeDuration) * linearVelocity - totalTranslation; | ||
|
||
SbRotation newOrientation; | ||
if (activeDuration >= animationDuration) { | ||
// Animation is finished, set exact orientation and unschedule animation | ||
newOrientation = targetOrientation; | ||
navigation->getAnimator()->stop(); | ||
} | ||
else { | ||
newOrientation = cameraStartOrientation * rotation; | ||
} | ||
navigation->setCameraOrientation(newOrientation, rotationCenter, false, false, false); | ||
|
||
// Apply translation | ||
navigation->translateCamera(translationDelta, false, false); | ||
totalTranslation += translationDelta; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
/**************************************************************************** | ||
* * | ||
* Copyright (c) 2023 Bas Ruigrok (Rexbas) <rexbasie@gmail.com> * | ||
* * | ||
* This file is part of FreeCAD. * | ||
* * | ||
* FreeCAD is free software: you can redistribute it and/or modify it * | ||
* under the terms of the GNU Lesser General Public License as * | ||
* published by the Free Software Foundation, either version 2.1 of the * | ||
* License, or (at your option) any later version. * | ||
* * | ||
* FreeCAD is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||
* Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public * | ||
* License along with FreeCAD. If not, see * | ||
* <https://www.gnu.org/licenses/>. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef GUI_NAVIGATIONANIMATION_H | ||
#define GUI_NAVIGATIONANIMATION_H | ||
|
||
#include <Inventor/SbRotation.h> | ||
#include <Inventor/SbVec3f.h> | ||
#include <Inventor/nodes/SoCamera.h> | ||
#include "NavigationAnimator.h" | ||
|
||
namespace Gui | ||
{ | ||
|
||
class GuiExport NavigationAnimation | ||
{ | ||
public: | ||
NavigationAnimation(); | ||
void reset(const SoCamera* camera); | ||
void setDuration(float duration); | ||
void setTargetOrientation(const SbRotation& orientation); | ||
void translate(SbVec3f translation); | ||
|
||
private: | ||
SbTime startTime; | ||
float animationDuration; // [s] | ||
float angularVelocity; // [rad/s] | ||
SbVec3f linearVelocity; // [/s] | ||
|
||
SbRotation targetOrientation; | ||
SbVec3f targetTranslation; | ||
SbVec3f totalTranslation; | ||
|
||
SbVec3f rotationCenter; | ||
SbVec3f rotationAxis; | ||
SbRotation cameraStartOrientation; | ||
|
||
friend class NavigationAnimator; | ||
|
||
void initialize(const NavigationStyle* navigation); | ||
void animate(NavigationStyle* navigation); | ||
}; | ||
|
||
} // namespace Gui | ||
|
||
#endif // GUI_NAVIGATIONANIMATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
/**************************************************************************** | ||
* * | ||
* Copyright (c) 2023 Bas Ruigrok (Rexbas) <rexbasie@gmail.com> * | ||
* * | ||
* This file is part of FreeCAD. * | ||
* * | ||
* FreeCAD is free software: you can redistribute it and/or modify it * | ||
* under the terms of the GNU Lesser General Public License as * | ||
* published by the Free Software Foundation, either version 2.1 of the * | ||
* License, or (at your option) any later version. * | ||
* * | ||
* FreeCAD is distributed in the hope that it will be useful, but * | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||
* Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public * | ||
* License along with FreeCAD. If not, see * | ||
* <https://www.gnu.org/licenses/>. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "PreCompiled.h" | ||
#include "NavigationAnimator.h" | ||
#include "NavigationAnimation.h" | ||
#include "View3DInventorViewer.h" | ||
|
||
using namespace Gui; | ||
|
||
NavigationAnimator::NavigationAnimator(NavigationStyle* navigation) : navigation(navigation), animation(nullptr) | ||
{ | ||
sensor = new SoTimerSensor(NavigationAnimator::animateCB, navigation); | ||
sensor->setInterval(SbTime(1 / 60.0)); // Animate at 60 Hz | ||
} | ||
|
||
NavigationAnimator::~NavigationAnimator() | ||
{ | ||
stop(); | ||
delete sensor; | ||
} | ||
|
||
void NavigationAnimator::start(NavigationAnimation* animation) | ||
{ | ||
this->animation = animation; | ||
this->animation->initialize(navigation); | ||
if (!sensor->isScheduled()) { | ||
sensor->schedule(); | ||
navigation->interactiveCountInc(); | ||
} | ||
} | ||
|
||
void NavigationAnimator::stop() | ||
{ | ||
if (sensor->isScheduled()) { | ||
sensor->unschedule(); | ||
navigation->interactiveCountDec(); | ||
} | ||
} | ||
|
||
void NavigationAnimator::animateCB(void* data, SoSensor* sensor) | ||
{ | ||
Q_UNUSED(sensor); | ||
auto navigation = static_cast<NavigationStyle*>(data); | ||
navigation->getAnimator()->animation->animate(navigation); | ||
} |
Oops, something went wrong.