Skip to main content
GameDev.net gamedev.net
🔒 Locked

CatMullRom

Started by jviruss Oct 22, 2008 at 5:06 AM 2 replies 1k views
Original Post
jviruss
jviruss
Hello I´m have a Callmuth Rom equation,but it dont work well. My Equation is: float t2 = t * t; float t3 = t2 * t; output.x = 0.5f * ( ( 2.0f * p1.x ) + ( -p0.x + p2.x ) * t + ( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 + ( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 ); output.y = 0.5f * ( ( 2.0f * p1.y ) + ( -p0.y + p2.y ) * t + ( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 + ( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 ); output.z = 0.5f * ( ( 2.0f * p1.z ) + ( -p0.z + p2.z ) * t + ( 2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z ) * t2 + ( -p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z ) * t3 ); The curve isnt smooth between two interpolations.My up axis is z,my right axis is x and my front axis is y. Somebody know if the equation change dependent of axis system? if it change,somebody know the solution for my axis system?
Cygon
Cygon
If you take a closer look at those calculations, you'll find that they do the exact same thing for each axis, so they cannot depend on what you define each axis as.

I can't spot any errors, so maybe the problem is in your usage of the function, but just for reference, here's one that provided me with good results:

double interpolateCatmulRom(  double a, double b, double c, double d, double t)  double t2 = t * t;  double t3 = t2 * t;  t2 = t * t  t3 = t2 * t  // Tangents at b and c  tb = 0.5 * (b - a) + 0.5 * (c - b)  tc = 0.5 * (c - b) + 0.5 * (d - c)      return    b * (2 * t3 - 3 * t2 + 1) +    c * (3 * t2 - 2 * t3) +    tb * (t3 - 2 * t2 + t) +    tc * (t3 - t2);}

Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
jviruss
jviruss
This is for float values,Somebody know to vector interpolation?
swiftcoder
swiftcoder
Quote:
Original post by jviruss
This is for float values,Somebody know to vector interpolation?
Run it for each component of the vector - i.e. once for x, once for y and once for z.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.