# quaternion damping

This topic is 3906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I have a formula that allows me to damp any scalar with a damping factor, on a frame-independent basis : I always a current value and an ideal value. The ideal value evolves randomly along time (it can be a character position, for example, so it's unpredictable) and the current value always tries to reach the ideal value. I'm currently trying to do the same kind of damping on quaternions but the scalar algebraic is not appliable on them. I could treat the quaternion as vector4 (thus using the same formula) and then renormalize the resulting quaternion but I guess it wouldn't take the shortest path between the current quaternion and the ideal quaternion. In other words, it would appear to work on 2 quaternions with small numerical differences (assuming that each of the 4 members evolves continuously over the quaternion sphere... is it a good assumption ?), but it's not the proper mathematical way to do it, I'm sure. I hope I've been clear enough and that some cartesian mind here can help my limited knowledge of quaternions :) Thanks Jo

##### Share on other sites
Did you try using Slerp?

##### Share on other sites
Slerp requires a t factor, which I don't have, as my damping is not a function of time, it's a continuous damping : the ideal quaternion always changes.

##### Share on other sites
Quote:
 Original post by jojobainusSlerp requires a t factor, which I don't have, as my damping is not a function of time, it's a continuous damping : the ideal quaternion always changes.
Can you post your damping function, and perhaps show how you're using it?

##### Share on other sites
t != time. t == interpolation amount. Rename it α if you like.

##### Share on other sites
Quote:
 Can you post your damping function, and perhaps show how you're using it?

Oh my... I knew this moment would come :)... The damping function I'm using is absolutely not standard, I've taken it from some old code somewhere, and to be honest I still don't understand how it works. It uses the difference between the current and ideal scalar, the velocity (kind of...), a damping factor, and some fudge factors. The good thing is that it works really well !

Here it is (the update function, the idealValue is passed in parameter):

- DataType is the scalar type on which the damping occurs.
- m_DampedValue is of type DataType and is the current value
- m_IdealValue is of type DataType and is the ideal value we want to reach
- m_SpringDampingVelocity is of type DataType and is calculated in the code below
- deltaTime is the time passed since last computation

this->m_IdealValue = idealValuePassedInParameter;DataType displacement = this->m_DampedValue - this->m_IdealValue;ubiFloat x = spring * deltaTime;ubiFloat exponent = 1.0f / (1.0f + x + 0.48f*x*x + 0.235f*x*x*x);DataType temp = (m_SpringDampingVelocity + (displacement * spring)) * deltaTime;m_SpringDampingVelocity = (m_SpringDampingVelocity - temp * spring) * exponent;m_DampedValue = m_IdealValue + ((displacement + temp) * exponent);

By the way, if you know where this formula comes from, I would be interested also.
Thank you !

Jo

##### Share on other sites
Quote:
 t != time. t == interpolation amount. Rename it α if you like.

Sure, but I still don't have any way to know what amount of interpolation I want between my current and ideal value (the formula with scalars makes makes the damping slower and slower as we approach the ideal value, but there's no way to predict when it's gonna reach the ideal value).

##### Share on other sites
Quote:
 Original post by jojobainus...as my damping is not a function of time....

Quote:
 Original post by jojobainusubiFloat x = spring * deltaTime;

Looks like a function of time to me.

##### Share on other sites
Quote:
 Original post by jojobainusBy the way, if you know where this formula comes from, I would be interested also.

It comes from Game Programming Gems 4 Chapter 1.10

##### Share on other sites
Quote:
 Looks like a function of time to me.

Sorry, I explained badly. English is not my natural language so I tend to do smaller sentences ;)
What I meant is that I can't say : ok here's my starting value, here's my ideal value, and go reach this ideal value in x seconds. If my ideal quaternion didn't change, that would work, but here, the ideal quaternion always changes and the damped quaternion always tries to reach this ideal value, more or less quickly depending on the difference between the 2 orientations (the farthest they are, the quickest...)

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 43
• ### Forum Statistics

• Total Topics
632635
• Total Posts
3007560
• ### Who's Online (See full list)

There are no registered users currently online

×