-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fire 34747: Refactor for Base/Delta-Rotations, bug fixes #51
Open
AngeldarkRaymaker
wants to merge
12
commits into
FirestormViewer:master
Choose a base branch
from
AngeldarkRaymaker:FIRE-34747
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+834
−758
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8a228da
FIRE-34747: Move FSJointPose to own class
AngeldarkRaymaker 16a0431
FIRE-34747: Tidy up UI code behind
AngeldarkRaymaker 951ca0a
FIRE-34747: Refactor poser to work in deltas only
AngeldarkRaymaker aad003c
FIRE-34747: Update
AngeldarkRaymaker 572cea4
FIRE-34747: Tidy up and add UI cues to own work
AngeldarkRaymaker b8fd571
FIRE-34747: Keep scroll lists up to date
AngeldarkRaymaker d38a74e
Merge branch 'FirestormViewer:master' into FIRE-34747
AngeldarkRaymaker 1b3b086
FIRE-34747: Fix collision volumes
AngeldarkRaymaker 0f9776d
Merge branch 'FirestormViewer:master' into FIRE-34747
AngeldarkRaymaker bc2c5e7
FIRE-34747: Review fixes
AngeldarkRaymaker 04e7412
FIRE-34747: More review fixes
AngeldarkRaymaker 2196b66
Merge branch 'FirestormViewer:master' into FIRE-34747
AngeldarkRaymaker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,232 @@ | ||
/** | ||
* @file fsjointpose.cpp | ||
* @brief Container for the pose of a joint. | ||
* | ||
* $LicenseInfo:firstyear=2024&license=viewerlgpl$ | ||
* Phoenix Firestorm Viewer Source Code | ||
* Copyright (c) 2024 Angeldark Raymaker @ Second Life | ||
* | ||
* This library 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; | ||
* version 2.1 of the License only. | ||
* | ||
* This library 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 this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA | ||
* $/LicenseInfo$ | ||
*/ | ||
|
||
#include <deque> | ||
#include <boost/algorithm/string.hpp> | ||
#include "fsposingmotion.h" | ||
#include "llcharacter.h" | ||
|
||
constexpr size_t MaximumUndoQueueLength = 20; | ||
|
||
/// <summary> | ||
/// The constant time interval, in seconds, specifying whether an 'undo' value should be added. | ||
/// </summary> | ||
constexpr std::chrono::duration<double> UndoUpdateInterval = std::chrono::duration<double>(0.3); | ||
|
||
FSJointPose::FSJointPose(LLJoint* joint, U32 usage, bool isCollisionVolume) | ||
{ | ||
mJointState = new LLJointState; | ||
mJointState->setJoint(joint); | ||
mJointState->setUsage(usage); | ||
|
||
mJointName = joint->getName(); | ||
mIsCollisionVolume = isCollisionVolume; | ||
|
||
mRotation = FSJointRotation(joint->getRotation()); | ||
mBeginningPosition = joint->getPosition(); | ||
mBeginningScale = joint->getScale(); | ||
} | ||
|
||
void FSJointPose::setPositionDelta(const LLVector3& pos) | ||
{ | ||
addToUndo(mPositionDelta, &mUndonePositionIndex, &mLastSetPositionDeltas, &mTimeLastUpdatedPosition); | ||
mPositionDelta.set(pos); | ||
} | ||
|
||
void FSJointPose::setRotationDelta(const LLQuaternion& rot) | ||
{ | ||
addToUndo(mRotation, &mUndoneRotationIndex, &mLastSetRotationDeltas, &mTimeLastUpdatedRotation); | ||
mRotation = FSJointRotation(mRotation.baseRotation, rot); | ||
} | ||
|
||
void FSJointPose::setScaleDelta(LLVector3 scale) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
addToUndo(mScaleDelta, &mUndoneScaleIndex, &mLastSetScaleDeltas, &mTimeLastUpdatedScale); | ||
mScaleDelta.set(scale); | ||
} | ||
|
||
void FSJointPose::undoLastPositionChange() | ||
{ | ||
mPositionDelta.set(undoLastChange(mPositionDelta, &mUndonePositionIndex, &mLastSetPositionDeltas)); | ||
} | ||
|
||
void FSJointPose::undoLastRotationChange() | ||
{ | ||
mRotation.set(undoLastChange(mRotation, &mUndoneRotationIndex, &mLastSetRotationDeltas)); | ||
} | ||
|
||
void FSJointPose::undoLastScaleChange() { mScaleDelta.set(undoLastChange(mScaleDelta, &mUndoneScaleIndex, &mLastSetScaleDeltas)); } | ||
|
||
void FSJointPose::redoLastPositionChange() | ||
{ | ||
mPositionDelta.set(redoLastChange(mPositionDelta, &mUndonePositionIndex, &mLastSetPositionDeltas)); | ||
} | ||
|
||
void FSJointPose::redoLastRotationChange() | ||
{ | ||
mRotation.set(redoLastChange(mRotation, &mUndoneRotationIndex, &mLastSetRotationDeltas)); | ||
} | ||
|
||
void FSJointPose::redoLastScaleChange() { mScaleDelta.set(redoLastChange(mScaleDelta, &mUndoneScaleIndex, &mLastSetScaleDeltas)); } | ||
|
||
template <typename T> | ||
inline void FSJointPose::addToUndo(T delta, size_t* undoIndex, std::deque<T>* dequeue, | ||
std::chrono::system_clock::time_point* timeLastUpdated) | ||
{ | ||
auto timeIntervalSinceLastChange = std::chrono::system_clock::now() - *timeLastUpdated; | ||
*timeLastUpdated = std::chrono::system_clock::now(); | ||
|
||
if (timeIntervalSinceLastChange < UndoUpdateInterval) | ||
return; | ||
|
||
if (*undoIndex > 0) | ||
{ | ||
for (size_t i = 0; i < *undoIndex; i++) | ||
dequeue->pop_front(); | ||
|
||
*undoIndex = 0; | ||
} | ||
|
||
dequeue->push_front(delta); | ||
|
||
while (dequeue->size() > MaximumUndoQueueLength) | ||
dequeue->pop_back(); | ||
} | ||
|
||
template <typename T> T FSJointPose::undoLastChange(T thingToSet, size_t* undoIndex, std::deque<T>* dequeue) | ||
{ | ||
if (dequeue->empty()) | ||
return thingToSet; | ||
|
||
if (*undoIndex == 0) | ||
dequeue->push_front(thingToSet); | ||
|
||
*undoIndex += 1; | ||
*undoIndex = llclamp(*undoIndex, 0, dequeue->size() - 1); | ||
|
||
return dequeue->at(*undoIndex); | ||
} | ||
|
||
template <typename T> T FSJointPose::redoLastChange(T thingToSet, size_t* undoIndex, std::deque<T>* dequeue) | ||
{ | ||
if (dequeue->empty()) | ||
return thingToSet; | ||
if (*undoIndex == 0) | ||
return thingToSet; | ||
|
||
*undoIndex -= 1; | ||
*undoIndex = llclamp(*undoIndex, 0, dequeue->size() - 1); | ||
T result = dequeue->at(*undoIndex); | ||
if (*undoIndex == 0) | ||
dequeue->pop_front(); | ||
|
||
return result; | ||
} | ||
|
||
void FSJointPose::recaptureJoint() | ||
{ | ||
if (mIsCollisionVolume) | ||
return; | ||
|
||
LLJoint* joint = mJointState->getJoint(); | ||
if (!joint) | ||
return; | ||
|
||
addToUndo(mRotation, &mUndoneRotationIndex, &mLastSetRotationDeltas, &mTimeLastUpdatedRotation); | ||
mRotation = FSJointRotation(joint->getRotation()); | ||
} | ||
|
||
void FSJointPose::swapRotationWith(FSJointPose* oppositeJoint) | ||
{ | ||
if (!oppositeJoint) | ||
return; | ||
if (mIsCollisionVolume) | ||
return; | ||
|
||
LLJoint* joint = mJointState->getJoint(); | ||
if (!joint) | ||
return; | ||
|
||
auto tempRot = FSJointRotation(mRotation); | ||
mRotation = FSJointRotation(oppositeJoint->mRotation); | ||
oppositeJoint->mRotation = tempRot; | ||
} | ||
|
||
void FSJointPose::revertJointScale() | ||
{ | ||
LLJoint* joint = mJointState->getJoint(); | ||
if (!joint) | ||
return; | ||
|
||
joint->setScale(mBeginningScale); | ||
} | ||
|
||
void FSJointPose::revertJointPosition() | ||
{ | ||
LLJoint* joint = mJointState->getJoint(); | ||
if (!joint) | ||
return; | ||
|
||
joint->setPosition(mBeginningPosition); | ||
} | ||
|
||
void FSJointPose::revertCollisionVolume() | ||
{ | ||
if (!mIsCollisionVolume) | ||
return; | ||
|
||
LLJoint* joint = mJointState->getJoint(); | ||
if (!joint) | ||
return; | ||
|
||
joint->setRotation(mRotation.baseRotation); | ||
joint->setPosition(mBeginningPosition); | ||
joint->setScale(mBeginningScale); | ||
} | ||
|
||
void FSJointPose::reflectRotation() | ||
{ | ||
if (mIsCollisionVolume) | ||
return; | ||
|
||
mRotation.reflectRotation(); | ||
} | ||
|
||
void FSJointPose::zeroBaseRotation() | ||
{ | ||
if (mIsCollisionVolume) | ||
return; | ||
|
||
mRotation.baseRotation = LLQuaternion::DEFAULT; | ||
} | ||
|
||
bool FSJointPose::isBaseRotationZero() const | ||
{ | ||
if (mIsCollisionVolume) | ||
return true; | ||
|
||
return mRotation.baseRotation == LLQuaternion::DEFAULT; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to add the header file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot a bunch of them... all added, thanks