x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

What is the opposite function of RotateVector ?

I would like to have the opposite of RotateVector, that takes two vectors as input and returns a rotator. So not UnrotateVector.

In the following example, I know the return value, the input value A, and I want to know the B value. I think it's basic maths, but I got a bit lost in the C++ code and the rotation/transformation matrix. Can someone help me ?

Screenshot

Thanks.

Product Version: UE 4.15
Tags:
more ▼

asked Apr 03 '17 at 01:23 PM in Blueprint Scripting

avatar image

antoinegloum
54 6 13 14

avatar image antoinegloum Apr 04 '17 at 08:36 AM

I tried to explore the C++ source code, but I'm giving up. It's very complicated behind RotateVector

 FVector FRotator::RotateVector(const FVector& V) const
 {
   return FRotationMatrix(*this).TransformVector( V );
 } 
 
 FRotationMatrix(const FRotator& Rot)
     : FRotationTranslationMatrix(Rot, FVector::ZeroVector)
   { }
 
 FRotationTranslationMatrix::FRotationTranslationMatrix(const FRotator& Rot, const FVector& Origin)
 {
   float SP, SY, SR;
   float CP, CY, CR;
   FMath::SinCos(&SP, &CP, FMath::DegreesToRadians(Rot.Pitch));
   FMath::SinCos(&SY, &CY, FMath::DegreesToRadians(Rot.Yaw));
   FMath::SinCos(&SR, &CR, FMath::DegreesToRadians(Rot.Roll));
 
   M[0][0] = CP * CY;
   M[0][1] = CP * SY;
   M[0][2] = SP;
   M[0][3] = 0.f;
 
   M[1][0] = SR * SP * CY - CR * SY;
   M[1][1] = SR * SP * SY + CR * CY;
   M[1][2] = - SR * CP;
   M[1][3] = 0.f;
 
   M[2][0] = -( CR * SP * CY + SR * SY );
   M[2][1] = CY * SR - CR * SP * SY;
   M[2][2] = CR * CP;
   M[2][3] = 0.f;
 
   M[3][0] = Origin.X;
   M[3][1] = Origin.Y;
   M[3][2] = Origin.Z;
   M[3][3] = 1.f;
 }
 
 FVector4 FMatrix::TransformVector(const FVector& V) const
 {
   return TransformFVector4(FVector4(V.X,V.Y,V.Z,0.0f));
 }
 
 // Homogeneous transform.
 
 FVector4 FMatrix::TransformFVector4(const FVector4 &P) const
 {
   FVector4 Result;
   VectorRegister VecP = VectorLoadAligned(&P);
   VectorRegister VecR = VectorTransformVector(VecP, this);
   VectorStoreAligned(VecR, &Result);
   return Result;
 }


avatar image antoinegloum Apr 04 '17 at 08:36 AM
 /**
  * Calculate Homogeneous transform.
  *
  * @param VecP      VectorRegister 
  * @param MatrixM   FMatrix pointer to the Matrix to apply transform
  * @return VectorRegister = VecP*MatrixM
  */
 FORCEINLINE VectorRegister VectorTransformVector(const VectorRegister&  VecP,  const void* MatrixM )
 {
   const VectorRegister *M = (const VectorRegister *) MatrixM;
   VectorRegister VTempX, VTempY, VTempZ, VTempW;
 
   // Splat x,y,z and w
   VTempX = VectorReplicate(VecP, 0);
   VTempY = VectorReplicate(VecP, 1);
   VTempZ = VectorReplicate(VecP, 2);
   VTempW = VectorReplicate(VecP, 3);
   // Mul by the matrix
   VTempX = VectorMultiply(VTempX, M[0]);
   VTempY = VectorMultiply(VTempY, M[1]);
   VTempZ = VectorMultiply(VTempZ, M[2]);
   VTempW = VectorMultiply(VTempW, M[3]);
   // Add them all together
   VTempX = VectorAdd(VTempX, VTempY);
   VTempZ = VectorAdd(VTempZ, VTempW);
   VTempX = VectorAdd(VTempX, VTempZ);
 
   return VTempX;
 }
 
avatar image Motanum Apr 04 '17 at 02:08 PM

The math's behind rotators are quaternions IIRC. https://en.wikipedia.org/wiki/Quaternion.

(comments are locked)
10|2000 characters needed characters left

4 answers: sort voted first

Hi,

I think you want Find Look At Rotator. It finds the rotation of going from Point A, to Point B.

Then there is also Make Rotator from Axis, which takes 3 vectors and gets one rotator.

alt text

more ▼

answered Apr 03 '17 at 02:56 PM

avatar image

Motanum
620 55 61 304

avatar image antoinegloum Apr 03 '17 at 03:52 PM

I tried these, and while they might be useful for what I need, they aren't enough.

(comments are locked)
10|2000 characters needed characters left

Hi, You may want this: FRotator::UnRotateVector

more ▼

answered Sep 30 '18 at 01:48 PM

avatar image

Mahmood215
5 1 4

(comments are locked)
10|2000 characters needed characters left

Hi, You may want this: FRotator::UnRotateVector

more ▼

answered Sep 30 '18 at 01:48 PM

avatar image

Mahmood215
5 1 4

(comments are locked)
10|2000 characters needed characters left
 FRotator VecRotDiff(const FVector& A, const FVector& Target)
 {
     // GetNormalized is optional. It gets the "shortest rotation path" (e.g. not turning 270° but -90° instead)
     return (Target.Rotation() - A.Rotation()).GetNormalized(); 
 }


Is this what you looking for?

more ▼

answered Sep 30 '18 at 03:22 PM

avatar image

birdfreeyahoo
860 46 43 79

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question