Jump to content
• Advertisement

# quaternion damping

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

If you intended to correct an error in the post then please contact us.

## 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 this post

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

#### Share this post

##### 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 this post

##### 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 this post

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

#### Share this post

##### 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 this post

##### 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 this post

##### 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 this post

##### 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 this post

##### 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...)

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14
• Advertisement

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013636
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!