Game Development Reference
In-Depth Information
side of t are used in the calculation, as are their two neighbors, as shown in
Figure 10.16.
Once some position can be obtained for a value of t (0-1) between any two
neighboring points, then this can be extended so that t (0-1) can be mapped on
to the entire line, not just one section. The calculation to get a position from t
and four points is as follows.
2
3
2
3
13
3
1
P 0
P 1
P 2
P 3
4
5
4
5
1
1010
0200
2
5
4
5 ½
t 3
t 2
f
ð
t
Þ¼
0
:
t
1
This looks a little intimidating; three matrices are multiplied by a scalar that
weighs all four points and decides how the t value is transformed into a position.
It's not important to understand exactly how this works (though you are
encouraged to investigate!); it's good enough to know what results will occur
when you apply it.
Here is the C# implementation of a Catmull-Rom spline. This class should be
added to the Engine project as it will be useful for more than this project. The
spline code works in 3D so it can also be useful for tasks such as manipulating
cameras or moving 3D entities along a path. The interface for this spline class
Figure 10.16
Catmull-Rom splines.
 
Search WWH ::




Custom Search