Created
August 2, 2012 15:24
-
-
Save rikwatson/8af5b6b0a760a747df0e to your computer and use it in GitHub Desktop.
Some Catmull-Rom code scraped from the web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void PointOnCurve(TrackPoint &out, float t, TrackPoint p0, TrackPoint p1, TrackPoint p2, TrackPoint p3) | |
{ | |
float t2 = t * t; | |
float t3 = t2 * t; | |
float tension = 0.5f; | |
out.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 ); | |
out.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 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment