1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0032570: Visualization, AIS_AnimationObject - define rotation around axis

When using AIS_AnimationObject, linear interpolation is performed from one gp_Trsf transformation to another.
But when an object rotates around a specific axis, the object moves not along a linear trajectory,
but along a circle. Therefore, a separate class AIS_AnimationAxisRotation was created that
allows to animate rotation around a specific axis.

Test case tests/v3d/bugs/bug32570 was added.
This commit is contained in:
mzernova
2021-12-27 23:57:13 +00:00
committed by Vadim Glukhikh
parent d22b135217
commit 53eae1a935
9 changed files with 346 additions and 82 deletions

View File

@@ -20,6 +20,7 @@
#include <ViewerTest.hxx>
#include <AIS_AnimationAxisRotation.hxx>
#include <AIS_AnimationCamera.hxx>
#include <AIS_AnimationObject.hxx>
#include <AIS_Axis.hxx>
@@ -7596,6 +7597,11 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
gp_XYZ aLocPnts [2] = { aTrsfs[0].TranslationPart(), aTrsfs[1].TranslationPart() };
Standard_Real aScales [2] = { aTrsfs[0].ScaleFactor(), aTrsfs[1].ScaleFactor() };
Standard_Boolean isTrsfSet = Standard_False;
gp_Ax1 anAxis;
Standard_Real anAngles[2] = { 0.0, 0.0 };
Standard_Boolean isAxisRotationSet = Standard_False;
Standard_Integer aTrsfArgIter = anArgIter + 1;
for (; aTrsfArgIter < theArgNb; ++aTrsfArgIter)
{
@@ -7643,13 +7649,45 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
}
aScales[anIndex] = aScaleStr.RealValue();
}
else if (aTrsfArg == "-axis")
{
isAxisRotationSet = Standard_True;
gp_XYZ anOrigin, aDirection;
if (aTrsfArgIter + 6 >= theArgNb
|| !parseXYZ (theArgVec + aTrsfArgIter + 1, anOrigin)
|| !parseXYZ (theArgVec + aTrsfArgIter + 4, aDirection))
{
Message::SendFail() << "Syntax error at " << aTrsfArg;
return 1;
}
anAxis.SetLocation (anOrigin);
anAxis.SetDirection (aDirection);
aTrsfArgIter += 6;
}
else if (aTrsfArg.StartsWith ("-ang"))
{
isAxisRotationSet = Standard_True;
if (++aTrsfArgIter >= theArgNb)
{
Message::SendFail() << "Syntax error at " << aTrsfArg;
return 1;
}
const TCollection_AsciiString anAngleStr (theArgVec[aTrsfArgIter]);
if (!anAngleStr.IsRealValue (Standard_True))
{
Message::SendFail() << "Syntax error at " << aTrsfArg;
return 1;
}
anAngles[anIndex] = anAngleStr.RealValue();
}
else
{
anArgIter = aTrsfArgIter - 1;
break;
}
}
if (!isTrsfSet)
if (!isTrsfSet && !isAxisRotationSet)
{
Message::SendFail() << "Syntax error at " << anArg;
return 1;
@@ -7658,15 +7696,23 @@ static Standard_Integer VAnimation (Draw_Interpretor& theDI,
{
anArgIter = theArgNb;
}
Handle(AIS_BaseAnimationObject) anObjAnimation;
if (isTrsfSet)
{
aTrsfs[0].SetRotation (aRotQuats[0]);
aTrsfs[1].SetRotation (aRotQuats[1]);
aTrsfs[0].SetTranslationPart (aLocPnts[0]);
aTrsfs[1].SetTranslationPart (aLocPnts[1]);
aTrsfs[0].SetScaleFactor (aScales[0]);
aTrsfs[1].SetScaleFactor (aScales[1]);
aTrsfs[0].SetRotation (aRotQuats[0]);
aTrsfs[1].SetRotation (aRotQuats[1]);
aTrsfs[0].SetTranslationPart (aLocPnts[0]);
aTrsfs[1].SetTranslationPart (aLocPnts[1]);
aTrsfs[0].SetScaleFactor (aScales[0]);
aTrsfs[1].SetScaleFactor (aScales[1]);
Handle(AIS_AnimationObject) anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
anObjAnimation = new AIS_AnimationObject (anAnimation->Name(), aCtx, anObject, aTrsfs[0], aTrsfs[1]);
}
else
{
anObjAnimation = new AIS_AnimationAxisRotation (anAnimation->Name(), aCtx, anObject, anAxis,
anAngles[0] * (M_PI / 180.0), anAngles[1] * (M_PI / 180.0));
}
replaceAnimation (aParentAnimation, anAnimation, anObjAnimation);
}
else if (anArg == "-viewtrsf"
@@ -14394,6 +14440,11 @@ Object animation:
-rotX object Orientations pair (quaternions)
-scaleX object Scale factors pair (quaternions)
vanim name -object [-axis OX OY OZ DX DY DZ] [-ang1 A] [-ang2 A]
-axis rotation axis
-ang1 start rotation angle in degrees
-ang2 end rotation angle in degrees
Custom callback:
vanim name -invoke "Command Arg1 Arg2 %Pts %LocalPts %Normalized ArgN"