Announcement

Collapse
No announcement yet.

FQuat: add 45 degrees to the current value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    FQuat: add 45 degrees to the current value

    Hey. I cannot create the correct FQuat. I want to add to the current Relative Rotation for any axis for example 45 degrees.


    Code:
    FRotator Clear(0.0f, 0.0f, 0.0f);
    FQuat Current(GetRelativeRotation());
    FRotator Delta = SetAxisValueForwardType(Axis, Angle, Clear); // this creates Clear(45, 0, 0) or Clear(0, 45, 0) or Clear(0, 0, 45)
    FQuat DeltaQuat(Delta);
    
    FQuat AngleRotateQuat = Current * DeltaQuat; // local
    
    SetRelativeRotation(AngleRotateQuat);
    But this code does not work correctly, if the Y axis is not 0, then the Z axis shift is wrong.
    Any ideas?
    Plugin for HISM and ISMC https://www.unrealengine.com/marketp...nstance-editor

    #2
    I cant find description of method SetAxisValueForwardType. Is it a custom method?

    Anyway, is there a possibility that you've messed angle and radian? Or have you calculated correctly of roll\ pitch \yaw?´╝łnot x, y ,z)

    Comment


      #3
      Originally posted by wzspdw View Post
      I cant find description of method SetAxisValueForwardType. Is it a custom method?

      Anyway, is there a possibility that you've messed angle and radian? Or have you calculated correctly of roll\ pitch \yaw?´╝łnot x, y ,z)
      the SetAxisValueForwardType method adds 45 degrees to any axis of the Clear vector (0,0,0).

      i checked using UE_LOG and the angles are correct
      Delta is equal to Delta (45, 0, 0) or Delta (0, 45, 0) or Delta (0, 0, 45)
      Plugin for HISM and ISMC https://www.unrealengine.com/marketp...nstance-editor

      Comment


        #4
        Depends - do you want to add 45 degrees in the quaternions local-space or world-space?

        From Quat.h:

        Code:
        Example: LocalToWorld = (LocalToWorld * DeltaRotation) will change rotation in local space by DeltaRotation.
        Example: LocalToWorld = (DeltaRotation * LocalToWorld) will change rotation in world space by DeltaRotation.
        Also, that function you created is not stricly neccesary and will result in more conversions. FQuat already has a constructor for creating a Quat from an axis and angle.

        Code:
        FQuat(FVector Axis, float AngleRad);

        Comment


          #5
          I need a Relative rotation relative to the Parent Component, I somehow have to indicate that the rotation around the component


          Example: LocalToWorld = (LocalToWorld * DeltaRotation) will change rotation in local space by DeltaRotation.
          LocalToWorld = (DeltaRotation * LocalToWorld) will change rotation in world space by DeltaRotation.
          AngleRotateQuat = Current * DeltaQuat; // local
          AngleRotateQuat = DeltaQuat * Current; // world

          both options are incorrect, if not Z, then the Y-axis rotation will be incorrect. This only works for World or Local Rotation
          Last edited by Babush61; 10-26-2020, 12:18 PM.
          Plugin for HISM and ISMC https://www.unrealengine.com/marketp...nstance-editor

          Comment


            #6
            I still can't solve the problem, maybe I don't understand something in FQuat. If the Y angle of the component is greater than 0, then the X rotation is incorrect, the X rotation is as if I rotated the root component The following code gives different results:


            Code:
            FRotator delta (0, 0, 45);
            AddRelativeRotation(delta);
            And code 2

            Code:
            FRotator delta (0, 0, 45);
            AddRelativeRotation(delta.Quaternion());
            Is this a bug or am I creating FQuat incorrectly?
            Plugin for HISM and ISMC https://www.unrealengine.com/marketp...nstance-editor

            Comment


              #7
              A quaternion encodes an angle rotation about a specific axis. If you want to increase the quaternion's current rotation by 45 degrees, extract the axis and angle, add 45 degrees to the angle, then reconstruct the quaternion with your new axis/angle:

              Code:
              FQuat rotation(....);
              FVector axis;
              float angleRadians;
              rotation.ToAxisAndAngle(axis, angleRadians);
              angleRadians += 3.14 / 4; //add 45 degrees
              rotation = FQuat(axis, angleRadians);

              Comment


                #8
                @Teh_Masterer_ this also does not work correctly, the rotation is done like World Rotation

                Code:
                FQuat q1;
                if (Axis == EAxisType::X)
                {
                q1 = FQuat(FVector::ForwardVector, FMath::DegreesToRadians(Angle));
                }
                else if (Axis == EAxisType::Y)
                {
                q1 = FQuat(FVector::RightVector, FMath::DegreesToRadians(Angle *-1));
                }
                else if (Axis == EAxisType::Z)
                {
                q1 = FQuat(FVector::UpVector, FMath::DegreesToRadians(Angle));
                }
                
                AddRelativeRotation(q1);
                This code is identical
                Code:
                FRotator delta (0, 0, 45);
                AddWorldRotation(delta)

                This code works correctly for X and Y, but does not work correctly for Z axis if X and Y are not 0
                Code:
                FQuat q1;
                if (Axis == EAxisType::X)
                {
                q1 = FQuat(GetForwardVector(), FMath::DegreesToRadians(Angle));
                }
                else if (Axis == EAxisType::Y)
                {
                q1 = FQuat(GetRightVector(), FMath::DegreesToRadians(Angle *-1));
                }
                else if (Axis == EAxisType::Z)
                {
                q1 = FQuat(GetUpVector(), FMath::DegreesToRadians(Angle));
                
                
                AddRelativeRotation(q1);
                }
                Last edited by Babush61; 10-31-2020, 08:03 AM.
                Plugin for HISM and ISMC https://www.unrealengine.com/marketp...nstance-editor

                Comment


                  #9
                  Can you describe how the Z axis rotation is wrong? I'm having trouble understanding.

                  Also, the Z axis rotates in a different direction as opposed to X and Y. Try it in the editor with any object, adjust the rotation values under the Transform section in the details pane. Does using (0, 0, -1) for your Z vector work better?

                  Comment


                    #10
                    @Teh_Masterer_
                    original position

                    Click image for larger versionName:	UE4Editor_Oe889BbMpr.pngViews:	0Size:	523.8 KBID:	1828156

                    after applying FQuat
                    Click image for larger versionName:	UE4Editor_jmTPfM0ZIN.pngViews:	0Size:	514.6 KBID:	1828157
                    Not only rotate along the X axis, it rotates along the two axes X and Z.



                    on video up to 7 seconds this is use

                    Code:
                    FRotator delta (0, 0, 45);
                    AddRelativeRotation (delta);
                    This is the correct result, after 7 seconds this is using

                    FRotator delta (0, 0, 45);
                    AddRelativeRotation (delta.Quaternion ());
                    Not only rotate along the X axis, it rotates along the two axes X and Z.


                    I think FQuat is not designed to use Relative Rotation, only Local Rotation or World Rotation

                    If
                    Code:
                    q1 = FQuat(FVector::ForwardVector, FMath::DegreesToRadians(Angle));
                    AngleRotateQuat = Current  * q1;
                    SetRelativeRotation(AngleRotateQuat);
                    Then for X and Y the result is correct, but the rotation along the Z axis will be incorrect

                    This also incorrect
                    Code:
                    q1 = FQuat(FVector::ForwardVector, FMath::DegreesToRadians(Angle));
                    AddRelativeRotation(AngleRotateQuat);
                    Last edited by Babush61; 11-01-2020, 09:51 AM.
                    Plugin for HISM and ISMC https://www.unrealengine.com/marketp...nstance-editor

                    Comment

                    Working...
                    X