Jump to content
  • Advertisement
Sign in to follow this  


This topic is 2858 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

I have this code so far for a Catmull-Rom calculation would these be close?

template<typename T, unsigned int size>
cml::vector<T, cml::fixed<size>>& CatmullRom(const cml::vector<T, cml::fixed<size>>& vP0,
const cml::vector<T, cml::fixed<size>>& vP1,
const cml::vector<T, cml::fixed<size>>& vP2,
const cml::vector<T, cml::fixed<size>>& vP3,
cml::vector<T, cml::fixed<size>>& result,
T t)
T t2 = t * t;
T t3 = t2 * t;
result = 0.5 * ((2 * vP1) + (-vP0 + vP2) * t +
(2 * vP0 - 5 *vP1 + 4 * vP2 - vP3) * t2 +
(-vP0 + 3 * vP1 - 3 * vP2 + vP3) * t3);
return result;

NX::MATH::CatmullRom<float, 3>(cml::vector3f(1,0,1),

I get 2,0,2 for a result, if that is correct... But this seems more like a linear interpolation, but I am unsure...


Share this post

Link to post
Share on other sites
I've not checked the code but passing in 0 for 't' will give you P1 back - as it has done. Catmull-Rom interpolates between P1 and P2 where (t>=0 && t<=1) using P0 and P3 as control points. If you pass in 0.5 you will get the value halfway between P1 and P2.

In this case that will still be linearly interpolated because your points are all in a straight line!

Try something like (0,0,0), (10,0,0), (10,0,10), (0,0,10) 0.5

Sketching the points out and drawing a smooth line through then will help you visualise what should happen.

Share this post

Link to post
Share on other sites
Try something like (0,0,0), (10,0,0), (10,0,10), (0,0,10) 0.5

11.25, 0, 5 is the result

So how can 11.25 be a answer when 10 is the max range?


Share this post

Link to post
Share on other sites
10 is not the max range. A Catmull-Rom spline passes through all of the control points, and as a result usually is not fully within the convex hull of the control points. Consider -- how would it pass through p2 smoothly on its way from p1, and continue smoothly towards p3, without either an instant turn or approaching and leaving from outside the hull?

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!