Jump to content
  • Advertisement
Sign in to follow this  
Merlino

Animation Math

This topic is 4127 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

Hi, I am rather new to programming and I have a question about animation. Here's a theoric example: imagine that there are 2 variables and one evolves based on the other one, let's say that the width of a rectangle on screen evolves based on time.
So, when time is equal to a, width is equal to d, when time is equal to b, width is equal to e and so on. Imagine I know the values of a, b, c, d and f. How do I calculate e based on these values? Thanks in advance, Merlino Edit: please post only once; the Forum FAQ contains useful information about how to format your post (I mean, images are enclosed by normal <img> tags) -- .ED

Share this post


Link to post
Share on other sites
Advertisement
It really depends on the function F that maps a to d: F(a) = d, F(c) = f;

If you know F(), it'q quite easy to compute F(b) = e. If you don't know F(), it's tricky, maybe impossible.

Share this post


Link to post
Share on other sites
This depends on how it "evolves". What you're getting into here is called "interpolation", and there are several different ways to do this.



Assuming you just want to do linear interpolation (the first one), simply find the interval you're in, and weigh each point with the distance (in time) from you current point... something like:

//data
float a = 0.0f;
float b = 1.0f;
float d = 14.0f;
float e = 20.0f;

//interpolation
float cur_point = 0.5f;
float t = (cur_point-a)/(b-a); //you need to find a and b first...
float width_e = t*e + (1.0f-t)*d; //linear interpolation (lerp)


Hope this helps

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!