Archived

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.

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 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);
Diff.Normalise();
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 Bfloat max_speed = 1.0f; // max particle speed, one unit a secondfloat max_dt = (vertex_radius / max_speed) * 0.99f; // make sure the vertex won't move more                                                     // than the radius of a vertex in one frameVector Dir = (B - A);float  distance = Diff.Magnitude();if (distance <= vertex_radius) {    A = B;    return;}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 on other sites
eeek thanks so much

the result is now a "3 line solution"

Share on other sites
hm that was me - strange forum ...

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 18
• Forum Statistics

• Total Topics
632160
• Total Posts
3004500

×