문제

I want to create an animation system in c++ in wich I store keyframes, that have a time and a value. Those values shall be interpolated during playback, so i need them sortet by their time variable. Because when interpolating, i allways want to interpolate only between last and next keyframe (how it's usually done).

How would I store the keyframes, so I can easily (and fast) access the keyframe before and after a specific time?

At first std::map came to my mind, but there I have problems with the correct order of the keyframes... Any ideas how to do this better?

도움이 되었습니까?

해결책

You can use std::vector and keep the correct order of the keyframes. Assuming that the keyframes are sorted by time in the vector you can then extract the relevant keyframe with std::lower_bound or std::binary_search in logarithmic time.

std::map internally keeps the elements sorted by the key following a strict weak ordering criterion. So, if you use time as the key, you will keep the correct order of the keyframes.

Personally, I would use std::vector.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top