Announcement

Collapse
No announcement yet.

Improving RLerp

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

    Improving RLerp

    RLerp() is intended to smoothly interpolate between two rotations.

    I've always assumed RLerp used a quaternion solution, but in practice it appears to interpolate the pitch, yaw and roll components individually - fine in most cases, but breaks down with complex rotations or when you need six degrees of freedom.

    This is just an alternative to RLerp that shouldn't suffer from gimbal lock.

    Code:
    static function Rotator RLerpQuat( Rotator A, Rotator B, float Alpha, bool bShortestPath )
    {
        return QuatToRotator( QuatSlerp( QuatFromRotator( A ), QuatFromRotator( B ), Alpha, bShortestPath ) );
    }
    And this is the longhand version to better understand it:

    Code:
    static function Rotator RLerpQuat( Rotator A, Rotator B, float Alpha, bool bShortestPath )
    {
        local Quat Q, QA, QB;
    
        QA = QuatFromRotator( A ); // Quaternion for rotation A
        QB = QuatFromRotator( B ); // Quaternion for rotation B
        Q  = QuatSlerp( A, B, Alpha, bShortestPath ); // Spherical linear interpolation between A and B
        return QuatToRotator( Q ); // Convert back to rotation
    }

    #2
    Very nice. Bookmarked for future use.

    Comment


      #3
      Woohoo!


      Another Spoof tutorial!

      Thanks Spoof!



      Rama

      Update:

      I've tested your code on my critters in my game that do indeed rotate in 6 axis of freedom, and continously so, as they chase the player in full 3D world-space.

      Your algorithm definitely feels smoother and gives new life to my enemy critters.

      Thanks Spoof!

      Comment


        #4
        Hey, would you add that function to the object class, or could that be scary? :P

        Comment


          #5
          You should be able to add it to the Object class, yeah.

          Comment


            #6
            this is awesome!! thanks a ton for this Spoof!!!!

            Comment

            Working...
            X