Jump to content
  • Advertisement
Sign in to follow this  
Sevans

Train - Uniform Motion on Curve Track

This topic is 4273 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 trying to implement a train track using a Cardinal cubic spline in 3D. I would like a train, for now just a block :), to travel at a uniform speed down the track and around curves. How can this be done? I have been told arc length parameterization but I have not yet been able to find an algorithm that actually tells me how to do this in 3D and have thus botched everyone I have tried to adapt. Can anyone explain how to do this to me? an example would be best! Thanks much, -sevans

Share this post


Link to post
Share on other sites
Advertisement
I do not read the OpenGL forum here. In your post you mention using Simpson's rule for integration of a function f(x) on the interval [a,b]. If f(x) is a positive function, Simpson's rule gives you an approximation for the area under the graph of f(x) and between the lines x = a and x = b. The problem in your code is that you apply the rule only to the _entire_ interval. This is not accurate enough for the purpose of computing arc length.

In general, numerical integration involves selecting a "partition" of [a,b], which is a set of n+1 points x = a + i*h, where h = (b-a)/n and 0 <= i <= n. You apply Simpson's rule to each _subinterval_ [x,x[i+1]]. The practical problem is how to choose n. You want it to be large enough to give you enough accuracy in the approximation but you want it small enough to keep the computation time to a minimum. But in your application, you certainly want n to be larger than 1!

Share this post


Link to post
Share on other sites
I don't know anything about splines and curves.
So the approach I'd probably take is...

1 move the box forward based on prior velocity
2 measure the vector length from past to new location (speed approx)
3 project the position onto the path(some kinda nearest point function?)
4 take the vector from prior to new location and rescale it to match the above length/speed
5 repeat steps 3-4 a few more times, till the box is 'close enough' in terms of both distance from path and change from past position(speed)

uhh... that should end up making the train more or less follow a near constant speed... based on segmented approximation of the path to decide speed...
If your update time increment is small, who's going to notice?

Share this post


Link to post
Share on other sites
Generally, you need to recursively split the spline into small segments and get the (approximate) length of each segment. You can do this once and store the information in the spline's data structure if memory is cheap and CPU time isn't.

Alternatively, for relatively short frame times and if this type of spline is parametric: calculate the size of ds/dt (t being the parametric parameter) at the current point of the train and assume that remains constant over the current frame, then move the train in t-space. This only works for low curvature tracks, but it's a train track so that might be a fair assumption.

Share this post


Link to post
Share on other sites
I would just like to note, even though this may be a matter of aesthetics, that an otherwise unrestricted object traveling along a straight path will speed up if its path is constrained to a curve.

Therefore, if you're seeking realism, you may not have a problem. If it's just a matter of taste, then you can use the first derivative of the spline to calculate how far you should be moving during your integration time.

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.

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!