Jump to content
  • Advertisement

Tristan85

Member
  • Content count

    24
  • Joined

  • Last visited

Community Reputation

221 Neutral

About Tristan85

  • Rank
    Member
  1. Tristan85

    Interpolate spline with constant speed

    Hi guys,   Perhaps the problem is somewhere in my current implementation. Every function in my spline class seems to work fine on it's one, except for the InterpolatePositionByDistance() function.   See below: public Vector3 InterpolatePositionByDistance(float s) { //Assertions.Assert((s >= 0.0f) && (s <= Length));    const int n = 20;  // step size    float t = 0;    float h = length / n;    for (int i = 0; i < n; ++i)    {     // The divisions here might be a problem if the divisors are     // nearly zero.     float k1 = h / InterpolateDerivative(t).magnitude;     float k2 = h / InterpolateDerivative(t + k1/2).magnitude;     float k3 = h / InterpolateDerivative(t + k2/2).magnitude;     float k4 = h / InterpolateDerivative(t + k3).magnitude;     t += (k1 + 2 * (k2 + k3) + k4) / 6;    }    Debug.Log(t); // when s == length, and #segments > 1, t > 1 (for example t == 4.12334) return InterpolatePosition(t); }     For full source code, check the Spline class in attachment.   Kind regards, Tristan
  2. Hi guys,   As hinted at by the topic title, I'm currently trying to move an object along a parameterized curve with constant speed. Following advice in several older forum posts, I'm using the numerical solution for reparameterization that's presented at page 8 of this paper.   This works great for the simplest case, in which there's only 1 segment. But when calling GetCurveParameter(curve.length) for a curve with more than 1 segment, it will return a t-value which is much larger than 1 (my chosen tmax).   The solution is most likely described at page 11 ("Handling Multiple Contiguous Curves"), but I'm having trouble understanding the how and why of this approach. For example the comment that says // We know that LSegment[i-1] <= s < LSegment.  seems wrong to me, given that earlier code seems to fill the LSegment array with the length of each segment.   If anyone here could help me understand this in any way, I would be much obliged!   Thanks in advance,   Tristan    
  3. In my current and past projects, several things have helped me to keep track of code structure: - strive for a clean design with minimal dependencies between parts (as these are hard to keep track of) - make code as "self-documenting" as possible (i.e. use descriptive variable, class and function names) - make UML class and/or activity diagrams depicting the public interfaces of high-level components - when working in a team, make sure a single team member is responsible for each piece of code (so you can quickly ask a person to refresh your memory) - use comments wisely (in my opinion, never to explain syntax...always to explain semantics) Something I don't do quite often enough, but which might help as well: - create unit and/or integration tests that demonstrate typical use cases for a (collection of) class(es). I hope this might help a bit, and would be interested to read some additional insights.
  4. Tristan85

    need help on a simple math equation.

    Thank you all for these elaborate and insightful replies. (Whether they were written down whilst being intoxicated or not.)
  5. Tristan85

    need help on a simple math equation.

    @Brother Bob Fascinating! I'd be quite interested to learn how you've managed to derive the formula from the OP's data. Could you perhaps elaborate a little?
  • 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!