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"

Pitch Rotation stucks at [-90 90] C++

I searched all relative questions on this topic and i couldn't find something useful. I use 4.15 and the pitch rotation bug is still there. My problem is not Gimbal Lock . My Actor just stops pitch rotating at (-)90 degrees. I tried SetActorLocation, LocalRotation,SetWorldRotation,SetActorRelativeLocation and every time i get the same result. I even tried quaternions.

Pitch code:

 void ATest::Pitch(float Val) {
 
     SphereMovement.Pitch = FMath::Clamp(Val, -1.0f, 1.0f);
     if (Val != 0) {
         UE_LOG(LogTemp, Warning, TEXT("Pitch = %f"), GetActorRotation().Pitch);
     }
 }

Tick:

  void ATest::Tick( float DeltaTime )
 {
     Super::Tick( DeltaTime );
 
     if (!SphereMovement.IsZero()) {
         FRotator newRotation = GetActorRotation() + (SphereMovement);
         SetActorRotation(newRotation);
     }
 }
Product Version: UE 4.15
Tags:
more ▼

asked Apr 22 '17 at 05:56 PM in C++ Programming

avatar image

nutellis
16 1 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

The solution to my problem was:

 void ATest::Tick( float DeltaTime )
 {
     Super::Tick( DeltaTime );
 
     if (!SphereMovement.IsZero()) {
         FRotator newRotation = SphereMovement ;
 
         FQuat quatRotation = FQuat(newRotation);
 
         AddActorLocalRotation(quatRotation,false,0,ETeleportType::None);
     }
 
 }

Had to remove GetActorRotation and change SetActorRotation to AddActorLocalRotation

The quaternion part is not necessary .

more ▼

answered Apr 29 '17 at 03:58 PM

avatar image

nutellis
16 1 4 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I looked a bit in the source code and saw, that the rotator is eventually turned into a quaternion. So when you call GetActorRotation, this quaternion is transformed back into a rotator, but because of mathematical reason I don't understand, the pitch angle is clamped between -90 and 90 degree.

(Yaw and roll seem to be calculated with an atan2, which ranges from -180 to 180 degree, and pitch seem to be calculated with an asin, which results in a range from -90 to 90 degree. But again, I have no understanding about the mathematical reasons why to use asin and atan2.)

In the source code I could find references to this quaternion-to-rotator-transformation, perhaps they are helpful for you. And the function is question is FRotator FQuat::Rotator() in case you want to look it up.

http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/

more ▼

answered Apr 23 '17 at 07:46 AM

avatar image

Benergy
831 21 4 29

avatar image nutellis Apr 24 '17 at 05:12 PM

The problem is happening on the "poles", ill try to add the branch code for the poles and see what will happen.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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