Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a velocity vector where my client is at and where its going, and I have the same vector that comes from the server telling where the client should be. Sometimes its a bit different, so I want to interpolate between my current position to the server correct position.

enter image description here

The black arrow is the client velocity vector, the red arrow is the client velocity vector on the server and the blue arrow is the one that I want to calculate and interpolate to.

How do I calculate the blue vector? Then, how can I linear interpolate between them?

share|improve this question

2 Answers 2

up vote 12 down vote accepted

Blue vector can be calculated easily: red - black (the sign between vectors is minus). But if you want just to interpolate between black and red vector, you don't have to calculate it. Linear interpolation is just linear combination. So you can just take: alpha * black + (1 - alpha) * red, where alpha has to be from interval <0,1>. If alpha will be 1, then you will get black vector, when alpha is 0, you will get red vector.

And if I understood it right, you will interpolate between these vectors in time. So just choose right increment of alpha in time.

Did I understand you right? Or did you meant something completelly diffent?

share|improve this answer
    
Yes, you got me right. Just one more question, how do i multiply the number for the vector? Will that operation return me a new vector? For instance, red is a vector (0, 10) with length of 8 and black is (-2, 5) with length of 4. How do i do alpha * black or (1 - alpha) * red? Thank you. –  Gilson Oct 17 '11 at 13:42
    
You just multiply each vector coordinate separately. If alpha is for example 0.5, then alpha * black + (1 - alpha) * red = (0,5) + (-1, 2.5) = (-1, 7.5) - if you will draw this to some paper, you will see it's really exactly between those two vectors. –  zacharmarz Oct 17 '11 at 13:55
    
Thank you for you help. Appreciated. –  Gilson Oct 18 '11 at 11:36

Taking this picture:

enter image description here

AB is the red vector from A to B.

Say P is 25% of the way from A to B. The basic way to get to P from the origin is

A + ( B - A ) / 4
= 3/4 A   +   B / 4

So 3/4 A and 1/4 B.

Another way to find that is saying you want a vector 75% "close" to A, and 25% "close" to B. (A vector that is 100% "close" to A is just the A vector.)

So you would also be able to find P as:

A*t + (1-t)*B

With t=0.75 (to say 75% "close" to A)

0.75A + 0.25B

So a simple LERP function in C for a Vector3f class would be:

static Vector3f lerp( const Vector3f& A, const Vector3f& B, float t ){
  return A*t + B*(1.f-t) ;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.