# intervals "taking the long path"?

How can you make a hpr interval “take the short path” for angles?
Right now if it gets 359 as start and 1 as end, it goes like this:

``359->349->339->...->1``

How would be the simplest way to make it go like this with intervals:

``359->0->1``

PS. I have huge code chunk that depends on intervals, so switching to tasks is most undesirable.

I know what you’re talking about too. I actually used a task to handle that in my first P3D project, the one I dumped because I learned more about the engine.

Tasks give more control in my opinion. For me, I seem to loose control using Intervals; or the Intervals seem to not nest well with the rest of my code.

But then again…I have one “heck” of a programming mind any way. Some of my friends wonder about my brain some time.

Isn’t there away to make your Interval run backwards or change direction (like feeding it a negative value)? …Since you wish to use Intervals only.

You don’t need to switch to tasks to use custom code, you can do that in intervals. You can just write a LerpFunctionInterval.

If you want the most control, you can write a class that inherits from LerpFunctionInterval. That way you can achieve anything in 20 or 30 lines of code or less, you keep the power and cleanness of Intervals and have your code easily reusable.

For your case, thought, you could probably subclass the LerpHprInterval and add that functionality. Or even add it directly into Panda, I’m sure others would like to use it too . The LerpIntervals are written in Python and they’re very simple pieces of code, you should have no trouble understanding them.

Another, the most provisional solution, could be to add a FunctionInterval (the Func, NOT LerpFunctionInterval) into your Sequences right before the LerpHprInterval (and, obviously, if it’s in a Parallel, wrapping the interval in a Sequence). In that FunctionInterval you can put a function that will translate your rotation from positive to negative (e.g. 355 -> -5). That way, you can easily control the rotations direction without much fuss, but obviously just adding that into the LerpHprInterval class would be more convenient for the future.

The choice is up to you, but as you can see, you have numerous options . Intervals don’t take away control, they’re a very powerful tool.

You just need to figure out the correct target angle :
[Point & Click Turning Bug!)

You could just be lazy like me and use nodepath.quatInterval:

``model.quatInterval(0.2, hpr = Point3(end_h, 0, 0), startHpr = Point3(start_h, 0, 0))``

Woah, I hadn’t noticed the last reply. LerpQuatInterval really does fix this.
I’m really interested why.

Quaternions give more degree of freedom when dealing with rotations that the Euler Angles. That means quaternions don’t get stuck in some orientations (see gimbal lock).

They also treat the rotation as one single operation, instead of a combination of three elementary sub-rotations. Therefore, a quatLerp only has to interpolate one operation, instead of doing three linear interpolations which may be sub-optimal.