Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Move one Vertex to another in D3D

This topic is 5204 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 board, im having a problem with a calculation - dunno why but my brain is completly out of order at this point :O There are two vectors in d3d space, lets say: Vector a = (100,200,1000)(x,y,z) Vector b = (-300,-200,0)(x,y,z) vector a should move to vector b in a smooth and direct way, like a ray, how do i calculate that ? thanks in advance Head [edited by - H34D on May 19, 2004 4:43:28 AM]

Share this post

Link to post
Share on other sites
two ways. exponential way (moves rapidely first, and settles down to b's position)

decay = 0.25f;
Vector Diff = (b - a);
a += Diff * decay;

not frame rate independent (the faster the framerate, the faster a will reach b).

or a linear movement, frame rate independent

float speed = 1.0f; // 1 unit a second movement
Vector Diff = (b - a);
a += Diff * (speed * time_step);

for the second one, you can't guarantee that a will reach b exactly (basically, get very close), depending on the frame rate, A might shuffle around B for a while on low frame rates. So, you need to cap the maximum amount A can move towards B, by the vertex radius. This depends on the frame rate.

Don;t know if this would work, but it would be something along those lines.

float vertex_radius = 0.1f; // vertices have a 0.01 unit in radius.

//when A reaches that radius, A and

// B are considered at the same position

// and A is snapped straight onto B

float max_speed = 1.0f; // max particle speed, one unit a second

float max_dt = (vertex_radius / max_speed) * 0.99f; // make sure the vertex won't move more

// than the radius of a vertex in one frame

Vector Dir = (B - A);
float distance = Diff.Magnitude();

if (distance <= vertex_radius)
A = B;

Dir /= distance;
if (dt > max_dt) dt = max_dt;
float speed = distance / dt;
if (speed > max_speed) speed = max_speed;
A += Dir * speed * dt;

[edited by - oliii on May 19, 2004 6:40:40 AM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
eeek thanks so much

the result is now a "3 line solution"

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!